summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-07-22 13:03:57 +0200
committerTor Andersson <tor@ccxvii.net>2022-11-17 13:11:25 +0100
commitbacef63f254d26e593bb59dc4799eee495136f06 (patch)
tree0c61f1625170a446c3401af9f82812f3b105ca06 /play.js
parent8908ec3b58873ce501ff3e19ac3167acd4d66fe8 (diff)
downloadrommel-in-the-desert-bacef63f254d26e593bb59dc4799eee495136f06.tar.gz
clean up normal battles and some logging stuff
Diffstat (limited to 'play.js')
-rw-r--r--play.js49
1 files changed, 49 insertions, 0 deletions
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 `<span class="hex" onmouseenter="on_focus_hex_tip(${x})" onmouseleave="on_blur_hex_tip(${x})">${n}</span>`
+}
+
+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, "&amp;")
+ text = text.replace(/</g, "&lt;")
+ text = text.replace(/>/g, "&gt;")
+
+ 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")