From 1c953368435de1be49f861d7717471dd28a17992 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Tue, 13 Nov 2018 12:01:40 +0200 Subject: [PATCH] Spell slot bubbles are limited to 10, overflow is shown numerically fixes #150 --- app/client/views/character/spells/spells.html | 18 ++++++++----- app/client/views/character/spells/spells.js | 26 +++++++++++++++---- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/app/client/views/character/spells/spells.html b/app/client/views/character/spells/spells.html index c992daa4..fb7b2a90 100644 --- a/app/client/views/character/spells/spells.html +++ b/app/client/views/character/spells/spells.html @@ -11,16 +11,20 @@
{{#each levels}}{{#if showSlots ..}}
-
-
+
+
{{name}}
-
+
{{#each slotBubbles ..}} - - + {{#unless overflow}} + + + {{else}} +
+{{overflow}}
+ {{/unless}} {{/each}}
diff --git a/app/client/views/character/spells/spells.js b/app/client/views/character/spells/spells.js index df7a68af..e9839200 100644 --- a/app/client/views/character/spells/spells.js +++ b/app/client/views/character/spells/spells.js @@ -122,6 +122,7 @@ Template.spells.helpers({ return false; }, slotBubbles: function(char){ + const MAX_SLOTS = 10; var baseSlots = Characters.calculate.attributeBase( char._id, "level" + this.level + "SpellSlots" ); @@ -130,16 +131,28 @@ Template.spells.helpers({ ); var slotsUsed = baseSlots - currentSlots; var bubbles = []; - var i; - for (i = 0; i < currentSlots; i++){ + var i, overflowFilled, overflowEmpty; + var filledSlots = currentSlots; + var maxEmptySlots = Math.max(MAX_SLOTS - filledSlots + 1, 1); + var emptySlots = slotsUsed; + if (baseSlots > MAX_SLOTS){ + filledSlots = Math.min(MAX_SLOTS, filledSlots); + overflowFilled = Math.max(currentSlots - MAX_SLOTS, 0); + emptySlots = Math.min(maxEmptySlots, emptySlots); + overflowEmpty = Math.max(slotsUsed - maxEmptySlots, 0); + } + for (i = 0; i < filledSlots; i++){ bubbles.push({ icon: "radio-button-checked", - disabled: i !== currentSlots - 1 || !canEditCharacter(char._id), //last full slot not disabled + disabled: i !== filledSlots - 1 || !canEditCharacter(char._id), //last full slot not disabled attribute: "level" + this.level + "SpellSlots", charId: char._id, }); } - for (i = 0; i < slotsUsed; i++){ + if (overflowFilled){ + bubbles.push({overflow: overflowFilled}); + } + for (i = 0; i < emptySlots; i++){ bubbles.push({ icon: "radio-button-unchecked", disabled: i !== 0 || !canEditCharacter(char._id), //first empty slot not disabled @@ -147,6 +160,9 @@ Template.spells.helpers({ charId: char._id, }); } + if (overflowEmpty){ + bubbles.push({overflow: overflowEmpty}); + } return bubbles; }, slotStatName: function() { @@ -178,7 +194,7 @@ Template.spells.events({ } event.stopPropagation(); }, - "click .spellSlot": function(event, instance) { + "click .spellLevelName": function(event, instance) { var name = "Level " + this.level + " Spell Slots"; var stat = "level" + this.level + "SpellSlots"; var charId = instance.data._id;