Minor fix to killing the animation when the sim is killed

This commit is contained in:
Sam El-Husseini 2017-12-19 14:55:43 -08:00
parent 2157af3e63
commit ef5fa9ae82
5 changed files with 15 additions and 30 deletions

View File

@ -140,6 +140,12 @@ namespace pxsim.visuals {
this.board.updateSubscribers.push(() => this.updateState()); this.board.updateSubscribers.push(() => this.updateState());
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<SVGSVGElement> { public getView(): SVGAndSize<SVGSVGElement> {
@ -350,6 +356,10 @@ namespace pxsim.visuals {
this.screenCanvasTemp.style.display = 'none'; this.screenCanvasTemp.style.display = 'none';
} }
private kill() {
if (this.lastAnimationId) cancelAnimationFrame(this.lastAnimationId);
}
private lastAnimationId: number; private lastAnimationId: number;
public updateState() { public updateState() {
if (this.lastAnimationId) cancelAnimationFrame(this.lastAnimationId); if (this.lastAnimationId) cancelAnimationFrame(this.lastAnimationId);
@ -372,7 +382,7 @@ namespace pxsim.visuals {
} }
private updateStateStep() { private updateStateStep() {
console.log("update state step"); const selected = this.layoutView.getSelected();
const inputNodes = ev3board().getInputNodes(); const inputNodes = ev3board().getInputNodes();
inputNodes.forEach((node, index) => { inputNodes.forEach((node, index) => {
if (!node.didChange()) return; 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)) { if (selected && (selected.getId() !== this.selectedNode || selected.getPort() !== this.selectedPort)) {
this.selectedNode = selected.getId(); this.selectedNode = selected.getId();
this.selectedPort = selected.getPort(); this.selectedPort = selected.getPort();
@ -409,16 +418,17 @@ namespace pxsim.visuals {
this.controlGroup.addView(control); this.controlGroup.addView(control);
} }
this.closeIconView.setVisible(true); this.closeIconView.setVisible(true);
this.resize();
} else if (!selected) { } else if (!selected) {
this.controlGroup.clear(); this.controlGroup.clear();
this.controlView = undefined; this.controlView = undefined;
this.selectedNode = undefined; this.selectedNode = undefined;
this.selectedPort = undefined; this.selectedPort = undefined;
this.closeIconView.setVisible(false); this.closeIconView.setVisible(false);
this.resize();
} }
this.updateScreenStep(); this.updateScreenStep();
//this.resize();
} }
private updateScreenStep() { private updateScreenStep() {

View File

@ -78,7 +78,7 @@ namespace pxsim.visuals {
return this.getInnerHeight() * 0.6; return this.getInnerHeight() * 0.6;
} }
onBoardStateChanged() { updateState() {
if (!this.isVisible) { if (!this.isVisible) {
return; return;
} }
@ -91,7 +91,6 @@ namespace pxsim.visuals {
onComponentVisible() { onComponentVisible() {
super.onComponentVisible(); super.onComponentVisible();
this.isVisible = true; this.isVisible = true;
this.onBoardStateChanged();
} }
onComponentHidden() { onComponentHidden() {

View File

@ -60,7 +60,7 @@ namespace pxsim.visuals {
return this.getInnerHeight() / 4; return this.getInnerHeight() / 4;
} }
onBoardStateChanged() { updateState() {
if (!this.isVisible) { if (!this.isVisible) {
return; return;
} }
@ -74,7 +74,6 @@ namespace pxsim.visuals {
onComponentVisible() { onComponentVisible() {
super.onComponentVisible(); super.onComponentVisible();
this.isVisible = true; this.isVisible = true;
this.onBoardStateChanged();
} }
onComponentHidden() { onComponentHidden() {

View File

@ -35,10 +35,6 @@ namespace pxsim.visuals {
return false; return false;
} }
public shouldUpdateState() {
return true;
}
public updateState() { public updateState() {
this.updateLight(); this.updateLight();
} }

View File

@ -61,10 +61,6 @@ namespace pxsim.visuals {
} }
} }
public shouldUpdateState() {
return true;
}
public updateState() { public updateState() {
} }
@ -179,23 +175,8 @@ namespace pxsim.visuals {
public setSelected(selected: boolean) { } public setSelected(selected: boolean) { }
protected getView() { protected getView() {
if (!this.rendered) {
this.subscribe();
}
return super.getView(); 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 { export class ViewContainer extends View {