- New selfmade Font
- persistent files - Hiscore
This commit is contained in:
parent
4676b83b61
commit
4c881027a1
56 changed files with 1711 additions and 175 deletions
146
addons/SignalVisualizer/Debugger/SignalDebugger.gd
Normal file
146
addons/SignalVisualizer/Debugger/SignalDebugger.gd
Normal file
|
@ -0,0 +1,146 @@
|
|||
extends Node
|
||||
|
||||
# Properties
|
||||
# |===================================|
|
||||
# |===================================|
|
||||
# |===================================|
|
||||
|
||||
var _signal_graph: SignalGraph
|
||||
var _lambda_map: Dictionary = {}
|
||||
|
||||
# Lifecycle
|
||||
# |===================================|
|
||||
# |===================================|
|
||||
# |===================================|
|
||||
|
||||
func _ready():
|
||||
if OS.is_debug_build():
|
||||
EngineDebugger.register_message_capture("signal_debugger", _on_signal_debugger_message_capture)
|
||||
|
||||
# Signals
|
||||
# |===================================|
|
||||
# |===================================|
|
||||
# |===================================|
|
||||
|
||||
func _on_signal_debugger_message_capture(message: String, data: Array) -> bool:
|
||||
if message == "start":
|
||||
_signal_graph = generate_signal_graph()
|
||||
for signal_item in _signal_graph.signals:
|
||||
_connect_to_signal(signal_item)
|
||||
EngineDebugger.send_message(
|
||||
"signal_debugger:generated_graph",
|
||||
[[_signal_graph.signals.map(func (item): return item.dictionary_representation), _signal_graph.edges.map(func (item): return item.dictionary_representation)]]
|
||||
)
|
||||
if message == "stop" and _signal_graph:
|
||||
for signal_item in _signal_graph.signals:
|
||||
_disconnect_from_signal(signal_item)
|
||||
|
||||
if message == "invoke_signal" and data.size() == 2:
|
||||
var node_name = data[0]
|
||||
var signal_name = data[1]
|
||||
|
||||
var root_node = get_tree().current_scene
|
||||
var node = root_node if root_node.name == node_name else root_node.find_child(node_name)
|
||||
if node:
|
||||
var connection_list = node.get_signal_connection_list(signal_name)
|
||||
for connection in connection_list:
|
||||
var callable = connection["callable"]
|
||||
var bound_args = callable.get_bound_arguments()
|
||||
var bound_args_count = callable.get_bound_arguments_count()
|
||||
var method = callable.get_method()
|
||||
callable.callv([node])
|
||||
|
||||
return true
|
||||
|
||||
func _on_signal_execution(signal_name: String, node_name: String, args):
|
||||
EngineDebugger.send_message(
|
||||
"signal_debugger:signal_executed",
|
||||
[Time.get_datetime_string_from_system(), node_name, signal_name]
|
||||
)
|
||||
|
||||
# Methods
|
||||
# |===================================|
|
||||
# |===================================|
|
||||
# |===================================|
|
||||
|
||||
func generate_signal_graph() -> SignalGraph:
|
||||
var graph = SignalGraphUtility.create_signal_graph_from_node(get_tree().current_scene)
|
||||
return graph
|
||||
#var signal_graph = SignalGraph.new(get_tree().current_scene.name)
|
||||
#var all_nodes: Array[Node] = _gather_nodes_in_scene()
|
||||
#var signals: Array[SignalDescription] = []
|
||||
#var edges: Array[SignalConnection] = []
|
||||
#
|
||||
#for node in all_nodes:
|
||||
#for signal_item in node.get_signal_list():
|
||||
#var existing_signals = []
|
||||
#var connection_list = node.get_signal_connection_list(signal_item["name"] as String)
|
||||
#if connection_list.size() > 0:
|
||||
#for connection in connection_list:
|
||||
#var should_display_connection = "name" in connection["callable"].get_object() and not connection["callable"].get_object().name.begins_with("@")
|
||||
#if should_display_connection:
|
||||
#var signal_description: SignalDescription
|
||||
#var filtered_signals = existing_signals.filter(func (element): return element.signal_name == signal_item.name and element.node_name == node.name)
|
||||
#if filtered_signals.size() == 1:
|
||||
#signal_description = filtered_signals[0]
|
||||
#else:
|
||||
#signal_description = SignalDescription.new(node.name, signal_item.name)
|
||||
#existing_signals.append(signal_description)
|
||||
#signals.append(signal_description)
|
||||
#
|
||||
#var signal_edge = SignalConnection.new(signal_description.id, signal_description.node_name, connection["callable"].get_object().name, connection["callable"].get_method())
|
||||
#if not signal_graph.edges.any(func (element): return element.signal_id == signal_description.id):
|
||||
#edges.append(signal_edge)
|
||||
#
|
||||
#var temp_signals = {}
|
||||
#for item in signals:
|
||||
#temp_signals[item.id] = item
|
||||
#
|
||||
#var temp_edges = {}
|
||||
#for item in edges:
|
||||
#temp_edges[item.dictionary_key] = item
|
||||
#
|
||||
#signal_graph.signals.assign(temp_signals.keys().map(func (key): return temp_signals[key]))
|
||||
#signal_graph.edges.assign(temp_edges.keys().map(func (key): return temp_edges[key]))
|
||||
#
|
||||
#return signal_graph
|
||||
|
||||
#func _gather_nodes_in_scene() -> Array[Node]:
|
||||
#var scene_root = get_tree().current_scene
|
||||
#var node_list: Array[Node] = [scene_root]
|
||||
#return node_list + _gather_nodes_from_node(scene_root)
|
||||
#
|
||||
#func _gather_nodes_from_node(node: Node) -> Array[Node]:
|
||||
#var nodes: Array[Node] = []
|
||||
#for child in node.get_children(false):
|
||||
#nodes.append(child)
|
||||
#nodes += _gather_nodes_from_node(child)
|
||||
#
|
||||
#return nodes
|
||||
|
||||
func _connect_to_signal(signal_item: SignalDescription):
|
||||
var root_node = get_tree().current_scene
|
||||
var _execute: Callable = func (args = []): _on_signal_execution(signal_item.signal_name, signal_item.node_name, args)
|
||||
if root_node.name == signal_item.node_name:
|
||||
root_node.connect(signal_item.signal_name, _execute)
|
||||
_lambda_map[signal_item] = _execute
|
||||
else:
|
||||
var child = root_node.find_child(signal_item.node_name)
|
||||
if child:
|
||||
child.connect(signal_item.signal_name, _execute)
|
||||
_lambda_map[signal_item] = _execute
|
||||
|
||||
func _disconnect_from_signal(signal_item: SignalDescription):
|
||||
var root_node = get_tree().current_scene
|
||||
if root_node.name == signal_item.node_name:
|
||||
var callable = _lambda_map[signal_item]
|
||||
if callable:
|
||||
root_node.disconnect(signal_item.signal_name, callable)
|
||||
_lambda_map.erase(signal_item)
|
||||
else:
|
||||
var child = root_node.find_child(signal_item.node_name)
|
||||
if child:
|
||||
var callable = _lambda_map[signal_item]
|
||||
if callable:
|
||||
child.disconnect(signal_item.signal_name, callable)
|
||||
_lambda_map.erase(signal_item)
|
97
addons/SignalVisualizer/Debugger/SignalDebugger.tscn
Normal file
97
addons/SignalVisualizer/Debugger/SignalDebugger.tscn
Normal file
|
@ -0,0 +1,97 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://cbsmvov8u78q"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SignalVisualizer/Debugger/signal_debugger_panel.gd" id="1_66cpc"]
|
||||
[ext_resource type="Texture2D" uid="uid://be3nwoioa311t" path="res://addons/SignalVisualizer/Play.svg" id="2_2wkuv"]
|
||||
[ext_resource type="Texture2D" uid="uid://oo1oq2colx5b" path="res://addons/SignalVisualizer/Stop.svg" id="3_bg5eu"]
|
||||
[ext_resource type="Texture2D" uid="uid://bmnff63evbdhv" path="res://addons/SignalVisualizer/Clear.svg" id="4_vg63r"]
|
||||
|
||||
[node name="SignalDebugger" type="Control"]
|
||||
clip_contents = true
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_66cpc")
|
||||
start_icon = ExtResource("2_2wkuv")
|
||||
stop_icon = ExtResource("3_bg5eu")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
clip_contents = true
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
custom_minimum_size = Vector2(2.08165e-12, 50)
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 8
|
||||
|
||||
[node name="ActionButton" type="Button" parent="VBoxContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
disabled = true
|
||||
text = "Start"
|
||||
icon = ExtResource("2_2wkuv")
|
||||
|
||||
[node name="ClearAllButton" type="Button" parent="VBoxContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "Clear All"
|
||||
icon = ExtResource("4_vg63r")
|
||||
|
||||
[node name="Spacer" type="Control" parent="VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="ClearLogsButton" type="Button" parent="VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Clear Logs"
|
||||
icon = ExtResource("4_vg63r")
|
||||
|
||||
[node name="HSplitContainer" type="HSplitContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="SignalTree" type="Tree" parent="VBoxContainer/HSplitContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(250, 2.08165e-12)
|
||||
layout_mode = 2
|
||||
columns = 2
|
||||
allow_reselect = true
|
||||
allow_rmb_select = true
|
||||
hide_root = true
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/HSplitContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="TabBar" type="TabBar" parent="VBoxContainer/HSplitContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
tab_count = 2
|
||||
tab_0/title = "Signal Log"
|
||||
tab_1/title = "Signal Graph"
|
||||
|
||||
[node name="LogLabel" type="RichTextLabel" parent="VBoxContainer/HSplitContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
theme_override_colors/default_color = Color(0.690196, 0.690196, 0.690196, 1)
|
||||
bbcode_enabled = true
|
||||
scroll_following = true
|
||||
|
||||
[node name="Graph" type="GraphEdit" parent="VBoxContainer/HSplitContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer/ActionButton" to="." method="_on_action_button_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer/ClearAllButton" to="." method="_on_clear_all_button_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer/ClearLogsButton" to="." method="_on_clear_logs_button_pressed"]
|
||||
[connection signal="item_selected" from="VBoxContainer/HSplitContainer/SignalTree" to="." method="_on_signal_tree_item_selected"]
|
||||
[connection signal="tab_changed" from="VBoxContainer/HSplitContainer/VBoxContainer/TabBar" to="." method="_on_tab_bar_tab_changed"]
|
192
addons/SignalVisualizer/Debugger/signal_debugger_panel.gd
Normal file
192
addons/SignalVisualizer/Debugger/signal_debugger_panel.gd
Normal file
|
@ -0,0 +1,192 @@
|
|||
@tool
|
||||
class_name SignalDebuggerPanel extends Control
|
||||
|
||||
signal open_script(node_name: String, method_signature: String)
|
||||
|
||||
signal start_signal_debugging
|
||||
signal stop_signal_debugging
|
||||
|
||||
var SignalGraphNode = preload("res://addons/SignalVisualizer/Visualizer/signal_graph_node.tscn")
|
||||
var GraphNodeItem = preload("res://addons/SignalVisualizer/Visualizer/signal_graph_node_item.tscn")
|
||||
|
||||
const SOURCE_COLOR: Color = Color.SKY_BLUE
|
||||
const DESTINATION_COLOR: Color = Color.CORAL
|
||||
const CONNECTION_TYPE: int = 0
|
||||
|
||||
enum Tabs {
|
||||
LOG,
|
||||
GRAPH
|
||||
}
|
||||
|
||||
# Properties
|
||||
# |===================================|
|
||||
# |===================================|
|
||||
# |===================================|
|
||||
|
||||
@export var start_icon: Texture2D
|
||||
@export var stop_icon: Texture2D
|
||||
|
||||
@onready var action_button: Button = %ActionButton
|
||||
@onready var clear_all_button: Button = %ClearAllButton
|
||||
@onready var signal_tree: Tree = %SignalTree
|
||||
@onready var log_label: RichTextLabel = %LogLabel
|
||||
@onready var graph_node: GraphEdit = %Graph
|
||||
|
||||
var is_started: bool = false :
|
||||
get: return is_started
|
||||
set(new_value):
|
||||
is_started = new_value
|
||||
_update_action_button()
|
||||
|
||||
var _signals: Array = []
|
||||
var _signal_filter: Array = []
|
||||
var _is_stack_trace_enabled: bool = false
|
||||
var _debugger_tab_state: Tabs = Tabs.LOG
|
||||
var _graph: SignalGraph
|
||||
|
||||
# Lifecycle
|
||||
# |===================================|
|
||||
# |===================================|
|
||||
# |===================================|
|
||||
|
||||
func _ready():
|
||||
disable()
|
||||
_handle_tab_update(0)
|
||||
|
||||
# Signals
|
||||
# |===================================|
|
||||
# |===================================|
|
||||
# |===================================|
|
||||
|
||||
func _on_action_button_pressed():
|
||||
if is_started:
|
||||
stop()
|
||||
else:
|
||||
start()
|
||||
|
||||
func _on_clear_all_button_pressed():
|
||||
log_label.clear()
|
||||
signal_tree.clear()
|
||||
graph_node.clear_connections()
|
||||
for child in graph_node.get_children():
|
||||
if child is SignalGraphNode:
|
||||
child.queue_free()
|
||||
|
||||
func _on_clear_logs_button_pressed():
|
||||
log_label.clear()
|
||||
|
||||
func _on_signal_tree_item_selected():
|
||||
# Updates the checkmark button
|
||||
var selected_item = signal_tree.get_selected()
|
||||
var is_checked = selected_item.is_checked(1)
|
||||
selected_item.set_checked(1, (not is_checked))
|
||||
|
||||
# Add / Remove signal from filters
|
||||
var selected_signal = _signals.filter(func (element): return element.signal_name == selected_item.get_text(0))[0]
|
||||
if _signal_filter.has(selected_signal.signal_name):
|
||||
var selected_index = _signal_filter.find(selected_signal.signal_name)
|
||||
_signal_filter.remove_at(selected_index)
|
||||
else:
|
||||
_signal_filter.append(selected_signal.signal_name)
|
||||
|
||||
func _on_tab_bar_tab_changed(tab: int):
|
||||
_handle_tab_update(tab)
|
||||
|
||||
func _on_stack_trace_button_pressed():
|
||||
_is_stack_trace_enabled = not _is_stack_trace_enabled
|
||||
|
||||
func _on_open_signal_in_script(data: SignalGraphNodeItem.Metadata):
|
||||
open_script.emit(data.node_name, data.method_signature)
|
||||
|
||||
# Methods
|
||||
# |===================================|
|
||||
# |===================================|
|
||||
# |===================================|
|
||||
|
||||
func enable():
|
||||
action_button.disabled = false
|
||||
|
||||
func disable():
|
||||
action_button.disabled = true
|
||||
|
||||
func start():
|
||||
if not is_started:
|
||||
is_started = true
|
||||
action_button.icon = stop_icon
|
||||
start_signal_debugging.emit()
|
||||
log_label.append_text("[color=#B0B0B0]Signal Debugging Started...[/color]")
|
||||
log_label.newline()
|
||||
log_label.newline()
|
||||
|
||||
func stop():
|
||||
if is_started:
|
||||
is_started = false
|
||||
action_button.icon = start_icon
|
||||
stop_signal_debugging.emit()
|
||||
log_label.newline()
|
||||
log_label.append_text("[color=#B0B0B0]Signal Debugging Stopped[/color]")
|
||||
log_label.newline()
|
||||
log_label.newline()
|
||||
|
||||
func create_tree_from_signals(signals: Array):
|
||||
_signals = signals
|
||||
var root = signal_tree.create_item()
|
||||
root.set_text(0, "Signals")
|
||||
|
||||
var tree_items: Dictionary = {}
|
||||
|
||||
for signal_item in signals:
|
||||
var node_tree_item: TreeItem
|
||||
if tree_items.has(signal_item.node_name):
|
||||
node_tree_item = tree_items[signal_item.node_name] as TreeItem
|
||||
else:
|
||||
node_tree_item = signal_tree.create_item(root)
|
||||
node_tree_item.set_text(0, signal_item.node_name)
|
||||
node_tree_item.set_selectable(0, false)
|
||||
node_tree_item.set_selectable(1, false)
|
||||
tree_items[signal_item.node_name] = node_tree_item
|
||||
|
||||
var signal_tree_item = signal_tree.create_item(node_tree_item)
|
||||
signal_tree_item.set_text(0, signal_item.signal_name)
|
||||
signal_tree_item.set_cell_mode(1, TreeItem.CELL_MODE_CHECK)
|
||||
signal_tree_item.set_checked(1, true)
|
||||
signal_tree_item.set_selectable(0, false)
|
||||
signal_tree_item.set_selectable(1, true)
|
||||
|
||||
func create_signal_graph(signals: Array, edges: Array):
|
||||
_graph = SignalGraphUtility.create_signal_graph(get_tree().edited_scene_root.scene_file_path, signals, edges)
|
||||
SignalGraphUtility.generate_signal_graph_nodes(_graph, graph_node, _on_open_signal_in_script)
|
||||
|
||||
func log_signal_execution(time: String, node_name: String, signal_name: String):
|
||||
if _signal_filter != null and _signal_filter.has(signal_name):
|
||||
return
|
||||
|
||||
if not log_label.text.is_empty():
|
||||
log_label.newline()
|
||||
log_label.append_text(
|
||||
"[color=#FFCC00]{time}[/color]\t\t{node_name}\t\t{signal_name}".format({ "time": time, "node_name": node_name, "signal_name": signal_name })
|
||||
)
|
||||
log_label.newline()
|
||||
|
||||
func _handle_tab_update(selected_tab_index: int):
|
||||
match selected_tab_index:
|
||||
1:
|
||||
_debugger_tab_state = Tabs.GRAPH
|
||||
_:
|
||||
_debugger_tab_state = Tabs.LOG
|
||||
|
||||
match _debugger_tab_state:
|
||||
Tabs.LOG:
|
||||
log_label.show()
|
||||
graph_node.hide()
|
||||
Tabs.GRAPH:
|
||||
log_label.hide()
|
||||
graph_node.show()
|
||||
|
||||
func _update_action_button():
|
||||
if is_started:
|
||||
action_button.text = "Stop"
|
||||
action_button.modulate = Color("#ff3b30")
|
||||
else:
|
||||
action_button.text = "Start"
|
||||
action_button.modulate = Color.WHITE
|
Loading…
Add table
Add a link
Reference in a new issue