diff --git a/sim/visuals/board.ts b/sim/visuals/board.ts index a3de0361..b3429ad7 100644 --- a/sim/visuals/board.ts +++ b/sim/visuals/board.ts @@ -140,6 +140,12 @@ namespace pxsim.visuals { this.board.updateSubscribers.push(() => this.updateState()); this.updateState(); } + + Runtime.messagePosted = (msg) => { + switch (msg.type || "") { + case "status": if ((msg as pxsim.SimulatorStateMessage).state == "killed") this.kill(); break; + } + } } public getView(): SVGAndSize { @@ -350,6 +356,10 @@ namespace pxsim.visuals { this.screenCanvasTemp.style.display = 'none'; } + private kill() { + if (this.lastAnimationId) cancelAnimationFrame(this.lastAnimationId); + } + private lastAnimationId: number; public updateState() { if (this.lastAnimationId) cancelAnimationFrame(this.lastAnimationId); @@ -372,7 +382,7 @@ namespace pxsim.visuals { } private updateStateStep() { - console.log("update state step"); + const selected = this.layoutView.getSelected(); const inputNodes = ev3board().getInputNodes(); inputNodes.forEach((node, index) => { if (!node.didChange()) return; @@ -398,7 +408,6 @@ namespace pxsim.visuals { } }); - const selected = this.layoutView.getSelected(); if (selected && (selected.getId() !== this.selectedNode || selected.getPort() !== this.selectedPort)) { this.selectedNode = selected.getId(); this.selectedPort = selected.getPort(); @@ -409,16 +418,17 @@ namespace pxsim.visuals { this.controlGroup.addView(control); } this.closeIconView.setVisible(true); + this.resize(); } else if (!selected) { this.controlGroup.clear(); this.controlView = undefined; this.selectedNode = undefined; this.selectedPort = undefined; this.closeIconView.setVisible(false); + this.resize(); } this.updateScreenStep(); - //this.resize(); } private updateScreenStep() { diff --git a/sim/visuals/controls/distanceSlider.ts b/sim/visuals/controls/distanceSlider.ts index 466cd24e..033b8b0d 100644 --- a/sim/visuals/controls/distanceSlider.ts +++ b/sim/visuals/controls/distanceSlider.ts @@ -78,7 +78,7 @@ namespace pxsim.visuals { return this.getInnerHeight() * 0.6; } - onBoardStateChanged() { + updateState() { if (!this.isVisible) { return; } @@ -91,7 +91,6 @@ namespace pxsim.visuals { onComponentVisible() { super.onComponentVisible(); this.isVisible = true; - this.onBoardStateChanged(); } onComponentHidden() { diff --git a/sim/visuals/controls/rotationSlider.ts b/sim/visuals/controls/rotationSlider.ts index c3539b4b..df5d8117 100644 --- a/sim/visuals/controls/rotationSlider.ts +++ b/sim/visuals/controls/rotationSlider.ts @@ -60,7 +60,7 @@ namespace pxsim.visuals { return this.getInnerHeight() / 4; } - onBoardStateChanged() { + updateState() { if (!this.isVisible) { return; } @@ -74,7 +74,6 @@ namespace pxsim.visuals { onComponentVisible() { super.onComponentVisible(); this.isVisible = true; - this.onBoardStateChanged(); } onComponentHidden() { diff --git a/sim/visuals/nodes/brickView.ts b/sim/visuals/nodes/brickView.ts index 9ff648d2..8619f053 100644 --- a/sim/visuals/nodes/brickView.ts +++ b/sim/visuals/nodes/brickView.ts @@ -35,10 +35,6 @@ namespace pxsim.visuals { return false; } - public shouldUpdateState() { - return true; - } - public updateState() { this.updateLight(); } diff --git a/sim/visuals/view.ts b/sim/visuals/view.ts index 9b5d27e6..029f139d 100644 --- a/sim/visuals/view.ts +++ b/sim/visuals/view.ts @@ -61,10 +61,6 @@ namespace pxsim.visuals { } } - public shouldUpdateState() { - return true; - } - public updateState() { } @@ -179,23 +175,8 @@ namespace pxsim.visuals { public setSelected(selected: boolean) { } protected getView() { - if (!this.rendered) { - this.subscribe(); - } return super.getView(); } - - protected onBoardStateChanged() { - // To be implemented by sub class - } - - protected subscribe() { - board().updateSubscribers.push(() => { - if (this.state.didChange()) { - this.onBoardStateChanged(); - } - }); - } } export class ViewContainer extends View {