From cf1cd26c41a5b4bdc2bebce84619e95bc38e6c35 Mon Sep 17 00:00:00 2001 From: Daan Vanden Bosch Date: Sat, 10 Aug 2019 19:37:34 +0200 Subject: [PATCH] Fixed a bug in area variants computation. --- src/domain/ObservableQuest.ts | 22 +++++++++++++++------- src/rendering/QuestRenderer.ts | 15 +++++++++------ src/scripting/AssemblyAnalyser.ts | 5 +++-- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/domain/ObservableQuest.ts b/src/domain/ObservableQuest.ts index 8bf991d0..5d03445c 100644 --- a/src/domain/ObservableQuest.ts +++ b/src/domain/ObservableQuest.ts @@ -95,34 +95,42 @@ export class ObservableQuest { return map; } + @observable.ref private _map_designations!: Map; + /** * Map of area IDs to area variant IDs. One designation per area. */ - @observable map_designations: Map; + get map_designations(): Map { + return this._map_designations; + } + + set_map_designations(map_designations: Map): void { + this._map_designations = map_designations; + } /** * One variant per area. */ @computed get area_variants(): ObservableAreaVariant[] { - const variants: ObservableAreaVariant[] = []; + const variants = new Map(); for (const area_id of this.entities_per_area.keys()) { try { - variants.push(area_store.get_variant(this.episode, area_id, 0)); + variants.set(area_id, area_store.get_variant(this.episode, area_id, 0)); } catch (e) { logger.warn(e); } } - for (const [area_id, variant_id] of this.map_designations) { + for (const [area_id, variant_id] of this._map_designations) { try { - variants.push(area_store.get_variant(this.episode, area_id, variant_id)); + variants.set(area_id, area_store.get_variant(this.episode, area_id, variant_id)); } catch (e) { logger.warn(e); } } - return variants; + return [...variants.values()]; } /** @@ -160,7 +168,7 @@ export class ObservableQuest { this.set_short_description(short_description); this.set_long_description(long_description); this.episode = episode; - this.map_designations = map_designations; + this.set_map_designations(map_designations); this.objects = objects; this.npcs = npcs; this.dat_unknowns = dat_unknowns; diff --git a/src/rendering/QuestRenderer.ts b/src/rendering/QuestRenderer.ts index 1f4b981f..47cfbaf7 100644 --- a/src/rendering/QuestRenderer.ts +++ b/src/rendering/QuestRenderer.ts @@ -66,12 +66,15 @@ export class QuestRenderer extends Renderer { const model_manager = new QuestModelManager(this); - autorun(() => { - model_manager.load_models( - quest_editor_store.current_quest, - quest_editor_store.current_area, - ); - }); + autorun( + () => { + model_manager.load_models( + quest_editor_store.current_quest, + quest_editor_store.current_area, + ); + }, + { name: "call load_models" }, + ); this.entity_controls = new QuestEntityControls(this); diff --git a/src/scripting/AssemblyAnalyser.ts b/src/scripting/AssemblyAnalyser.ts index e59092e1..290662dd 100644 --- a/src/scripting/AssemblyAnalyser.ts +++ b/src/scripting/AssemblyAnalyser.ts @@ -1,4 +1,4 @@ -import { observable } from "mobx"; +import { action, observable } from "mobx"; import { editor } from "monaco-editor"; import AssemblyWorker from "worker-loader!./assembly_worker"; import { @@ -38,12 +38,13 @@ export class AssemblyAnalyser { this.worker.terminate(); } + @action private process_worker_message = (e: MessageEvent): void => { const message: AssemblyWorkerOutput = e.data; if (message.type === "new_object_code_output" && this.quest) { this.quest.object_code.splice(0, this.quest.object_code.length, ...message.object_code); - this.quest.map_designations = message.map_designations; + this.quest.set_map_designations(message.map_designations); this.warnings = message.warnings; this.errors = message.errors; }