Files
armorpaint/base/sources/ts/tab_scripts.ts
T

78 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-03-14 15:31:22 +01:00
2025-08-11 21:57:34 +02:00
let tab_scripts_hscript: ui_handle_t = ui_handle_create();
let tab_scripts_text_coloring: ui_text_coloring_t = null;
2024-03-14 15:31:22 +01:00
2025-08-11 21:57:34 +02:00
function tab_scripts_draw(htab: ui_handle_t) {
2024-09-03 15:52:05 +02:00
let ui: ui_t = ui_base_ui;
2025-08-11 21:57:34 +02:00
if (ui_tab(htab, tr("Scripts"))) {
2024-03-14 15:31:22 +01:00
2024-09-03 15:52:05 +02:00
ui_begin_sticky();
2025-08-14 20:19:59 +02:00
let row: f32[] = [1 / 4, 1 / 4, 1 / 2];
ui_row(row);
2024-09-03 15:52:05 +02:00
if (ui_button(tr("Run"))) {
2025-08-11 21:57:34 +02:00
js_eval(tab_scripts_hscript.text);
2024-03-14 15:31:22 +01:00
}
2025-08-14 20:19:59 +02:00
if (ui_button(tr("Edit"))) {
ui_menu_draw(function (ui: ui_t) {
if (ui_menu_button(tr("Clear"))) {
tab_scripts_hscript.text = "";
}
if (ui_menu_button(tr("Import"))) {
ui_files_show("js", false, false, function (path: string) {
let b: buffer_t = data_get_blob(path);
tab_scripts_hscript.text = sys_buffer_to_string(b);
data_delete_blob(path);
});
2024-03-20 16:13:54 +01:00
}
2025-08-14 20:19:59 +02:00
if (ui_menu_button(tr("Export"))) {
ui_files_show("js", true, false, function (path: string) {
let str: string = tab_scripts_hscript.text;
let f: string = ui_files_filename;
if (f == "") {
f = tr("untitled");
}
path = path + path_sep + f;
if (!ends_with(path, ".js")) {
path += ".js";
}
iron_file_save_bytes(path, sys_string_to_buffer(str), 0);
});
2024-03-20 16:13:54 +01:00
}
2024-03-14 15:31:22 +01:00
});
2025-08-14 20:19:59 +02:00
2024-03-14 15:31:22 +01:00
}
2025-08-14 20:19:59 +02:00
let ar: string[] = ["script.js"];
let file_handle: ui_handle_t = ui_handle(__ID__);
ui_combo(file_handle, ar, tr("File"), false, ui_align_t.LEFT);
2024-09-03 15:52:05 +02:00
ui_end_sticky();
2024-03-14 15:31:22 +01:00
2025-03-02 21:07:17 +01:00
let _font: draw_font_t = ui.ops.font;
2024-03-14 15:31:22 +01:00
let _font_size: i32 = ui.font_size;
2025-03-02 21:07:17 +01:00
let f: draw_font_t = data_get_font("font_mono.ttf");
2024-09-03 15:52:05 +02:00
ui_set_font(ui, f);
ui.font_size = math_floor(15 * ui_SCALE(ui));
ui_text_area_line_numbers = true;
ui_text_area_scroll_past_end = true;
2025-08-11 21:57:34 +02:00
ui_text_area_coloring = tab_scripts_get_text_coloring();
ui_text_area(tab_scripts_hscript);
2024-09-03 15:52:05 +02:00
ui_text_area_line_numbers = false;
ui_text_area_scroll_past_end = false;
ui_text_area_coloring = null;
ui_set_font(ui, _font);
2024-03-14 15:31:22 +01:00
ui.font_size = _font_size;
}
}
2025-08-11 21:57:34 +02:00
function tab_scripts_get_text_coloring(): ui_text_coloring_t {
if (tab_scripts_text_coloring == null) {
2024-03-20 16:13:54 +01:00
let blob: buffer_t = data_get_blob("text_coloring.json");
2025-08-11 21:57:34 +02:00
tab_scripts_text_coloring = json_parse(sys_buffer_to_string(blob));
2024-03-14 15:31:22 +01:00
}
2025-08-11 21:57:34 +02:00
return tab_scripts_text_coloring;
2024-03-14 15:31:22 +01:00
}