From d8ee2aa09625cef593aaaaa259df1f3c2100bc37 Mon Sep 17 00:00:00 2001 From: Synthasmagoria Date: Sun, 14 Dec 2025 20:44:00 +0100 Subject: [PATCH] Initial commit --- .../objDebugAllInstancesList.object.gmx | 200 +++++++++++++++ .../objDebugInspector.object.gmx | 172 +++++++++++++ .../objDebugInspectorControl.object.gmx | 223 +++++++++++++++++ .../objDebugInspectorInstanceList.object.gmx | 80 ++++++ .../scrDebugInspectorGetView.gml | 13 + .../scrDebugInspectorInitialize.gml | 21 ++ objDebugList.object.gmx | 232 ++++++++++++++++++ 7 files changed, 941 insertions(+) create mode 100644 add after objDebugList/objDebugAllInstancesList.object.gmx create mode 100644 add after objDebugList/objDebugInspector.object.gmx create mode 100644 add after objDebugList/objDebugInspectorControl.object.gmx create mode 100644 add after objDebugList/objDebugInspectorInstanceList.object.gmx create mode 100644 add after objDebugList/scrDebugInspectorGetView.gml create mode 100644 add after objDebugList/scrDebugInspectorInitialize.gml create mode 100644 objDebugList.object.gmx diff --git a/add after objDebugList/objDebugAllInstancesList.object.gmx b/add after objDebugList/objDebugAllInstancesList.object.gmx new file mode 100644 index 0000000..7c68e45 --- /dev/null +++ b/add after objDebugList/objDebugAllInstancesList.object.gmx @@ -0,0 +1,200 @@ + + + <undefined> + 0 + -1 + 0 + -1 + objDebugList + <undefined> + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + event_inherited(); + +x = 4; +y = 4; + +header = "search..."; +written = false; +instances = -1; +items = -1; +keyboard_string = ""; +keyboard_string_prev = ""; +color_timer = 0; + +game_started_before = variable_global_get(global.__synthasmagoria_debug_inspector_global_game_start_name); +variable_global_set(global.__synthasmagoria_debug_inspector_global_game_start_name, false); +event_user(0); + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + variable_global_set(global.__synthasmagoria_debug_inspector_global_game_start_name, game_started_before); + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + event_inherited(); + +color_timer++; + +if (keyboard_string != keyboard_string_prev) { + header = keyboard_string; + keyboard_string_prev = keyboard_string; + event_user(0); +} + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + /// update instances +var +_search = string_lower(keyboard_string), +_instances = array_create(instance_count), +_items = array_create(instance_count), +_count = 0; +for (var i = 0; i < instance_count; i++) { + if (instance_exists(instance_id[i]) && + (_search == "" || (string_count(_search, string_lower(object_get_name(instance_id[i].object_index)))))) { + _instances[_count] = instance_id[i]; + _items[_count] = object_get_name(instance_id[i].object_index) + " - inst_" + string(instance_id[i]); + _count++; + } +} +instances = array_create(_count); +items = array_create(_count); +array_copy(instances, 0, _instances, 0, _count); +array_copy(items, 0, _items, 0, _count); + +item_highlight_index = -1; + +event_inherited(); + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + if (item_highlight_index != -1 && + instance_exists(instances[item_highlight_index]) && + instances[item_highlight_index].sprite_index != -1) { + var _inst = instances[item_highlight_index]; + var _view = scrDebugInspectorGetView(0); + draw_sprite_ext( + _inst.sprite_index, + _inst.image_index, + _inst.x - _view[0], + _inst.y - _view[1], + _inst.image_xscale, + _inst.image_yscale, + _inst.image_angle, + make_color_hsv(color_timer % 255, 255, 255), + 1.0); +} + +event_inherited(); + + + + + + + 0 + 0 + 0 + 0.5 + 0.100000001490116 + 0 + 0.100000001490116 + 0.100000001490116 + 0.200000002980232 + -1 + 0 + + diff --git a/add after objDebugList/objDebugInspector.object.gmx b/add after objDebugList/objDebugInspector.object.gmx new file mode 100644 index 0000000..cb85727 --- /dev/null +++ b/add after objDebugList/objDebugInspector.object.gmx @@ -0,0 +1,172 @@ + + + <undefined> + 0 + -1 + 0 + -1 + objDebugList + <undefined> + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + event_inherited(); + +enum __INSPECTOR_TYPES { + REAL, STRING, ARRAY, BOOL, UNDEFINED, UNKNOWN +} + +target = noone; +box_padding = 4; + +variable_values = -1; +variable_types = -1; +variable_names = -1; +variable_strings = -1; +variable_strings_rendered = -1; +variable_number = -1; + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + variable_names = variable_instance_get_names(target); +variable_number = array_length_1d(variable_names); +variable_types = array_create(variable_number); +variable_values = array_create(variable_number); +variable_strings = array_create(variable_number); +variable_strings_rendered = array_create(variable_number); + +var _val; +for (var i = 0; i < variable_number; i++) { + _val = variable_instance_get(target, variable_names[i]); + variable_values[i] = _val; + if (is_undefined(_val)) { + variable_strings[i] = string(_val); + variable_types[i] = __INSPECTOR_TYPES.UNDEFINED; + } else if (is_bool(_val)) { + variable_strings[i] = string(_val); + variable_types[i] = __INSPECTOR_TYPES.BOOL; + } else if (is_real(_val)) { + variable_strings[i] = string(_val); + variable_types[i] = __INSPECTOR_TYPES.REAL; + } else if (is_string(_val)) { + variable_strings[i] = "'" + _val + "'"; + variable_types[i] = __INSPECTOR_TYPES.STRING; + } else if (is_array(_val)) { + var _buf_str = buffer_create(512, buffer_grow, 1); + buffer_write(_buf_str, buffer_text, "["); + for (var ii = 0, nn = array_length_1d(_val); ii < nn; ii++) { + buffer_write(_buf_str, buffer_text, string(_val[ii]) + ", "); + } + buffer_write(_buf_str, buffer_text, "]"); + buffer_seek(_buf_str, buffer_seek_start, 0); + variable_strings[i] = buffer_read(_buf_str, buffer_text); + buffer_delete(_buf_str); + variable_types[i] = __INSPECTOR_TYPES.ARRAY; + } else { + variable_strings[i] = string(_val); + variable_types[i] = __INSPECTOR_TYPES.UNKNOWN; + } + + variable_strings_rendered[i] = variable_names[i] + ": " + variable_strings[i]; +} + +header = object_get_name(target.object_index) + " inst_" + string(target.id); +items = variable_strings_rendered; + +event_inherited(); + +var _view = scrDebugInspectorGetView(0); +x = target.bbox_right + box_padding - _view[0]; +if (x + width >= _view[2]) { + x = target.bbox_left - width - box_padding - _view[0]; +} +y = target.bbox_bottom + box_padding - _view[1]; +y -= max(0, (y + height) - (_view[3] - box_padding)); + +x = clamp(x, _view[0] + box_padding, _view[2] - width - box_padding); +y = clamp(y, _view[1] + box_padding, _view[3] - height - box_padding); + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + var _view = scrDebugInspectorGetView(0); +if (instance_exists(target)) { + draw_set_color(c_black); + draw_line(x, y - 1, target.x - _view[0], target.y - _view[1] - 1); + draw_line(x, y + 1, target.x - _view[0], target.y - _view[1] + 1); + draw_set_color(c_white); + draw_line(x, y, target.x - _view[0], target.y - _view[1]); +} + +event_inherited(); + + + + + + + 0 + 0 + 0 + 0.5 + 0.100000001490116 + 0 + 0.100000001490116 + 0.100000001490116 + 0.200000002980232 + -1 + 0 + + diff --git a/add after objDebugList/objDebugInspectorControl.object.gmx b/add after objDebugList/objDebugInspectorControl.object.gmx new file mode 100644 index 0000000..9b7f78c --- /dev/null +++ b/add after objDebugList/objDebugInspectorControl.object.gmx @@ -0,0 +1,223 @@ + + + <undefined> + 0 + -1 + 0 + -1 + <undefined> + <undefined> + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + selection = ds_list_create(); +selection_instance = noone; +inspector_instance = noone; +search_instance = noone; + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + if (instance_exists(selection_instance)) + instance_destroy(selection_instance); +if (instance_exists(inspector_instance)) + instance_destroy(inspector_instance); +if (instance_exists(search_instance)) + instance_destroy(search_instance); + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + var _debug_key_held = true; +if (global.__synthasmagoria_debug_inspector_debug_key != -1) { + _debug_key_held = keyboard_check(global.__synthasmagoria_debug_inspector_debug_key); +} + +if (_debug_key_held && mouse_check_button_pressed(mb_left)) { + if (instance_exists(selection_instance) || instance_exists(inspector_instance) || instance_exists(search_instance)) { + // nothing + } else { + ds_list_clear(selection); + var _inst; + with (all) { + _inst = collision_point(mouse_x, mouse_y, id, true, false); + if (_inst != noone) { + ds_list_add(other.selection, _inst); + } + } + var _selection_number = ds_list_size(selection); + if (_selection_number > 1) { + var _selection = array_create(_selection_number); + var _instances = array_create(_selection_number); + for (var i = 0; i < _selection_number; i++) { + _selection[i] = object_get_name(selection[|i].object_index) + " - inst_" + string(selection[|i]); + _instances[i] = selection[|i]; + } + selection_instance = instance_create(mouse_x - view_xview[0], mouse_y - view_yview[0], objDebugInspectorInstanceList); + with (selection_instance) { + instances = _instances; + header = "Instances"; + items = _selection; + selection_callback_instance = other.id; + selection_callback_user_event = 0; + event_user(0); + } + } else if (_selection_number == 1) { + inspector_instance = instance_create(0, 0, objDebugInspector); + with (inspector_instance) { + target = other.selection[|0]; + event_user(0); + } + } + } +} + +if (_debug_key_held && mouse_check_button_pressed(mb_middle)) { + if (instance_exists(search_instance)) { + // nothing + } else { + if (instance_exists(selection_instance)) + instance_destroy(selection_instance); + if (instance_exists(inspector_instance)) + instance_destroy(inspector_instance); + search_instance = instance_create(4, 4, objDebugAllInstancesList); + with (search_instance) { + selection_callback_instance = other.id; + selection_callback_user_event = 1; + } + } +} + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + /// all instances list selection callback +var _selected_instance = search_instance.instances[search_instance.item_highlight_index]; +if (instance_exists(_selected_instance)) { + inspector_instance = instance_create(0, 0, objDebugInspector); + with (inspector_instance) { + target = _selected_instance; + event_user(0); + } +} +instance_destroy(search_instance); + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + /// instance list selection callback +var _selected_instance = selection[|selection_instance.item_highlight_index]; +if (instance_exists(_selected_instance)) { + inspector_instance = instance_create(0, 0, objDebugInspector); + with (inspector_instance) { + target = _selected_instance; + event_user(0); + } +} +instance_destroy(selection_instance); + + + + + + + 0 + 0 + 0 + 0.5 + 0.100000001490116 + 0 + 0.100000001490116 + 0.100000001490116 + 0.200000002980232 + -1 + 0 + + diff --git a/add after objDebugList/objDebugInspectorInstanceList.object.gmx b/add after objDebugList/objDebugInspectorInstanceList.object.gmx new file mode 100644 index 0000000..11c8e38 --- /dev/null +++ b/add after objDebugList/objDebugInspectorInstanceList.object.gmx @@ -0,0 +1,80 @@ + + + <undefined> + 0 + -1 + 0 + -1 + objDebugList + <undefined> + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + event_inherited(); + +instances = -1; + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + event_inherited(); + +for (var i = array_length_1d(instances) - 1; i >= 0; i--) { + if (instance_exists(instances[i])) { + item_colors[i] = c_white; + } else { + item_colors[i] = c_red; + } +} + + + + + + + 0 + 0 + 0 + 0.5 + 0.100000001490116 + 0 + 0.100000001490116 + 0.100000001490116 + 0.200000002980232 + -1 + 0 + + diff --git a/add after objDebugList/scrDebugInspectorGetView.gml b/add after objDebugList/scrDebugInspectorGetView.gml new file mode 100644 index 0000000..c7cae15 --- /dev/null +++ b/add after objDebugList/scrDebugInspectorGetView.gml @@ -0,0 +1,13 @@ +///scrDebugInspectorGetView(view_index) +var _view = array_create(4); +if (view_enabled && view_visible[argument0]) { + _view[0] = view_xview[argument0]; + _view[1] = view_yview[argument0]; + _view[2] = view_wview[argument0]; + _view[3] = view_hview[argument0]; + return _view; +} +_view[0] = 0; +_view[1] = 0; +_view[2] = window_get_width(); +_view[3] = window_get_height(); diff --git a/add after objDebugList/scrDebugInspectorInitialize.gml b/add after objDebugList/scrDebugInspectorInitialize.gml new file mode 100644 index 0000000..ea4cb7f --- /dev/null +++ b/add after objDebugList/scrDebugInspectorInitialize.gml @@ -0,0 +1,21 @@ +///scrDebugInspectorInitialize(global_game_start_name, [debug_key], [font]) +if (instance_exists(objDebugInspectorControl)) { + exit; +} +if (variable_global_exists(argument0)) { + global.__synthasmagoria_debug_inspector_global_game_start_name = argument0; +} else { + show_error("Global variable '" + argument0 + "' didn't exist", false); + global.__synthasmagoria_debug_inspector_global_game_start_name = "@"; +} +var _debug_key = -1; +if (argument_count > 1) { + _debug_key = argument[1]; +} +global.__synthasmagoria_debug_inspector_debug_key = _debug_key; +var _font = -1; +if (argument_count > 2) { + _font = argument[2]; +} +global.__synthasmagoria_debug_inspector_font = _font; +instance_create(0, 0, objDebugInspectorControl); diff --git a/objDebugList.object.gmx b/objDebugList.object.gmx new file mode 100644 index 0000000..a3af4c5 --- /dev/null +++ b/objDebugList.object.gmx @@ -0,0 +1,232 @@ + + + <undefined> + 0 + -1 + 0 + -1 + <undefined> + <undefined> + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + margin = 4; +item_yoffset = -4; +item_epsilon = 96; +header = ""; +header_margin = 4; +selection_callback_instance = noone; +selection_callback_user_event = -1; +box_padding = 4; +item_display_max = 12; +dim = 0.8; + +item_display_start = 0; +item_scroll_speed = 2; +height = -1; +width = -1; +items = -1; +item_colors = -1; +item_number = -1; +item_height = -1; +item_highlight_index = -1; +character_height = -1; +character_width = -1; + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + var _view = scrDebugInspectorGetView(0); +var _item_ystart = y + item_height + header_margin; +var _mx = mouse_x - _view[0], _my = mouse_y - _view[1]; +if (point_in_rectangle(_mx, _my, x, _item_ystart, x + width, y + height)) { + item_highlight_index = clamp( + item_display_start + floor((_my - _item_ystart) / item_height), + item_display_start, + min(item_display_start + item_display_max, item_number - 1)); +} else { + item_highlight_index = -1; +} + +var _debug_key_held = true; +if (global.__synthasmagoria_debug_inspector_debug_key != -1) { + _debug_key_held = keyboard_check(global.__synthasmagoria_debug_inspector_debug_key); +} + +if (_debug_key_held && mouse_check_button_pressed(mb_left)) { + if (point_in_rectangle(_mx, _my, x, y, x + width, y + height)) { + if (item_highlight_index != -1 && instance_exists(selection_callback_instance) && selection_callback_user_event > -1) { + with (selection_callback_instance) { + event_user(other.selection_callback_user_event); + } + } + } else { + instance_destroy(); + } +} + +if (_debug_key_held && mouse_check_button_pressed(mb_right)) { + instance_destroy(); +} + +if (item_number > item_display_max) { + item_display_start = clamp( + item_display_start + (mouse_wheel_down() - mouse_wheel_up()) * item_scroll_speed, + 0, + max(0, item_number - item_display_max)); +} + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + draw_set_font(global.__synthasmagoria_debug_inspector_font); +character_width = string_width("A"); +character_height = string_height("A"); + +for (var i = array_length_1d(items) - 1; i >= 0; i--) { + if (string_length(items[i]) > item_epsilon) { + items[i] = string_copy(items[i], 0, item_epsilon) + "..."; + } +} + +item_height = character_height + item_yoffset; +var _longest_string = string_length(header); +item_number = array_length_1d(items); +item_colors = array_create(item_number); +for (var i = 0; i < item_number; i++) { + item_colors[i] = c_white; + _longest_string = max(_longest_string, string_length(items[i])); +} +width = _longest_string * character_width + margin * 2; + +height = item_height + header_margin + + item_height * min(item_number, item_display_max) + + margin * 2; + +var _view = scrDebugInspectorGetView(0); +x = clamp(x, 0, _view[2] - width - box_padding); +y = clamp(y, 0, _view[3] - height - box_padding); + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + draw_set_color(c_black); +draw_set_alpha(dim); +draw_rectangle(x, y, x + width, y + height, false); +draw_set_color(c_white); +draw_set_alpha(1.0); +draw_rectangle(x, y, x + width, y + height, true); + +draw_set_font(global.__synthasmagoria_debug_inspector_font); +var _dx = x + margin, _dy = y + margin; +draw_text(_dx, _dy, header); +_dy += item_height; +draw_line(_dx, _dy + 1, _dx + width - margin * 2, _dy + 1); +_dy += header_margin; + +if (item_highlight_index != -1) { + draw_set_alpha(0.4); + draw_rectangle( + x, + _dy + (item_highlight_index - item_display_start) * item_height, + x + width, + _dy + (item_highlight_index + 1 - item_display_start) * item_height - 1, + false); + draw_set_alpha(1.0); +} + +draw_set_halign(fa_left); +draw_set_valign(fa_top); +for (var i = 0; i < item_number - item_display_start && i < item_display_max; i++) { + draw_set_color(item_colors[i + item_display_start]); + draw_text(_dx, _dy + item_height * i, items[i + item_display_start]); +} +draw_set_color(c_white); + + + + + + + 0 + 0 + 0 + 0.5 + 0.100000001490116 + 0 + 0.100000001490116 + 0.100000001490116 + 0.200000002980232 + -1 + 0 + +