From 08735ea4f7042bfc51134aa7873ee503e1ee015a Mon Sep 17 00:00:00 2001 From: Jacob Date: Wed, 9 Aug 2017 15:01:20 +0100 Subject: [PATCH] Added ability to add/edit buffs --- rpg-docs/Model/Character/CustomBuffs.js | 24 +++--- .../client/globalHelpers/openParentDialog.js | 3 + .../applyBuffDialog/applyBuffDialog.html | 40 +++++++++ .../buffs/applyBuffDialog/applyBuffDialog.js | 83 +++++++++++++++++++ .../buffs/buffDialog/buffDialog.html | 2 +- .../character/buffs/buffDialog/buffDialog.js | 15 ++-- .../buffs/customBuffEdit/customBuffEdit.html | 15 ++++ .../buffs/customBuffEdit/customBuffEdit.js | 35 ++++++++ .../customBuffEditList.html | 30 +++++++ .../customBuffEditList/customBuffEditList.js | 41 +++++++++ .../buffs/customBuffView/customBuffView.html | 6 ++ .../buffs/customBuffView/customBuffView.js | 9 ++ .../customBuffViewList.html | 12 +++ .../customBuffViewList/customBuffViewList.js | 9 ++ .../features/featureDialog/featureDialog.html | 2 + .../inventory/itemDialog/itemDialog.html | 3 + .../spells/spellDialog/spellDialog.html | 2 + .../client/views/character/stats/stats.html | 3 +- 18 files changed, 308 insertions(+), 26 deletions(-) create mode 100644 rpg-docs/client/views/character/buffs/applyBuffDialog/applyBuffDialog.html create mode 100644 rpg-docs/client/views/character/buffs/applyBuffDialog/applyBuffDialog.js create mode 100644 rpg-docs/client/views/character/buffs/customBuffEdit/customBuffEdit.html create mode 100644 rpg-docs/client/views/character/buffs/customBuffEdit/customBuffEdit.js create mode 100644 rpg-docs/client/views/character/buffs/customBuffEditList/customBuffEditList.html create mode 100644 rpg-docs/client/views/character/buffs/customBuffEditList/customBuffEditList.js create mode 100644 rpg-docs/client/views/character/buffs/customBuffView/customBuffView.html create mode 100644 rpg-docs/client/views/character/buffs/customBuffView/customBuffView.js create mode 100644 rpg-docs/client/views/character/buffs/customBuffViewList/customBuffViewList.html create mode 100644 rpg-docs/client/views/character/buffs/customBuffViewList/customBuffViewList.js 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 @@ + + 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 @@ + \ 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 @@ + + + + \ 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 @@ + 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 @@ + 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}} 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}} 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}}
Buffs
- View All
{{/if}}