diff --git a/rpg-docs/Model/Inventory/Containers.js b/rpg-docs/Model/Inventory/Containers.js index 7a8a7d78..2c92c8de 100644 --- a/rpg-docs/Model/Inventory/Containers.js +++ b/rpg-docs/Model/Inventory/Containers.js @@ -5,7 +5,27 @@ Containers = new Meteor.Collection("containers"); Schemas.Container = new SimpleSchema({ name: { type: String }, charId: { type: String, regEx: SimpleSchema.RegEx.Id}, - isCarried: { type: Boolean } + isCarried: { type: Boolean }, + weight: {type: Number, min: 0, defaultValue: 0, decimal: true}, + value: {type: Number, min: 0, defaultValue: 0, decimal: true}, + description:{type: String, optional: true} }); -Containers.attachSchema(Schemas.Container); \ No newline at end of file +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){ + value += item.totalValue(); + }); + return value; + }, + totalWeight: function(){ + var weight = this.weight; + Items.find({container: this._id, equipped: false}, {fields: {weight: 1, value: 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 7333f4cc..5894ab95 100644 --- a/rpg-docs/Model/Inventory/Items.js +++ b/rpg-docs/Model/Inventory/Items.js @@ -3,7 +3,7 @@ Items = new Meteor.Collection('items'); Schemas.Item = new SimpleSchema({ name: {type: String, defaultValue: "New Item"}, plural: {type: String, optional: true}, - description:{type: String, defaultValue: ""}, + description:{type: String, optional: true}, container: {type: String, regEx: SimpleSchema.RegEx.Id}, //id of container it is normally stowed in charId: {type: String, regEx: SimpleSchema.RegEx.Id}, //id of owner quantity: {type: Number, min: 0, defaultValue: 1}, diff --git a/rpg-docs/client/views/character/inventory/containerDialog/containerDialog.html b/rpg-docs/client/views/character/inventory/containerDialog/containerDialog.html new file mode 100644 index 00000000..bbf5ab72 --- /dev/null +++ b/rpg-docs/client/views/character/inventory/containerDialog/containerDialog.html @@ -0,0 +1,31 @@ + \ No newline at end of file diff --git a/rpg-docs/client/views/character/inventory/containerDialog/containerDialog.js b/rpg-docs/client/views/character/inventory/containerDialog/containerDialog.js new file mode 100644 index 00000000..28b94f47 --- /dev/null +++ b/rpg-docs/client/views/character/inventory/containerDialog/containerDialog.js @@ -0,0 +1,41 @@ +Template.containerDialog.rendered = function(){ + var self = this; + this.autorun(function(){ + var container = Containers.findOne(Template.currentData().containerId, {fields: {name: 1}}); + if(container) Session.set("global.ui.dialogHeader", container.name); + }) + //after the dialog is built, open it + _.defer(function(){GlobalUI.dialog.open()}); +} + +Template.containerDialog.events({ + "tap #deleteContainer": function(){ + Containers.remove(this._id); + GlobalUI.closeDialog() + }, + //TODO clean up String -> num here so they don't need casting by Schema.clean + //TODO validate input (integer, non-negative, etc) for these inputs and give validation errors + "change #containerNameInput, input #containerNameInput": function(event){ + console.log("changed Nameinput") + var name = Template.instance().find("#containerNameInput").value; + Containers.update(this._id, {$set: {name: name}}); + }, + "change #weightInput, input #weightInput": function(event){ + var weight = Template.instance().find("#weightInput").value; + Containers.update(this._id, {$set: {weight: weight}}); + }, + "change #valueInput, input #valueInput": function(event){ + var value = Template.instance().find("#valueInput").value; + Containers.update(this._id, {$set: {value: value}}); + }, + "change #containerDescriptionInput": function(event){ + var description = Template.instance().find("#containerDescriptionInput").value; + Containers.update(this._id, {$set: {description: description}}); + } +}); + +Template.containerDialog.helpers({ + container: function(){ + return Containers.findOne(this.containerId); + } +}); \ No newline at end of file diff --git a/rpg-docs/client/views/character/inventory/inventory.css b/rpg-docs/client/views/character/inventory/inventory.css index e69de29b..6ff60de4 100644 --- a/rpg-docs/client/views/character/inventory/inventory.css +++ b/rpg-docs/client/views/character/inventory/inventory.css @@ -0,0 +1,3 @@ +.containerName { + cursor: pointer; +} \ No newline at end of file diff --git a/rpg-docs/client/views/character/inventory/inventory.html b/rpg-docs/client/views/character/inventory/inventory.html index 30a5d8f5..9219b29d 100644 --- a/rpg-docs/client/views/character/inventory/inventory.html +++ b/rpg-docs/client/views/character/inventory/inventory.html @@ -3,7 +3,13 @@
Armor:
- {{#if armor}}{{armor.name}}{{else}}none{{/if}} + {{#if armor}} + {{#with armor}} + {{name}} + {{/with}} + {{else}} + none + {{/if}} Equipment:
{{#each equipment}} @@ -14,7 +20,7 @@
{{#each containers}} -

{{name}}

+

{{name}}

{{#each items ../_id _id}} {{#if gt1 quantity}}{{quantity}}{{/if}} {{pluralName}} diff --git a/rpg-docs/client/views/character/inventory/inventory.js b/rpg-docs/client/views/character/inventory/inventory.js index e4662631..baf46ec1 100644 --- a/rpg-docs/client/views/character/inventory/inventory.js +++ b/rpg-docs/client/views/character/inventory/inventory.js @@ -53,5 +53,12 @@ Template.inventory.events({ data: {itemId: this._id, charId: this.charId}, fullOnMobile: true }); + }, + "tap .containerName": function(event){ + GlobalUI.setDialog({ + template: "containerDialog", + data: {containerId: this._id, charId: this.charId}, + fullOnMobile: true + }); } }) \ No newline at end of file