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.css | 11 +++++++++++ play.js | 43 +++++++++++++++++++++++++++++++++++-------- rules.js | 23 +++++++++++++++++++++-- 3 files changed, 67 insertions(+), 10 deletions(-) diff --git a/play.css b/play.css index 3f9e331..0ea7f5a 100644 --- a/play.css +++ b/play.css @@ -116,6 +116,17 @@ body.America header.your_turn { background-color: hsl(211, 50%, 75%) } /* MARKERS */ +#combat { + position: absolute; + pointer-events: none; + width: 48px; + height: 48px; + background-image: url(bang.svg); + background-size: contain; + background-repeat: no-repeat; + z-index: 2000; +} + .marker { position: absolute; background-size: 100%; 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) diff --git a/rules.js b/rules.js index 8132a93..b644ddf 100644 --- a/rules.js +++ b/rules.js @@ -1753,6 +1753,7 @@ states.ops_british_reinforcements_where = { view.prompt = "Reinforcements: choose a port space." view.prompt += " Carrying " + game.count + " British CU." view.move = { from: BRITISH_REINFORCEMENTS, to: BRITISH_REINFORCEMENTS, who: game.who, carry_british: game.count } + view.selected_general = game.who gen_british_reinforcements_where() }, drop_british_cu() { @@ -1795,6 +1796,7 @@ states.ops_american_reinforcements_where = { prompt() { view.prompt = "Reinforcements: choose a space." view.move = { from: AMERICAN_REINFORCEMENTS, to: AMERICAN_REINFORCEMENTS, who: game.who, carry_american: game.count } + view.selected_general = game.who gen_american_reinforcements_where(game.who) }, space(space) { @@ -2097,6 +2099,8 @@ states.ops_general_move = { format_move_prompt() view.prompt += " " + game.move.count + " MP left." + view.selected_general = view.move.who + // Cannot stop on enemy general if (!has_enemy_general(location_of_general(game.move.who))) view.actions.stop = 1 @@ -2187,6 +2191,7 @@ states.confirm_move_intercept = { prompt() { format_move_prompt() view.prompt += " You may be intercepted." + view.selected_general = view.move.who view.actions.next = 1 }, next() { @@ -2198,6 +2203,7 @@ states.confirm_move_battle = { prompt() { format_move_prompt() view.prompt += " Approach battle?" + view.selected_general = view.move.who view.actions.next = 1 }, next() { @@ -2407,11 +2413,13 @@ states.intercept_who = { states.intercept_roll = { prompt() { - view.prompt = "Intercept " + game.move.who + " at " + game.move.to + "?" + view.prompt = "Intercept " + general_name(game.move.who) + " at " + space_name(game.move.to) + " with " + general_name(game.intercept.who) + "?" + view.selected_general = game.intercept.who view.react = game.intercept view.actions.roll = 1 }, roll() { + clear_undo() let g = game.intercept.who let die = roll_d6() if (die <= GENERALS[g].agility) { @@ -2427,7 +2435,9 @@ states.intercept_roll = { } else { log(g + " failed to intercept (" + die + " > " + GENERALS[g].agility + ")") delete game.intercept - if (!can_intercept_to(game.move.to)) + if (can_intercept_to(game.move.to)) + game.state = "intercept_who" + else end_intercept() } }, @@ -2499,6 +2509,7 @@ function goto_retreat_before_battle() { states.retreat_before_battle = { prompt() { view.prompt = "Attempt retreat before battle?" + view.selected_general = find_american_or_french_general(game.move.to) view.actions.pass = 1 gen_defender_retreat() }, @@ -2514,6 +2525,7 @@ states.retreat_before_battle = { game.state = "retreat_before_battle_roll" }, pass() { + clear_undo() end_retreat_before_battle() }, } @@ -2521,6 +2533,7 @@ states.retreat_before_battle = { states.retreat_before_battle_roll = { prompt() { view.prompt = "Attempt retreat before battle?" + view.selected_general = find_american_or_french_general(game.move.to) view.react = game.retreat view.actions.roll = 1 // TODO: choose which CU to retreat with if mix of french/american @@ -3075,6 +3088,11 @@ function gen_defender_retreat() { let is_lone = is_general_without_cu(here) let can_retreat = false + if (game.active === P_BRITAIN) + view.selected_general = find_british_general(here) + else + view.selected_general = find_american_or_french_general(here) + for (let to of SPACES[here].adjacent) { if (can_defender_retreat(to, is_lone)) { gen_action_space(to) @@ -3100,6 +3118,7 @@ function gen_defender_retreat() { } function gen_attacker_retreat() { + view.selected_general = game.move.who if (can_attacker_retreat()) gen_action_space(game.move.from) else -- cgit v1.2.3