Added ability to add/edit buffs
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<!-- data is the CustomBuff -->
|
||||
<template name="applyBuffDialog">
|
||||
<div class="fit layout vertical">
|
||||
<app-header-layout has-scrolling-region class="feedback flex">
|
||||
<app-header fixed effects="waterfall">
|
||||
<app-toolbar>
|
||||
Apply Buff
|
||||
</app-toolbar>
|
||||
</app-header>
|
||||
<div class="form flex">
|
||||
<paper-dropdown-menu class=flex label="Target" style="flex-basis: 150px; max-width: 200px;">
|
||||
<dicecloud-selector selected="default" class="dropdown-content target-dropdown">
|
||||
{{#if canApplyToSelf}}
|
||||
<paper-item name="default" style="width: 150px;">
|
||||
Self
|
||||
</paper-item>
|
||||
{{else}}
|
||||
<paper-item name="default" style="width: 150px;">
|
||||
Choose a character
|
||||
</paper-item>
|
||||
{{/if}}
|
||||
{{#each character in writableCharacters}}
|
||||
<paper-item name="{{character._id}}">
|
||||
{{character.name}}
|
||||
</paper-item>
|
||||
{{/each}}
|
||||
</dicecloud-selector>
|
||||
</paper-dropdown-menu>
|
||||
</div>
|
||||
</app-header-layout>
|
||||
<div class="buttons layout horizontal end-justified">
|
||||
<paper-button id="cancelButton">
|
||||
Cancel
|
||||
</paper-button>
|
||||
<paper-button id="applyButton" disabled={{cantApply}}>
|
||||
Apply
|
||||
</paper-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,83 @@
|
||||
Template.applyBuffDialog.onCreated(function(){
|
||||
this.selectedTarget = new ReactiveVar("default");
|
||||
});
|
||||
|
||||
Template.applyBuffDialog.helpers({
|
||||
cantApply: function() {
|
||||
return this.buff.target === "others" && Template.instance().selectedTarget.get() === "default"; //this is the only case where we can't apply a buff
|
||||
},
|
||||
canApplyToSelf: function() {
|
||||
return this.buff.target !== "others"; //i.e. it is "self" or "both"
|
||||
},
|
||||
writableCharacters: function() {
|
||||
var returnArray = [];
|
||||
Characters.find({}).forEach(function(char){ //we look through all characters we have access to
|
||||
if (canEditCharacter(char._id)) {
|
||||
returnArray.push(char)
|
||||
}
|
||||
});
|
||||
return returnArray;
|
||||
},
|
||||
});
|
||||
|
||||
Template.applyBuffDialog.events({
|
||||
"iron-select .target-dropdown": function(event){
|
||||
var detail = event.originalEvent.detail;
|
||||
var value = detail.item.getAttribute("name");
|
||||
Template.instance().selectedTarget.set(value);
|
||||
},
|
||||
"click #applyButton": function(event, instance){
|
||||
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 (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);
|
||||
});
|
||||
popDialogStack();
|
||||
},
|
||||
"click #cancelButton": function(event, instance){
|
||||
popDialogStack();
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user