diff --git a/src/quest_editor/QuestRunner.ts b/src/quest_editor/QuestRunner.ts index b8efc917..43917d5a 100644 --- a/src/quest_editor/QuestRunner.ts +++ b/src/quest_editor/QuestRunner.ts @@ -2,9 +2,13 @@ import { ExecutionResult, VirtualMachine } from "./scripting/vm"; import { QuestModel } from "./model/QuestModel"; import { VirtualMachineIO } from "./scripting/vm/io"; import { AsmToken } from "./scripting/instructions"; -import Logger from "js-logger"; +import { quest_editor_store } from "./stores/QuestEditorStore"; -const logger = Logger.get("quest_editor/QuestRunner"); +const logger = quest_editor_store.get_logger("quest_editor/QuestRunner"); + +function srcloc_to_string(srcloc: AsmToken): string { + return `[${srcloc.line_no}:${srcloc.col}]`; +} export class QuestRunner { private readonly vm: VirtualMachine; @@ -62,11 +66,11 @@ export class QuestRunner { mesend: (): void => {}, warning: (msg: string, srcloc?: AsmToken): void => { - logger.warn(msg); + logger.warning(msg, srcloc && srcloc_to_string(srcloc)); }, error: (err: Error, srcloc?: AsmToken): void => { - logger.error(err); + logger.error(err, srcloc && srcloc_to_string(srcloc)); }, }; }; diff --git a/src/quest_editor/stores/QuestEditorStore.ts b/src/quest_editor/stores/QuestEditorStore.ts index f4b0785c..20dad0b2 100644 --- a/src/quest_editor/stores/QuestEditorStore.ts +++ b/src/quest_editor/stores/QuestEditorStore.ts @@ -27,7 +27,6 @@ import { RemoveEntityAction } from "../actions/RemoveEntityAction"; import { Euler, Vector3 } from "three"; import { RotateEntityAction } from "../actions/RotateEntityAction"; import { convert_quest_from_model, convert_quest_to_model } from "./model_conversion"; -import { QuestRunner } from "../QuestRunner"; import Logger = require("js-logger"); import { MessageLogStore, LogMessage, LogLevel, LogGroup } from "../../core/gui/MessageLog"; import { ListProperty } from "../../core/observable/property/list/ListProperty"; @@ -37,7 +36,6 @@ const logger = Logger.get("quest_editor/gui/QuestEditorStore"); export class QuestEditorStore implements Disposable, MessageLogStore { private readonly disposer = new Disposer(); - private readonly quest_runner = new QuestRunner(); /** * Log levels as Record @@ -311,11 +309,15 @@ export class QuestEditorStore implements Disposable, MessageLogStore { }; run_current_quest = (): void => { - const quest = this.current_quest.val; + // workaround for circular dependency + import("../QuestRunner").then(({ QuestRunner }) => { + const quest = this.current_quest.val; + const quest_runner = new QuestRunner(); - if (quest) { - this.quest_runner.run(quest); - } + if (quest) { + quest_runner.run(quest); + } + }); }; private log_message_predicate = (msg: LogMessage): boolean => {