From 048c9064a827b55bce6dda74e2007d616a33964d Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 2 Oct 2022 22:55:13 +0200 Subject: New log format. --- play.js | 75 ++++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 29 deletions(-) (limited to 'play.js') diff --git a/play.js b/play.js index ea429df..ccac1cb 100644 --- a/play.js +++ b/play.js @@ -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 `${n}` +} + function on_log(text) { - let p = document.createElement("div"); - text = text.replace(/&/g, "&"); - text = text.replace(//g, ">"); - - text = text.replace(/\u2192 /g, "\u2192\xa0"); - - text = text.replace(/^([A-Z]):/, ' $1 '); - - 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(/\u2192 /g, "\u2192\xa0") + + text = text.replace(/^([A-Z]):/, ' $1 ') + + 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) { -- cgit v1.2.3