summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
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")