From 5946fbf8041947ac65d1a07b412a28035cef5264 Mon Sep 17 00:00:00 2001 From: U~man Date: Sat, 11 Jul 2020 22:00:52 +0200 Subject: [PATCH] ENH: Weapon tags --- src/lang/en.json | 1 + src/module/actor/character-sheet.js | 2 - src/module/item/item-sheet.js | 50 ++++++++++++++- src/scss/character.scss | 5 +- src/scss/item.scss | 39 +++++++++--- src/template.json | 1 + src/templates/items/weapon-sheet.html | 89 +++++++++++++++++++++++---- 7 files changed, 159 insertions(+), 28 deletions(-) diff --git a/src/lang/en.json b/src/lang/en.json index d5de8bb..be33de5 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -173,6 +173,7 @@ "OSE.items.roundAttacksMax": "Maximum Attacks per Round", "OSE.items.resetAttacks": "Reset all Attacks per Round", "OSE.items.hasShield": "Has a Shield bonus", + "OSE.items.typeTag": "Type a comma separated list of tag e.g 'Melee,Missile (5’–10’ / 11’–20’ / 21’–30’)'", "OSE.armor.type": "Armor Type", "OSE.armor.unarmored": "Unarmored", diff --git a/src/module/actor/character-sheet.js b/src/module/actor/character-sheet.js index 6d63a6c..4d40fcb 100644 --- a/src/module/actor/character-sheet.js +++ b/src/module/actor/character-sheet.js @@ -183,7 +183,6 @@ export class OseActorSheetCharacter extends OseActorSheet { let update = duplicate(data[table]); this._chooseLang().then((dialogInput) => { const name = CONFIG.OSE.languages[dialogInput.choice]; - console.log(name); if (update.value) { update.value.push(name); } else { @@ -200,7 +199,6 @@ export class OseActorSheetCharacter extends OseActorSheet { _popLang(table, lang) { const data = this.actor.data.data; let update = data[table].value.filter((el) => el != lang); - console.log(update); let newData = {}; newData[table] = { value: update }; return this.actor.update({ data: newData }).then(() => { diff --git a/src/module/item/item-sheet.js b/src/module/item/item-sheet.js index 464cd64..4d27b0d 100644 --- a/src/module/item/item-sheet.js +++ b/src/module/item/item-sheet.js @@ -18,8 +18,8 @@ export class OseItemSheet extends ItemSheet { static get defaultOptions() { return mergeObject(super.defaultOptions, { classes: ["ose", "sheet", "item"], - width: 500, - height: 370, + width: 520, + height: 380, resizable: false, tabs: [ { @@ -51,11 +51,57 @@ export class OseItemSheet extends ItemSheet { /* -------------------------------------------- */ + _pushTag(values) { + const data = this.object.data.data; + let update = []; + if (data.tags) { + update = duplicate(data.tags); + } + var regExp = /\(([^)]+)\)/; + if (update) { + values.forEach(val => { + // Catch infos in brackets + var matches = regExp.exec(val); + let title = ""; + if (matches) { + title = matches[1]; + val = val.substring(0, matches.index); + } + update.push({title: title, value: val}); + }) + } else { + update = values; + } + let newData = { + tags: update + }; + return this.object.update({ data: newData }); + } + + _popTag(value) { + const data = this.object.data.data; + let update = data.tags.filter((el) => el.value != value); + let newData = { + tags: update + }; + return this.object.update({ data: newData }); + } /** * Activate event listeners using the prepared sheet HTML * @param html {HTML} The prepared HTML object ready to be rendered into the DOM */ activateListeners(html) { + html.find('input[data-action="add-tag"]').keypress((ev) => { + if (event.which == 13) { + let value = $(ev.currentTarget).val(); + let values = value.split(','); + this._pushTag(values); + } + }); + html.find('.tag-delete').click((ev) => { + let value = ev.currentTarget.parentElement.dataset.tag; + this._popTag(value); + }); super.activateListeners(html); } } diff --git a/src/scss/character.scss b/src/scss/character.scss index 97b6071..2ad4d6b 100644 --- a/src/scss/character.scss +++ b/src/scss/character.scss @@ -41,9 +41,8 @@ } } .resources { - margin: 20px; display: flex; - justify-content: space-around; + justify-content: space-evenly; flex-direction: column; .attribute { flex: 0 0 55px; @@ -86,7 +85,7 @@ .tox .tox-tbtn { height: 24px; } - height: 100px; + height: 110px; } } &.notes { diff --git a/src/scss/item.scss b/src/scss/item.scss index 2811145..54f769e 100644 --- a/src/scss/item.scss +++ b/src/scss/item.scss @@ -1,8 +1,31 @@ .ose.sheet.item { - .profile-img { - border: none; - flex: 0 0 84px; - height: 84px; + .sheet-header { + .profile-img { + border: none; + flex: 0 0 84px; + height: 84px; + } + .tag-list { + margin: 0; + height: 20px; + overflow: auto; + list-style: none; + padding: 0; + display: flex; + .tag { + background: $colorFaint; + border-radius: 10px; + color: $colorDark; + padding: 2px 5px; + box-shadow: 0 0 1px $colorDark; + margin: 0 2px; + i { + font-size: 8px; + vertical-align: top; + color: $colorOlive; + } + } + } } .sheet-body { .stats { @@ -29,8 +52,6 @@ } &.narrow { .form-group { - label { - } input { height: 18px; } @@ -40,8 +61,10 @@ .editor { height: 240px; } - .weapon-editor .editor { - height: 215px; + .weapon-editor { + .editor { + height: 215px; + } } } } diff --git a/src/template.json b/src/template.json index 4cb0e2e..943c0a6 100644 --- a/src/template.json +++ b/src/template.json @@ -171,6 +171,7 @@ "description": "", "damage": "1d6", "bonus": 0, + "tags": [], "qualities": "", "slow": false, "missile": true, diff --git a/src/templates/items/weapon-sheet.html b/src/templates/items/weapon-sheet.html index b129f2d..b832a30 100644 --- a/src/templates/items/weapon-sheet.html +++ b/src/templates/items/weapon-sheet.html @@ -1,58 +1,121 @@
- +

- +

+
    + {{#each data.tags as |tag|}} +
  1. + {{tag.value}} + +
  2. + {{/each}} +
-
- -
+
+
+ +
+
- +
- +
- +
- +
- +
- +
- +
@@ -62,4 +125,4 @@
-
\ No newline at end of file +