Lazily load the level in the player and editor, so an unplayable level doesn't break the editor too

This commit is contained in:
Eevee (Evelyn Woods) 2020-12-30 18:21:21 -07:00
parent 93d77ea297
commit 130b917c81

View File

@ -2776,6 +2776,9 @@ class Conductor {
this.editor = new Editor(this);
this.player = new Player(this);
this.loaded_in_editor = false;
this.loaded_in_player = false;
// Bind the header buttons
document.querySelector('#main-options').addEventListener('click', ev => {
new OptionsOverlay(this).open();
@ -2833,7 +2836,9 @@ class Conductor {
document.querySelector('#editor-play').addEventListener('click', ev => {
// Restart the level to ensure it takes edits into account
// TODO need to finish thinking out the exact flow between editor/player and what happens when...
if (this.loaded_in_player) {
this.player.restart_level();
}
this.switch_to_player();
});
@ -2869,6 +2874,10 @@ class Conductor {
if (this.current) {
this.current.deactivate();
}
if (! this.loaded_in_editor) {
this.editor.load_level(this.stored_level);
this.loaded_in_editor = true;
}
this.editor.activate();
this.current = this.editor;
document.body.setAttribute('data-mode', 'editor');
@ -2878,6 +2887,10 @@ class Conductor {
if (this.current) {
this.current.deactivate();
}
if (! this.loaded_in_player) {
this.player.load_level(this.stored_level);
this.loaded_in_player = true;
}
this.player.activate();
this.current = this.player;
document.body.setAttribute('data-mode', 'player');
@ -2965,8 +2978,16 @@ class Conductor {
this.update_level_title();
this.update_nav_buttons();
this.loaded_in_editor = false;
this.loaded_in_player = false;
if (this.current === this.player) {
this.player.load_level(this.stored_level);
this.loaded_in_player = true;
}
if (this.current === this.editor) {
this.editor.load_level(this.stored_level);
this.loaded_in_editor = true;
}
return true;
}