Adds debugging system

combat_refactor
Joey Pollack 1 year ago
parent dcb3966d54
commit 7044168b2e

@ -31,6 +31,38 @@ folder_colors={
[input]
ui_left={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null)
]
}
ui_right={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null)
]
}
ui_up={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194320,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null)
]
}
ui_down={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194322,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
]
}
Move_Left={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null)

@ -28,7 +28,7 @@ func state_enter(_params: Dictionary):
# Connect to all needed signals and initialize the combatants
for team in teams:
for combatant in team.members:
combatant.init_combat()
combatant.init_combat(self)
if !combatant.damaged.is_connected(on_combatant_damaged):
combatant.damaged.connect(on_combatant_damaged)

@ -11,11 +11,19 @@ extends Node2D
signal damaged(damaged_combatant: Combatant, source: DamageSource, final_amount: int)
@onready var attack_btn = $"Combat Menu/PanelContainer/MarginContainer/VBoxContainer/BtnAttack"
@onready var defend_btn = $"Combat Menu/PanelContainer/MarginContainer/VBoxContainer/BtnDefend"
@export var combat_stats: CombatStats
@export var actions: Array[CombatAction] = []
@export var is_player_driven = true
var next_action: CombatAction = null
@export_category("Debug")
@export var enable_debug_logging: bool = true
var _combat_context: CombatState
var _next_action: CombatAction = null
var _has_focus: = false
# current state
var hp: int = 0 # Health Points
@ -23,12 +31,14 @@ var ps: int = 0 # Physical Stamina
var ms: int = 0 # Mental Stamina
var atb: float = 0 # ATB Timer - counts down, turn is ready at 0
func init_combat():
print("Initing Combatant")
func init_combat(context: CombatState):
context.debugger.log(DebugLogger.LogLevel.INFO, "Initing Combatant", !enable_debug_logging)
_combat_context = context
if !is_player_driven:
$"Combat Menu".visible = false
pass
func is_defeated():
@ -40,11 +50,17 @@ func is_defeated():
func is_turn_ready():
return atb <= 0
func set_focus(focused: bool):
_has_focus = focused
func has_focus():
return _has_focus
func process_tick(delta, _team: CombatTeam):
if atb > 0:
atb -= delta
# TODO: handle input
# TODO: handle input if has_focus
func take_damage(source: DamageSource):
@ -62,6 +78,3 @@ func take_damage(source: DamageSource):
hp -= final_amount
damaged.emit(self, source, final_amount)
func on_action_clicked(btn):
print("Action Clicked: %s" % btn.text)

@ -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"

@ -5,7 +5,7 @@ extends CombatAction
var target: Combatant
var damage: DamageSource
func init():
func _init():
print("Setting action name")
name = "Attack"

@ -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")

@ -8,12 +8,18 @@ extends Node
# constants (CONSTANT_CASE)
# @export variables (snake_case)
# public variables (non-underscore-prefixed snake_case)
@export var debugger: Debugger = null
# private variables (underscore-prefixed _snake_case)
# @onready variables (snake_case)
#
# optional built-in virtual _init method
# optional built-in virtual _enter_tree() method
# built-in virtual _ready method
func _ready():
if !debugger:
push_warning("Debugger not set in GameState")
# remaining built-in virtual methods (underscore-prefixed _snake_case)
# public methods (non-underscore-prefixed snake_case)
func state_enter(_params: Dictionary):

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save