Update source files

This commit is contained in:
2025-10-13 16:40:21 -05:00
commit 3b2598f24f
178 changed files with 30153 additions and 0 deletions

View File

@@ -0,0 +1,543 @@
:root {
font-family: "Inter Variable", Inter, Avenir, Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 24px;
font-weight: 400;
color: #1e293b;
background-color: transparent; /* Transparent to show game canvas */
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}
/**
* Input blocking system for desktop mode:
*
* In desktop mode, the InputForwarder component captures all input events
* (mouse, keyboard, wheel) from the window and forwards them to the Bevy game engine.
*
* To prevent UI elements (menus, overlays, etc.) from accidentally forwarding clicks
* to the game, those elements should be tagged with the 'block-game-input' class.
*
* The InputForwarder checks `event.target.closest('.block-game-input')` and skips
* forwarding if the event originated from within a blocking element.
*
* For overlays that SHOULD allow clicks through (like spawn phase instructions),
* simply don't add the 'block-game-input' class.
*/
.block-game-input {
/* This class serves as a marker - no styles needed */
}
/* Make the entire React overlay transparent to pointer events */
html,
body,
#root {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
pointer-events: none;
position: fixed;
top: 0;
left: 0;
background-color: transparent; /* Transparent to show game canvas */
z-index: 1; /* Above canvas (z-index: 0) */
}
/* In browser mode, enable pointer events on the game canvas */
#game-canvas {
pointer-events: auto;
}
.container {
margin: 0;
padding-top: 10vh;
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
pointer-events: none; /* Let clicks pass through to interaction layer */
position: relative;
z-index: 1; /* Above interaction layer */
}
/* Game canvas - PixiJS renderer layer */
.game-canvas {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
pointer-events: auto; /* Capture input events */
z-index: 0; /* Behind all UI elements */
}
.game-ui {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none; /* Let clicks pass through to interaction layer */
z-index: 1; /* Above interaction layer and canvas */
}
h1 {
text-align: center;
pointer-events: auto; /* Make text selectable if needed */
}
p {
pointer-events: auto; /* Make text selectable */
}
a {
font-weight: 500;
color: #3b82f6;
text-decoration: inherit;
pointer-events: auto; /* Make links clickable */
}
a:hover {
color: #2563eb;
}
form {
pointer-events: auto; /* Make form interactive */
}
input,
button {
border-radius: 8px;
border: 1px solid #e2e8f0;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
color: #1e293b;
background-color: #ffffff;
transition: border-color 0.25s;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
pointer-events: auto; /* Re-enable clicks on interactive elements */
}
button {
cursor: pointer;
pointer-events: auto; /* Re-enable clicks on buttons */
}
button:hover {
border-color: #3b82f6;
}
button:active {
border-color: #3b82f6;
background-color: #f1f5f9;
}
input,
button {
outline: none;
}
/* Leaderboard styles */
.no-drag {
-webkit-app-region: no-drag;
}
.leaderboard {
position: fixed;
top: 0;
left: 12px;
z-index: 10;
user-select: none;
pointer-events: auto;
opacity: 0.6;
transition: opacity 400ms ease;
font-size: 13px; /* Base font size for scaling everything */
}
.leaderboard:hover {
opacity: 1;
}
.leaderboard__header {
background: rgba(15, 23, 42, 0.75);
color: white;
padding: 0.5em 0.83em; /* 6px 10px scaled to em */
border-radius: 0 0 0 0;
font-weight: 500;
font-size: 1.25em;
cursor: pointer;
display: flex;
align-items: center;
justify-content: space-between;
}
.leaderboard__header--collapsed {
border-radius: 0 0 0.2em 0.2em;
}
.leaderboard__body {
background: rgba(15, 23, 42, 0.6);
backdrop-filter: blur(2px);
border-radius: 0 0 0.5em 0.5em; /* 6px scaled to em */
}
.leaderboard__table-container {
/* Height set dynamically via JavaScript */
overflow: hidden;
}
.leaderboard__table {
width: 23.5em; /* Increased to accommodate position column */
border-collapse: collapse;
}
.leaderboard__player-highlight {
background: rgba(15, 23, 42, 0.65);
backdrop-filter: blur(2px);
border-radius: 0.5em;
}
.leaderboard__row {
cursor: pointer;
transition: background-color 0.15s ease;
color: rgba(255, 255, 255, 0.75);
font-size: 1.1em;
> td {
padding-top: 0.25em;
padding-bottom: 0.25em;
}
}
.leaderboard__row:hover {
background: rgba(255, 255, 255, 0.06);
}
.leaderboard__row--player {
color: white;
}
.leaderboard__row--eliminated {
cursor: default;
}
.leaderboard__row--eliminated:hover {
background: transparent;
}
.leaderboard__row--highlighted {
background: rgba(255, 255, 255, 0.12) !important;
}
.leaderboard__position {
padding-left: 0.67em;
padding-right: 0.5em;
text-align: center;
font-variant-numeric: tabular-nums;
white-space: nowrap;
width: 3em;
min-width: 3em;
font-size: 0.9em;
letter-spacing: -0.02em;
vertical-align: middle;
}
.leaderboard__name {
padding: 0 0.67em 0 0; /* Reduced left padding since position column has right padding */
text-align: left;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 55%; /* Reduced to make room for position column */
}
.leaderboard__name-content {
display: flex;
align-items: center;
gap: 0.5em;
}
.leaderboard__color-circle {
width: 0.75em;
height: 0.75em;
border-radius: 50%;
flex-shrink: 0;
box-shadow:
0 0 0.15em rgba(0, 0, 0, 0.4),
0 0 0.3em rgba(0, 0, 0, 0.2),
0 0 0.5em rgba(0, 0, 0, 0.1),
inset 0 0 0.1em rgba(255, 255, 255, 0.2);
}
.leaderboard__percent {
padding: 0 0.67em; /* 6px 8px scaled to em */
text-align: right;
font-variant-numeric: tabular-nums;
white-space: nowrap;
width: 20%; /* Fixed width for percentage column */
}
.leaderboard__troops {
padding-left: 0.45em;
padding-right: 0.86em;
text-align: right;
font-variant-numeric: tabular-nums;
white-space: nowrap;
width: 20%; /* Fixed width for troops column */
min-width: 5em; /* 60px scaled to em (60/12) */
}
.leaderboard__placeholder {
padding: 1em;
text-align: center;
color: #94a3b8;
font-style: italic;
}
/* Responsive font sizing based on window size */
@media (max-width: 1200px) {
.leaderboard {
font-size: 12px;
}
}
@media (max-width: 1000px) {
.leaderboard {
font-size: 12px;
}
}
@media (max-width: 800px) {
.leaderboard {
font-size: 11.5px;
}
}
@media (max-width: 600px) {
.leaderboard {
font-size: 10px;
}
}
/* Attacks styles */
.attacks {
user-select: none;
opacity: 0.6;
transition: opacity 400ms ease;
font-size: 13px; /* Base font size for scaling everything */
display: flex;
flex-direction: column;
gap: 2px;
}
.attacks:hover {
opacity: 1;
}
.attacks__row {
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.5em 0.83em;
border: none;
background: rgba(15, 23, 42, 0.6);
backdrop-filter: blur(2px);
color: white;
cursor: pointer;
transition: background-color 0.15s ease;
font-size: 1.1em;
font-family: inherit;
width: 21.67em;
border-radius: 0.5em;
overflow: hidden;
}
.attacks__row:hover {
background: rgba(15, 23, 42, 0.75);
}
.attacks__background {
position: absolute;
top: 0;
right: 0;
height: 100%;
pointer-events: none;
transition: width 0.3s ease;
}
.attacks__nation {
text-align: left;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
flex: 1;
padding-right: 1em;
position: relative;
z-index: 1;
}
.attacks__troops {
text-align: right;
font-variant-numeric: tabular-nums;
white-space: nowrap;
min-width: 5em;
position: relative;
z-index: 1;
}
@media (max-width: 1200px) {
.attacks {
font-size: 12px;
}
}
@media (max-width: 1000px) {
.attacks {
font-size: 12px;
}
}
@media (max-width: 800px) {
.attacks {
font-size: 11.5px;
}
}
@media (max-width: 600px) {
.attacks {
font-size: 10px;
}
}
/* Attack Controls styles */
.attack-controls {
position: fixed;
bottom: 12px;
left: 12px;
z-index: 10;
user-select: none;
opacity: 0.95;
transition: opacity 400ms ease;
font-size: 15.6px;
pointer-events: none;
}
.attack-controls:hover {
opacity: 1;
}
.attack-controls__content {
display: flex;
flex-direction: column;
pointer-events: auto;
}
.attack-controls__header {
display: flex;
flex-direction: row;
align-items: flex-end;
gap: 0.5em;
min-width: 26em;
}
.attack-controls__label {
font-size: 0.7em;
color: white;
opacity: 0.6;
padding-bottom: 0.15em;
text-transform: uppercase;
letter-spacing: 0.05em;
font-weight: 500;
white-space: nowrap;
flex-shrink: 0;
text-shadow:
0 1px 2px rgba(0, 0, 0, 0.8),
0 2px 4px rgba(0, 0, 0, 0.6),
1px 0 2px rgba(0, 0, 0, 0.8),
-1px 0 2px rgba(0, 0, 0, 0.8);
}
.attack-controls__attacks {
flex: 1;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 2px;
margin-bottom: 0.25em;
}
.attack-controls__slider-wrapper {
width: 26em;
}
.attack-controls__slider {
height: 2.75em;
background: rgba(0, 0, 0, 0.4);
backdrop-filter: blur(2px);
border-radius: 0.4em;
position: relative;
cursor: pointer;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.attack-controls__slider-fill {
height: 100%;
background: rgba(59, 130, 246, 0.6);
position: absolute;
left: 0;
top: 0;
pointer-events: none;
border-radius: 0.15em;
}
.attack-controls__percentage {
position: absolute;
left: 0.8em;
top: 50%;
transform: translateY(-50%);
font-size: 1.15em;
font-weight: 500;
font-variant-numeric: tabular-nums;
color: white;
pointer-events: none;
z-index: 1;
opacity: 0.85;
text-shadow:
0 1px 2px rgba(0, 0, 0, 0.4),
0 2px 4px rgba(0, 0, 0, 0.4),
1px 0 2px rgba(0, 0, 0, 0.4),
-1px 0 2px rgba(0, 0, 0, 0.4);
}
@media (max-width: 1200px) {
.attack-controls {
font-size: 14.4px;
}
}
@media (max-width: 1000px) {
.attack-controls {
font-size: 14.4px;
}
}
@media (max-width: 800px) {
.attack-controls {
font-size: 13.8px;
}
}
@media (max-width: 600px) {
.attack-controls {
font-size: 12px;
}
}

View File

@@ -0,0 +1,75 @@
import { useState, useEffect, lazy, Suspense } from "react";
import "./+Page.css";
import { MenuScreen } from "@/shared/components/MenuScreen";
import { useAnalytics } from "@/shared/analytics";
// Lazy load components that aren't needed immediately
const GameContainer = lazy(() => import("./GameContainer.client").then(m => ({ default: m.GameContainer })));
const AlphaWarningModal = lazy(() => import("@/shared/components/AlphaWarningModal"));
function App() {
const [showMenu, setShowMenu] = useState(true);
const [isHydrated, setIsHydrated] = useState(false);
const analytics = useAnalytics();
// Mark as hydrated after first render to prevent hydration mismatch
useEffect(() => {
setIsHydrated(true);
}, []);
// Prefetch components after initial render
useEffect(() => {
const timer = setTimeout(() => {
// Trigger chunk downloads without rendering
// Preload game container so lazy loading doesn't delay start
import("./GameContainer.client");
import("@/shared/components/AlphaWarningModal");
// Also preload game renderer and canvas components
import("@/shared/render/GameRenderer");
import("@/shared/components/GameCanvas");
}, 1000); // Start earlier since user is reading menu
return () => clearTimeout(timer);
}, []);
// Track app started on mount
useEffect(() => {
if (!analytics) return;
analytics.track("app_started", {
platform: __DESKTOP__ ? "desktop" : "browser",
});
}, [analytics]);
const handleStartSingleplayer = () => {
setShowMenu(false);
};
const handleExit = async () => {
if (__DESKTOP__) {
const { invoke } = await import("@tauri-apps/api/core");
await invoke("request_exit").catch((err) => {
console.error("Failed to request exit:", err);
});
}
};
// Don't render game components until hydration is complete
if (!isHydrated) {
return null;
}
return (
<>
{/* Menu Screen - pre-renderable, covers everything when visible */}
{showMenu && <MenuScreen onStartSingleplayer={handleStartSingleplayer} onExit={handleExit} />}
{/* Game Container - client-only, lazy loaded when game starts */}
{!showMenu && (
<Suspense fallback={null}>
<GameContainer onReturnToMenu={() => setShowMenu(true)} />
</Suspense>
)}
</>
);
}
export default App;

View File

@@ -0,0 +1,170 @@
import { useState, useEffect, lazy, Suspense } from "react";
import { Attacks } from "@/shared/components/Attacks";
import { AttackControls } from "@/shared/components/AttackControls";
import { Leaderboard } from "@/shared/components/Leaderboard";
import { GameMenu } from "@/shared/components/GameMenu";
import { SpawnPhaseOverlay } from "@/shared/components/SpawnPhaseOverlay";
import { GameCanvas } from "@/shared/components/GameCanvas";
import { useGameAPI } from "@/shared/api/GameAPIContext";
import { useAnalytics } from "@/shared/analytics";
import type { GameOutcome, LeaderboardSnapshot } from "@/shared/api/types";
import type { GameRenderer } from "@/shared/render/GameRenderer";
const GameEndOverlay = lazy(() => import("@/shared/components/GameEndOverlay"));
interface GameContainerProps {
onReturnToMenu: () => void;
}
export function GameContainer({ onReturnToMenu }: GameContainerProps) {
const [gameOutcome, setGameOutcome] = useState<GameOutcome | null>(null);
const [spawnPhaseActive, setSpawnPhaseActive] = useState(false);
const [spawnCountdown, setSpawnCountdown] = useState<{
startedAtMs: number;
durationSecs: number;
} | null>(null);
const [initialGameState, setInitialGameState] = useState<any | null>(null);
const [initialLeaderboard, setInitialLeaderboard] = useState<LeaderboardSnapshot | null>(null);
const [renderer, setRenderer] = useState<GameRenderer | null>(null);
const [highlightedNation, setHighlightedNation] = useState<number | null>(null);
const api = useGameAPI();
const analytics = useAnalytics();
// Check for existing game state on mount (for reload recovery)
// Skip this in browser since WASM doesn't persist state
useEffect(() => {
if (!api || typeof api.getGameState !== "function") return;
// Only check for state recovery on desktop (Tauri)
// In browser, this always returns null so skip the async call
if (import.meta.env.MODE === 'browser') return;
api.getGameState().then((state) => {
// Only recover if we actually have render data (indicates a running game)
if (state && state.render_init) {
console.log("Recovered game state after reload:", state);
setInitialGameState(state.render_init);
setInitialLeaderboard(state.leaderboard_snapshot);
}
});
}, [api]);
// Start the game on mount
useEffect(() => {
if (api) {
api.startGame();
}
// Track game started
if (analytics) {
analytics.track("game_started", {
mode: "singleplayer",
});
}
}, [api, analytics]);
// Subscribe to spawn phase events
useEffect(() => {
if (!api) return;
const unsubUpdate = api.onSpawnPhaseUpdate((update) => {
setSpawnPhaseActive(true);
setSpawnCountdown(update.countdown);
});
const unsubEnd = api.onSpawnPhaseEnded(() => {
setSpawnPhaseActive(false);
setSpawnCountdown(null);
});
return () => {
unsubUpdate();
unsubEnd();
};
}, [api]);
// Subscribe to game end events
useEffect(() => {
if (!api) return;
const unsubscribe = api.onGameEnded((outcome) => {
console.log("Game outcome received:", outcome);
setGameOutcome(outcome);
setSpawnPhaseActive(false);
// Track game ended
if (analytics) {
analytics.track("game_ended", {
outcome: outcome.toString().toLowerCase(),
});
}
});
return () => unsubscribe();
}, [api, analytics]);
// Track renderer initialization with GPU info
useEffect(() => {
if (renderer && analytics) {
const rendererInfo = renderer.getRendererInfo();
analytics.track("renderer_initialized", rendererInfo);
}
}, [renderer, analytics]);
// Sync highlighted nation with renderer
useEffect(() => {
if (renderer) {
renderer.setHighlightedNation(highlightedNation);
}
}, [highlightedNation, renderer]);
const handleExit = () => {
if (api) {
api.quitGame();
}
setGameOutcome(null);
onReturnToMenu();
};
return (
<>
{/* Game Canvas - always rendered at root */}
<GameCanvas
className="game-canvas"
initialState={initialGameState}
onRendererReady={setRenderer}
onNationHover={setHighlightedNation}
/>
{/* Game UI */}
<div className="game-ui">
{/* Spawn Phase Overlay */}
<SpawnPhaseOverlay isVisible={spawnPhaseActive} countdown={spawnCountdown} />
<Leaderboard
initialSnapshot={initialLeaderboard}
highlightedNation={highlightedNation}
onNationHover={setHighlightedNation}
/>
<AttackControls>
<Attacks onNationHover={setHighlightedNation} />
</AttackControls>
<GameMenu
onExit={handleExit}
onSettings={() => {
// TODO: Implement settings
}}
/>
{/* Game End Overlay */}
{gameOutcome && (
<Suspense fallback={null}>
<GameEndOverlay
outcome={gameOutcome}
onSpectate={() => setGameOutcome(null)}
onExit={handleExit}
/>
</Suspense>
)}
</div>
</>
);
}