2019-08-11 01:37:34 +08:00
|
|
|
import { action, observable } from "mobx";
|
2019-07-23 21:54:42 +08:00
|
|
|
import { editor } from "monaco-editor";
|
2019-07-25 23:02:35 +08:00
|
|
|
import AssemblyWorker from "worker-loader!./assembly_worker";
|
2019-08-11 00:11:27 +08:00
|
|
|
import {
|
|
|
|
AssemblyChangeInput,
|
|
|
|
AssemblyWorkerOutput,
|
|
|
|
NewAssemblyInput,
|
|
|
|
} from "./assembly_worker_messages";
|
|
|
|
import { AssemblyError, AssemblyWarning } from "./assembly";
|
2019-07-23 21:54:42 +08:00
|
|
|
import { disassemble } from "./disassembly";
|
2019-08-11 00:11:27 +08:00
|
|
|
import { ObservableQuest } from "../domain/ObservableQuest";
|
2019-07-23 21:54:42 +08:00
|
|
|
|
2019-07-29 07:02:22 +08:00
|
|
|
export class AssemblyAnalyser {
|
2019-08-11 00:11:27 +08:00
|
|
|
@observable warnings: AssemblyWarning[] = [];
|
2019-07-23 21:54:42 +08:00
|
|
|
@observable errors: AssemblyError[] = [];
|
|
|
|
|
|
|
|
private worker = new AssemblyWorker();
|
2019-08-11 00:11:27 +08:00
|
|
|
private quest?: ObservableQuest;
|
2019-07-23 21:54:42 +08:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.worker.onmessage = this.process_worker_message;
|
|
|
|
}
|
|
|
|
|
2019-08-11 00:11:27 +08:00
|
|
|
disassemble(quest: ObservableQuest): string[] {
|
|
|
|
this.quest = quest;
|
|
|
|
const assembly = disassemble(quest.object_code);
|
2019-07-23 21:54:42 +08:00
|
|
|
const message: NewAssemblyInput = { type: "new_assembly_input", assembly };
|
|
|
|
this.worker.postMessage(message);
|
|
|
|
return assembly;
|
|
|
|
}
|
|
|
|
|
|
|
|
update_assembly(changes: editor.IModelContentChange[]): void {
|
|
|
|
const message: AssemblyChangeInput = { type: "assembly_change_input", changes };
|
|
|
|
this.worker.postMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
dispose(): void {
|
|
|
|
this.worker.terminate();
|
|
|
|
}
|
|
|
|
|
2019-08-11 01:37:34 +08:00
|
|
|
@action
|
2019-07-23 21:54:42 +08:00
|
|
|
private process_worker_message = (e: MessageEvent): void => {
|
2019-08-11 00:11:27 +08:00
|
|
|
const message: AssemblyWorkerOutput = e.data;
|
2019-07-23 21:54:42 +08:00
|
|
|
|
2019-08-11 00:11:27 +08:00
|
|
|
if (message.type === "new_object_code_output" && this.quest) {
|
|
|
|
this.quest.object_code.splice(0, this.quest.object_code.length, ...message.object_code);
|
2019-08-11 01:37:34 +08:00
|
|
|
this.quest.set_map_designations(message.map_designations);
|
2019-08-11 00:11:27 +08:00
|
|
|
this.warnings = message.warnings;
|
2019-07-23 21:54:42 +08:00
|
|
|
this.errors = message.errors;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|