diff options
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -97,6 +97,7 @@ let ui = { onmap: document.getElementById("units"), focus: null, + loaded: false, } const AXIS = 'Axis' @@ -522,6 +523,8 @@ function build_hexes() { ui.benghazi = document.getElementById("mapsvg").getElementById("fortress_benghazi") ui.bardia = document.getElementById("mapsvg").getElementById("fortress_bardia") ui.tobruk = document.getElementById("mapsvg").getElementById("fortress_tobruk") + + ui.loaded = true } function build_units() { @@ -565,7 +568,6 @@ function build_cards() { build_card(i, false) } -build_hexes() build_units() build_cards() @@ -761,6 +763,11 @@ function target_button(action) { } function on_update() { + if (!ui.loaded) { + document.getElementById("prompt").textContent = "Waiting for map..." + return setTimeout(on_update, 500) + } + update_map() update_cards() @@ -899,3 +906,17 @@ function on_log(text) { drag_element_with_mouse("#battle", "#battle_header") drag_element_with_mouse("#pursuit", "#pursuit_header") scroll_with_middle_mouse("main") + +fetch("map.svg") + .then(r => { + if (!r.ok) + throw new Error("Could not fetch \"map.svg\": " + r.statusText) + return r.text() + }) + .then(text => { + document.getElementById("mapsvg").outerHTML = text + build_hexes() + }) + .catch(error => { + window.alert(error.message) + }) |