Add game UI panels, keyboard shortcuts, docs narrative overhaul, and unified dev script
- Add MiniStarMap, NpcMarketPanel, ShipStatusPanel, useKeyboardShortcuts - Add progress bars for approach/mining operations and cargo fill indicator - Rewrite docs from spreadsheet-first to exploration-first open-world RPG - Replace dev:db + dev:standalone with unified dev script (scripts/dev.sh) - Add Vite chunk splitting for three.js and spacetimedb - Fix displayName dependency in useSpacetimeConnection - Remove stale usePlayerSession.ts - Add AGENTS.md files across all packages
This commit is contained in:
68
apps/game/src/ui/useKeyboardShortcuts.ts
Normal file
68
apps/game/src/ui/useKeyboardShortcuts.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { useEffect } from "react";
|
||||
|
||||
export type ShipActions = {
|
||||
onUndock: () => void;
|
||||
onStartApproach: () => void;
|
||||
onDock: () => void;
|
||||
onStartMining: () => void;
|
||||
onSelectTarget?: (index: number) => void;
|
||||
};
|
||||
|
||||
export function useKeyboardShortcuts(
|
||||
ship: {
|
||||
dockedStationId: string;
|
||||
flightMode: string;
|
||||
selectedPoiId: string;
|
||||
currentPoiId: string;
|
||||
} | undefined,
|
||||
pois: Array<{ poiId: string; poiType: string }>,
|
||||
operation: { operationType: string } | undefined,
|
||||
actions: ShipActions,
|
||||
) {
|
||||
useEffect(() => {
|
||||
function handleKeyDown(event: KeyboardEvent) {
|
||||
if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) return;
|
||||
|
||||
const key = event.key.toLowerCase();
|
||||
|
||||
if (key === "u" && !operation) {
|
||||
if (ship && ship.dockedStationId.length > 0) {
|
||||
event.preventDefault();
|
||||
actions.onUndock();
|
||||
}
|
||||
}
|
||||
|
||||
if (key === "d" && !operation) {
|
||||
if (ship && ship.dockedStationId.length === 0 && ship.flightMode === "flight") {
|
||||
event.preventDefault();
|
||||
actions.onDock();
|
||||
}
|
||||
}
|
||||
|
||||
if (key === "a" && !operation) {
|
||||
if (ship && ship.dockedStationId.length === 0 && ship.selectedPoiId.length > 0 && ship.selectedPoiId !== ship.currentPoiId) {
|
||||
event.preventDefault();
|
||||
actions.onStartApproach();
|
||||
}
|
||||
}
|
||||
|
||||
if (key === "m" && !operation) {
|
||||
if (ship && ship.dockedStationId.length === 0 && ship.flightMode === "flight") {
|
||||
event.preventDefault();
|
||||
actions.onStartMining();
|
||||
}
|
||||
}
|
||||
|
||||
if (key >= "1" && key <= "9") {
|
||||
const index = parseInt(key) - 1;
|
||||
if (index < pois.length && actions.onSelectTarget) {
|
||||
event.preventDefault();
|
||||
actions.onSelectTarget(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("keydown", handleKeyDown);
|
||||
return () => window.removeEventListener("keydown", handleKeyDown);
|
||||
}, [ship, pois, operation, actions]);
|
||||
}
|
||||
Reference in New Issue
Block a user