Implemented Features and Items granting effects, actions, attacks and spells
This commit is contained in:
22
rpg-docs/lib/methods/actionUtils.js
Normal file
22
rpg-docs/lib/methods/actionUtils.js
Normal file
@@ -0,0 +1,22 @@
|
||||
Meteor.methods({
|
||||
updateAction: function (charId, oldAction, newAction) {
|
||||
var selector = {_id: charId, "actions._id": oldAction._id};
|
||||
var setter = {"actions.$": newAction};
|
||||
Characters.update(
|
||||
selector,
|
||||
{ $set: setter }
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
pullAction = function(id, action){
|
||||
var pullObject = {};
|
||||
pullObject["actions"] = {_id: action._id};
|
||||
Characters.update(id, {$pull: pullObject });
|
||||
};
|
||||
|
||||
pushAction = function(id, action){
|
||||
var pushObject = {};
|
||||
pushObject["actions"] = action;
|
||||
Characters.update(id, {$push: pushObject});
|
||||
};
|
||||
22
rpg-docs/lib/methods/attackUtils.js
Normal file
22
rpg-docs/lib/methods/attackUtils.js
Normal file
@@ -0,0 +1,22 @@
|
||||
Meteor.methods({
|
||||
updateAttack: function (charId, oldAttack, newAttack) {
|
||||
var selector = {_id: charId, "attacks._id": oldAttack._id};
|
||||
var setter = {"attacks.$": newAttack};
|
||||
Characters.update(
|
||||
selector,
|
||||
{ $set: setter }
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
pullAttack = function(id, attack){
|
||||
var pullObject = {};
|
||||
pullObject["attacks"] = {_id: attack._id};
|
||||
Characters.update(id, {$pull: pullObject });
|
||||
};
|
||||
|
||||
pushAttack = function(id, attack){
|
||||
var pushObject = {};
|
||||
pushObject["attacks"] = attack;
|
||||
Characters.update(id, {$push: pushObject});
|
||||
};
|
||||
27
rpg-docs/lib/methods/effectUtils.js
Normal file
27
rpg-docs/lib/methods/effectUtils.js
Normal file
@@ -0,0 +1,27 @@
|
||||
Meteor.methods({
|
||||
updateEffect: function (charId, attributeName, effectId, newEffect) {
|
||||
var selector = {_id: charId};
|
||||
selector[attributeName + ".effects._id"] = effectId;
|
||||
var setter = {};
|
||||
setter[attributeName + ".effects.$"] = newEffect
|
||||
Characters.update(
|
||||
selector,
|
||||
{ $set: setter }
|
||||
)
|
||||
}
|
||||
});
|
||||
|
||||
//pull a single effect by stat and id
|
||||
pullEffect = function(id, effect){
|
||||
var pullObject = {};
|
||||
pullObject[effect.stat + ".effects"] = {_id: effect._id};
|
||||
Characters.update(id, {$pull: pullObject });
|
||||
}
|
||||
|
||||
pushEffect = function(id, effect){
|
||||
var pushObject = {};
|
||||
pushObject[effect.stat + ".effects"] = effect;
|
||||
Characters.update(id, {$push: pushObject});
|
||||
}
|
||||
|
||||
|
||||
56
rpg-docs/lib/methods/featureUtils.js
Normal file
56
rpg-docs/lib/methods/featureUtils.js
Normal file
@@ -0,0 +1,56 @@
|
||||
Meteor.methods({
|
||||
addFeature: function(charId, newFeature){
|
||||
Characters.update(
|
||||
charId,
|
||||
{ $push: {"customFeatures": newFeature} }
|
||||
);
|
||||
addFeatureEffects(charId, newFeature);
|
||||
},
|
||||
removeFeature: function(charId, oldFeature){
|
||||
Characters.update(
|
||||
charId,
|
||||
{ $pull: { "customFeatures": {"_id": oldFeature._id} } }
|
||||
);
|
||||
removeFeatureEffects(charId, oldFeature);
|
||||
},
|
||||
updateFeature: function (charId, oldFeature, newFeature) {
|
||||
var selector = {_id: charId, "customFeatures._id": oldFeature._id};
|
||||
var setter = {"customFeatures.$": newFeature};
|
||||
Characters.update(
|
||||
selector,
|
||||
{ $set: setter }
|
||||
);
|
||||
removeFeatureEffects(charId, oldFeature);
|
||||
addFeatureEffects(charId, newFeature);
|
||||
}
|
||||
});
|
||||
|
||||
addFeatureEffects = function(charId, newFeature){
|
||||
_.each(newFeature.effects, function(effect){
|
||||
pushEffect(charId, effect);
|
||||
});
|
||||
_.each(newFeature.actions, function(action){
|
||||
pushAction(charId, action);
|
||||
});
|
||||
_.each(newFeature.attacks, function(attack){
|
||||
pushAttack(charId, attack);
|
||||
});
|
||||
_.each(newFeature.spells, function(spell){
|
||||
pushSpell(charId, spell);
|
||||
});
|
||||
}
|
||||
|
||||
removeFeatureEffects = function(charId, oldFeature){
|
||||
_.each(oldFeature.effects, function(effect){
|
||||
pullEffect(charId, effect);
|
||||
});
|
||||
_.each(oldFeature.actions, function(action){
|
||||
pullAction(charId, action);
|
||||
});
|
||||
_.each(newFeature.attacks, function(attack){
|
||||
pushAttack(charId, attack);
|
||||
});
|
||||
_.each(newFeature.spells, function(spell){
|
||||
pushSpell(charId, spell);
|
||||
});
|
||||
};
|
||||
22
rpg-docs/lib/methods/spellUtils.js
Normal file
22
rpg-docs/lib/methods/spellUtils.js
Normal file
@@ -0,0 +1,22 @@
|
||||
Meteor.methods({
|
||||
updateSpell: function (charId, oldSpell, newSpell) {
|
||||
var selector = {_id: charId, "spells._id": oldSpell._id};
|
||||
var setter = {"spells.$": newSpell};
|
||||
Characters.update(
|
||||
selector,
|
||||
{ $set: setter }
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
pullSpell = function(id, spell){
|
||||
var pullObject = {};
|
||||
pullObject["spells"] = {_id: spell._id};
|
||||
Characters.update(id, {$pull: pullObject });
|
||||
};
|
||||
|
||||
pushSpell = function(id, spell){
|
||||
var pushObject = {};
|
||||
pushObject["spells"] = spell;
|
||||
Characters.update(id, {$push: pushObject});
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
Meteor.methods({
|
||||
updateEffect: function (charId, attributeName, effectId, newEffect) {
|
||||
var selector = {_id: charId};
|
||||
selector[attributeName + ".effects._id"] = effectId;
|
||||
var setter = {};
|
||||
setter[attributeName + ".effects.$"] = newEffect
|
||||
Characters.update(
|
||||
selector,
|
||||
{ $set: setter }
|
||||
)
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user