Skip to content
This repository was archived by the owner on Nov 7, 2026. It is now read-only.

Commit 3bd59a5

Browse files
Web 0.13.0: VisuBot-Simulation fährt im Fenster „mBot2 live“ (#198)
Die 3D-Welt der Simulation (Welten-Knöpfe, Ansicht, Messwerte) wird während der Simulation in das Fenster „mBot2 live“ umgehängt, statt eine zweite 3D-Ansicht in der Simulationsspalte zu zeigen. Das Fenster öffnet sich dafür und schließt sich danach wieder, wenn es vorher zu war. Claude-Session: https://claude.ai/code/session_01Ugz28V9NrfhNdeq9UpcjNC Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4b1d882 commit 3bd59a5

19 files changed

Lines changed: 127 additions & 28 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is loosely inspired by Keep a Changelog.
88

99
### Added
1010

11+
- **Web 0.13.0, VisuBot simulation in the „mBot2 live“ window:** in the VisuBot world „Simulation starten“ no longer shows a second 3D world in the simulation column; the mBot2 of the simulation drives in the „mBot2 live“ window instead (title „🤖 Simulation“, world buttons and distance/line values there, its own ▶ rests until the simulation ends). The window opens by itself for the simulation and closes again afterwards if it was closed before; if it is closed during the simulation, the 3D world goes back to the simulation column. Controls, variables, console, sensor sliders and the real mBot2 stay in the simulation column.
1112
- **Web 0.12.12, misspelled data types:** a misspelled basic type at the start of a declaration (`booelan`, `Int`, `string`, `dobule`) is marked red in Programmieren with „Meintest du boolean?“ and ▶ does not start (like javac); the VisuObject debugger reports it with file and line. Valid types (`Boolean`, `Integer`) and own classes stay untouched. The simulation now runs declarations without a start value (`boolean fertig;`, `int a, b;`) and prints conditions like `System.out.println(b == true)` or `x > 3` as true/false (#195).
1213
- **Web 0.12.11, Scanner line suggested:** typing `Scanner` in Programmieren and VisuObject suggests the whole line `Scanner scanner = new Scanner(System.in);` (Tab/Enter, variable name selected to change it); if `import java.util.Scanner;` (or `java.util.*`) is missing, it is added at the top.
1314
- **Web 0.12.10, VisuBot shows the whole series:** in the VisuBot world the lessons are one continuous series again: all VisuStruct lessons with the 22 robot lessons (🤖) in between, each right after the lesson on the same topic (62 lessons, numbers and references like „Lektion 2“ renumbered, both task sets, progress kept); VisuStruct stays without robot (#197).

‎web/package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎web/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "visustruct-web",
33
"private": true,
4-
"version": "0.12.12",
4+
"version": "0.13.0",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

‎web/src/i18n/de.strings‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@
373373
"web_learn_start_without_hint" = "Dann ist dein Lernstand nach dem Schließen weg.";
374374
"web_visubot_preview_title" = "mBot2 live";
375375
"web_visubot_preview_hint" = "Zeigt sofort, wohin dein Programm den mBot2 fährt.";
376+
"web_visubot_preview_sim_title" = "Simulation";
377+
"web_visubot_preview_sim_hint" = "Hier fährt der mBot2 mit, während die Simulation läuft.";
378+
"web_visubot_world_in_preview" = "Der mBot2 fährt im Fenster „Simulation“.";
376379
"web_visubot_preview_play" = "Fahrt abspielen";
377380
"web_visubot_preview_stop" = "Anhalten";
378381
"web_visubot_preview_hide" = "mBot2 live einklappen";

‎web/src/i18n/en.strings‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@
373373
"web_learn_start_without_hint" = "Your learning progress is then lost when you close the page.";
374374
"web_visubot_preview_title" = "mBot2 live";
375375
"web_visubot_preview_hint" = "Shows right away where your program drives the mBot2.";
376+
"web_visubot_preview_sim_title" = "Simulation";
377+
"web_visubot_preview_sim_hint" = "The mBot2 drives here while the simulation runs.";
378+
"web_visubot_world_in_preview" = "The mBot2 drives in the “Simulation” window.";
376379
"web_visubot_preview_play" = "Play the drive";
377380
"web_visubot_preview_stop" = "Stop";
378381
"web_visubot_preview_hide" = "Collapse mBot2 live";

‎web/src/i18n/pt-PT.strings‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@
371371
"web_learn_start_without_hint" = "Assim o teu progresso perde-se ao fechar a página.";
372372
"web_visubot_preview_title" = "mBot2 ao vivo";
373373
"web_visubot_preview_hint" = "Mostra logo para onde o teu programa leva o mBot2.";
374+
"web_visubot_preview_sim_title" = "Simulação";
375+
"web_visubot_preview_sim_hint" = "O mBot2 anda aqui enquanto a simulação corre.";
376+
"web_visubot_world_in_preview" = "O mBot2 anda na janela «Simulação».";
374377
"web_visubot_preview_play" = "Reproduzir o percurso";
375378
"web_visubot_preview_stop" = "Parar";
376379
"web_visubot_preview_hide" = "Recolher mBot2 ao vivo";

‎web/src/ui/app.ts‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ export class App {
322322
private live: LiveCodePanel
323323
private preview = new RobotPreviewPanel()
324324
private previewOpen = false
325+
/** „mBot2 live“ war zu und wurde nur für die Simulation geöffnet: danach wieder schließen. */
326+
private previewOpenedForSim = false
325327
private codeMain = false
326328
private previewStacked = false
327329
private previewResizer!: HTMLElement
@@ -608,6 +610,7 @@ export class App {
608610
this.visuBot ??= new VisuBotView()
609611
this.sim.setRobot(this.visuBot)
610612
} else {
613+
this.preview.hostSimulation(undefined)
611614
this.visuBot?.dispose()
612615
this.visuBot = undefined
613616
}
@@ -1523,9 +1526,17 @@ export class App {
15231526
this.setEditorHidden(false)
15241527
// VisuBot: Die Simulation zeigt die Welten der Übung in diesem Reiter (sonst die freie Fläche).
15251528
this.visuBot?.setWorlds(exerciseWorlds(this.tab.exerciseId))
1529+
// VisuBot: Der mBot2 der Simulation fährt im Fenster „mBot2 live“ (das dafür aufgeht).
1530+
if (this.visuBot && !this.previewOpen) {
1531+
this.setPreviewOpen(true)
1532+
this.previewOpenedForSim = true
1533+
}
1534+
this.placeSimulationRobot()
15261535
this.sim.begin()
15271536
} else {
15281537
this.sim.end()
1538+
this.placeSimulationRobot()
1539+
if (this.previewOpenedForSim) this.setPreviewOpen(false)
15291540
this.simPath = undefined
15301541
if (!this.selected && this.doc.elements.length > 0) this.selected = [0]
15311542
}
@@ -1602,8 +1613,13 @@ export class App {
16021613
// MARK: - mBot2 live
16031614

16041615
private setupPreview() {
1605-
this.preview.onHide = () => this.setPreviewOpen(false)
1606-
this.preview.rail.addEventListener('click', () => this.setPreviewOpen(true))
1616+
// Selbst auf- oder zugeklappt: bleibt so, auch nach der Simulation.
1617+
const open = (on: boolean) => {
1618+
this.previewOpenedForSim = false
1619+
this.setPreviewOpen(on)
1620+
}
1621+
this.preview.onHide = () => open(false)
1622+
this.preview.rail.addEventListener('click', () => open(true))
16071623
this.preview.onToggleStacked = () => {
16081624
this.previewStacked = !this.previewStacked
16091625
storeValue(previewStackedKey, this.previewStacked ? '1' : '0')
@@ -1659,9 +1675,18 @@ export class App {
16591675
storeValue(previewKey, on ? '1' : '0')
16601676
if (!on) this.preview.pause()
16611677
this.placePreview()
1678+
this.placeSimulationRobot()
16621679
if (this.canvasHost) this.render()
16631680
}
16641681

1682+
/** Simulation in VisuBot: ihre 3D-Ansicht im offenen Fenster „mBot2 live“, sonst im Simulationspanel. */
1683+
private placeSimulationRobot() {
1684+
const robot = this.visuBot
1685+
const inPreview = !!robot && this.simulating && this.previewOpen
1686+
this.preview.hostSimulation(inPreview ? robot.viewport : undefined)
1687+
if (!inPreview) robot?.restoreViewport()
1688+
}
1689+
16651690
/** Eigene Spalte ganz rechts oder unten in „Programmieren“ (nur wenn diese Spalte offen ist). */
16661691
private placePreview() {
16671692
const stacked = this.previewStacked && this.liveCoding

‎web/src/ui/robotPreview.ts‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export class RobotPreviewPanel {
4242
private pending?: number
4343
private playTimer?: number
4444
private input?: { doc: VSDocument; resolve?: SubprogramResolver }
45+
/** Während der Simulation: deren 3D-Ansicht mit Welten und Messwerten statt der eigenen. */
46+
private simulation?: HTMLElement
4547

4648
constructor() {
4749
this.element = document.createElement('aside')
@@ -74,11 +76,28 @@ export class RobotPreviewPanel {
7476
this.relabel()
7577
}
7678

79+
/**
80+
* Simulation läuft: ihre 3D-Ansicht (`viewport` aus dem Simulationspanel) hier zeigen, die eigene Vorschau ruht.
81+
* `undefined`: wieder die Vorschau (die Ansicht der Simulation hängt der Aufrufer zurück).
82+
*/
83+
hostSimulation(viewport: HTMLElement | undefined) {
84+
if (viewport === this.simulation) return
85+
this.simulation?.remove()
86+
this.simulation = viewport
87+
this.element.classList.toggle('simulation', !!viewport)
88+
if (viewport) {
89+
this.pause()
90+
this.status.after(viewport)
91+
}
92+
this.relabel()
93+
}
94+
7795
/** Nach einem Sprachwechsel: Beschriftungen neu. */
7896
relabel() {
7997
const q = <T extends Element>(s: string) => this.element.querySelector(s) as T
80-
q('h2').textContent = `🤖 ${t('web_visubot_preview_title')}`
81-
q('.hint').textContent = t('web_visubot_preview_hint')
98+
const sim = !!this.simulation
99+
q('h2').textContent = `🤖 ${t(sim ? 'web_visubot_preview_sim_title' : 'web_visubot_preview_title')}`
100+
q('.hint').textContent = t(sim ? 'web_visubot_preview_sim_hint' : 'web_visubot_preview_hint')
82101
this.heightBar.title = t('web_visubot_preview_resize')
83102
const hide = q<HTMLButtonElement>('.learn-hide')
84103
hide.title = t('web_visubot_preview_hide')
@@ -118,6 +137,7 @@ export class RobotPreviewPanel {
118137
* damit schnelles Tippen nicht bremst. `worlds`: Welten der geöffneten Übung (leer = freie Fläche).
119138
*/
120139
update(doc: VSDocument, resolve: SubprogramResolver | undefined, worlds: RobotWorldSetup[], worldsKey: string, allDocs: VSDocument[]) {
140+
if (this.simulation) return
121141
this.show()
122142
if (worldsKey !== this.worldsKey) {
123143
this.worldsKey = worldsKey

‎web/src/ui/styles.css‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3637,6 +3637,33 @@ button.danger-text:not(:disabled) {
36373637
.robotpreview-height {
36383638
display: none;
36393639
}
3640+
/* Während der Simulation fährt hier deren mBot2 (Welten, 3D-Ansicht und Messwerte aus dem Simulationspanel). */
3641+
.robotpreview.simulation > .visubot-worlds,
3642+
.robotpreview.simulation > .robotpreview-stage,
3643+
.robotpreview.simulation > .robotpreview-status,
3644+
.robotpreview.simulation .robotpreview-play {
3645+
display: none;
3646+
}
3647+
.robotpreview .visubot-viewport {
3648+
display: flex;
3649+
flex: 1 1 auto;
3650+
flex-direction: column;
3651+
min-height: 0;
3652+
}
3653+
.robotpreview .visubot-viewport .visubot-stage {
3654+
flex: 1 1 auto;
3655+
height: auto;
3656+
min-height: 160px;
3657+
}
3658+
.visubot-elsewhere {
3659+
display: none;
3660+
margin: 0 0 8px;
3661+
font-size: 12px;
3662+
color: var(--muted);
3663+
}
3664+
.visubot:not(:has(> .visubot-viewport)) .visubot-elsewhere {
3665+
display: block;
3666+
}
36403667
/* Unter dem Code: volle Breite der Spalte, Höhe an der Linie darüber verschieben. */
36413668
.shell.preview-stacked .robotpreview {
36423669
flex: 0 0 auto;

‎web/src/ui/visubotView.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export class VisuBotView {
8888
/** Befehle, die der echte mBot2 schon gefahren ist. */
8989
private sent = 0
9090
private liveStatus: HTMLElement
91+
/** Welten-Knöpfe, 3D-Ansicht und Messwerte: stehen während der Simulation im Fenster „mBot2 live“. */
92+
readonly viewport: HTMLElement
9193
private stopListening: () => void
9294
private realSensors?: MBotSensorValues
9395
/** Regler und Knöpfe „Sensoren ausprobieren“: Werte, die keine Welt liefert. */
@@ -103,11 +105,12 @@ export class VisuBotView {
103105
this.world = new RobotWorld(setup)
104106
this.element = document.createElement('section')
105107
this.element.className = 'visubot'
106-
this.element.innerHTML = `<h2>${t('web_visubot_world')}</h2><p class="visubot-live"></p><div class="visubot-worlds" hidden></div><div class="visubot-stage"></div><p class="visubot-status mono" dir="ltr"></p>${controlsHTML()}${checkHTML()}`
108+
this.element.innerHTML = `<h2>${t('web_visubot_world')}</h2><p class="visubot-live"></p><p class="visubot-elsewhere hint">${t('web_visubot_world_in_preview')}</p><div class="visubot-viewport"><div class="visubot-worlds" hidden></div><div class="visubot-stage"></div><p class="visubot-status mono" dir="ltr"></p></div>${controlsHTML()}${checkHTML()}`
107109
this.stage = this.element.querySelector('.visubot-stage')!
108110
this.picker = this.element.querySelector('.visubot-worlds')!
109111
this.status = this.element.querySelector('.visubot-status')!
110112
this.liveStatus = this.element.querySelector('.visubot-live')!
113+
this.viewport = this.element.querySelector('.visubot-viewport')!
111114
this.stopListening = mbotLink.listen(() => this.updateLive())
112115
this.setupControls()
113116
this.check = this.element.querySelector('.visubot-check')!
@@ -128,6 +131,11 @@ export class VisuBotView {
128131
})
129132
}
130133

134+
/** 3D-Ansicht zurück ins Simulationspanel (wenn „mBot2 live“ zu ist oder die Simulation endet). */
135+
restoreViewport() {
136+
if (this.viewport.parentElement !== this.element) this.liveStatus.after(this.viewport)
137+
}
138+
131139
/**
132140
* Welten einer Übung (Labyrinth usw.): Knöpfe zum Umschalten über der Ansicht; leer = freie Fläche.
133141
* Programme laufen in der gewählten Welt.

0 commit comments

Comments
 (0)