From 48f8cef928afc4bb003fa59b3914a1494f5e2fd5 Mon Sep 17 00:00:00 2001 From: Thaum Date: Fri, 20 Mar 2015 09:12:38 +0000 Subject: [PATCH] implemented UI for new parenting --- rpg-docs/Model/Character/Effects.js | 24 +++++++++-- rpg-docs/Model/Inventory/Containers.js | 4 +- rpg-docs/Model/Inventory/Items.js | 13 ++++-- .../attackEditList/attackEditList.html | 2 +- .../attacks/attackEditList/attackEditList.js | 12 +++--- .../effects/effectView/effectView.html | 8 ++-- .../effects/effectView/effectView.js | 16 +++---- .../effectsEditList/effectsEditList.html | 2 +- .../effectsEditList/effectsEditList.js | 7 ++- .../effectsViewList/effectsViewList.html | 2 +- .../effectsViewList/effectsViewList.js | 4 +- .../features/featureDialog/featureDialog.html | 2 +- .../views/character/inventory/inventory.css | 2 +- .../views/character/inventory/inventory.js | 43 +++++++------------ .../inventory/itemDialog/itemDialog.html | 8 ++-- .../inventory/itemDialog/itemDialog.js | 10 ++--- .../journal/classDialog/classDialog.html | 2 +- .../journal/raceDialog/raceDialog.html | 2 +- .../spells/spellDialog/spellDialog.html | 2 +- .../spells/spellDialog/spellDialog.js | 4 +- .../client/views/character/spells/spells.js | 18 +++++--- .../stats/skillDialog/skillDialog.js | 2 +- rpg-docs/lib/functions/parenting.js | 36 +++++++++++----- 23 files changed, 126 insertions(+), 99 deletions(-) diff --git a/rpg-docs/Model/Character/Effects.js b/rpg-docs/Model/Character/Effects.js index 1af8b531..cdf794fe 100644 --- a/rpg-docs/Model/Character/Effects.js +++ b/rpg-docs/Model/Character/Effects.js @@ -60,7 +60,11 @@ Characters.after.insert(function (userId, char) { name: "Constitution modifier for each level", stat: "hitPoints", operation: "add", - calculation: "level * constitutionMod" + calculation: "level * constitutionMod", + parent: { + id: char._id, + collection: "Characters" + } }); Effects.insert({ charId: char._id, @@ -68,7 +72,11 @@ Characters.after.insert(function (userId, char) { name: "Proficiency bonus by level", stat: "proficiencyBonus", operation: "add", - calculation: "floor(level / 4 + 1.75)" + calculation: "floor(level / 4 + 1.75)", + parent: { + id: char._id, + collection: "Characters" + } }); Effects.insert({ charId: char._id, @@ -76,7 +84,11 @@ Characters.after.insert(function (userId, char) { name: "Dexterity Armor Bonus", stat: "armor", operation: "add", - calculation: "dexterityArmor" + calculation: "dexterityArmor", + parent: { + id: char._id, + collection: "Characters" + } }); Effects.insert({ charId: char._id, @@ -84,7 +96,11 @@ Characters.after.insert(function (userId, char) { name: "Natural Armor", stat: "armor", operation: "base", - value: 10 + value: 10, + parent: { + id: char._id, + collection: "Characters" + } }); } }); diff --git a/rpg-docs/Model/Inventory/Containers.js b/rpg-docs/Model/Inventory/Containers.js index 5335414f..c942e3a4 100644 --- a/rpg-docs/Model/Inventory/Containers.js +++ b/rpg-docs/Model/Inventory/Containers.js @@ -16,14 +16,14 @@ Containers.attachSchema(Schemas.Container); Containers.helpers({ totalValue: function(){ var value = this.value; - Items.find({container: this._id, equipped: false}, {fields: {quantity: 1, value: 1}}).forEach(function(item){ + Items.find({"parent.id": this._id}, {fields: {quantity: 1, value: 1}}).forEach(function(item){ value += item.totalValue(); }); return value; }, totalWeight: function(){ var weight = this.weight; - Items.find({container: this._id, equipped: false}, {fields: {quantity: 1, weight: 1}}).forEach(function(item){ + Items.find({"parent.id": this._id}, {fields: {quantity: 1, weight: 1}}).forEach(function(item){ weight += item.totalWeight(); }); return weight; diff --git a/rpg-docs/Model/Inventory/Items.js b/rpg-docs/Model/Inventory/Items.js index c1eb687a..0675621a 100644 --- a/rpg-docs/Model/Inventory/Items.js +++ b/rpg-docs/Model/Inventory/Items.js @@ -33,17 +33,24 @@ Items.helpers({ return this.name; } }, - equip: function(){ - Items.update(this._id, {$set: {enabled: true}}); + equip: function(characterId){ + var charId = characterId || this.charId; + if(!charId || ! Characters.findOne(charId)) throw "Invalid character"; + if(this.parent.collection === "Characters" && this.parent.id === charId && this.enabled) return; + Items.update(this._id, {$set: {"parent.collection": "Characters", "parent.id": charId, enabled: true}}); }, unequip: function(){ + if(!this.enabled) return; Items.update(this._id, {$set: {enabled: false}}); }, moveToContainer: function(containerId){ + if( !containerId || !Containers.findOne(containerId) ) throw "Invalid container"; + if(this.parent.collection === "Containers" && this.parent.id === containerId && !this.enabled) return; Items.update(this._id, {$set: {"parent.collection": "Containers", "parent.id": containerId, enabled: false}}); }, moveToCharacter: function(characterId){ - if(this.charId === characterId) return; + if(!characterId || ! Characters.findOne(characterId)) throw "Invalid character"; + if(this.parent.collection === "Characters" && this.parent.id === characterId && !this.enabled) return; Items.update(this._id, {$set: {"parent.collection": "Characters", "parent.id": characterId, charId: characterId, enabled: false}}); } }); diff --git a/rpg-docs/client/views/character/attacks/attackEditList/attackEditList.html b/rpg-docs/client/views/character/attacks/attackEditList/attackEditList.html index 789f916f..8ce4c03d 100644 --- a/rpg-docs/client/views/character/attacks/attackEditList/attackEditList.html +++ b/rpg-docs/client/views/character/attacks/attackEditList/attackEditList.html @@ -1,4 +1,4 @@ - +