Fixed bug in assembly worker. Improved undo stack management in quest editor. Improved robustness of quest editor layout persistence.

This commit is contained in:
Daan Vanden Bosch 2019-07-25 17:02:35 +02:00
parent 7f404ff35a
commit 7f4569d40a
4 changed files with 36 additions and 19 deletions

View File

@ -1,6 +1,6 @@
import { observable } from "mobx";
import { editor } from "monaco-editor";
import AssemblyWorker from "worker-loader!./assembly_worker_init";
import AssemblyWorker from "worker-loader!./assembly_worker";
import { Instruction } from "../data_formats/parsing/quest/bin";
import { AssemblyChangeInput, NewAssemblyInput, ScriptWorkerOutput } from "./assembler_messages";
import { AssemblyError } from "./assembly";

View File

@ -90,7 +90,7 @@ function replace_line_part(
line_no - 1,
1,
line_start + new_line_parts[0],
...new_line_parts.slice(1, new_line_parts.length - 2),
...new_line_parts.slice(1, new_line_parts.length - 1),
new_line_parts[new_line_parts.length - 1] + line_end
);
}

View File

@ -110,7 +110,7 @@ editor.defineTheme("phantasmal-world", {
},
});
export class ScriptEditorComponent extends Component {
export class AssemblyEditorComponent extends Component {
render(): ReactNode {
return (
<section id="qe-ScriptEditorComponent" className="qe-ScriptEditorComponent">

View File

@ -1,4 +1,4 @@
import GoldenLayout, { ItemConfigType } from "golden-layout";
import GoldenLayout, { ItemConfigType, ContentItem } from "golden-layout";
import Logger from "js-logger";
import { observer } from "mobx-react";
import React, { Component, createRef, FocusEvent, ReactNode } from "react";
@ -8,11 +8,19 @@ import { EntityInfoComponent } from "./EntityInfoComponent";
import "./QuestEditorComponent.less";
import { QuestInfoComponent } from "./QuestInfoComponent";
import { QuestRendererComponent } from "./QuestRendererComponent";
import { ScriptEditorComponent } from "./ScriptEditorComponent";
import { AssemblyEditorComponent } from "./AssemblyEditorComponent";
import { Toolbar } from "./Toolbar";
const logger = Logger.get("ui/quest_editor/QuestEditorComponent");
// Don't change these ids, as they are persisted in the user's browser.
const CMP_TO_NAME = new Map([
[QuestInfoComponent, "quest_info"],
[QuestRendererComponent, "quest_renderer"],
[AssemblyEditorComponent, "assembly_editor"],
[EntityInfoComponent, "entity_info"],
]);
const DEFAULT_LAYOUT_CONFIG = {
settings: {
showPopoutIcon: false,
@ -35,7 +43,7 @@ const DEFAULT_LAYOUT_CONTENT: ItemConfigType[] = [
{
title: "Info",
type: "react-component",
component: QuestInfoComponent.name,
component: CMP_TO_NAME.get(QuestInfoComponent),
isClosable: false,
width: 3,
},
@ -46,13 +54,13 @@ const DEFAULT_LAYOUT_CONTENT: ItemConfigType[] = [
{
title: "3D View",
type: "react-component",
component: QuestRendererComponent.name,
component: CMP_TO_NAME.get(QuestRendererComponent),
isClosable: false,
},
{
title: "Script",
type: "react-component",
component: ScriptEditorComponent.name,
component: CMP_TO_NAME.get(AssemblyEditorComponent),
isClosable: false,
},
],
@ -60,7 +68,7 @@ const DEFAULT_LAYOUT_CONTENT: ItemConfigType[] = [
{
title: "Entity",
type: "react-component",
component: EntityInfoComponent.name,
component: CMP_TO_NAME.get(EntityInfoComponent),
isClosable: false,
width: 2,
},
@ -81,12 +89,7 @@ export class QuestEditorComponent extends Component {
setTimeout(async () => {
if (this.layout_element.current && !this.layout) {
const content = await quest_editor_ui_persister.load_layout_config(
[
QuestInfoComponent.name,
QuestRendererComponent.name,
EntityInfoComponent.name,
ScriptEditorComponent.name,
],
[...CMP_TO_NAME.values()],
DEFAULT_LAYOUT_CONTENT
);
@ -109,10 +112,10 @@ export class QuestEditorComponent extends Component {
);
}
this.layout.registerComponent(QuestInfoComponent.name, QuestInfoComponent);
this.layout.registerComponent(QuestRendererComponent.name, QuestRendererComponent);
this.layout.registerComponent(EntityInfoComponent.name, EntityInfoComponent);
this.layout.registerComponent(ScriptEditorComponent.name, ScriptEditorComponent);
for (const [component, name] of CMP_TO_NAME) {
this.layout.registerComponent(name, component);
}
this.layout.on("stateChanged", () => {
if (this.layout) {
quest_editor_ui_persister.persist_layout_config(
@ -121,6 +124,20 @@ export class QuestEditorComponent extends Component {
}
});
this.layout.on("stackCreated", (stack: ContentItem) => {
stack.on("activeContentItemChanged", (item: ContentItem) => {
if ("component" in item.config) {
if (
item.config.component === CMP_TO_NAME.get(AssemblyEditorComponent)
) {
quest_editor_store.script_undo.make_current();
} else {
quest_editor_store.undo.make_current();
}
}
});
});
this.layout.init();
}
}, 0);