mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-05-25 23:25:51 +00:00
perf(ultimateGear): move ultimateGear from ops to fns so it only runs once
This commit is contained in:
parent
2283093845
commit
a501d5c3ba
2 changed files with 60 additions and 69 deletions
66
dist/habitrpg-shared.js
vendored
66
dist/habitrpg-shared.js
vendored
|
|
@ -11884,11 +11884,7 @@ var process=require("__browserify_process");(function() {
|
|||
message = "Bought " + item.text + ".";
|
||||
}
|
||||
if (!user.achievements.ultimateGear && item.last) {
|
||||
user.ops.ultimateGear({
|
||||
params: {},
|
||||
query: {},
|
||||
body: {}
|
||||
});
|
||||
user.fns.ultimateGear();
|
||||
}
|
||||
}
|
||||
user.stats.gp -= item.value;
|
||||
|
|
@ -12241,38 +12237,6 @@ var process=require("__browserify_process");(function() {
|
|||
cb(null, user);
|
||||
}
|
||||
return delta;
|
||||
},
|
||||
ultimateGear: function(req, cb) {
|
||||
var gear, lastGearClassTypeMatrix, ownedLastGear, shouldGrant;
|
||||
|
||||
gear = typeof window !== "undefined" && window !== null ? user.items.gear.owned : user.items.gear.owned.toObject();
|
||||
ownedLastGear = _.chain(content.gear.flat).pick(_.keys(gear)).values().filter(function(gear) {
|
||||
return gear.last;
|
||||
});
|
||||
lastGearClassTypeMatrix = {};
|
||||
_.each(content.classes, function(klass) {
|
||||
lastGearClassTypeMatrix[klass] = {};
|
||||
return _.each(content.gearTypes, function(type) {
|
||||
lastGearClassTypeMatrix[klass][type] = false;
|
||||
return true;
|
||||
});
|
||||
});
|
||||
ownedLastGear.each(function(gear) {
|
||||
if (gear.twoHanded) {
|
||||
lastGearClassTypeMatrix[gear.klass]["shield"] = true;
|
||||
}
|
||||
return lastGearClassTypeMatrix[gear.klass][gear.type] = true;
|
||||
});
|
||||
shouldGrant = _(lastGearClassTypeMatrix).values().reduce((function(ans, klass) {
|
||||
return ans || _(klass).values().reduce((function(ans, gearType) {
|
||||
return ans && gearType;
|
||||
}), true);
|
||||
}), false).valueOf();
|
||||
user.achievements.ultimateGear = shouldGrant;
|
||||
if (typeof cb === "function") {
|
||||
cb(null, user);
|
||||
}
|
||||
return shouldGrant;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -12731,6 +12695,34 @@ var process=require("__browserify_process");(function() {
|
|||
if (user.history.todos.length > minHistLen) {
|
||||
return user.history.todos = preenHistory(user.history.todos);
|
||||
}
|
||||
},
|
||||
ultimateGear: function() {
|
||||
var gear, lastGearClassTypeMatrix, ownedLastGear, shouldGrant;
|
||||
|
||||
gear = typeof window !== "undefined" && window !== null ? user.items.gear.owned : user.items.gear.owned.toObject();
|
||||
ownedLastGear = _.chain(content.gear.flat).pick(_.keys(gear)).values().filter(function(gear) {
|
||||
return gear.last;
|
||||
});
|
||||
lastGearClassTypeMatrix = {};
|
||||
_.each(content.classes, function(klass) {
|
||||
lastGearClassTypeMatrix[klass] = {};
|
||||
return _.each(content.gearTypes, function(type) {
|
||||
lastGearClassTypeMatrix[klass][type] = false;
|
||||
return true;
|
||||
});
|
||||
});
|
||||
ownedLastGear.each(function(gear) {
|
||||
if (gear.twoHanded) {
|
||||
lastGearClassTypeMatrix[gear.klass]["shield"] = true;
|
||||
}
|
||||
return lastGearClassTypeMatrix[gear.klass][gear.type] = true;
|
||||
});
|
||||
shouldGrant = _(lastGearClassTypeMatrix).values().reduce((function(ans, klass) {
|
||||
return ans || _(klass).values().reduce((function(ans, gearType) {
|
||||
return ans && gearType;
|
||||
}), true);
|
||||
}), false).valueOf();
|
||||
return user.achievements.ultimateGear = shouldGrant;
|
||||
}
|
||||
};
|
||||
Object.defineProperty(user, '_statsComputed', {
|
||||
|
|
|
|||
|
|
@ -601,7 +601,7 @@ api.wrap = (user, main=true) ->
|
|||
message = user.fns.handleTwoHanded(item)
|
||||
message ?= "Bought #{item.text}."
|
||||
if not user.achievements.ultimateGear and item.last
|
||||
user.ops.ultimateGear({params:{}, query:{}, body:{}})
|
||||
user.fns.ultimateGear()
|
||||
user.stats.gp -= item.value
|
||||
cb? {code:200, message}, _.pick(user,$w 'items achievements stats')
|
||||
|
||||
|
|
@ -877,37 +877,6 @@ api.wrap = (user, main=true) ->
|
|||
cb? null, user
|
||||
return delta
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Achievements
|
||||
# ----------------------------------------------------------------------
|
||||
ultimateGear: (req, cb) ->
|
||||
# on the server this is a LoDash transform, on the client its an object
|
||||
gear = if window? then user.items.gear.owned else user.items.gear.owned.toObject()
|
||||
ownedLastGear = _.chain(content.gear.flat)
|
||||
.pick(_.keys gear)
|
||||
.values()
|
||||
.filter (gear) -> gear.last
|
||||
|
||||
lastGearClassTypeMatrix = {}
|
||||
_.each content.classes, (klass) ->
|
||||
lastGearClassTypeMatrix[klass] = {}
|
||||
_.each content.gearTypes, (type) ->
|
||||
lastGearClassTypeMatrix[klass][type] = false
|
||||
return true # false exits the each loop early
|
||||
|
||||
ownedLastGear.each (gear) ->
|
||||
lastGearClassTypeMatrix[gear.klass]["shield"] = true if gear.twoHanded
|
||||
lastGearClassTypeMatrix[gear.klass][gear.type] = true
|
||||
|
||||
shouldGrant = _(lastGearClassTypeMatrix)
|
||||
.values()
|
||||
.reduce(((ans, klass) -> ans or _(klass).values().reduce(((ans, gearType) -> ans and gearType), true)), false)
|
||||
.valueOf()
|
||||
|
||||
user.achievements.ultimateGear = shouldGrant
|
||||
cb? null, user
|
||||
shouldGrant
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# user.fns helpers
|
||||
# ----------------------------------------------------------------------
|
||||
|
|
@ -1261,6 +1230,36 @@ api.wrap = (user, main=true) ->
|
|||
#user.markModified? 'habits'
|
||||
#user.markModified? 'dailys'
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Achievements
|
||||
# ----------------------------------------------------------------------
|
||||
ultimateGear: () ->
|
||||
# on the server this is a LoDash transform, on the client its an object
|
||||
gear = if window? then user.items.gear.owned else user.items.gear.owned.toObject()
|
||||
ownedLastGear = _.chain(content.gear.flat)
|
||||
.pick(_.keys gear)
|
||||
.values()
|
||||
.filter (gear) -> gear.last
|
||||
|
||||
lastGearClassTypeMatrix = {}
|
||||
_.each content.classes, (klass) ->
|
||||
lastGearClassTypeMatrix[klass] = {}
|
||||
_.each content.gearTypes, (type) ->
|
||||
lastGearClassTypeMatrix[klass][type] = false
|
||||
return true # false exits the each loop early
|
||||
|
||||
ownedLastGear.each (gear) ->
|
||||
lastGearClassTypeMatrix[gear.klass]["shield"] = true if gear.twoHanded
|
||||
lastGearClassTypeMatrix[gear.klass][gear.type] = true
|
||||
|
||||
shouldGrant = _(lastGearClassTypeMatrix)
|
||||
.values()
|
||||
.reduce(((ans, klass) -> ans or _(klass).values().reduce(((ans, gearType) -> ans and gearType), true)), false)
|
||||
.valueOf()
|
||||
|
||||
user.achievements.ultimateGear = shouldGrant
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Virtual Attributes
|
||||
# ----------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Reference in a new issue