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/index.html | 5 | ||||
-rw-r--r-- | src/index.js | 5 | ||||
-rw-r--r-- | src/modules/map_select_dialog.js | 13 | ||||
-rw-r--r-- | src/modules/scenarios.js | 15 |
4 files changed, 21 insertions, 17 deletions
diff --git a/public/index.html b/public/index.html index c30ac99..5badb7c 100644 --- a/public/index.html +++ b/public/index.html @@ -227,13 +227,10 @@ <label> Load scenario: <select> - <!-- <option value="scenario-side_show">BattleTroops Scenario 1: Side Show</option> - <option value="scenario-dragon_hunting">BattleTroops Scenario 2: Dragon Hunting</option> - <option value="scenario-race_against_time">BattleTroops Scenario 3: Race Against Time</option> <option value="map4">Test</option> <option value="contour-lines">Contour Lines</option> <option value="pendle">Pendle</option> - <option value="10-simplex_t03">10-simplex family polytope graph, in A10 Coxeter plane</option> --> + <option value="10-simplex_t03">10-simplex family polytope graph, in A10 Coxeter plane</option> </select> </label> </p> diff --git a/src/index.js b/src/index.js index d677b01..992366a 100644 --- a/src/index.js +++ b/src/index.js @@ -3,7 +3,7 @@ import * as gameboard from './modules/gameboard.js'; import * as recordSheet from './modules/record_sheet.js'; import * as mapSelectDialog from './modules/map_select_dialog.js'; import { Observable } from './modules/observable.js'; -import sideShow from './assets/images/scenario-side_show.svg'; +import { scenarios } from './modules/scenarios.js'; globalThis.svgns = 'http://www.w3.org/2000/svg'; @@ -13,8 +13,7 @@ const mapPlaceholder = document.querySelector('.map-placeholder'), contentVisToggleEl = document.querySelector('#content input[type="checkbox"].visible'), // fileName = localStorage.getItem('map') || (env === 'test' ? 'test_map' : 'map1'), fileName = localStorage.getItem('map') || 'scenario-side_show', - // map = `assets/images/${fileName}.svg`, - map = sideShow, + map = scenarios[fileName]?.hashed || `assets/images/${fileName}.svg`, fileInputEl = document.querySelector('input[type="file"]'), dice = document.querySelectorAll('.die'), diff --git a/src/modules/map_select_dialog.js b/src/modules/map_select_dialog.js index 24215f6..359477d 100644 --- a/src/modules/map_select_dialog.js +++ b/src/modules/map_select_dialog.js @@ -6,17 +6,17 @@ export function init() { selectEl = mapDialog.querySelector('select'), confirmBtn = mapDialog.querySelector('#confirm-btn'); - Object.keys(scenarios).forEach(scenario => { + Object.keys(scenarios).reverse().forEach(scenario => { const option = document.createElement('option'); option.setAttribute('value', scenario); - option.textContent = scenarios[scenario]; - selectEl.appendChild(option); + option.textContent = scenarios[scenario].title; + selectEl.prepend(option); }); return { selectCurrentOptionOnPageLoad() { - mapDialog.querySelectorAll('option').forEach(option => - option.value === localStorage.getItem('map') && (option.selected = true) + mapDialog.querySelectorAll('option').forEach((option, index) => + option.selected = option.value === localStorage.getItem('map') || index === 0 ); return this; @@ -43,8 +43,7 @@ export function init() { e.preventDefault(); localStorage.removeItem('pan-zoom'); localStorage.setItem('map', selectEl.value); - // loadFn(`assets/images/${selectEl.value}.svg`); - loadFn(selectEl.value); + loadFn(scenarios[selectEl.value]?.hashed || `assets/images/${selectEl.value}.svg`); mapDialog.close(); }); } diff --git a/src/modules/scenarios.js b/src/modules/scenarios.js index afe375f..2a4af26 100644 --- a/src/modules/scenarios.js +++ b/src/modules/scenarios.js @@ -3,7 +3,16 @@ import dragonHunting from './assets/images/scenario-dragon_hunting.svg'; import raceAgainstTime from './assets/images/scenario-race_against_time.svg'; export const scenarios = { - [sideShow]: 'BattleTroops Scenario 1: Side Show', - [dragonHunting]: 'BattleTroops Scenario 2: Dragon Hunting', - [raceAgainstTime]: 'BattleTroops Scenario 3: Race Against Time', + 'scenario-side_show': { + hashed: sideShow, + title: 'BattleTroops Scenario 1: Side Show', + }, + 'scenario-dragon_hunting': { + hashed: dragonHunting, + title: 'BattleTroops Scenario 2: Dragon Hunting', + }, + 'scenario-race_against_time': { + hashed: raceAgainstTime, + title: 'BattleTroops Scenario 3: Race Against Time', + }, } |