diff options
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 75 |
1 files changed, 46 insertions, 29 deletions
@@ -62,38 +62,55 @@ let ui = { present: new Set(), } +function on_focus_space_tip(x) { + ui.areas[x].classList.add("tip") +} + +function on_blur_space_tip(x) { + ui.areas[x].classList.remove("tip") +} + +function on_click_space_tip(x) { + ui.areas[x].scrollIntoView({ block:"center", inline:"center", behavior:"smooth" }) +} + +function sub_space_name(match, p1, offset, string) { + let x = p1 | 0 + let n = AREAS[x].name + return `<span class="tip" onmouseenter="on_focus_space_tip(${x})" onmouseleave="on_blur_space_tip(${x})" onclick="on_click_space_tip(${x})">${n}</span>` +} + function on_log(text) { - let p = document.createElement("div"); - text = text.replace(/&/g, "&"); - text = text.replace(/</g, "<"); - text = text.replace(/>/g, ">"); - - text = text.replace(/\u2192 /g, "\u2192\xa0"); - - text = text.replace(/^([A-Z]):/, '<span class="$1"> $1 </span>'); - - if (text.match(/^Scenario: /)) { - p.className = 'st', text = text.substring(10); - } else if (text.match(/^~ .* ~$/)) { - p.className = 'br', text = text.substring(2, text.length-2); - } else if (text.match(/^Start Lancaster turn/)) { - text = "Lancaster"; - p.className = 'L'; - } else if (text.match(/^Start York turn/)) { - text = "York"; - p.className = 'Y'; - } else if (text.match(/^Start /)) { - p.className = 'st', text = text.replace(/\.$/, ""); - } else if (text.match(/^Battle in/)) { - text = text.substring(0,text.length-1); - p.className = 'bs'; - } + let p = document.createElement("div") + + if (text.match(/^>/)) { + text = text.substring(1) + p.className = "i" + } + + text = text.replace(/&/g, "&") + text = text.replace(/</g, "<") + text = text.replace(/>/g, ">") + + text = text.replace(/\u2192 /g, "\u2192\xa0") + + text = text.replace(/^([A-Z]):/, '<span class="$1"> $1 </span>') + + text = text.replace(/#(\d+)/g, sub_space_name) - if (text.match(/^Start /)) - text = text.substring(6); + if (text.match(/^\.h1 /)) + p.className = 'h1', text = text.substring(4) + if (text.match(/^\.h2 L/)) + p.className = 'h2 L', text = text.substring(4) + if (text.match(/^\.h2 Y/)) + p.className = 'h2 Y', text = text.substring(4) + if (text.match(/^\.h3 /)) + p.className = 'h3', text = text.substring(4) + if (text.match(/^\.h4 /)) + p.className = 'h4', text = text.substring(4) - p.innerHTML = text; - return p; + p.innerHTML = text + return p } function is_known_block(b) { |