Implemented Feature editing UI

This commit is contained in:
Thaum
2015-01-21 11:16:00 +00:00
parent 078f873219
commit 84512beb72
32 changed files with 1072 additions and 161 deletions

View File

@@ -8,20 +8,34 @@ Meteor.methods({
selector,
{ $set: setter }
)
},
updateFeatureEffect: function (featureId, newEffect) {
var selector = {_id: featureId};
selector["effects._id"] = newEffect._id;
var setter = {};
setter["effects.$"] = newEffect
Features.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 });
}
if(effect.stat){
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});
if(effect.stat){
var pushObject = {};
pushObject[effect.stat + ".effects"] = effect;
Characters.update(id, {$push: pushObject});
}
}

View File

@@ -1,32 +1,6 @@
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){
if(newFeature.name) effect.name = newFeature.name;
pushEffect(charId, effect);
});
_.each(newFeature.actions, function(action){
@@ -47,10 +21,10 @@ removeFeatureEffects = function(charId, oldFeature){
_.each(oldFeature.actions, function(action){
pullAction(charId, action);
});
_.each(newFeature.attacks, function(attack){
pushAttack(charId, attack);
_.each(oldFeature.attacks, function(attack){
pullAttack(charId, attack);
});
_.each(newFeature.spells, function(spell){
pushSpell(charId, spell);
_.each(oldFeature.spells, function(spell){
pullSpell(charId, spell);
});
};