diff --git a/rpg-docs/Model/Character/CustomBuffs.js b/rpg-docs/Model/Character/CustomBuffs.js
index 2920a547..7a766b01 100644
--- a/rpg-docs/Model/Character/CustomBuffs.js
+++ b/rpg-docs/Model/Character/CustomBuffs.js
@@ -16,6 +16,15 @@ Schemas.CustomBuff = new SimpleSchema({
optional: true,
trim: false,
},
+ target: {
+ type: String,
+ allowedValues: [
+ "self",
+ "others",
+ "both"
+ ],
+ defaultValue: "self",
+ },
enabled: {
type: Boolean,
autoValue: function(){
@@ -23,27 +32,14 @@ Schemas.CustomBuff = new SimpleSchema({
//enabled is ALWAYS false on these, so that its children are also not enabled, so that the buff templates have no effects.
},
},
- type: {
- type: String,
- allowedValues: [
- "inate", //this should be "innate", but changing it could be problematic
- "custom",
- ],
- },
"lifeTime.total": {
type: Number,
defaultValue: 0, //0 is infinite
min: 0,
},
- color: {
- type: String,
- allowedValues: _.pluck(colorOptions, "key"),
- defaultValue: "q",
- },
//the id of the feature, buff or item that creates this buff
parent: {
type: Schemas.Parent,
- optional: true,
},
});
@@ -51,7 +47,7 @@ CustomBuffs.attachSchema(Schemas.CustomBuff);
CustomBuffs.attachBehaviour("softRemovable");
makeParent(CustomBuffs, ["name", "enabled"]); //parents of effects, attacks, proficiencies. Since this represents a template, "enabled" is always false.
-makeChild(CustomBuffs, ["enabled"]); //children of lots of things
+makeChild(CustomBuffs); //children of lots of things
CustomBuffs.allow(CHARACTER_SUBSCHEMA_ALLOW);
CustomBuffs.deny(CHARACTER_SUBSCHEMA_DENY);
diff --git a/rpg-docs/client/globalHelpers/openParentDialog.js b/rpg-docs/client/globalHelpers/openParentDialog.js
index 139428fe..b220a652 100644
--- a/rpg-docs/client/globalHelpers/openParentDialog.js
+++ b/rpg-docs/client/globalHelpers/openParentDialog.js
@@ -18,6 +18,9 @@ openParentDialog = function({
} else if (parent.collection === "Spells") {
template = "spellDialog";
data = {spellId: parent.id};
+ } else if (parent.collection === "Buffs") {
+ template = "buffDialog";
+ data = {buffId: parent.id};
}
pushDialogStack({template, data, element, returnElement, callback});
};
diff --git a/rpg-docs/client/views/character/buffs/applyBuffDialog/applyBuffDialog.html b/rpg-docs/client/views/character/buffs/applyBuffDialog/applyBuffDialog.html
new file mode 100644
index 00000000..5618141e
--- /dev/null
+++ b/rpg-docs/client/views/character/buffs/applyBuffDialog/applyBuffDialog.html
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+ Apply Buff
+
+
+
+
+
+
+
diff --git a/rpg-docs/client/views/character/buffs/applyBuffDialog/applyBuffDialog.js b/rpg-docs/client/views/character/buffs/applyBuffDialog/applyBuffDialog.js
new file mode 100644
index 00000000..0100145a
--- /dev/null
+++ b/rpg-docs/client/views/character/buffs/applyBuffDialog/applyBuffDialog.js
@@ -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();
+ },
+});
diff --git a/rpg-docs/client/views/character/buffs/buffDialog/buffDialog.html b/rpg-docs/client/views/character/buffs/buffDialog/buffDialog.html
index d194ff85..78fef7c5 100644
--- a/rpg-docs/client/views/character/buffs/buffDialog/buffDialog.html
+++ b/rpg-docs/client/views/character/buffs/buffDialog/buffDialog.html
@@ -17,6 +17,6 @@
{{#markdown}}{{evaluateString charId description}}{{/markdown}}
{{/if}}
{{> effectsViewList charId=charId parentId=_id}}
- {{> attacksViewList charId=charId parentId=_id}}
{{> proficiencyViewList charId=charId parentId=_id}}
+ {{> attacksViewList charId=charId parentId=_id}}
diff --git a/rpg-docs/client/views/character/buffs/buffDialog/buffDialog.js b/rpg-docs/client/views/character/buffs/buffDialog/buffDialog.js
index 90bb0c10..a2b5cff6 100644
--- a/rpg-docs/client/views/character/buffs/buffDialog/buffDialog.js
+++ b/rpg-docs/client/views/character/buffs/buffDialog/buffDialog.js
@@ -6,7 +6,7 @@ Template.buffDialog.helpers({
Template.buffDialog.events({
"click #deleteButton": function(event, instance){
- Buffs.remove(instance.data.buffId);
+ Buffs.softRemoveNode(instance.data.buffId);
popDialogStack();
},
});
@@ -29,18 +29,15 @@ Template.buffDetails.helpers({
if (applierCharacter.name === myName) {
var charName = "your "
} else {
- if (applierCharacter.charName[applierCharacter.charName.length -1] === 's') {
- var charName = applierCharacter.charName + "' ";
+ if (applierCharacter.name[applierCharacter.name.length - 1] === 's') {
+ var charName = applierCharacter.name + "' ";
} else {
- var charName = applierCharacter.charName + "'s ";
+ var charName = applierCharacter.name + "'s ";
}
}
- var type = typeDict[this.appliedByDetails.collection] || "";
- var applierThing = global[this.appliedByDetails.collection]
- && global[this.appliedByDetails.collection].findOne(this.appliedByDetails.id)
- && global[this.appliedByDetails.collection].findOne(this.appliedByDetails.id).name
- || "unknown ability";
+ var type = typeDict[this.appliedByDetails.collection] + " ";
+ var applierThing = this.appliedByDetails.name;
return "Applied by " + charName + type + applierThing + ".";
}
diff --git a/rpg-docs/client/views/character/buffs/customBuffEdit/customBuffEdit.html b/rpg-docs/client/views/character/buffs/customBuffEdit/customBuffEdit.html
new file mode 100644
index 00000000..5a12d152
--- /dev/null
+++ b/rpg-docs/client/views/character/buffs/customBuffEdit/customBuffEdit.html
@@ -0,0 +1,15 @@
+
+ {{#with buff}}
+ {{#baseEditDialog title=name hideColor=true}}
+
+
+
+
+
+
+ {{> effectsEditList parentId=_id parentCollection="Buffs" charId=charId name=name enabled=false}}
+ {{> attackEditList parentId=_id parentCollection="Buffs" charId=charId name=name enabled=false}}
+ {{> proficiencyEditList parentId=_id parentCollection="Buffs" charId=charId enabled=false}}
+ {{/baseEditDialog}}
+ {{/with}}
+
\ No newline at end of file
diff --git a/rpg-docs/client/views/character/buffs/customBuffEdit/customBuffEdit.js b/rpg-docs/client/views/character/buffs/customBuffEdit/customBuffEdit.js
new file mode 100644
index 00000000..aed7d9b9
--- /dev/null
+++ b/rpg-docs/client/views/character/buffs/customBuffEdit/customBuffEdit.js
@@ -0,0 +1,35 @@
+Template.customBuffEdit.helpers({
+ buff: function(){
+ return CustomBuffs.findOne(this.buffId);
+ },
+});
+
+const debounce = (f) => _.debounce(f, 300);
+
+Template.customBuffEdit.events({
+ "input #buffNameInput": debounce(function(event){
+ const input = event.currentTarget;
+ var name = input.value;
+ if (!name){
+ input.invalid = true;
+ input.errorMessage = "Name is required";
+ } else {
+ input.invalid = false;
+ CustomBuffs.update(this._id, {
+ $set: {name: name}
+ }, {
+ removeEmptyStrings: false,
+ trimStrings: false,
+ });
+ }
+ }),
+ "input #buffDescriptionInput": debounce(function(event){
+ var description = event.currentTarget.value;
+ CustomBuffs.update(this._id, {
+ $set: {description: description}
+ }, {
+ removeEmptyStrings: false,
+ trimStrings: false,
+ });
+ }),
+});
diff --git a/rpg-docs/client/views/character/buffs/customBuffEditList/customBuffEditList.html b/rpg-docs/client/views/character/buffs/customBuffEditList/customBuffEditList.html
new file mode 100644
index 00000000..a3f8cf78
--- /dev/null
+++ b/rpg-docs/client/views/character/buffs/customBuffEditList/customBuffEditList.html
@@ -0,0 +1,30 @@
+
+
+ {{#if buffs.count}}
+
+
+ Buffs
+
+
+ {{#each buff in buffs}}
+ {{> customBuffEditListItem buff=buff}}
+ {{/each}}
+
+
+ {{/if}}
+
+ Add Buff
+
+
+
+
+
+ {{> customBuffView buff=buff}}
+ |
+
+
+ |
+
+
\ No newline at end of file
diff --git a/rpg-docs/client/views/character/buffs/customBuffEditList/customBuffEditList.js b/rpg-docs/client/views/character/buffs/customBuffEditList/customBuffEditList.js
new file mode 100644
index 00000000..a7d955f4
--- /dev/null
+++ b/rpg-docs/client/views/character/buffs/customBuffEditList/customBuffEditList.js
@@ -0,0 +1,41 @@
+Template.customBuffEditList.helpers({
+ buffs: function(){
+ var selector = {
+ "parent.id": this.parentId,
+ "charId": this.charId,
+ };
+ return CustomBuffs.find(selector);
+ }
+});
+
+Template.customBuffEditList.events({
+ "tap #addBuffButton": function(event, instance){
+ if (!_.isBoolean(this.enabled)) {
+ this.enabled = true;
+ }
+ const customBuffId = CustomBuffs.insert({
+ name: "New Buff",
+ charId: this.charId,
+ parent: {
+ id: this.parentId,
+ collection: this.parentCollection,
+ },
+ });
+ pushDialogStack({
+ template: "customBuffEdit",
+ data: {id: customBuffId},
+ element: event.currentTarget,
+ returnElement: () => instance.find(`tr.buff[data-id='${customBuffId}']`),
+ });
+ },
+});
+
+Template.customBuffEditListItem.events({
+ "tap .edit-buff": function(event, template){
+ pushDialogStack({
+ template: "customBuffEdit",
+ data: {id: this.buff._id},
+ element: event.currentTarget.parentElement.parentElement,
+ });
+ },
+});
\ No newline at end of file
diff --git a/rpg-docs/client/views/character/buffs/customBuffView/customBuffView.html b/rpg-docs/client/views/character/buffs/customBuffView/customBuffView.html
new file mode 100644
index 00000000..63c6a5b6
--- /dev/null
+++ b/rpg-docs/client/views/character/buffs/customBuffView/customBuffView.html
@@ -0,0 +1,6 @@
+
+ {{buff.name}} |
+
+ Apply
+ |
+
diff --git a/rpg-docs/client/views/character/buffs/customBuffView/customBuffView.js b/rpg-docs/client/views/character/buffs/customBuffView/customBuffView.js
new file mode 100644
index 00000000..eab7ec97
--- /dev/null
+++ b/rpg-docs/client/views/character/buffs/customBuffView/customBuffView.js
@@ -0,0 +1,9 @@
+Template.customBuffView.events({
+ "click .apply-buff-button": function(){
+ pushDialogStack({
+ template: "applyBuffDialog",
+ data: {buff: this.buff},
+ element: event.currentTarget,
+ });
+ },
+});
\ No newline at end of file
diff --git a/rpg-docs/client/views/character/buffs/customBuffViewList/customBuffViewList.html b/rpg-docs/client/views/character/buffs/customBuffViewList/customBuffViewList.html
new file mode 100644
index 00000000..ea002b05
--- /dev/null
+++ b/rpg-docs/client/views/character/buffs/customBuffViewList/customBuffViewList.html
@@ -0,0 +1,12 @@
+
+ {{#if buffs.count}}
+
+
+ Buffs
+
+ {{#each buff in buffs}}
+ {{> customBuffView buff=buff}}
+ {{/each}}
+
+ {{/if}}
+
diff --git a/rpg-docs/client/views/character/buffs/customBuffViewList/customBuffViewList.js b/rpg-docs/client/views/character/buffs/customBuffViewList/customBuffViewList.js
new file mode 100644
index 00000000..2efa4dd4
--- /dev/null
+++ b/rpg-docs/client/views/character/buffs/customBuffViewList/customBuffViewList.js
@@ -0,0 +1,9 @@
+Template.customBuffViewList.helpers({
+ buffs: function(){
+ var selector = {
+ "parent.id": this.parentId,
+ "charId": this.charId,
+ };
+ return CustomBuffs.find(selector);
+ }
+});
diff --git a/rpg-docs/client/views/character/features/featureDialog/featureDialog.html b/rpg-docs/client/views/character/features/featureDialog/featureDialog.html
index 02ea0ccf..b9d0a437 100644
--- a/rpg-docs/client/views/character/features/featureDialog/featureDialog.html
+++ b/rpg-docs/client/views/character/features/featureDialog/featureDialog.html
@@ -36,6 +36,7 @@
{{> effectsViewList charId=charId parentId=_id}}
{{> proficiencyViewList charId=charId parentId=_id}}
+ {{> customBuffViewList charId=charId parentId=_id}}
@@ -73,4 +74,5 @@
{{> effectsEditList parentId=_id parentCollection="Features" charId=charId name=name enabled=enabled}}
{{> proficiencyEditList parentId=_id parentCollection="Features" charId=charId enabled=enabled}}
+ {{> customBuffEditList parentId=_id parentCollection="Features" charId=charId}}
diff --git a/rpg-docs/client/views/character/inventory/itemDialog/itemDialog.html b/rpg-docs/client/views/character/inventory/itemDialog/itemDialog.html
index 9692c27f..874c5d82 100644
--- a/rpg-docs/client/views/character/inventory/itemDialog/itemDialog.html
+++ b/rpg-docs/client/views/character/inventory/itemDialog/itemDialog.html
@@ -23,6 +23,7 @@
{{/if}}
{{> effectsViewList charId=charId parentId=_id}}
{{> attacksViewList charId=charId parentId=_id}}
+ {{> customBuffViewList charId=charId parentId=_id}}
@@ -68,6 +69,8 @@
{{> effectsEditList parentId=_id parentCollection="Items" charId=charId enabled=equipped name=name}}
{{> attackEditList parentId=_id parentCollection="Items" charId=charId enabled=equipped name=name}}
+
+ {{> customBuffEditList parentId=_id parentCollection="Items" charId=charId}}
diff --git a/rpg-docs/client/views/character/spells/spellDialog/spellDialog.html b/rpg-docs/client/views/character/spells/spellDialog/spellDialog.html
index 7de0fdd8..886df6ed 100644
--- a/rpg-docs/client/views/character/spells/spellDialog/spellDialog.html
+++ b/rpg-docs/client/views/character/spells/spellDialog/spellDialog.html
@@ -38,6 +38,7 @@
{{#markdown}}{{evaluateSpellString charId parent.id description}}{{/markdown}}
{{> attacksViewList charId=charId parentId=_id}}
+ {{> customBuffViewList charId=charId parentId=_id}}
@@ -115,4 +116,5 @@
{{> attackEditList parentId=_id parentCollection="Spells" charId=charId enabled=true name=name}}
+ {{> customBuffEditList parentId=_id parentCollection="Spells" charId=charId}}
diff --git a/rpg-docs/client/views/character/stats/stats.html b/rpg-docs/client/views/character/stats/stats.html
index 4da78330..5ecdb947 100644
--- a/rpg-docs/client/views/character/stats/stats.html
+++ b/rpg-docs/client/views/character/stats/stats.html
@@ -57,10 +57,9 @@
{{>buffListItem buff=condition}}
{{/each}}
- {{#if totalBuffs.count}}
+ {{#if buffs.count}}
{{/if}}