Lazily load the level in the player and editor, so an unplayable level doesn't break the editor too
This commit is contained in:
parent
93d77ea297
commit
130b917c81
27
js/main.js
27
js/main.js
@ -2776,6 +2776,9 @@ class Conductor {
|
|||||||
this.editor = new Editor(this);
|
this.editor = new Editor(this);
|
||||||
this.player = new Player(this);
|
this.player = new Player(this);
|
||||||
|
|
||||||
|
this.loaded_in_editor = false;
|
||||||
|
this.loaded_in_player = false;
|
||||||
|
|
||||||
// Bind the header buttons
|
// Bind the header buttons
|
||||||
document.querySelector('#main-options').addEventListener('click', ev => {
|
document.querySelector('#main-options').addEventListener('click', ev => {
|
||||||
new OptionsOverlay(this).open();
|
new OptionsOverlay(this).open();
|
||||||
@ -2833,7 +2836,9 @@ class Conductor {
|
|||||||
document.querySelector('#editor-play').addEventListener('click', ev => {
|
document.querySelector('#editor-play').addEventListener('click', ev => {
|
||||||
// Restart the level to ensure it takes edits into account
|
// 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...
|
// TODO need to finish thinking out the exact flow between editor/player and what happens when...
|
||||||
this.player.restart_level();
|
if (this.loaded_in_player) {
|
||||||
|
this.player.restart_level();
|
||||||
|
}
|
||||||
this.switch_to_player();
|
this.switch_to_player();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -2869,6 +2874,10 @@ class Conductor {
|
|||||||
if (this.current) {
|
if (this.current) {
|
||||||
this.current.deactivate();
|
this.current.deactivate();
|
||||||
}
|
}
|
||||||
|
if (! this.loaded_in_editor) {
|
||||||
|
this.editor.load_level(this.stored_level);
|
||||||
|
this.loaded_in_editor = true;
|
||||||
|
}
|
||||||
this.editor.activate();
|
this.editor.activate();
|
||||||
this.current = this.editor;
|
this.current = this.editor;
|
||||||
document.body.setAttribute('data-mode', 'editor');
|
document.body.setAttribute('data-mode', 'editor');
|
||||||
@ -2878,6 +2887,10 @@ class Conductor {
|
|||||||
if (this.current) {
|
if (this.current) {
|
||||||
this.current.deactivate();
|
this.current.deactivate();
|
||||||
}
|
}
|
||||||
|
if (! this.loaded_in_player) {
|
||||||
|
this.player.load_level(this.stored_level);
|
||||||
|
this.loaded_in_player = true;
|
||||||
|
}
|
||||||
this.player.activate();
|
this.player.activate();
|
||||||
this.current = this.player;
|
this.current = this.player;
|
||||||
document.body.setAttribute('data-mode', 'player');
|
document.body.setAttribute('data-mode', 'player');
|
||||||
@ -2965,8 +2978,16 @@ class Conductor {
|
|||||||
this.update_level_title();
|
this.update_level_title();
|
||||||
this.update_nav_buttons();
|
this.update_nav_buttons();
|
||||||
|
|
||||||
this.player.load_level(this.stored_level);
|
this.loaded_in_editor = false;
|
||||||
this.editor.load_level(this.stored_level);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user