// Copyright (c) 2025-2026, RTE (https://www.rte-france.com) // This Source Code Form is subject to the terms of the Mozilla Public License, version 2.0. // If a copy of the Mozilla Public License, version 2.0 was not distributed with this file, // you can obtain one at http://mozilla.org/MPL/2.0/. // SPDX-License-Identifier: MPL-2.0 // This file is part of Co-Study4Grid a Power Grid Study tool Assistant Interface to help solve contigencies for a grid state under study. import App from '../App'; import { colors, space, text, radius } from '../styles/tokens'; import GameConfigScreen from './GameConfigScreen'; import GameHud from './GameHud'; import GameResults from './GameResults'; import { useGameSession } from './useGameSession'; /** Best (lowest) resulting loading among the player's chosen actions. */ function bestRho(rhos: (number | null)[]): number | null { const valid = rhos.filter((r): r is number => typeof r === 'number'); return valid.length ? Math.min(...valid) : null; } /** * The Game Mode entry point. Mounted by `main.tsx` instead of bare `` * when the app is launched with `?game=1`. Drives a session state machine * over the unchanged Co-Study4Grid workspace. */ export default function GameShell() { const game = useGameSession(); if (game.phase === 'config') { return ; } if (game.phase === 'results' && game.sessionLog) { return ; } // playing | loading → HUD on top, the live workspace below. const cfg = game.config!; const study = cfg.studies[game.currentIndex]; const finalMaxRho = bestRho(game.snapshot.chosenActions.map((a) => a.maxRho)); return ( <>
{game.phase === 'loading' && (
{game.loadError ? ( <>
⚠ Failed to load study
{game.loadError}
) : ( <>
Loading study {game.currentIndex + 1}…
{study?.label}
)}
)} ); }