Fix automator bugs related to script indexing, add more debug text for player

This commit is contained in:
SpectralFlame 2022-05-18 05:30:58 -05:00 committed by cyip92
parent b8b4a762b3
commit ed9b995573
6 changed files with 63 additions and 21 deletions

View File

@ -242,20 +242,29 @@ export const AutomatorBackend = {
return this.isOn && this.mode === AUTOMATOR_MODE.RUN;
},
findRawScriptObject(id) {
const auto = player.reality.automator;
const index = Object.values(auto.scripts).findIndex(s => s.id === id);
return auto.scripts[parseInt(Object.keys(auto.scripts)[index], 10)];
},
get currentRunningScript() {
return player.reality.automator.scripts[this.state.topLevelScript];
return this.findRawScriptObject(this.state.topLevelScript);
},
get currentEditingScript() {
const saveIndex = Object.values(player.reality.automator.scripts)
.findIndex(s => s.id === player.reality.automator.state.editorScript);
return player.reality.automator.scripts[saveIndex];
return this.findRawScriptObject(player.reality.automator.state.editorScript);
},
get scriptName() {
return this.currentRunningScript?.name ?? "";
},
hasDuplicateName(name) {
const nameArray = Object.values(player.reality.automator.scripts).map(s => s.name);
return nameArray.filter(n => n === name).length > 1;
},
get currentLineNumber() {
if (!this.stack.top)
return -1;
@ -385,7 +394,7 @@ export const AutomatorBackend = {
} else {
this._scripts = scriptIds.map(s => new AutomatorScript(s));
}
if (!scriptIds.includes(`${this.state.topLevelScript}`)) this.state.topLevelScript = scriptIds[0];
if (!scriptIds.includes(this.state.topLevelScript)) this.state.topLevelScript = scriptIds[0];
const currentScript = this.findScript(this.state.topLevelScript);
if (currentScript.commands) {
const commands = currentScript.commands;
@ -411,7 +420,7 @@ export const AutomatorBackend = {
deleteScript(id) {
// We need to delete scripts from two places - in the savefile and compiled AutomatorScript Objects
const saveId = Object.values(player.reality.automator.scripts).findIndex(s => s.id === id);
delete player.reality.automator.scripts[saveId];
delete player.reality.automator.scripts[parseInt(Object.keys(player.reality.automator.scripts)[saveId], 10)];
const idx = this._scripts.findIndex(e => e.id === id);
this._scripts.splice(idx, 1);
if (this._scripts.length === 0) {

View File

@ -1318,6 +1318,11 @@ GameStorage.devMigrations = {
delete player.celestials.effarig.unlocksBits;
delete player.celestials.ra.unlocksBits;
},
player => {
for (const script of Object.values(player.reality.automator.scripts)) {
script.id = parseInt(script.id, 10);
}
},
],
patch(player) {

View File

@ -15,8 +15,10 @@ export default {
followExecution: false,
hasErrors: false,
currentLine: 0,
runningName: "",
statusName: "",
editingName: "",
duplicateStatus: false,
duplicateEditing: false,
};
},
computed: {
@ -43,10 +45,10 @@ export default {
let lineNum = `0000${this.currentLine}`;
lineNum = lineNum.slice(lineNum.length - digits);
if (this.isPaused) return `Paused: "${this.runningName}" (Resumes on Line ${lineNum})`;
if (this.isRunning) return `Running: "${this.runningName}" (Line ${lineNum})`;
if (this.hasErrors) return `Stopped: "${this.editingName}" has errors (Cannot run)`;
return `Stopped: Will start running "${this.editingName}"`;
if (this.isPaused) return `Paused: "${this.statusName}" (Resumes on Line ${lineNum})`;
if (this.isRunning) return `Running: "${this.statusName}" (Line ${lineNum})`;
if (this.hasErrors) return `Stopped: "${this.statusName}" has errors (Cannot run)`;
return `Stopped: Will start running "${this.statusName}"`;
},
},
methods: {
@ -58,8 +60,15 @@ export default {
this.followExecution = AutomatorBackend.state.followExecution;
this.hasErrors = AutomatorData.currentErrors().length !== 0;
this.currentLine = AutomatorBackend.currentLineNumber;
this.runningName = AutomatorBackend.scriptName;
// When the automator isn't running, the script name contains the last run script instead of the
// to-be-run script, which is the currently displayed one in the editor
this.statusName = (this.isPaused || this.isRunning)
? AutomatorBackend.scriptName
: AutomatorBackend.currentEditingScript.name;
this.editingName = AutomatorBackend.currentEditingScript.name;
this.duplicateStatus = AutomatorBackend.hasDuplicateName(this.statusName);
this.duplicateEditing = AutomatorBackend.hasDuplicateName(this.editingName);
},
rewind: () => AutomatorBackend.restart(),
play() {
@ -129,14 +138,31 @@ export default {
@click="follow"
/>
<div class="c-automator__status-text c-automator__status-text--edit">
<span
v-if="duplicateEditing"
v-tooltip="'More than one script has this name!'"
class="fas fa-exclamation-triangle c-automator__status-text--error"
/>
{{ editingName }}
</div>
</div>
<div
class="l-automator-button-row c-automator__status-text"
:class="{ 'c-automator__status-text--error' : hasErrors && !isRunning }"
>
{{ statusText }}
<div class="l-automator-button-row">
<span
v-if="duplicateStatus"
v-tooltip="'More than one script has this name!'"
class="fas fa-exclamation-triangle c-automator__status-text c-automator__status-text--error"
/>
<span
v-if="statusName !== editingName"
v-tooltip="'The automator is running a different script than the editor is showing'"
class="fas fa-circle-exclamation c-automator__status-text c-automator__status-text--warning"
/>
<span
class="c-automator__status-text"
:class="{ 'c-automator__status-text--error' : hasErrors && !isRunning }"
>
{{ statusText }}
</span>
</div>
</div>
</template>
@ -153,6 +179,10 @@ export default {
color: var(--color-accent);
}
.c-automator__status-text--warning {
color: var(--color-good-paused);
}
.c-automator__status-text--error {
color: var(--color-bad);
}

View File

@ -211,6 +211,7 @@ export default {
@click="infoPaneID = 4"
/>
<AutomatorModeSwitch />
Switching will stop scripts
<AutomatorButton
v-tooltip="fullScreenTooltip"
class="l-automator__maximize-button"

View File

@ -45,6 +45,7 @@ export default {
methods: {
update() {
this.automatorType = player.reality.automator.type;
if (!AutomatorBackend.isOn && AutomatorTextUI.editor) AutomatorTextUI.editor.performLint();
},
onGameLoad() {
this.updateCurrentScriptID();

View File

@ -179,7 +179,3 @@ export const AutomatorTextUI = {
class="c-automator-editor l-automator-editor l-automator-pane__content"
/>
</template>
<style scoped>
</style>