From e354a30a4479c1caaf26a29aed908ff28763b567 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 5 May 2026 03:42:58 +0200 Subject: [PATCH] =?UTF-8?q?Klima=203D:=20Live-State-Hook=20f=C3=BCr=20Lehr?= =?UTF-8?q?er-Spectator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Atlas-Auftrag aus _inbox/klima/2026-05-05-0140 — analog zum 2D-Hook, plus 3D-spezifische Felder. - game-3d.html: window.GGS_LIVE_STATE liefert {variant:'3d', tick, year, level, phase, budget, population, co2, temp, floodedPct, seaLevelCm, speed, measures, levelWon, tourism, hasShield, hasBeach, placing}. Aufruf alle ~4s durch live-client.js, gepostet an /api/live. - klima-3d.php: Live-Client-Script-Tag nachgezogen (war nur in klima-2d.php). Wird wie üblich vor injiziert. Heartbeat → DB live_sessions, Lehrer-Cockpit zeigt Karten an mit Live-Kennzahlen. Co-Authored-By: Claude Opus 4.7 (1M context) --- App/pages/klima-3d.php | 7 +++++-- App/sims/klima/game-3d.html | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/App/pages/klima-3d.php b/App/pages/klima-3d.php index 3baaac0..4aebea5 100644 --- a/App/pages/klima-3d.php +++ b/App/pages/klima-3d.php @@ -111,10 +111,13 @@ if ($html === false) { $bp = BASE_PATH; $baseTag = ''; $ctxJs = ''; +// Plattform-Live-Client: Heartbeat + Pause-Overlay + Spectator-Mode für ?view=teacher +$liveJs = ''; // -Tag direkt nach einfügen, damit relative Pfade aus /sims/klima/ heraus auflösen $html = preg_replace('//i', '' . "\n" . $baseTag, $html, 1); -// Session-Kontext vor -$html = str_replace('', $ctxJs . "\n", $html); +// Session-Kontext + Live-Client vor +$html = str_replace('', $ctxJs . "\n" . $liveJs . "\n", $html); +$html = str_replace('href="/schueler"', 'href="' . cockpit_href() . '"', $html); echo $html; diff --git a/App/sims/klima/game-3d.html b/App/sims/klima/game-3d.html index 4d1eed9..0b01fde 100644 --- a/App/sims/klima/game-3d.html +++ b/App/sims/klima/game-3d.html @@ -793,7 +793,7 @@ HEADER ============================================================ --> @@ -1544,6 +1544,34 @@ Object.assign(state, { pendingCitizenEvent: null, }); +// Live-State-Hook für Lehrer-Spectator (s. _inbox/klima/2026-05-05-0140-…). +// Plattform-`live-client.js` ruft das alle ~4 s und sendet den Snapshot +// an `/api/live`. Selbe Felder wie 2D plus drei 3D-spezifische Flags +// (variant, placing, tourismus) und Citizen-Event-Indikatoren. +window.GGS_LIVE_STATE = function () { + if (!state) return null; + return { + variant: '3d', + tick: state.tick, + year: (state.startYear || 2025) + (state.tick || 0), + level: state.difficulty || state.level || null, + phase: state.phase || null, + budget: Math.round(state.budget || 0), + population: Math.round(state.population || 0), + co2: Math.round(state.co2Ppm || 0), + temp: +(state.currentTemp || 0).toFixed(2), + floodedPct: Math.round(state.floodedPct || 0), + seaLevelCm: Math.round(state.seaLevelCm || 0), + speed: state.speed || 0, + measures: Array.isArray(state.actionLog) ? state.actionLog.filter(a=>a.action==='buy').length : 0, + levelWon: !!state.levelWon, + tourism: !!state.tourismMode, + hasShield: !!state.hasMountainShield, + hasBeach: !!state.hasSandBeach, + placing: typeof placementId !== 'undefined' && placementId !== null ? placementId : null, + }; +}; + /* ============================================================ UI HELPERS ============================================================ */ @@ -5704,6 +5732,11 @@ const GLOSSAR_DB_KNOWN = new Set([ 'klimawandel','kohlenstoffkreislauf','megawatt','methan','nachhaltigkeit', 'pariser-abkommen','permafrost','photovoltaik','ppm','treibhauseffekt', 'treibhausgas','wasserkraft','watt','windenergie', + // Klima-Sim-Begriffe (Migration 2026-05-02): 4 Aliasse + 14 Volleinträge + 'windpark','solaranlage','erneuerbar','kohlekraftwerk', + 'budget','strom','mangrove','klimafolgen','kuestenschutz', + 'wartung','tourismus','blackout','steuern','temperatur', + 'meeresspiegel','bevoelkerung','ueberflutung','co2_filter', ]); function resolveGlossarDbKey(key) { const aliased = KLIMA_TO_DB_KEY[key] || key;