diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-09-25 14:23:01 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-02-18 11:54:52 +0100 |
commit | 5a84afa4f4ae02dcc38cc752be4c2a7b801c7c4d (patch) | |
tree | 3f284a1b9bc81f105e8e8affba179076ea6220bc /play.js | |
parent | f6f01f7536b21bdea793de78238f4deebc48572c (diff) | |
download | wilderness-war-5a84afa4f4ae02dcc38cc752be4c2a7b801c7c4d.tar.gz |
Space tool tips in log.
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -285,6 +285,18 @@ function on_blur_bpa() { document.getElementById("status").textContent = "" } +function on_focus_space_tip(s) { + ui.space_list[s].classList.add("tip") +} + +function on_blur_space_tip(s) { + ui.space_list[s].classList.remove("tip") +} + +function on_click_space_tip(s) { + ui.space_list[s].scrollIntoView({ block:"center", inline:"center", behavior:"smooth" }) +} + function on_log_line(text, cn) { let p = document.createElement("div") if (cn) p.className = cn @@ -292,6 +304,12 @@ function on_log_line(text, cn) { return p } +function sub_space_name(match, p1, offset, string) { + let s = p1 | 0 + let n = spaces[s].name + return `<span class="spacetip" onmouseenter="on_focus_space_tip(${s})" onmouseleave="on_blur_space_tip(${s})" onclick="on_click_space_tip(${s})">${n}</span>` +} + function on_log(text) { let p = document.createElement("div") text = text.replace(/&/g, "&") @@ -299,6 +317,8 @@ function on_log(text) { text = text.replace(/>/g, ">") text = text.replace(/#(\d+)[^\]]*\]/g, '<span class="tip" onmouseenter="on_focus_card_tip($1)" onmouseleave="on_blur_card_tip()">$&</span>') + text = text.replace(/%(\d+)/g, sub_space_name) + if (text.match(/^\.h1/)) { text = text.substring(4) p.className = 'h1' @@ -387,6 +407,7 @@ let ui = { pieces: document.getElementById("pieces"), cards: document.getElementById("cards"), last_card: document.getElementById("last_card"), + space_list: [], } const marker_info = { @@ -895,6 +916,8 @@ function build_space(id) { elt.classList.add(pieces[box_leader(id)].faction) ui.spaces.appendChild(elt) + + ui.space_list[id] = elt } function build_leader(id) { |