Klima: Snapshot — pages/klima-2d.php nachgezogen + WIP-Cleanup
Sicherheits-Commit, damit der Stand vor möglichem Shutdown gesichert ist. App/pages/klima-2d.php war noch untracked, jetzt im Repo. Restliche modified-Markierungen waren reine Line-Ending-Normalisierung.
This commit is contained in:
@@ -0,0 +1,115 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Klimawächter 2D (V2) — PHP-Wrapper
|
||||||
|
* Lädt sims/klima/game-2d.html, injiziert Session-Kontext und Level-Config.
|
||||||
|
* URL: /geograsim/App/klima-2d (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 (Titel, Icon) werden vom Admin in der DB-Tabelle
|
||||||
|
// `module_info` gepflegt — hier mit sinnvollen Defaults laden.
|
||||||
|
$simName = 'Klimawächter 2D';
|
||||||
|
$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'];
|
||||||
|
if (!empty($mi['icon'])) $simIcon = $mi['icon'];
|
||||||
|
}
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
// DB nicht erreichbar → Defaults
|
||||||
|
}
|
||||||
|
|
||||||
|
// Level-Konfiguration — fachlich passend zur Spiellogik (V1).
|
||||||
|
// easy = Lernen, medium = Üben, hard = Profi
|
||||||
|
$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-2d.html');
|
||||||
|
if ($html === false) {
|
||||||
|
http_response_code(500);
|
||||||
|
echo 'game-2d.html nicht gefunden';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$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>';
|
||||||
|
|
||||||
|
// <base>-Tag direkt nach <head> einfügen, damit relative Pfade aus /sims/klima/ heraus auflösen
|
||||||
|
$html = preg_replace('/<head>/i', '<head>' . "\n" . $baseTag, $html, 1);
|
||||||
|
// Session-Kontext vor </body>
|
||||||
|
$html = str_replace('</body>', $ctxJs . "\n</body>", $html);
|
||||||
|
|
||||||
|
echo $html;
|
||||||
Reference in New Issue
Block a user