99 lines
3.7 KiB
GDScript
99 lines
3.7 KiB
GDScript
extends Node
|
|
## Central registry for all runtime-tunable parameters.
|
|
## Add a new param with one _reg_f() call in _register_all() — the menu picks it up automatically.
|
|
## Access: DP.f("key") • Persist: DP.save() / DP.load_saved() • Reset: DP.reset_all()
|
|
|
|
signal any_changed(key: String, value: Variant)
|
|
|
|
const SAVE_PATH := "user://debug_params.cfg"
|
|
|
|
var _params: Dictionary = {}
|
|
|
|
|
|
func _ready() -> void:
|
|
_register_all()
|
|
load_saved()
|
|
|
|
|
|
func _register_all() -> void:
|
|
# ── Movement ──────────────────────────────────────────────────────────────
|
|
_reg_f("Movement", "walk_speed", 6.0, 1.0, 40.0)
|
|
_reg_f("Movement", "charge_speed", 18.0, 5.0, 60.0)
|
|
_reg_f("Movement", "walk_accel", 14.0, 1.0, 80.0)
|
|
_reg_f("Movement", "charge_accel", 40.0, 5.0, 120.0)
|
|
_reg_f("Movement", "deceleration", 12.0, 1.0, 50.0)
|
|
_reg_f("Movement", "charge_decel", 3.5, 0.5, 20.0)
|
|
_reg_f("Movement", "jump_velocity", 4.5, 1.0, 20.0)
|
|
# ── Turning ───────────────────────────────────────────────────────────────
|
|
_reg_f("Turning", "walk_turn_fast", 8.0, 0.5, 25.0)
|
|
_reg_f("Turning", "walk_turn_slow", 3.5, 0.5, 15.0)
|
|
_reg_f("Turning", "charge_turn", 0.55, 0.05, 3.0, 0.01)
|
|
_reg_f("Turning", "visual_turn_speed", 12.0, 1.0, 40.0)
|
|
# ── Dust ──────────────────────────────────────────────────────────────────
|
|
_reg_f("Dust", "dust_lifetime", 0.9, 0.1, 4.0)
|
|
_reg_f("Dust", "dust_explosiveness", 0.35, 0.0, 1.0)
|
|
_reg_f("Dust", "dust_spread", 45.0, 5.0, 90.0)
|
|
_reg_f("Dust", "dust_gravity_y", -1.5,-15.0, 0.0)
|
|
_reg_f("Dust", "walk_scale_min", 0.35, 0.05, 3.0)
|
|
_reg_f("Dust", "walk_scale_max", 0.65, 0.05, 3.0)
|
|
_reg_f("Dust", "walk_vel_min", 0.8, 0.1, 12.0)
|
|
_reg_f("Dust", "walk_vel_max", 1.8, 0.1, 12.0)
|
|
_reg_f("Dust", "charge_scale_min", 1.0, 0.05, 6.0)
|
|
_reg_f("Dust", "charge_scale_max", 2.2, 0.05, 6.0)
|
|
_reg_f("Dust", "charge_vel_min", 2.8, 0.1, 20.0)
|
|
_reg_f("Dust", "charge_vel_max", 5.5, 0.1, 20.0)
|
|
|
|
|
|
func _reg_f(section: String, key: String, default: float,
|
|
min_val: float, max_val: float, step: float = 0.05) -> void:
|
|
_params[key] = {
|
|
"value": default,
|
|
"default": default,
|
|
"section": section,
|
|
"type": TYPE_FLOAT,
|
|
"min": min_val,
|
|
"max": max_val,
|
|
"step": step,
|
|
}
|
|
|
|
|
|
## Read a float param. Panics on unknown key — intentional: typos should be loud.
|
|
func f(key: String) -> float:
|
|
return _params[key]["value"] as float
|
|
|
|
|
|
func set_value(key: String, value: Variant) -> void:
|
|
if not _params.has(key):
|
|
return
|
|
_params[key]["value"] = value
|
|
any_changed.emit(key, value)
|
|
|
|
|
|
## Returns the full metadata dict — used by DebugMenu to build UI.
|
|
func get_all() -> Dictionary:
|
|
return _params
|
|
|
|
|
|
func save() -> void:
|
|
var cfg := ConfigFile.new()
|
|
for key: String in _params:
|
|
var p: Dictionary = _params[key]
|
|
cfg.set_value(p["section"], key, p["value"])
|
|
cfg.save(SAVE_PATH)
|
|
|
|
|
|
func load_saved() -> void:
|
|
var cfg := ConfigFile.new()
|
|
if cfg.load(SAVE_PATH) != OK:
|
|
return
|
|
for section: String in cfg.get_sections():
|
|
for key: String in cfg.get_section_keys(section):
|
|
if _params.has(key):
|
|
_params[key]["value"] = cfg.get_value(section, key)
|
|
|
|
|
|
func reset_all() -> void:
|
|
for key: String in _params:
|
|
_params[key]["value"] = _params[key]["default"]
|
|
any_changed.emit("__all__", null)
|