Move away from browser as a main plataform
This commit is contained in:
@@ -124,14 +124,6 @@ function handle(message: ClientMessage) {
|
||||
game_window.show_error("bworld", message.message);
|
||||
close();
|
||||
break;
|
||||
case "ask":
|
||||
game_window.set_grabbed(false);
|
||||
send({
|
||||
type: "answer",
|
||||
id: message.id,
|
||||
yes: game_window.ask(message.title, message.text, message.yes, message.no),
|
||||
});
|
||||
break;
|
||||
case "read_clipboard":
|
||||
send({ type: "clipboard", id: message.id, text: game_window.read_clipboard() });
|
||||
break;
|
||||
|
||||
@@ -31,16 +31,12 @@ const SYMBOLS = {
|
||||
SDL_GetClipboardText: { parameters: [], result: "pointer" },
|
||||
SDL_SetClipboardText: { parameters: ["buffer"], result: "bool" },
|
||||
SDL_ShowSimpleMessageBox: { parameters: ["u32", "buffer", "buffer", "pointer"], result: "bool" },
|
||||
SDL_ShowMessageBox: { parameters: ["buffer", "buffer"], result: "bool" },
|
||||
} as const;
|
||||
|
||||
const INIT_VIDEO = 0x20;
|
||||
const WINDOW_FULLSCREEN = 0x1n;
|
||||
const WINDOW_RESIZABLE = 0x20n;
|
||||
const MESSAGEBOX_ERROR = 0x10;
|
||||
const MESSAGEBOX_WARNING = 0x20;
|
||||
const BUTTON_RETURNKEY_DEFAULT = 0x1;
|
||||
const BUTTON_ESCAPEKEY_DEFAULT = 0x2;
|
||||
|
||||
const EVENT_QUIT = 0x100;
|
||||
const EVENT_WINDOW_SHOWN = 0x202;
|
||||
@@ -227,34 +223,6 @@ export class SdlWindow {
|
||||
this.#sdl.SDL_ShowSimpleMessageBox(MESSAGEBOX_ERROR, c_string(title), c_string(text), this.#window);
|
||||
}
|
||||
|
||||
// waits for the player to pick yes or no, no if the box can't be shown
|
||||
ask(title: string, text: string, yes: string, no: string): boolean {
|
||||
const [title_text, message, yes_text, no_text] = [title, text, yes, no].map(c_string);
|
||||
const ptr = (buffer: Uint8Array<ArrayBuffer>) =>
|
||||
BigInt(Deno.UnsafePointer.value(Deno.UnsafePointer.of(buffer)));
|
||||
// SDL_MessageBoxButtonData: flags, id, text
|
||||
const buttons = new ArrayBuffer(32);
|
||||
const button_view = new DataView(buttons);
|
||||
button_view.setUint32(0, BUTTON_ESCAPEKEY_DEFAULT, true);
|
||||
button_view.setInt32(4, 0, true);
|
||||
button_view.setBigUint64(8, ptr(no_text), true);
|
||||
button_view.setUint32(16, BUTTON_RETURNKEY_DEFAULT, true);
|
||||
button_view.setInt32(20, 1, true);
|
||||
button_view.setBigUint64(24, ptr(yes_text), true);
|
||||
// SDL_MessageBoxData: flags, window, title, message, button count, buttons, colors
|
||||
const data = new ArrayBuffer(56);
|
||||
const data_view = new DataView(data);
|
||||
data_view.setUint32(0, MESSAGEBOX_WARNING, true);
|
||||
data_view.setBigUint64(8, BigInt(Deno.UnsafePointer.value(this.#window)), true);
|
||||
data_view.setBigUint64(16, ptr(title_text), true);
|
||||
data_view.setBigUint64(24, ptr(message), true);
|
||||
data_view.setInt32(32, 2, true);
|
||||
data_view.setBigUint64(40, ptr(new Uint8Array(buttons)), true);
|
||||
const picked = new Int32Array([0]);
|
||||
const shown = this.#sdl.SDL_ShowMessageBox(new Uint8Array(data), picked);
|
||||
return shown && picked[0] === 1;
|
||||
}
|
||||
|
||||
// everything that happened since the last call, as the client's messages. on_close is for the window being closed
|
||||
poll(send: (message: WindowMessage) => void, on_close: () => void) {
|
||||
const sdl = this.#sdl;
|
||||
|
||||
Reference in New Issue
Block a user