mirror of
https://github.com/db9979/uconsole_asw_game.git
synced 2026-12-06 12:54:18 +01:00
Web damage control: team cards with compartment names and status, click picks the team
The browser's repair-team list showed raw compartment keys ("engine",
"sonar") and no state. Each team card now names its destination in the
player's language (or "free"), says whether the team is standing by, on
the way (seconds left) or on scene, carries a matching stripe, frames the
team the selector holds, and a click or Enter on a card picks that team
for the next assignment. The compartment rows drop the raw key row. The
damage projection gains each team's transit_s.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AYDCcBWFmT4ipVCfJeKESR
This commit is contained in:
7 files changed
+61
-7
No files matched your search
@@ -372,3 +372,11 @@ body.shock-dust::after {
|
||||
.mic-problem p { flex: 1 1 100%; margin: 0; color: var(--caution); font-size: var(--font-sm); line-height: 1.35; }
|
||||
.mic-problem button { min-height: 2rem; font-size: var(--font-xs); }
|
||||
.mic-problem #mic-problem-close { margin-left: auto; min-width: 2rem; }
|
||||
/* Damage-control team cards: stripe by state, the picked team framed; a
|
||||
click picks the team for the next assignment. */
|
||||
.station-row.team-card { cursor: pointer; }
|
||||
.station-row.team-card[data-state="ready"] { border-left-color: var(--muted); }
|
||||
.station-row.team-card[data-state="transit"] { border-left-color: var(--caution); }
|
||||
.station-row.team-card[data-state="scene"] { border-left-color: var(--live); }
|
||||
.station-row.team-card.selected { border-color: var(--focus); border-left-width: 3px; background: var(--live-bg); }
|
||||
.station-row.team-card:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
|
||||
@@ -612,7 +612,7 @@ export function validateV2State(state) {
|
||||
rowsExact(payload.target_choices, 128, ["ref", "label", "domain", "source", "affiliation", "classification", "bearing", "range_nm", "x", "y", "depth_m", "course", "speed_kn", "quality", "age_s", "fix_age_s", "bearing_uncertainty_deg", "range_uncertainty_nm"]);
|
||||
} else if (state.role === "damage") {
|
||||
if (!crewOk(payload.crew) || !boundedArray(payload.compartments, 16) || payload.compartments.some((row) => !exactKeys(row, ["key", "name", "state", "flood", "fire", "leak", "inflow", "repairable", "trend"]) || typeof row.repairable !== "boolean" || !["none", "open", "patched"].includes(row.leak) || !finite(row.inflow) || !exactKeys(row.trend, ["flood_rate", "fire_rate", "repairable"])) ||
|
||||
!boundedArray(payload.teams, 16) || payload.teams.some((row) => !exactKeys(row, ["team", "compartment"])) ||
|
||||
!boundedArray(payload.teams, 16) || payload.teams.some((row) => !exactKeys(row, ["team", "compartment", "transit_s"]) || !finite(row.transit_s) || row.transit_s < 0) ||
|
||||
!exactKeys(payload.stability, ["list_deg", "draft_m", "trim_deg", "counterflood_room", "can_counterflood"]) || !finite(payload.stability.draft_m) ||
|
||||
typeof payload.stability.can_counterflood !== "boolean") throw new Error("protocol");
|
||||
} else if (state.role === "opz") {
|
||||
|
||||
@@ -7,6 +7,37 @@ function compartmentName(payload, key) {
|
||||
return payload.compartments.find((room) => room.key === key)?.name || key;
|
||||
}
|
||||
|
||||
function teamStatus(team) {
|
||||
if (!team.compartment) return t("damage_team_ready");
|
||||
return team.transit_s > 0 ? t("damage_team_en_route", {seconds: number(team.transit_s, 0)})
|
||||
: t("damage_team_on_scene");
|
||||
}
|
||||
|
||||
// Team cards: the team the selector holds is highlighted, and a click on a
|
||||
// card picks that team for the next assignment (like the selector).
|
||||
function markTeams(list, teams, selector) {
|
||||
[...list.children].forEach((card) => {
|
||||
const team = teams.find((item) => String(item.team) === card.dataset.rowKey);
|
||||
if (!team) return;
|
||||
card.classList.add("team-card");
|
||||
card.dataset.state = !team.compartment ? "ready" : team.transit_s > 0 ? "transit" : "scene";
|
||||
card.classList.toggle("selected", selector.value === String(team.team));
|
||||
if (!card.dataset.pick) {
|
||||
card.dataset.pick = "1";
|
||||
card.tabIndex = 0;
|
||||
const pick = () => {
|
||||
selector.value = card.dataset.rowKey;
|
||||
selector.dispatchEvent(new Event("change", {bubbles: true}));
|
||||
[...list.children].forEach((other) => other.classList.toggle("selected", other === card));
|
||||
};
|
||||
card.addEventListener("click", pick);
|
||||
card.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Enter" || event.key === " ") { event.preventDefault(); pick(); }
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function renderDamageStation(payload) {
|
||||
metrics($("damage-summary"), [["damage_total", unit(payload.total, "%")], ["sunk", yesNo(payload.sunk)]]);
|
||||
renderCrew($("damage-crew"), $("damage-crew-actions"), payload.crew,
|
||||
@@ -21,9 +52,12 @@ export function renderDamageStation(payload) {
|
||||
valve.disabled = !stability.counterflood_room && !stability.can_counterflood;
|
||||
const selector = $("damage-team");
|
||||
setOptions(selector, payload.teams.map((team) => [String(team.team), number(team.team, 0)]));
|
||||
stationRows($("damage-teams"), payload.teams, (team) => [["team", team.team], ["compartment", team.compartment]]);
|
||||
stationRows($("damage-teams"), payload.teams, (team) => [["team", t("damage_team_title", {team: team.team})],
|
||||
["compartment", team.compartment ? compartmentName(payload, team.compartment) : t("damage_team_free")],
|
||||
["state", teamStatus(team)]]);
|
||||
markTeams($("damage-teams"), payload.teams, selector);
|
||||
stationRows($("damage-compartments"), payload.compartments, (room) => [["compartment", room.name],
|
||||
["reference", room.key], ["state", enumText(damageStates, room.state)], ["flood", unit(room.flood, "%")],
|
||||
["state", enumText(damageStates, room.state)], ["flood", unit(room.flood, "%")],
|
||||
["fire", unit(room.fire, "%")], ["flood_trend", number(room.trend.flood_rate, 2)],
|
||||
["fire_trend", number(room.trend.fire_rate, 2)], ["damage_repairable", yesNo(room.repairable)]], "station_none", (room) =>
|
||||
payload.teams.map((team) => actionButton(team.compartment === room.key ? "damage_unassign" : "damage_assign",
|
||||
|
||||
+6
-1
@@ -7493,5 +7493,10 @@
|
||||
"damage.panel.teams": "LECKWEHRTRUPPS",
|
||||
"damage.card.team_ready": "In Bereitschaft",
|
||||
"damage.card.team_en_route": "Unterwegs · {eta} s",
|
||||
"damage.teams.hint": "Trupp anklicken, links eine Abteilung wählen, Enter schickt ihn los."
|
||||
"damage.teams.hint": "Trupp anklicken, links eine Abteilung wählen, Enter schickt ihn los.",
|
||||
"commander.web.damage_team_title": "Trupp {team}",
|
||||
"commander.web.damage_team_free": "frei",
|
||||
"commander.web.damage_team_ready": "In Bereitschaft",
|
||||
"commander.web.damage_team_en_route": "Unterwegs · {seconds} s",
|
||||
"commander.web.damage_team_on_scene": "Vor Ort"
|
||||
}
|
||||
+6
-1
@@ -7493,5 +7493,10 @@
|
||||
"damage.panel.teams": "REPAIR TEAMS",
|
||||
"damage.card.team_ready": "Standing by",
|
||||
"damage.card.team_en_route": "On the way · {eta} s",
|
||||
"damage.teams.hint": "Click a team, pick a compartment on the left, then Enter sends it."
|
||||
"damage.teams.hint": "Click a team, pick a compartment on the left, then Enter sends it.",
|
||||
"commander.web.damage_team_title": "Team {team}",
|
||||
"commander.web.damage_team_free": "free",
|
||||
"commander.web.damage_team_ready": "Standing by",
|
||||
"commander.web.damage_team_en_route": "On the way · {seconds} s",
|
||||
"commander.web.damage_team_on_scene": "On scene"
|
||||
}
|
||||
@@ -913,7 +913,9 @@ def _damage(game):
|
||||
for key, value in game.damage.compartment_trend(
|
||||
room.key).items()})
|
||||
for room in game.damage.compartments.values()]
|
||||
teams = [dict(team=team, compartment=game.damage.teams[team])
|
||||
teams = [dict(team=team, compartment=game.damage.teams[team],
|
||||
transit_s=_number(max(0.0, float(game.damage.team_eta.get(team, 0.0)))
|
||||
if game.damage.teams[team] is not None else 0.0))
|
||||
for team in sorted(game.damage.teams)]
|
||||
return dict(compartments=compartments, teams=teams, crew=_crew(game),
|
||||
total=_number(game.damage.total), sunk=bool(game.damage.ship_sunk),
|
||||
|
||||
@@ -1093,7 +1093,7 @@ def _direct_fire_browser_states():
|
||||
compartments=[dict(key="engine", name="Engine", state="BESCHAEDIGT",
|
||||
flood=20.0, fire=10.0, leak="patched", inflow=0.0, repairable=True,
|
||||
trend=dict(flood_rate=.1, fire_rate=-.2, repairable=True))],
|
||||
teams=[dict(team=1, compartment=None), dict(team=2, compartment="engine")],
|
||||
teams=[dict(team=1, compartment=None, transit_s=0.0), dict(team=2, compartment="engine", transit_s=0.0)],
|
||||
total=15.0, sunk=False,
|
||||
stability=dict(list_deg=0.5, draft_m=7.5, trim_deg=-0.2, counterflood_room=None,
|
||||
can_counterflood=True), crew=_projected_crew()))
|
||||
|
||||
Reference in new issue
Block a user