summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-08-04 14:12:04 +0200
committerTor Andersson <tor@ccxvii.net>2024-08-21 00:28:20 +0200
commit78bc73ae429395406382c5adea0f7f59b6c56360 (patch)
treef41f846761d5502040e1d98ebe07526a97897262 /play.js
parent08a6dd93a3d475a9f9f666fe00505131e1bd231e (diff)
downloadwashingtons-war-78bc73ae429395406382c5adea0f7f59b6c56360.tar.gz
tweak army layout
Diffstat (limited to 'play.js')
-rw-r--r--play.js43
1 files changed, 35 insertions, 8 deletions
diff --git a/play.js b/play.js
index 7e6852b..3565ae4 100644
--- a/play.js
+++ b/play.js
@@ -318,12 +318,27 @@ function on_init() {
ui.french_navy = build_piece("marker large french_navy", 55+2, 55+2)
ui.turn_marker = build_piece("marker large turn", 55+2, 55+2)
ui.french_alliance = build_piece("marker large french_alliance", 55+2, 55+2)
+
+ ui.combat = document.createElement("div")
+ ui.combat.id = "combat"
}
on_init()
/* UPDATE UI */
+function lerp(a, b, t) {
+ return a + t * (b - a)
+}
+
+function show_combat_marker() {
+ let x = Math.round(lerp(data.spaces[view.move.from].x, data.spaces[view.move.to].x, 0.75))
+ let y = Math.round(lerp(data.spaces[view.move.from].y, data.spaces[view.move.to].y, 0.75))
+ ui.combat.style.left = x - 20 + "px"
+ ui.combat.style.top = y - 20 + "px"
+ ui.pieces_element.appendChild(ui.combat)
+}
+
function show_marker(e) {
ui.pieces_element.appendChild(e)
}
@@ -416,9 +431,9 @@ function get_army_xy_lerp(s1, s2) {
}
if (Math.abs(dx) < 180 && Math.abs(dy) < 60)
- y -= 40
+ y -= 20
- return [ x - 15 , y ]
+ return [ x - 15, y ]
}
function get_army_xy(s) {
@@ -441,6 +456,7 @@ function get_static_xy(s) {
} else {
x = data.spaces[s].x - 20
y = data.spaces[s].y + 15
+ y = data.spaces[s].y + 10
}
return [ x, y ]
}
@@ -540,6 +556,16 @@ function on_update() {
}
if (view.move) {
+ let xy = null
+ if (view.move.from === view.move.to &&
+ view.move.carry_american === count_american_cu(view.move.from) &&
+ view.move.carry_french === count_french_cu(view.move.from) &&
+ view.move.carry_british === count_british_cu(view.move.from)
+ )
+ xy = get_static_xy(view.move.from)
+ else
+ xy = get_army_xy_lerp(view.move.from, view.move.to)
+
ui.layout_move = layout_all_cu(
view.move.carry_american | 0,
view.move.carry_french | 0,
@@ -547,8 +573,11 @@ function on_update() {
ui.a_mcu,
ui.f_mcu,
ui.b_mcu,
- get_army_xy_lerp(view.move.from, view.move.to)
+ xy
)
+
+ if (view.move.from !== view.move.to)
+ show_combat_marker()
}
if (view.react) {
@@ -576,15 +605,13 @@ function on_update() {
let [ x, y ] = pos
- if (s >= 66)
- y -= 60
+ ui.generals[g].classList.toggle("selected", view.selected_general === g)
if (view.move && view.move.who === g) {
- ui.generals[g].classList.add("selected")
+ // already laid out
} else if (view.react && view.react.who === g) {
- ui.generals[g].classList.add("selected")
+ // already laid out
} else {
- ui.generals[g].classList.remove("selected")
if (s < 66) {
let offset = general_offset(g)