From bacef63f254d26e593bb59dc4799eee495136f06 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 22 Jul 2022 13:03:57 +0200 Subject: clean up normal battles and some logging stuff --- play.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'play.js') diff --git a/play.js b/play.js index 75290bb..e3b22b4 100644 --- a/play.js +++ b/play.js @@ -624,6 +624,55 @@ function on_update() { action_button("undo", "Undo") } +function sub_hex_name(match, p1, offset, string) { + let x = p1 | 0 + let n = hex_name[x] + return `${n}` +} + +function sub_unit_name(match, p1, offset, string) { + let u = p1 | 0 + return units[u].name +} + +function on_log(text) { + let p = document.createElement("div") + text = text.replace(/&/g, "&") + text = text.replace(//g, ">") + + text = text.replace(/#(\d+)/g, sub_hex_name) + text = text.replace(/%(\d+)/g, sub_unit_name) + + if (text.match(/^\.h1/)) { + text = text.substring(4) + p.className = 'h1' + } + if (text.match(/^\.h2/)) { + text = text.substring(4) + if (text.startsWith('Axis')) + p.className = 'h2 axis' + else if (text.startsWith('Allied')) + p.className = 'h2 allied' + else + p.className = 'h2' + } + if (text.match(/^\.h3/)) { + text = text.substring(4) + p.className = 'h3' + } + + if (text.indexOf("\n") < 0) { + p.innerHTML = text + } else { + text = text.split("\n") + p.appendChild(on_log_line(text[0])) + for (let i = 1; i < text.length; ++i) + p.appendChild(on_log_line(text[i], "indent")) + } + return p +} + drag_element_with_mouse("#battle", "#battle_header") drag_element_with_mouse("#pursuit", "#pursuit_header") scroll_with_middle_mouse("main") -- cgit v1.2.3