mirror of
https://github.com/DaanVandenBosch/phantasmal-world.git
synced 2025-04-05 15:28:29 +08:00
Added a checkbox for enabling inline arguments transformation mode to the script editor toolbar.
This commit is contained in:
parent
463685ffa1
commit
0618ca0b87
@ -1,12 +1,35 @@
|
||||
import { ToolBar } from "../../core/gui/ToolBar";
|
||||
import { Button } from "../../core/gui/Button";
|
||||
import { CheckBox } from "../../core/gui/CheckBox";
|
||||
import { asm_editor_store } from "../stores/AsmEditorStore";
|
||||
|
||||
export class AsmEditorToolBar extends ToolBar {
|
||||
constructor() {
|
||||
const inline_args_mode_checkbox = new CheckBox(true, {
|
||||
label: "Inline args mode",
|
||||
tooltip: asm_editor_store.has_issues.map((has_issues) => {
|
||||
let text = "Transform arg_push* opcodes to be inline with the opcode the arguments are given to.";
|
||||
|
||||
if (has_issues) {
|
||||
text += "\nThis mode cannot be toggled because there are issues in the script.";
|
||||
}
|
||||
|
||||
return text;
|
||||
}),
|
||||
});
|
||||
|
||||
super({
|
||||
children: [],
|
||||
children: [
|
||||
inline_args_mode_checkbox
|
||||
],
|
||||
});
|
||||
|
||||
this.disposables(
|
||||
asm_editor_store.inline_args_mode.bind_to(inline_args_mode_checkbox.checked),
|
||||
|
||||
inline_args_mode_checkbox.enabled.bind_to(asm_editor_store.has_issues.map(b => !b)),
|
||||
);
|
||||
|
||||
|
||||
this.finalize_construction(AsmEditorToolBar.prototype);
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,9 @@ import {
|
||||
NewAssemblyInput,
|
||||
OutputMessageType,
|
||||
SignatureHelpInput,
|
||||
AssemblySettingsChangeInput,
|
||||
} from "./assembly_worker_messages";
|
||||
import { AssemblyError, AssemblyWarning } from "./assembly";
|
||||
import { AssemblyError, AssemblyWarning, AssemblySettings } from "./assembly";
|
||||
import { disassemble } from "./disassembly";
|
||||
import { QuestModel } from "../model/QuestModel";
|
||||
import { Kind, OPCODES } from "./opcodes";
|
||||
@ -130,6 +131,14 @@ export class AssemblyAnalyser implements Disposable {
|
||||
});
|
||||
}
|
||||
|
||||
update_settings(changed_settings: Partial<AssemblySettings>): void {
|
||||
const message: AssemblySettingsChangeInput = {
|
||||
type: InputMessageType.SettingsChange,
|
||||
settings: changed_settings
|
||||
};
|
||||
this.worker.postMessage(message);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.worker.terminate();
|
||||
}
|
||||
|
@ -35,6 +35,10 @@ export type AssemblyWarning = {
|
||||
|
||||
export type AssemblyError = AssemblyWarning;
|
||||
|
||||
export type AssemblySettings = {
|
||||
manual_stack: boolean
|
||||
};
|
||||
|
||||
export function assemble(
|
||||
assembly: string[],
|
||||
manual_stack: boolean = false,
|
||||
|
@ -6,8 +6,9 @@ import {
|
||||
OutputMessageType,
|
||||
SignatureHelpInput,
|
||||
SignatureHelpOutput,
|
||||
AssemblySettingsChangeInput,
|
||||
} from "./assembly_worker_messages";
|
||||
import { assemble } from "./assembly";
|
||||
import { assemble, AssemblySettings } from "./assembly";
|
||||
import Logger from "js-logger";
|
||||
import { SegmentType } from "./instructions";
|
||||
import { Opcode, OPCODES_BY_MNEMONIC } from "./opcodes";
|
||||
@ -24,6 +25,10 @@ let lines: string[] = [];
|
||||
const messages: AssemblyWorkerInput[] = [];
|
||||
let timeout: any;
|
||||
|
||||
const assembly_settings: AssemblySettings = {
|
||||
manual_stack: false
|
||||
};
|
||||
|
||||
ctx.onmessage = (e: MessageEvent) => {
|
||||
messages.push(e.data);
|
||||
|
||||
@ -52,6 +57,9 @@ function process_messages(): void {
|
||||
case InputMessageType.SignatureHelp:
|
||||
signature_help(message);
|
||||
break;
|
||||
case InputMessageType.SettingsChange:
|
||||
settings_change(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -130,8 +138,17 @@ function signature_help(message: SignatureHelpInput): void {
|
||||
ctx.postMessage(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply changes to settings.
|
||||
*/
|
||||
function settings_change(message: AssemblySettingsChangeInput): void {
|
||||
if (message.settings.hasOwnProperty("manual_stack")) {
|
||||
assembly_settings.manual_stack = Boolean(message.settings.manual_stack);
|
||||
}
|
||||
}
|
||||
|
||||
function assemble_and_send(): void {
|
||||
const assembler_result = assemble(lines);
|
||||
const assembler_result = assemble(lines, assembly_settings.manual_stack);
|
||||
const map_designations = new Map<number, number>();
|
||||
|
||||
for (const segment of assembler_result.object_code) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { AssemblyError, AssemblyWarning } from "./assembly";
|
||||
import { AssemblyError, AssemblyWarning, AssemblySettings } from "./assembly";
|
||||
import { Segment } from "./instructions";
|
||||
import { Opcode } from "./opcodes";
|
||||
|
||||
@ -6,9 +6,10 @@ export enum InputMessageType {
|
||||
NewAssembly,
|
||||
AssemblyChange,
|
||||
SignatureHelp,
|
||||
SettingsChange,
|
||||
}
|
||||
|
||||
export type AssemblyWorkerInput = NewAssemblyInput | AssemblyChangeInput | SignatureHelpInput;
|
||||
export type AssemblyWorkerInput = NewAssemblyInput | AssemblyChangeInput | SignatureHelpInput | AssemblySettingsChangeInput;
|
||||
|
||||
export type NewAssemblyInput = {
|
||||
readonly type: InputMessageType.NewAssembly;
|
||||
@ -33,6 +34,11 @@ export type SignatureHelpInput = {
|
||||
readonly col: number;
|
||||
};
|
||||
|
||||
export type AssemblySettingsChangeInput = {
|
||||
readonly type: InputMessageType.SettingsChange;
|
||||
readonly settings: Partial<AssemblySettings>;
|
||||
};
|
||||
|
||||
export enum OutputMessageType {
|
||||
NewObjectCode,
|
||||
SignatureHelp,
|
||||
|
@ -69,6 +69,9 @@ export class AsmEditorStore implements Disposable {
|
||||
() => this._did_redo.emit({ value: "asm undo" }),
|
||||
);
|
||||
|
||||
readonly inline_args_mode: WritableProperty<boolean> = property(true);
|
||||
readonly has_issues: WritableProperty<boolean> = property(false);
|
||||
|
||||
private readonly disposer = new Disposer();
|
||||
private readonly model_disposer = this.disposer.add(new Disposer());
|
||||
private readonly _model: WritableProperty<ITextModel | undefined> = property(undefined);
|
||||
@ -88,6 +91,17 @@ export class AsmEditorStore implements Disposable {
|
||||
assembly_analyser.issues.observe(({ value }) => this.update_model_markers(value), {
|
||||
call_now: true,
|
||||
}),
|
||||
|
||||
this.inline_args_mode.observe(() => {
|
||||
// don't allow changing inline args mode if there are issues
|
||||
if (!this.has_issues.val) {
|
||||
this.update_assembly_settings();
|
||||
}
|
||||
}),
|
||||
|
||||
assembly_analyser.issues.observe(({ value }) => {
|
||||
this.has_issues.val = Boolean(value.warnings.length) || Boolean(value.errors.length);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@ -188,6 +202,12 @@ export class AsmEditorStore implements Disposable {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
private update_assembly_settings(): void {
|
||||
assembly_analyser.update_settings({
|
||||
manual_stack: !this.inline_args_mode.val
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const asm_editor_store = new AsmEditorStore();
|
||||
|
Loading…
Reference in New Issue
Block a user