1e51ef7def
- Konzept/, didaktik_geografie/, didaktik_simulation/, v2-modules/, v2-platform/ - 12 code-workspace-Files - STATUS-*.md - viele M/D/R-Änderungen an bereits getrackten Files - .gitignore verstärkt: **/.humaninput/, **/secret_keys.txt Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
133 lines
4.7 KiB
PHP
133 lines
4.7 KiB
PHP
<?php
|
|
/**
|
|
* Klimawächter 3D (V2) — PHP-Wrapper
|
|
* Lädt sims/klima/game-3d.html, injiziert Session-Kontext und Level-Config.
|
|
* Teilt sich mit klima-2d die gleiche `module_info` und `game_levels`-
|
|
* Quelle, damit Admin-Einstellungen für beide Varianten identisch gelten.
|
|
*
|
|
* URL: /geograsim/App/klima-3d (via index.php Front-Controller)
|
|
* ?level=1|2|3 Schwierigkeit (Default: 1)
|
|
*/
|
|
|
|
require_once __DIR__ . '/../php/config/app.php';
|
|
require_once __DIR__ . '/../php/lib/Database.php';
|
|
require_once __DIR__ . '/../php/lib/Session.php';
|
|
|
|
if (session_status() === PHP_SESSION_NONE) Session::start();
|
|
|
|
$level = max(1, min(3, (int)($_GET['level'] ?? 1)));
|
|
$sessionId = Session::studentId() ?? '';
|
|
$studentName = 'Gast';
|
|
$classId = null;
|
|
// Modul-Metadaten werden vom Admin in `module_info` gepflegt; 3D bekommt
|
|
// denselben Titel wie 2D, aber mit "3D"-Suffix, damit der Header-Badge
|
|
// klar macht welche Variante läuft.
|
|
$simName = 'Klimawächter 3D';
|
|
$simIcon = '🌍';
|
|
|
|
try {
|
|
$db = Database::get();
|
|
if ($sessionId) {
|
|
$row = $db->fetchOne(
|
|
'SELECT class_id, display_name FROM student_sessions WHERE id = ?',
|
|
[$sessionId]
|
|
);
|
|
if ($row) {
|
|
$studentName = $row['display_name'] ?: 'Schüler*in';
|
|
$classId = (int)$row['class_id'];
|
|
}
|
|
}
|
|
// Modul-Info aus DB (Atlas-verwaltet). Defaults greifen, wenn Tabelle
|
|
// fehlt oder kein Eintrag für "klima" existiert.
|
|
$mi = $db->fetchOne(
|
|
'SELECT title, icon FROM module_info WHERE module_id = ?',
|
|
['klima']
|
|
);
|
|
if ($mi) {
|
|
if (!empty($mi['title'])) $simName = $mi['title'] . ' 3D';
|
|
if (!empty($mi['icon'])) $simIcon = $mi['icon'];
|
|
}
|
|
} catch (Throwable $e) {
|
|
// DB nicht erreichbar → Defaults
|
|
}
|
|
|
|
// Level-Konfiguration — gleiche Werte wie klima-2d. 2D und 3D teilen sich
|
|
// die Admin-Einstellungen; wenn Thomas Budget oder Runden-Limit anpasst,
|
|
// gilt das für beide Varianten.
|
|
$levelConfigs = [
|
|
1 => [
|
|
'difficulty' => 'easy',
|
|
'label' => 'Lernen',
|
|
'startBudget' => 600,
|
|
'startPopulation'=> 6000,
|
|
'incomePer10k' => 220,
|
|
'blackoutGrace' => 5,
|
|
'timeLimit' => 75,
|
|
'eventFrequency' => 0.3,
|
|
],
|
|
2 => [
|
|
'difficulty' => 'medium',
|
|
'label' => 'Üben',
|
|
'startBudget' => 480,
|
|
'startPopulation'=> 6000,
|
|
'incomePer10k' => 155,
|
|
'blackoutGrace' => 0,
|
|
'timeLimit' => 75,
|
|
'eventFrequency' => 0.5,
|
|
],
|
|
3 => [
|
|
'difficulty' => 'hard',
|
|
'label' => 'Profi',
|
|
'startBudget' => 220,
|
|
'startPopulation'=> 7000,
|
|
'incomePer10k' => 110,
|
|
'blackoutGrace' => 0,
|
|
'timeLimit' => 75,
|
|
'eventFrequency' => 0.7,
|
|
],
|
|
];
|
|
|
|
$ctx = [
|
|
'sessionId' => $sessionId,
|
|
'studentName' => $studentName,
|
|
'classId' => $classId,
|
|
'simId' => 'klima',
|
|
'simName' => $simName,
|
|
'simIcon' => $simIcon,
|
|
'level' => $level,
|
|
'levelConfig' => $levelConfigs[$level],
|
|
'baseUrl' => BASE_URL,
|
|
'basePath' => BASE_PATH,
|
|
'apiUrl' => BASE_URL . '/php/api',
|
|
];
|
|
|
|
$html = file_get_contents(__DIR__ . '/../sims/klima/game-3d.html');
|
|
if ($html === false) {
|
|
http_response_code(500);
|
|
echo 'game-3d.html nicht gefunden';
|
|
exit;
|
|
}
|
|
|
|
// Cache-Bust für engine.js anhand Datei-mtime — Browser cached sonst aggressiv
|
|
$engineFile = __DIR__ . '/../sims/klima/engine.js';
|
|
$engineV = is_file($engineFile) ? filemtime($engineFile) : time();
|
|
$html = str_replace('<script src="engine.js"></script>', '<script src="engine.js?v=' . $engineV . '"></script>', $html);
|
|
|
|
$bp = BASE_PATH;
|
|
$baseTag = '<base href="' . htmlspecialchars($bp . '/sims/klima/', ENT_QUOTES) . '">';
|
|
$ctxJs = '<script>window.__GGS__ = ' . json_encode($ctx, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . ';</script>';
|
|
// Plattform-Live-Client: Heartbeat + Pause-Overlay + Spectator-Mode für ?view=teacher
|
|
$liveJs = '<script src="' . htmlspecialchars($bp . '/assets/js/live-client.js', ENT_QUOTES) . '" defer></script>';
|
|
|
|
// <base>-Tag UND __GGS__-Setup direkt nach <head> einfügen — WICHTIG:
|
|
// __GGS__ MUSS vor allen anderen Scripts da sein, sonst greift der
|
|
// Fallback-Init in game-3d.html zuerst und setzt basePath auf
|
|
// '/klima-3d' (aus location.pathname) — `const GLOSSAR_PAGE` wird dann
|
|
// mit dem falschen basePath ausgewertet und kaputte Links erzeugen.
|
|
$html = preg_replace('/<head>/i', '<head>' . "\n" . $baseTag . "\n" . $ctxJs, $html, 1);
|
|
// Live-Client (deferred) vor </body>
|
|
$html = str_replace('</body>', $liveJs . "\n</body>", $html);
|
|
$html = str_replace('href="/schueler"', 'href="' . cockpit_href() . '"', $html);
|
|
|
|
echo $html;
|