Skip to content

Commit c0dc6c7

Browse files
committed
Fix disabled ship UX and improve input handling
- Block burn/overload/weak-gravity input for disabled ships - Skip disabled and landed ships in ordnance phase selection - Tab key cycles ships in ordnance and combat phases too - Ordnance buttons disabled when selected ship lacks cargo capacity (mine needs 10, torpedo/nuke need 20 mass) - Button opacity indicates availability 138 tests passing.
1 parent 42d0bbc commit c0dc6c7

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

src/client/input.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export class InputHandler {
162162
// Check if clicking a burn or overload direction arrow
163163
if (this.planningState.selectedShipId) {
164164
const ship = this.gameState.ships.find(s => s.id === this.planningState.selectedShipId);
165-
if (ship && ship.fuel > 0) {
165+
if (ship && ship.fuel > 0 && ship.damage.disabledTurns === 0) {
166166
const currentBurn = this.planningState.burns.get(ship.id) ?? null;
167167
const predDest = ship.landed
168168
? computeCourse(ship, null, this.map).path[0] // launch hex
@@ -252,9 +252,10 @@ export class InputHandler {
252252
}
253253
}
254254

255-
// Check if clicking on own ship to select it
255+
// Check if clicking on own ship to select it (skip disabled/landed ships for ordnance)
256256
for (const ship of this.gameState.ships) {
257257
if (ship.owner !== this.playerId || ship.destroyed) continue;
258+
if (ship.damage.disabledTurns > 0 || ship.landed) continue;
258259
if (hexEqual(clickHex, ship.position)) {
259260
this.planningState.selectedShipId = ship.id;
260261
this.planningState.torpedoAccel = null;

src/client/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class GameClient {
6161

6262
// Keyboard shortcuts
6363
document.addEventListener('keydown', (e) => {
64-
if (e.key === 'Tab' && this.state === 'playing_astrogation' && this.gameState) {
64+
if (e.key === 'Tab' && this.gameState &&
65+
(this.state === 'playing_astrogation' || this.state === 'playing_ordnance' || this.state === 'playing_combat')) {
6566
e.preventDefault();
6667
this.cycleShip(e.shiftKey ? -1 : 1);
6768
} else if (e.key === 'Escape') {

src/client/ui.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,27 @@ export class UIManager {
137137
const confirmBtn = document.getElementById('confirmBtn')!;
138138
confirmBtn.style.display = isMyTurn && phase === 'astrogation' ? 'inline-block' : 'none';
139139

140-
const launchMineBtn = document.getElementById('launchMineBtn')!;
141-
const launchTorpedoBtn = document.getElementById('launchTorpedoBtn')!;
142-
const launchNukeBtn = document.getElementById('launchNukeBtn')!;
140+
const launchMineBtn = document.getElementById('launchMineBtn')! as HTMLButtonElement;
141+
const launchTorpedoBtn = document.getElementById('launchTorpedoBtn')! as HTMLButtonElement;
142+
const launchNukeBtn = document.getElementById('launchNukeBtn')! as HTMLButtonElement;
143143
const skipOrdnanceBtn = document.getElementById('skipOrdnanceBtn')!;
144-
launchMineBtn.style.display = isMyTurn && phase === 'ordnance' ? 'inline-block' : 'none';
145-
launchTorpedoBtn.style.display = isMyTurn && phase === 'ordnance' ? 'inline-block' : 'none';
146-
launchNukeBtn.style.display = isMyTurn && phase === 'ordnance' ? 'inline-block' : 'none';
147-
skipOrdnanceBtn.style.display = isMyTurn && phase === 'ordnance' ? 'inline-block' : 'none';
144+
const showOrd = isMyTurn && phase === 'ordnance';
145+
launchMineBtn.style.display = showOrd ? 'inline-block' : 'none';
146+
launchTorpedoBtn.style.display = showOrd ? 'inline-block' : 'none';
147+
launchNukeBtn.style.display = showOrd ? 'inline-block' : 'none';
148+
skipOrdnanceBtn.style.display = showOrd ? 'inline-block' : 'none';
149+
// Disable buttons based on cargo capacity
150+
if (showOrd) {
151+
const canMine = cargoFree >= 10; // mine mass
152+
const canTorpedo = cargoFree >= 20; // torpedo mass
153+
const canNuke = cargoFree >= 20; // nuke mass
154+
launchMineBtn.disabled = !canMine;
155+
launchTorpedoBtn.disabled = !canTorpedo;
156+
launchNukeBtn.disabled = !canNuke;
157+
launchMineBtn.style.opacity = canMine ? '1' : '0.4';
158+
launchTorpedoBtn.style.opacity = canTorpedo ? '1' : '0.4';
159+
launchNukeBtn.style.opacity = canNuke ? '1' : '0.4';
160+
}
148161

149162
const skipCombatBtn = document.getElementById('skipCombatBtn')!;
150163
skipCombatBtn.style.display = isMyTurn && phase === 'combat' ? 'inline-block' : 'none';

0 commit comments

Comments
 (0)