index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
-rw-r--r-- | public/damage_block.css | 62 | ||||
-rw-r--r-- | public/index.html | 12 | ||||
-rw-r--r-- | public/soldier_record_block.js | 62 | ||||
-rw-r--r-- | src/index.js | 22 | ||||
-rw-r--r-- | src/modules/game.js | 3 |
5 files changed, 60 insertions, 101 deletions
diff --git a/public/damage_block.css b/public/damage_block.css index f050e36..cc7e4dc 100644 --- a/public/damage_block.css +++ b/public/damage_block.css @@ -1,64 +1,18 @@ -.damage-selector, .damage-effect-indicator, label { - width: 20px; -} - -.damage-selector, .damage-effect-indicator { - height: 30px; -} - -.damage-selector { - margin: 0; - padding: 0; - border: 1px solid black; - display: inline-block; -} - -.damage-effect-indicator { - position: absolute; - margin: 0; - padding: 0; - display: block; - pointer-events: none; - font-family: monospace; -} - -.damage-selector.clear { - background-color: white; -} - -.damage-selector.bruise { +.damage-effect-indicator.bruise { background-color: orange; } -.damage-selector.lethal { +.damage-effect-indicator.lethal { background-color: red; } -label input[type="radio"] { - position: absolute; - opacity: 0; - margin: 0; - padding: 0; -} - -label { - display: none; +.damage-effect-indicator { + width: 20px; + height: 30px; margin: 0 auto; padding: 0; -} - -label:first-of-type { - display: block; -} - -label:has(input:checked) { - display: none; -} - -label:has(+ label input:checked) { - display: none; -} - -label:has(input:checked) + label { + border: 1px solid black; display: block; + user-select: none; + font-family: monospace; } diff --git a/public/index.html b/public/index.html index 718654c..a7e84e0 100644 --- a/public/index.html +++ b/public/index.html @@ -13,18 +13,6 @@ <slot name="firing-modifier"></slot><br> <slot name="movement-points"></slot> </span> - <label> - <input type="radio" name="damage" checked> - <span class="damage-selector lethal"></span> - </label> - <label> - <input type="radio" name="damage"> - <span class="damage-selector clear"></span> - </label> - <label> - <input type="radio" name="damage"> - <span class="damage-selector bruise"></span> - </label> </template> <template id="soldier-record-block"> diff --git a/public/soldier_record_block.js b/public/soldier_record_block.js index b2465ab..fd1c661 100644 --- a/public/soldier_record_block.js +++ b/public/soldier_record_block.js @@ -1,40 +1,52 @@ -class SoldierRecordBlock extends HTMLDivElement { - constructor() { - super(); - - let template = document.getElementById('soldier-record-block'); - let templateContent = template.content; - - const shadowRoot = this.attachShadow({ mode: "open" }); - shadowRoot.appendChild(templateContent.cloneNode(true)); - - // console.log(shadowRoot) - - // this.shadowRoot - // .querySelectorAll('p:has(input[type="number"]), .physical-status-track') - // .forEach(el => el.addEventListener('click', e => e.stopPropagation())) - // ; - } -} - customElements.define( 'damage-block', class extends HTMLSpanElement { constructor() { super(); - let template = document.getElementById('damage-block'); - let templateContent = template.content; + const template = document.querySelector('#damage-block'), + templateContent = template.content, + shadowRoot = this.attachShadow({ mode: "open" }); - const shadowRoot = this.attachShadow({ mode: "open" }); shadowRoot.appendChild(templateContent.cloneNode(true)); } + + connectedCallback() { + const el = this.shadowRoot.querySelector('.damage-effect-indicator'); + + el.addEventListener('click', e => { + e.stopPropagation() + + this.#cycleThroughDamageStates(el); + }); + } + + #cycleThroughDamageStates(el) { + if (el.classList.contains('bruise')) { + el.classList.remove('bruise'); + el.classList.add('lethal'); + } else if (el.classList.contains('lethal')) { + el.classList.remove('lethal'); + } else { + el.classList.add('bruise'); + } + } }, { extends: 'span' } ); customElements.define( 'soldier-record-block', - SoldierRecordBlock, - { extends: 'div'} -);
\ No newline at end of file + class extends HTMLDivElement { + constructor() { + super(); + + const template = document.querySelector('#soldier-record-block'), + templateContent = template.content, + shadowRoot = this.attachShadow({ mode: "open" }); + + shadowRoot.appendChild(templateContent.cloneNode(true)); + } + }, + { extends: 'div' } +); diff --git a/src/index.js b/src/index.js index a0a99f4..fd679d2 100644 --- a/src/index.js +++ b/src/index.js @@ -3,18 +3,23 @@ import Game from './modules/game.js'; const PanZoom = new function () { const vb = 'viewBox'; + let svg; - function storeLatestViewBoxVal(svg) { + function storeViewBoxVal() { + localStorage.setItem(vb, svg.getAttribute(vb)); + } + + function observeViewBoxChanges() { const observer = new MutationObserver(mutations => { if (mutations.find(m => m.target == svg && m.attributeName == vb)) { - localStorage.setItem(vb, svg.getAttribute(vb)); + storeViewBoxVal(svg); } }); observer.observe(svg, { attributes: true }); } - function restoreViewboxVal(svg) { + function restoreViewBoxVal() { const storedVbVal = localStorage.getItem(vb); if (storedVbVal) { @@ -22,9 +27,7 @@ const PanZoom = new function () { } } - this.start = function (svg) { - restoreViewboxVal(svg); - + function addEventListeners() { svg.addEventListener('wheel', e => { e.preventDefault(); @@ -36,8 +39,13 @@ const PanZoom = new function () { pan(svg, e); }, { passive: false }); + } - storeLatestViewBoxVal(svg); + this.start = function (el) { + svg = el; + restoreViewBoxVal(); + addEventListeners(); + observeViewBoxChanges(); }; }; diff --git a/src/modules/game.js b/src/modules/game.js index 2903b05..0435c28 100644 --- a/src/modules/game.js +++ b/src/modules/game.js @@ -142,7 +142,6 @@ export default class Game { this.setUpSightLine(this); this.setUpCounter(this); - // this.setUpRecordSheet(); this.setUpCells(); } @@ -343,7 +342,6 @@ export default class Game { if (selected) { this.Counter.endMove(selected); - // this.RecordSheet.endMove(); } } @@ -557,7 +555,6 @@ export default class Game { } } else { e.stopPropagation(); - // this.RecordSheet.select(e.target); container.Counter.select(e.target); } }, |