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 { observable } from "mobx";
import { editor } from "monaco-editor"; 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 { Instruction } from "../data_formats/parsing/quest/bin";
import { AssemblyChangeInput, NewAssemblyInput, ScriptWorkerOutput } from "./assembler_messages"; import { AssemblyChangeInput, NewAssemblyInput, ScriptWorkerOutput } from "./assembler_messages";
import { AssemblyError } from "./assembly"; import { AssemblyError } from "./assembly";

View File

@ -90,7 +90,7 @@ function replace_line_part(
line_no - 1, line_no - 1,
1, 1,
line_start + new_line_parts[0], 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 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 { render(): ReactNode {
return ( return (
<section id="qe-ScriptEditorComponent" className="qe-ScriptEditorComponent"> <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 Logger from "js-logger";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import React, { Component, createRef, FocusEvent, ReactNode } from "react"; import React, { Component, createRef, FocusEvent, ReactNode } from "react";
@ -8,11 +8,19 @@ import { EntityInfoComponent } from "./EntityInfoComponent";
import "./QuestEditorComponent.less"; import "./QuestEditorComponent.less";
import { QuestInfoComponent } from "./QuestInfoComponent"; import { QuestInfoComponent } from "./QuestInfoComponent";
import { QuestRendererComponent } from "./QuestRendererComponent"; import { QuestRendererComponent } from "./QuestRendererComponent";
import { ScriptEditorComponent } from "./ScriptEditorComponent"; import { AssemblyEditorComponent } from "./AssemblyEditorComponent";
import { Toolbar } from "./Toolbar"; import { Toolbar } from "./Toolbar";
const logger = Logger.get("ui/quest_editor/QuestEditorComponent"); 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 = { const DEFAULT_LAYOUT_CONFIG = {
settings: { settings: {
showPopoutIcon: false, showPopoutIcon: false,
@ -35,7 +43,7 @@ const DEFAULT_LAYOUT_CONTENT: ItemConfigType[] = [
{ {
title: "Info", title: "Info",
type: "react-component", type: "react-component",
component: QuestInfoComponent.name, component: CMP_TO_NAME.get(QuestInfoComponent),
isClosable: false, isClosable: false,
width: 3, width: 3,
}, },
@ -46,13 +54,13 @@ const DEFAULT_LAYOUT_CONTENT: ItemConfigType[] = [
{ {
title: "3D View", title: "3D View",
type: "react-component", type: "react-component",
component: QuestRendererComponent.name, component: CMP_TO_NAME.get(QuestRendererComponent),
isClosable: false, isClosable: false,
}, },
{ {
title: "Script", title: "Script",
type: "react-component", type: "react-component",
component: ScriptEditorComponent.name, component: CMP_TO_NAME.get(AssemblyEditorComponent),
isClosable: false, isClosable: false,
}, },
], ],
@ -60,7 +68,7 @@ const DEFAULT_LAYOUT_CONTENT: ItemConfigType[] = [
{ {
title: "Entity", title: "Entity",
type: "react-component", type: "react-component",
component: EntityInfoComponent.name, component: CMP_TO_NAME.get(EntityInfoComponent),
isClosable: false, isClosable: false,
width: 2, width: 2,
}, },
@ -81,12 +89,7 @@ export class QuestEditorComponent extends Component {
setTimeout(async () => { setTimeout(async () => {
if (this.layout_element.current && !this.layout) { if (this.layout_element.current && !this.layout) {
const content = await quest_editor_ui_persister.load_layout_config( const content = await quest_editor_ui_persister.load_layout_config(
[ [...CMP_TO_NAME.values()],
QuestInfoComponent.name,
QuestRendererComponent.name,
EntityInfoComponent.name,
ScriptEditorComponent.name,
],
DEFAULT_LAYOUT_CONTENT DEFAULT_LAYOUT_CONTENT
); );
@ -109,10 +112,10 @@ export class QuestEditorComponent extends Component {
); );
} }
this.layout.registerComponent(QuestInfoComponent.name, QuestInfoComponent); for (const [component, name] of CMP_TO_NAME) {
this.layout.registerComponent(QuestRendererComponent.name, QuestRendererComponent); this.layout.registerComponent(name, component);
this.layout.registerComponent(EntityInfoComponent.name, EntityInfoComponent); }
this.layout.registerComponent(ScriptEditorComponent.name, ScriptEditorComponent);
this.layout.on("stateChanged", () => { this.layout.on("stateChanged", () => {
if (this.layout) { if (this.layout) {
quest_editor_ui_persister.persist_layout_config( 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(); this.layout.init();
} }
}, 0); }, 0);