From b200478425757da8424a442576dca5ac47d43e2a Mon Sep 17 00:00:00 2001 From: Thaum Date: Fri, 13 Feb 2015 08:44:30 +0000 Subject: [PATCH] Added SpellList Dialog --- rpg-docs/Model/Character/SpellLists.js | 4 +- rpg-docs/client/globalHelpers/evaluate.js | 8 +++ .../views/character/inventory/inventory.css | 16 +++-- .../spellListDialog/spellListDialog.css | 3 + .../spellListDialog/spellListDialog.html | 48 +++++++++++++ .../spells/spellListDialog/spellListDialog.js | 61 ++++++++++++++++ .../client/views/character/spells/spells.css | 3 - .../client/views/character/spells/spells.html | 23 ++++-- .../client/views/character/spells/spells.js | 71 ++++++++++++++----- rpg-docs/client/views/layout/imports.html | 1 + 10 files changed, 207 insertions(+), 31 deletions(-) create mode 100644 rpg-docs/client/globalHelpers/evaluate.js create mode 100644 rpg-docs/client/views/character/spells/spellListDialog/spellListDialog.css create mode 100644 rpg-docs/client/views/character/spells/spellListDialog/spellListDialog.html create mode 100644 rpg-docs/client/views/character/spells/spellListDialog/spellListDialog.js delete mode 100644 rpg-docs/client/views/character/spells/spells.css diff --git a/rpg-docs/Model/Character/SpellLists.js b/rpg-docs/Model/Character/SpellLists.js index 0cac6445..50e1bc1a 100644 --- a/rpg-docs/Model/Character/SpellLists.js +++ b/rpg-docs/Model/Character/SpellLists.js @@ -3,10 +3,12 @@ SpellLists = new Meteor.Collection("spellLists"); Schemas.SpellLists = new SimpleSchema({ charId: {type: String, regEx: SimpleSchema.RegEx.Id}, name: {type: String}, + description: {type: String, optional: true}, saveDC: {type: String, optional: true}, attackBonus: {type: String, optional: true}, maxPrepared: {type: String, optional: true}, - "settings.showUnprepared": {type: Boolean, defaultValue: true} + color: {type: String, allowedValues: _.keys(colorOptions), defaultValue: "green"}, + "settings.showUnprepared": {type: Boolean, defaultValue: true}, }); SpellLists.attachSchema(Schemas.SpellLists); diff --git a/rpg-docs/client/globalHelpers/evaluate.js b/rpg-docs/client/globalHelpers/evaluate.js new file mode 100644 index 00000000..14b04ac8 --- /dev/null +++ b/rpg-docs/client/globalHelpers/evaluate.js @@ -0,0 +1,8 @@ +Template.registerHelper("evaluate", function(charId, string){ + return evaluate(charId, string); +}); + +Template.registerHelper("evaluateSigned", function(charId, string){ + var number = evaluate(charId, string); + return number > 0? "+" + number : "" + number; +}); diff --git a/rpg-docs/client/views/character/inventory/inventory.css b/rpg-docs/client/views/character/inventory/inventory.css index 323e74ce..61058be5 100644 --- a/rpg-docs/client/views/character/inventory/inventory.css +++ b/rpg-docs/client/views/character/inventory/inventory.css @@ -1,10 +1,7 @@ -#inventory { - padding: 4px; -} - .containers { display: flex; flex-wrap: wrap; + padding: 4px; } .container { @@ -16,6 +13,7 @@ cursor: pointer; margin: -16px -16px 0 -16px; padding: 16px; + position: relative; } .equipmentTop { @@ -39,6 +37,16 @@ transition: box-shadow 0.35s cubic-bezier(0.4, 0, 0.2, 1); height: 40px; margin: 1px 0 1px 0; + font-size: 16px; + color: rgba(0,0,0,0.87); + letter-spacing: 0.010em; +} + +.inventoryItem /deep/ .button-content { + -webkit-flex: 1; + flex: 1; + -webkit-flex-basis: 0.000000001px; + flex-basis: 0.000000001px; } .inventoryItem[hero] { diff --git a/rpg-docs/client/views/character/spells/spellListDialog/spellListDialog.css b/rpg-docs/client/views/character/spells/spellListDialog/spellListDialog.css new file mode 100644 index 00000000..bb3c280d --- /dev/null +++ b/rpg-docs/client/views/character/spells/spellListDialog/spellListDialog.css @@ -0,0 +1,3 @@ +.spellListDialog .colorDropdown { + top: 0; +} \ No newline at end of file diff --git a/rpg-docs/client/views/character/spells/spellListDialog/spellListDialog.html b/rpg-docs/client/views/character/spells/spellListDialog/spellListDialog.html new file mode 100644 index 00000000..fd4301b1 --- /dev/null +++ b/rpg-docs/client/views/character/spells/spellListDialog/spellListDialog.html @@ -0,0 +1,48 @@ + \ No newline at end of file diff --git a/rpg-docs/client/views/character/spells/spellListDialog/spellListDialog.js b/rpg-docs/client/views/character/spells/spellListDialog/spellListDialog.js new file mode 100644 index 00000000..7e3b4888 --- /dev/null +++ b/rpg-docs/client/views/character/spells/spellListDialog/spellListDialog.js @@ -0,0 +1,61 @@ +Template.spellListDialog.rendered = function(){ + var self = this; + //update all autogrows after they've been filled + var pata = this.$("paper-autogrow-textarea"); + pata.each(function(index, el){ + el.update($(el).children().get(0)); + }) + //update all input fields as well + var input = this.$("paper-input"); + input.each(function(index, el){ + el.valueChanged(); + }) + //after the dialog is built, open it + if (!this.alreadyRendered){ + Session.set("global.ui.detailShow", true); + this.alreadyRendered = true; + } +} + +Template.spellListDialog.events({ + "tap #backButton": function(){ + GlobalUI.closeDetail(); + }, + "tap #deleteSpellList": function(){ + SpellLists.remove(this._id); + GlobalUI.closeDetail(); + }, + //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 #spellListNameInput, input #spellListNameInput": function(event){ + var value = event.currentTarget.value + SpellLists.update(this._id, {$set: {name: value}}); + }, + "change #spellListSaveDCInput, input #spellListNameInput": function(event){ + var value = event.currentTarget.value + SpellLists.update(this._id, {$set: {saveDC: value}}); + }, + "change #spellListAttackBonusInput, input #spellListNameInput": function(event){ + var value = event.currentTarget.value + SpellLists.update(this._id, {$set: {attackBonus: value}}); + }, + "change #spellListMaxPreparedInput, input #spellListNameInput": function(event){ + var value = event.currentTarget.value + SpellLists.update(this._id, {$set: {maxPrepared: value}}); + }, + "core-select .colorDropdown": function(event){ + var detail = event.originalEvent.detail; + if(!detail.isSelected) return; + var value = detail.item.getAttribute("name"); + SpellLists.update(this._id, {$set: {color: value}}); + } +}); + +Template.spellListDialog.helpers({ + spellList: function(){ + return SpellLists.findOne(this.spellListId); + }, + colorClass: function(){ + return getColorClass(this.color) + } +}); \ No newline at end of file diff --git a/rpg-docs/client/views/character/spells/spells.css b/rpg-docs/client/views/character/spells/spells.css deleted file mode 100644 index 6f3de0d1..00000000 --- a/rpg-docs/client/views/character/spells/spells.css +++ /dev/null @@ -1,3 +0,0 @@ -#spells { - padding: 4px; -} \ No newline at end of file diff --git a/rpg-docs/client/views/character/spells/spells.html b/rpg-docs/client/views/character/spells/spells.html index 8a7644de..182c686b 100644 --- a/rpg-docs/client/views/character/spells/spells.html +++ b/rpg-docs/client/views/character/spells/spells.html @@ -3,12 +3,23 @@
{{#each spellLists}} - -
-
{{name}}
+ +
+
+
{{name}}
+
+ {{#if saveDC}} + Save DC: {{evaluate charId saveDC}} +
+ {{/if}} + {{#if attackBonus}} + Attack Bonus: {{evaluateSigned charId attackBonus}} + {{/if}} +
+
{{#if maxPrepared}}
{{numPrepared}} / {{maxPrepared}}
{{/if}}
-
+
{{#each levels}} {{#if spellCount ../_id ../../_id}}
{{name}}
@@ -16,7 +27,9 @@ {{#each spells ../_id ../../_id}}
-
{{name}}
+ +
{{name}}
+
{{/each}} diff --git a/rpg-docs/client/views/character/spells/spells.js b/rpg-docs/client/views/character/spells/spells.js index 8513379e..37f328ed 100644 --- a/rpg-docs/client/views/character/spells/spells.js +++ b/rpg-docs/client/views/character/spells/spells.js @@ -1,31 +1,66 @@ var spellLevels = [ - { name: "Cantrips", level: 0 }, - { name: "Level 1", level: 1 }, - { name: "Level 2", level: 2 }, - { name: "Level 3", level: 3 }, - { name: "Level 4", level: 4 }, - { name: "Level 5", level: 5 }, - { name: "Level 6", level: 6 }, - { name: "Level 7", level: 7 }, - { name: "Level 8", level: 8 }, - { name: "Level 9", level: 9 }, + { name: "Cantrips", level: 0 }, + { name: "Level 1", level: 1 }, + { name: "Level 2", level: 2 }, + { name: "Level 3", level: 3 }, + { name: "Level 4", level: 4 }, + { name: "Level 5", level: 5 }, + { name: "Level 6", level: 6 }, + { name: "Level 7", level: 7 }, + { name: "Level 8", level: 8 }, + { name: "Level 9", level: 9 }, ]; Template.spells.helpers({ - spellLists: function(){ - return SpellLists.find({charId: this._id}); - }, + spellLists: function(){ + return SpellLists.find({charId: this._id}); + }, spellCount: function(listId, charId){ - console.log(listId, charId); return Spells.find( {charId: charId, listId: listId, level: this.level}, {fields: {_id: 1, level: 1}} ).count() > 0; }, - spells: function(listId, charId){ - return Spells.find( {charId: charId, listId: listId, level: this.level} ); - }, + spells: function(listId, charId){ + return Spells.find( {charId: charId, listId: listId, level: this.level} ); + }, levels: function(){ return spellLevels; }, numPrepared: function(){ return Spells.find({charId: Template.parentData()._id, listId: this._id, prepared: "prepared"}).count(); + }, + order: function(){ + return _.indexOf(_.keys(colorOptions), this.color); } -}) \ No newline at end of file +}); + +Template.spells.events({ + "tap .containerTop": function(event){ + GlobalUI.setDetail({ + template: "spellListDialog", + data: {spellListId: this._id, charId: this.charId}, + heroId: this._id + }); + }, + "tap #addSpellList": function(event){ + var charId = this.charId; + SpellLists.insert({ + name: "New SpellList", + charId: this._id, + saveDC: "8 + intelligenceMod + proficiencyBonus", + attackBonus: "intelligenceMod + proficiencyBonus" + }, function(error, id){ + if(!error){ + GlobalUI.setDetail({ + template: "spellListDialog", + data: {spellListId: id, charId: charId}, + heroId: id + }); + } + }); + }, + "downAction .castButton": function(event){ + event.stopPropagation() + }, + "upAction .castButton": function(event){ + event.stopPropagation() + } +}); diff --git a/rpg-docs/client/views/layout/imports.html b/rpg-docs/client/views/layout/imports.html index d9af3669..168141aa 100644 --- a/rpg-docs/client/views/layout/imports.html +++ b/rpg-docs/client/views/layout/imports.html @@ -6,6 +6,7 @@ +