Refactored code which applies buffs
This commit is contained in:
@@ -28,54 +28,12 @@ Template.applyBuffDialog.events({
|
|||||||
},
|
},
|
||||||
"click #applyButton": function(event, instance){
|
"click #applyButton": function(event, instance){
|
||||||
var targetId = Template.instance().selectedTarget.get();
|
var targetId = Template.instance().selectedTarget.get();
|
||||||
var parent = global[this.buff.parent.collection].findOne(this.buff.parent.id);
|
|
||||||
console.log(parent, this.buff.parent);
|
|
||||||
if (targetId === "default") {
|
if (targetId === "default") {
|
||||||
if (this.buff.target === "others") return; //we have "Select a character" selected
|
if (this.buff.target === "others") return; //since we have "Select a character" selected
|
||||||
targetId = this.buff.charId; //i.e. target self
|
targetId = this.buff.charId; //otherwise, the default is to target self
|
||||||
}
|
}
|
||||||
|
|
||||||
//insert new buff
|
popDialogStack(targetId);
|
||||||
newBuffId = Buffs.insert({
|
|
||||||
charId: targetId,
|
|
||||||
name: this.buff.name,
|
|
||||||
description: this.buff.description,
|
|
||||||
lifeTime: {total: this.buff.lifeTime.total},
|
|
||||||
type: "custom",
|
|
||||||
|
|
||||||
appliedBy: this.buff.charId,
|
|
||||||
appliedByDetails: {
|
|
||||||
name: parent.name,
|
|
||||||
collection: this.buff.parent.collection,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
//insert children
|
|
||||||
Attacks.find({"parent.id": this.buff._id}).forEach(function(doc){
|
|
||||||
temp = _.clone(doc);
|
|
||||||
temp.parent.id = newBuffId;
|
|
||||||
temp.parent.collection = "Buffs";
|
|
||||||
delete temp._id;
|
|
||||||
|
|
||||||
Attacks.insert(temp);
|
|
||||||
});
|
|
||||||
Effects.find({"parent.id": this.buff._id}).forEach(function(doc){
|
|
||||||
temp = _.clone(doc);
|
|
||||||
temp.parent.id = newBuffId;
|
|
||||||
temp.parent.collection = "Buffs";
|
|
||||||
delete temp._id;
|
|
||||||
|
|
||||||
Effects.insert(temp);
|
|
||||||
});
|
|
||||||
Proficiencies.find({"parent.id": this.buff._id}).forEach(function(doc){
|
|
||||||
temp = _.clone(doc);
|
|
||||||
temp.parent.id = newBuffId;
|
|
||||||
temp.parent.collection = "Buffs";
|
|
||||||
delete temp._id;
|
|
||||||
|
|
||||||
Proficiencies.insert(temp);
|
|
||||||
});
|
|
||||||
popDialogStack();
|
|
||||||
},
|
},
|
||||||
"click #cancelButton": function(event, instance){
|
"click #cancelButton": function(event, instance){
|
||||||
popDialogStack();
|
popDialogStack();
|
||||||
|
|||||||
@@ -1,3 +1,48 @@
|
|||||||
|
const applyBuff = function(targetId, buff) {
|
||||||
|
var parent = global[buff.parent.collection].findOne(buff.parent.id);
|
||||||
|
|
||||||
|
//insert new buff
|
||||||
|
newBuffId = Buffs.insert({
|
||||||
|
charId: targetId,
|
||||||
|
name: buff.name,
|
||||||
|
description: buff.description,
|
||||||
|
lifeTime: {total: buff.lifeTime.total},
|
||||||
|
type: "custom",
|
||||||
|
|
||||||
|
appliedBy: buff.charId,
|
||||||
|
appliedByDetails: {
|
||||||
|
name: parent.name,
|
||||||
|
collection: buff.parent.collection,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
//insert children
|
||||||
|
Attacks.find({"parent.id": buff._id}).forEach(function(doc){
|
||||||
|
temp = _.clone(doc);
|
||||||
|
temp.parent.id = newBuffId;
|
||||||
|
temp.parent.collection = "Buffs";
|
||||||
|
delete temp._id;
|
||||||
|
|
||||||
|
Attacks.insert(temp);
|
||||||
|
});
|
||||||
|
Effects.find({"parent.id": buff._id}).forEach(function(doc){
|
||||||
|
temp = _.clone(doc);
|
||||||
|
temp.parent.id = newBuffId;
|
||||||
|
temp.parent.collection = "Buffs";
|
||||||
|
delete temp._id;
|
||||||
|
|
||||||
|
Effects.insert(temp);
|
||||||
|
});
|
||||||
|
Proficiencies.find({"parent.id": buff._id}).forEach(function(doc){
|
||||||
|
temp = _.clone(doc);
|
||||||
|
temp.parent.id = newBuffId;
|
||||||
|
temp.parent.collection = "Buffs";
|
||||||
|
delete temp._id;
|
||||||
|
|
||||||
|
Proficiencies.insert(temp);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Template.customBuffView.helpers({
|
Template.customBuffView.helpers({
|
||||||
toSelf: function() {
|
toSelf: function() {
|
||||||
if (this.buff.target === "self") {
|
if (this.buff.target === "self") {
|
||||||
@@ -15,56 +60,15 @@ Template.customBuffView.events({
|
|||||||
template: "applyBuffDialog",
|
template: "applyBuffDialog",
|
||||||
data: {buff: this.buff},
|
data: {buff: this.buff},
|
||||||
element: event.currentTarget,
|
element: event.currentTarget,
|
||||||
|
callback: (targetId) => {
|
||||||
|
if (!targetId) return;
|
||||||
|
applyBuff(targetId, this.buff);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var targetId = this.buff.charId;
|
var targetId = this.buff.charId;
|
||||||
var parent = global[this.buff.parent.collection].findOne(this.buff.parent.id);
|
applyBuff(targetId, this.buff);
|
||||||
if (targetId === "default") {
|
|
||||||
if (this.buff.target === "others") return; //we have "Select a character" selected
|
|
||||||
targetId = this.buff.charId; //i.e. target self
|
|
||||||
}
|
|
||||||
|
|
||||||
//insert new buff
|
|
||||||
newBuffId = Buffs.insert({
|
|
||||||
charId: targetId,
|
|
||||||
name: this.buff.name,
|
|
||||||
description: this.buff.description,
|
|
||||||
lifeTime: {total: this.buff.lifeTime.total},
|
|
||||||
type: "custom",
|
|
||||||
|
|
||||||
appliedBy: this.buff.charId,
|
|
||||||
appliedByDetails: {
|
|
||||||
name: parent.name,
|
|
||||||
collection: this.buff.parent.collection,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
//insert children
|
|
||||||
Attacks.find({"parent.id": this.buff._id}).forEach(function(doc){
|
|
||||||
temp = _.clone(doc);
|
|
||||||
temp.parent.id = newBuffId;
|
|
||||||
temp.parent.collection = "Buffs";
|
|
||||||
delete temp._id;
|
|
||||||
|
|
||||||
Attacks.insert(temp);
|
|
||||||
});
|
|
||||||
Effects.find({"parent.id": this.buff._id}).forEach(function(doc){
|
|
||||||
temp = _.clone(doc);
|
|
||||||
temp.parent.id = newBuffId;
|
|
||||||
temp.parent.collection = "Buffs";
|
|
||||||
delete temp._id;
|
|
||||||
|
|
||||||
Effects.insert(temp);
|
|
||||||
});
|
|
||||||
Proficiencies.find({"parent.id": this.buff._id}).forEach(function(doc){
|
|
||||||
temp = _.clone(doc);
|
|
||||||
temp.parent.id = newBuffId;
|
|
||||||
temp.parent.collection = "Buffs";
|
|
||||||
delete temp._id;
|
|
||||||
|
|
||||||
Proficiencies.insert(temp);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -46,6 +46,6 @@ Meteor.publish("singleCharacterName", function(characterId){
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
if (char) {
|
if (char) {
|
||||||
return Characters.find(characterId, {fields:"name"});
|
return Characters.find(characterId, {fields:{"name": 1}});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user