Adds debugging system
parent
dcb3966d54
commit
7044168b2e
@ -1,38 +1,9 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://4glu7reewmf3"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://4glu7reewmf3"]
|
||||
|
||||
[ext_resource type="Script" path="res://systems/combat/combatant/combatant.gd" id="1_7ynxf"]
|
||||
[ext_resource type="PackedScene" uid="uid://by6mq2xbbkqns" path="res://systems/combat/combatant/ui/combat_menu.tscn" id="2_781jy"]
|
||||
|
||||
[node name="Combatant" type="Node2D"]
|
||||
script = ExtResource("1_7ynxf")
|
||||
|
||||
[node name="Combat Menu" type="Control" parent="."]
|
||||
texture_filter = 2
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="Combat Menu"]
|
||||
layout_mode = 2
|
||||
offset_right = 44.0
|
||||
offset_bottom = 48.0
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Combat Menu/PanelContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 2
|
||||
theme_override_constants/margin_top = 2
|
||||
theme_override_constants/margin_right = 2
|
||||
theme_override_constants/margin_bottom = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Combat Menu/PanelContainer/MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="BtnAttack" type="Button" parent="Combat Menu/PanelContainer/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 10
|
||||
text = "Attack"
|
||||
|
||||
[node name="BtnDefend" type="Button" parent="Combat Menu/PanelContainer/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 10
|
||||
text = "Defend"
|
||||
[node name="Combat Menu" parent="." instance=ExtResource("2_781jy")]
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
extends Control
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
@ -0,0 +1,36 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://by6mq2xbbkqns"]
|
||||
|
||||
[ext_resource type="Script" path="res://systems/combat/combatant/ui/combat_menu.gd" id="1_2ftpt"]
|
||||
|
||||
[node name="Combat Menu" type="Control"]
|
||||
texture_filter = 2
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
script = ExtResource("1_2ftpt")
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="."]
|
||||
layout_mode = 2
|
||||
offset_right = 44.0
|
||||
offset_bottom = 48.0
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 2
|
||||
theme_override_constants/margin_top = 2
|
||||
theme_override_constants/margin_right = 2
|
||||
theme_override_constants/margin_bottom = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="BtnAttack" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 10
|
||||
text = "Attack"
|
||||
|
||||
[node name="BtnDefend" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 10
|
||||
text = "Defend"
|
||||
@ -0,0 +1,47 @@
|
||||
class_name DebugLogger
|
||||
extends Node
|
||||
|
||||
|
||||
|
||||
enum LogLevel
|
||||
{
|
||||
ERROR,
|
||||
WARNING,
|
||||
INFO,
|
||||
TRACE
|
||||
}
|
||||
|
||||
|
||||
var _log_level: LogLevel = LogLevel.INFO
|
||||
var _log_history: Array[LogMessage] = []
|
||||
|
||||
|
||||
func log(level: LogLevel, message: String, silent = false):
|
||||
var msg = LogMessage.new()
|
||||
msg.level = level
|
||||
msg.message = message
|
||||
msg.timestamp = get_timestamp()
|
||||
_log_history.append(msg)
|
||||
|
||||
if !silent:
|
||||
if msg.level <= _log_level:
|
||||
print("%s" % msg.get_formatted())
|
||||
|
||||
if msg.level == LogLevel.ERROR:
|
||||
push_error("%s" % msg.get_formatted())
|
||||
|
||||
if msg.level == LogLevel.WARNING:
|
||||
push_warning("%s" % msg.get_formatted())
|
||||
|
||||
func get_timestamp():
|
||||
return Time.get_datetime_string_from_system(false, true)
|
||||
|
||||
|
||||
func dump_log_file():
|
||||
var output = ""
|
||||
for msg in _log_history:
|
||||
output += "%s\n" % msg.get_formatted()
|
||||
|
||||
var file = FileAccess.open("debug.log", FileAccess.WRITE)
|
||||
output.trim_suffix("\n")
|
||||
file.store_string(output)
|
||||
@ -0,0 +1,14 @@
|
||||
|
||||
class_name LogMessage
|
||||
extends RefCounted
|
||||
|
||||
|
||||
var level: DebugLogger.LogLevel
|
||||
var message: String
|
||||
var timestamp: String
|
||||
|
||||
func get_formatted():
|
||||
var lvl_strs = ["ERROR", "WARNING", "INFO", "TRACE"]
|
||||
|
||||
var formatted = "[%s][%s] %s" % [lvl_strs[level], timestamp, message]
|
||||
return formatted
|
||||
@ -0,0 +1,70 @@
|
||||
class_name DebugPanel
|
||||
extends Node
|
||||
|
||||
@export var log_max_lines = 2
|
||||
|
||||
@onready var db_panel_container = $CanvasLayer/PanelContainer
|
||||
@onready var db_label = $CanvasLayer/PanelContainer/DebugUI/Info
|
||||
|
||||
var sections := {} # { String - Name : DebugSection }
|
||||
var log_history: Array[String]
|
||||
|
||||
const DEFAULT_SECTION = "DEFAULT_SECTION"
|
||||
|
||||
func initialize():
|
||||
sections[DEFAULT_SECTION] = DebugSection.new()
|
||||
sections[DEFAULT_SECTION].section_name = DEFAULT_SECTION
|
||||
|
||||
func set_visible(vis):
|
||||
db_panel_container.visible = vis
|
||||
|
||||
func is_visible():
|
||||
return db_panel_container.visible
|
||||
|
||||
func clear():
|
||||
db_label.text = ""
|
||||
sections.clear()
|
||||
log_history.clear()
|
||||
|
||||
func update_value(section: String, label: String, val: String):
|
||||
section = section.dedent().trim_prefix("\n").trim_suffix("\n")
|
||||
label = label.dedent().trim_prefix("\n").trim_suffix("\n")
|
||||
val = val.dedent().trim_prefix("\n").trim_suffix("\n")
|
||||
|
||||
if section == "":
|
||||
sections[DEFAULT_SECTION].section_values[label] = val
|
||||
else:
|
||||
if !sections.has(section):
|
||||
add_section(section)
|
||||
sections[section].section_name = section
|
||||
sections[section].section_values[label] = val
|
||||
|
||||
func remove_value(section: String, label: String):
|
||||
section = section.dedent().trim_prefix("\n").trim_suffix("\n")
|
||||
label = label.dedent().trim_prefix("\n").trim_suffix("\n")
|
||||
|
||||
if section == "":
|
||||
sections[DEFAULT_SECTION].section_values.erase(label)
|
||||
else:
|
||||
sections[section].section_values.erase(label)
|
||||
|
||||
func add_section(sname: String):
|
||||
if sections.has(sname):
|
||||
return
|
||||
|
||||
sections[sname] = DebugSection.new()
|
||||
sections[sname].section_name = name
|
||||
|
||||
func update():
|
||||
db_label.text = "Debug Panel"
|
||||
|
||||
for section in sections:
|
||||
if sections[section].section_values.size() == 0:
|
||||
continue
|
||||
|
||||
db_label.text += "\n--------------------\n"
|
||||
|
||||
if DEFAULT_SECTION != section:
|
||||
db_label.text += "::%s::\n--------------------\n" % section
|
||||
|
||||
db_label.text += sections[section].get_section_text()
|
||||
@ -0,0 +1,24 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://b4vfwfbq4c355"]
|
||||
|
||||
[ext_resource type="Script" path="res://systems/debug/debug panel/debug_panel.gd" id="1_bx2jn"]
|
||||
|
||||
[node name="Debug Panel" type="Node"]
|
||||
script = ExtResource("1_bx2jn")
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="CanvasLayer"]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[node name="DebugUI" type="MarginContainer" parent="CanvasLayer/PanelContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
theme_override_constants/margin_left = 5
|
||||
theme_override_constants/margin_right = 5
|
||||
|
||||
[node name="Info" type="Label" parent="CanvasLayer/PanelContainer/DebugUI"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "DEBUG PANEL YO"
|
||||
@ -0,0 +1,17 @@
|
||||
class_name DebugSection
|
||||
extends RefCounted
|
||||
|
||||
var section_name = ""
|
||||
var section_values = {} # { label : values }
|
||||
var is_hidden = false
|
||||
|
||||
func get_section_text():
|
||||
|
||||
if is_hidden:
|
||||
return "^"
|
||||
|
||||
var text = ""
|
||||
for label in section_values:
|
||||
text += "%s%s" % [label, section_values[label]]
|
||||
text += "\n"
|
||||
return text
|
||||
@ -0,0 +1,10 @@
|
||||
class_name Debugger
|
||||
extends Control
|
||||
|
||||
# public vars
|
||||
@onready var debug_panel = $"Debug Panel"
|
||||
@onready var debug_logger = $"DebugLogger"
|
||||
|
||||
|
||||
func log(level: DebugLogger.LogLevel, msg: String, silent = false):
|
||||
debug_logger.log(level, msg, silent)
|
||||
@ -0,0 +1,19 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://bnbxvjy2n20tj"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://b4vfwfbq4c355" path="res://systems/debug/debug panel/debug_panel.tscn" id="1_ka3q2"]
|
||||
[ext_resource type="Script" path="res://systems/debug/debugger.gd" id="1_ypa46"]
|
||||
[ext_resource type="Script" path="res://systems/debug/debug logger/debug_logger.gd" id="3_ehcbp"]
|
||||
|
||||
[node name="Debugger" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_ypa46")
|
||||
|
||||
[node name="Debug Panel" parent="." instance=ExtResource("1_ka3q2")]
|
||||
|
||||
[node name="DebugLogger" type="Node" parent="."]
|
||||
script = ExtResource("3_ehcbp")
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue