Merge pull request #2704 from IvarK/fix-switch-mode-inconsistent

Fix reactivity issues on switching modes
This commit is contained in:
IvarK 2022-06-14 20:38:04 +03:00 committed by GitHub
commit b6a8f4abac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 8 deletions

View File

@ -26,10 +26,7 @@ export default {
set(value) {
this.$viewModel.tabs.reality.automator.editorScriptID = value;
}
},
currentScriptContent() {
return player.reality.automator.scripts[this.currentScriptID].content;
},
}
},
methods: {
update() {
@ -42,7 +39,7 @@ export default {
// This saves the script after converting it.
BlockAutomator.parseTextFromBlocks();
player.reality.automator.type = AUTOMATOR_TYPE.TEXT;
} else if (BlockAutomator.fromText(this.currentScriptContent)) {
} else if (BlockAutomator.fromText(player.reality.automator.scripts[this.currentScriptID].content)) {
AutomatorBackend.saveScript(scriptID, AutomatorTextUI.editor.getDoc().getValue());
player.reality.automator.type = AUTOMATOR_TYPE.BLOCK;
} else {

View File

@ -73,7 +73,12 @@ export default {
},
rewind: () => AutomatorBackend.restart(),
play() {
if (this.hasErrors) return;
if (this.hasErrors) {
// This shouldn't be needed but someone's save was still on MODE.RUN when the script had errors so this
// is just an additional layer of failsafe in case something goes wrong
AutomatorBackend.mode = AUTOMATOR_MODE.PAUSED;
return;
}
if (this.isRunning) {
AutomatorBackend.pause();
return;

View File

@ -62,14 +62,16 @@ export default {
this.$nextTick(() => BlockAutomator.fromText(this.currentScript));
},
toggleAutomatorMode() {
if (AutomatorBackend.state.mode === AUTOMATOR_MODE.PAUSE || !player.options.confirmations.switchAutomatorMode) {
if (AutomatorBackend.mode !== AUTOMATOR_MODE.RUN || !player.options.confirmations.switchAutomatorMode) {
const scriptID = this.currentScriptID;
Tutorial.moveOn(TUTORIAL_STATE.AUTOMATOR);
if (this.automatorType === AUTOMATOR_TYPE.BLOCK) {
// This saves the script after converting it.
BlockAutomator.parseTextFromBlocks();
player.reality.automator.type = AUTOMATOR_TYPE.TEXT;
} else if (BlockAutomator.fromText(this.currentScriptContent)) {
// Don't use this.currentScriptContent here due to reactivity issues, but on the other hand reactively
// updating content might lead to decreased performance.
} else if (BlockAutomator.fromText(player.reality.automator.scripts[this.currentScriptID].content)) {
AutomatorBackend.saveScript(scriptID, AutomatorTextUI.editor.getDoc().getValue());
player.reality.automator.type = AUTOMATOR_TYPE.BLOCK;
} else {