Pixel-Composer/scripts/preferences/preferences.gml

296 lines
7.6 KiB
Text
Raw Normal View History

2022-01-13 05:24:03 +01:00
#region data
globalvar PREF_MAP;
PREF_MAP = ds_map_create();
#endregion
#region pref map
2022-11-21 06:38:44 +01:00
PREF_MAP[? "ui_framerate"] = 60;
2022-01-13 05:24:03 +01:00
PREF_MAP[? "path_resolution"] = 32;
2022-12-12 09:08:03 +01:00
PREF_MAP[? "double_click_delay"] = 0.25;
2023-04-07 21:25:27 +02:00
PREF_MAP[? "mouse_wheel_speed"] = 1.00;
2022-12-12 09:08:03 +01:00
PREF_MAP[? "keyboard_repeat_start"] = 0.50;
PREF_MAP[? "keyboard_repeat_speed"] = 0.10;
2022-01-13 05:24:03 +01:00
2023-03-05 07:16:44 +01:00
PREF_MAP[? "show_splash"] = true;
PREF_MAP[? "splash_expand_recent"] = false;
PREF_MAP[? "notification_time"] = 180;
2022-01-13 05:24:03 +01:00
PREF_MAP[? "display_scaling"] = 1;
PREF_MAP[? "window_width"] = 1600;
PREF_MAP[? "window_height"] = 800;
PREF_MAP[? "window_maximize"] = false;
2023-01-04 02:30:04 +01:00
PREF_MAP[? "connection_line_width"] = 2;
PREF_MAP[? "connection_line_sample"] = 1;
2023-03-05 07:16:44 +01:00
PREF_MAP[? "connection_line_corner"] = 8;
PREF_MAP[? "connection_line_aa"] = 2;
2023-03-28 06:58:28 +02:00
PREF_MAP[? "connection_line_transition"] = true;
2023-03-05 07:16:44 +01:00
PREF_MAP[? "curve_connection_line"] = 1;
2022-01-13 05:24:03 +01:00
PREF_MAP[? "default_surface_side"] = 32;
2023-03-11 01:40:17 +01:00
PREF_MAP[? "panel_layout_file"] = "Vertical";
2023-04-21 19:08:10 +02:00
PREF_MAP[? "panel_graph_dragging"] = MOD_KEY.alt;
PREF_MAP[? "panel_preview_dragging"] = MOD_KEY.alt;
2022-01-13 05:24:03 +01:00
2022-09-21 06:09:40 +02:00
PREF_MAP[? "inspector_line_break_width"] = 500;
2022-12-10 05:06:01 +01:00
PREF_MAP[? "node_show_render_status"] = false;
PREF_MAP[? "node_show_time"] = true;
2022-01-25 10:58:11 +01:00
PREF_MAP[? "collection_preview_speed"] = 60;
2022-11-14 03:16:15 +01:00
PREF_MAP[? "expand_hover"] = false;
2022-11-18 03:20:31 +01:00
2022-12-10 05:06:01 +01:00
PREF_MAP[? "graph_zoom_smoooth"] = 4;
2022-11-18 03:20:31 +01:00
PREF_MAP[? "theme"] = "default";
2023-06-04 18:28:29 +02:00
PREF_MAP[? "local"] = "en";
2023-01-09 03:14:20 +01:00
PREF_MAP[? "dialog_add_node_grouping"] = true;
PREF_MAP[? "dialog_add_node_view"] = 0;
2023-01-25 06:49:00 +01:00
PREF_MAP[? "physics_gravity"] = [ 0, 10 ];
2023-02-14 02:51:14 +01:00
PREF_MAP[? "test_mode"] = false;
2023-02-15 10:04:49 +01:00
PREF_MAP[? "auto_save_time"] = 300;
2023-02-19 02:13:19 +01:00
PREF_MAP[? "use_legacy_exception"] = false;
2023-02-23 07:02:19 +01:00
PREF_MAP[? "dialog_add_node_w"] = 532;
PREF_MAP[? "dialog_add_node_h"] = 400;
2023-03-02 07:59:14 +01:00
PREF_MAP[? "panel_menu_resource_monitor"] = false;
2023-03-11 06:40:34 +01:00
PREF_MAP[? "panel_menu_right_control"] = os_type == os_windows;
2023-04-09 21:24:16 +02:00
PREF_MAP[? "show_crash_dialog"] = false;
2023-05-03 21:42:17 +02:00
PREF_MAP[? "save_file_minify"] = true;
2022-01-13 05:24:03 +01:00
#endregion
#region hotkeys
function hotkeyObject(_context, _name, _key, _mod, _action) constructor {
context = _context;
name = _name;
key = _key;
modi = _mod;
action = _action;
2023-01-17 08:11:55 +01:00
dKey = _key;
dModi = _mod;
2022-01-13 05:24:03 +01:00
static serialize = function() {
var ll = ds_list_create();
ll[| 0] = context;
ll[| 1] = name;
ll[| 2] = key;
ll[| 3] = modi;
return ll;
}
static deserialize = function(ll) {
2023-01-17 08:11:55 +01:00
key = ll[| 2];
2022-01-13 05:24:03 +01:00
modi = ll[| 3];
}
}
function addHotkey(_context, _name, _key, _mod, _action) {
2023-01-17 08:11:55 +01:00
if(is_string(_key)) {
var ind = key_get_index(_key);
_key = ind? ind : ord(_key);
}
2022-01-13 05:24:03 +01:00
var key = new hotkeyObject(_context, _name, _key, _mod, _action);
if(!ds_map_exists(HOTKEYS, _context)) {
HOTKEYS[? _context] = ds_list_create();
2023-03-21 03:01:53 +01:00
if(!ds_list_exist(HOTKEY_CONTEXT, _context))
2022-01-13 05:24:03 +01:00
ds_list_add(HOTKEY_CONTEXT, _context);
}
for(var i = 0; i < ds_list_size(HOTKEYS[? _context]); i++) {
var hotkey = HOTKEYS[? _context][| i];
if(hotkey.name == key.name) {
delete HOTKEYS[? _context][| i];
HOTKEYS[? _context][| i] = key;
return;
}
}
if(_context == "")
ds_list_insert(HOTKEYS[? _context], 0, key);
else
ds_list_add(HOTKEYS[? _context], key);
}
#endregion
#region recent files
2023-03-05 07:16:44 +01:00
globalvar RECENT_FILES, RECENT_FILE_DATA;
RECENT_FILES = ds_list_create();
RECENT_FILE_DATA = ds_list_create();
2022-01-13 05:24:03 +01:00
function RECENT_SAVE() {
var map = ds_map_create();
var l = ds_list_create();
ds_list_copy(l, RECENT_FILES);
ds_map_add_list(map, "Recents", l);
var path = DIRECTORY + "recent.json";
var file = file_text_open_write(path);
2023-02-14 02:51:14 +01:00
file_text_write_string(file, json_encode_minify(map));
2022-01-13 05:24:03 +01:00
file_text_close(file);
ds_map_destroy(map);
}
function RECENT_LOAD() {
var path = DIRECTORY + "recent.json";
if(!file_exists(path)) return;
var file = file_text_open_read(path);
var load_str = "";
while(!file_text_eof(file)) {
load_str += file_text_readln(file);
}
file_text_close(file);
var map = json_decode(load_str);
if(ds_map_exists(map, "Recents")) {
2023-01-17 08:11:55 +01:00
var l = map[? "Recents"];
ds_list_clear(RECENT_FILES);
2022-01-13 05:24:03 +01:00
2023-01-17 08:11:55 +01:00
for(var i = 0; i < ds_list_size(l); i++) {
if(!file_exists(l[| i])) continue;
ds_list_add(RECENT_FILES, l[| i]);
2022-01-13 05:24:03 +01:00
}
}
2023-03-05 07:16:44 +01:00
RECENT_REFRESH();
}
function RECENT_REFRESH() {
for( var i = 0; i < ds_list_size(RECENT_FILE_DATA); i++ ) {
var d = RECENT_FILE_DATA[| i];
if(sprite_exists(d.spr)) sprite_delete(d.spr);
if(surface_exists(d.thumbnail)) surface_free(d.thumbnail);
}
ds_list_clear(RECENT_FILE_DATA);
for( var i = 0; i < ds_list_size(RECENT_FILES); i++ ) {
var p = RECENT_FILES[| i];
RECENT_FILE_DATA[| i] = new FileObject(filename_name_only(p), p);
}
2022-01-13 05:24:03 +01:00
}
#endregion
#region save load
function PREF_SAVE() {
var map = ds_map_create();
var save_l = ds_list_create();
for(var j = 0; j < ds_list_size(HOTKEY_CONTEXT); j++) {
var ll = HOTKEYS[? HOTKEY_CONTEXT[| j]];
for(var i = 0; i < ds_list_size(ll); i++) {
ds_list_add(save_l, ll[| i].serialize());
ds_list_mark_as_list(save_l, ds_list_size(save_l) - 1);
}
}
ds_map_add_list(map, "key", save_l);
2023-02-23 07:02:19 +01:00
PREF_MAP[? "window_maximize"] = gameframe_is_maximized();
PREF_MAP[? "window_width"] = gameframe_restoreRect_hx[2];
PREF_MAP[? "window_height"] = gameframe_restoreRect_hx[3];
2023-02-14 02:51:14 +01:00
2022-01-13 05:24:03 +01:00
var _pref = ds_map_create();
ds_map_override(_pref, PREF_MAP);
2023-01-25 06:49:00 +01:00
ds_map_arr_to_list(_pref);
2022-01-13 05:24:03 +01:00
ds_map_add_map(map, "preferences", _pref);
var path = DIRECTORY + "keys.json";
2023-02-28 09:43:01 +01:00
file_text_write_all(path, json_encode_minify(map));
2022-01-13 05:24:03 +01:00
ds_map_destroy(map);
2023-03-21 03:01:53 +01:00
2023-03-28 06:58:28 +02:00
json_save_struct(DIRECTORY + "Nodes/fav.json", global.FAV_NODES);
json_save_struct(DIRECTORY + "Nodes/recent.json", global.RECENT_NODES);
2022-01-13 05:24:03 +01:00
}
function PREF_LOAD() {
var path = DIRECTORY + "keys.json";
if(!file_exists(path)) return;
2023-02-28 09:43:01 +01:00
var load_str = file_text_read_all(path);
2022-01-13 05:24:03 +01:00
var map = json_decode(load_str);
if(ds_map_exists(map, "key")) {
var key = map[? "key"];
for(var i = 0; i < ds_list_size(key); i++) {
var key_list = key[| i];
var _context = key_list[| 0];
var name = key_list[| 1];
var _key = find_hotkey(_context, name);
2023-01-17 08:11:55 +01:00
if(_key) _key.deserialize(key_list);
2022-01-13 05:24:03 +01:00
}
}
if(ds_map_exists(map, "preferences")) {
2023-01-25 06:49:00 +01:00
ds_map_list_to_arr(map[? "preferences"]);
2022-01-13 05:24:03 +01:00
ds_map_override(PREF_MAP, map[? "preferences"]);
}
ds_map_destroy(map);
2023-04-08 20:06:27 +02:00
if(!directory_exists(DIRECTORY + "Themes/" + PREF_MAP[? "theme"]))
PREF_MAP[? "theme"] = "default";
2023-01-25 06:49:00 +01:00
}
function PREF_APPLY() {
2023-02-14 02:51:14 +01:00
if(PREF_MAP[? "double_click_delay"] > 1)
PREF_MAP[? "double_click_delay"] /= 60;
if(ds_map_exists(PREF_MAP, "test_mode"))
TESTING = PREF_MAP[? "test_mode"];
2022-09-27 06:37:28 +02:00
2023-02-19 02:13:19 +01:00
if(ds_map_exists(PREF_MAP, "use_legacy_exception")) {
if(PREF_MAP[? "use_legacy_exception"])
resetException();
else
setException();
}
2023-03-21 12:50:08 +01:00
if(OS != os_macosx && !LOADING) {
2023-02-23 07:02:19 +01:00
if(PREF_MAP[? "window_maximize"]) {
gameframe_maximize();
} else {
var ww = PREF_MAP[? "window_width"];
var hh = PREF_MAP[? "window_height"];
2023-02-14 02:51:14 +01:00
2023-02-23 07:02:19 +01:00
window_set_position(display_get_width() / 2 - ww / 2, display_get_height() / 2 - hh / 2);
window_set_size(ww, hh);
}
2022-01-13 05:24:03 +01:00
}
2022-11-21 06:38:44 +01:00
game_set_speed(PREF_MAP[? "ui_framerate"], gamespeed_fps);
2023-01-25 06:49:00 +01:00
2023-02-14 02:51:14 +01:00
if(ds_map_exists(PREF_MAP, "physics_gravity")) {
var grav = PREF_MAP[? "physics_gravity"];
if(!is_array(grav)) {
grav = [0, 10];
PREF_MAP[? "physics_gravity"] = grav;
}
physics_world_gravity(array_safe_get(grav, 0, 0), array_safe_get(grav, 1, 10));
}
2022-01-13 05:24:03 +01:00
}
function find_hotkey(_context, _name) {
2023-01-17 08:11:55 +01:00
if(!ds_map_exists(HOTKEYS, _context)) return noone;
for(var j = 0; j < ds_list_size(HOTKEYS[? _context]); j++) {
if(HOTKEYS[? _context][| j].name == _name)
return HOTKEYS[? _context][| j];
2022-01-13 05:24:03 +01:00
}
}
#endregion