From 78bc73ae429395406382c5adea0f7f59b6c56360 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 4 Aug 2024 14:12:04 +0200 Subject: tweak army layout --- play.js | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'play.js') 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) -- cgit v1.2.3