harvest/game/scripts/campaign_debug.gd
2026-10-04 12:07:36 -04:00

121 lines
4.8 KiB
GDScript

class_name CampaignDebug
extends CanvasLayer
## Debug readout and keys (debug builds). The readout is hidden until F1; the keys always work.
## F1 show / hide this readout
## F2 cycle tonight's plan through the debug scenarios (one enemy type, then
## pairs, then all three; game/resources/scenarios/) and back to the real one
## N start the night early (only when GameConfig.allow_early_night is on)
## R after Game Over: retry the night; after the farmers return: new vacation
## F6 end the current phase now
## F7 cycle game speed 1x / 5x / 20x
## F9 debug: scarecrow to 0 HP
## F10 debug: strip every farm asset
## T / G / H debug: send in a thief / a crow / a fence breaker (FarmSim)
const SPEEDS: Array[float] = [1.0, 5.0, 20.0]
const SCENARIOS: Array[String] = ["crows", "thieves", "breakers", "crows_thieves", "thieves_breakers", "all_three"]
const ENDINGS := {
CampaignController.Outcome.GAME_OVER_SCARECROW: "GAME OVER: the scarecrow was destroyed",
CampaignController.Outcome.GAME_OVER_STRIPPED: "GAME OVER: the farm was stripped bare",
CampaignController.Outcome.VACATION_COMPLETE: "THE FARMERS ARE BACK: vacation complete",
}
@export var campaign: CampaignController
## Optional: shows thieves and crops in flight.
@export var sim: FarmSim
var _label: Label
var _speed_index: int = 0
var _scenario: int = -1
func _ready() -> void:
_label = Label.new()
_label.position = Vector2(24.0, 140.0)
_label.add_theme_font_size_override("font_size", 22)
_label.add_theme_color_override("font_outline_color", Color.BLACK)
_label.add_theme_constant_override("outline_size", 6)
_label.visible = false
add_child(_label)
func _exit_tree() -> void:
Engine.time_scale = 1.0
func _process(_delta: float) -> void:
_label.text = _describe()
func _unhandled_input(event: InputEvent) -> void:
var s := campaign.state
if event.is_action_pressed("restart") and event is InputEventKey:
if s.phase == CampaignController.Phase.GAME_OVER:
campaign.retry_night()
elif s.phase == CampaignController.Phase.FARMERS_RETURN:
campaign.new_campaign()
var key := event as InputEventKey
if key == null or not key.pressed or key.echo:
return
match key.physical_keycode:
KEY_F1:
_label.visible = not _label.visible
KEY_F2:
cycle_scenario()
KEY_N:
campaign.start_night_early()
KEY_F6:
campaign.advance_phase()
KEY_F7:
_speed_index = (_speed_index + 1) % SPEEDS.size()
Engine.time_scale = SPEEDS[_speed_index]
KEY_F9:
s.scarecrow_hp = 0
KEY_F10:
s.strip()
## Next debug scenario as tonight's plan (after the last, the real plan again).
func cycle_scenario() -> void:
if sim == null:
return
_scenario = _scenario + 1 if _scenario + 1 < SCENARIOS.size() else -1
var plan: NightPlan = null
if _scenario >= 0:
plan = load("res://game/resources/scenarios/%s.tres" % SCENARIOS[_scenario]) as NightPlan
sim.waves.debug_plan = plan
if sim.toasts != null:
sim.toasts.push("Tonight (debug): %s" % (plan.title if plan != null else "the night's own plan"), Color(0.8, 0.9, 1.0))
func _describe() -> String:
var s := campaign.state
var lines: Array[String] = []
var phase_name: String = CampaignController.Phase.keys()[s.phase]
var head := "Night %d/%d · %s" % [s.night, campaign.config.campaign_nights, phase_name.replace("_", " ")]
if campaign.is_timed(s.phase):
var t := ceili(s.phase_time_left)
head += " · %d:%02d left" % [floori(t / 60.0), t % 60]
lines.append(head + " · speed %dx" % int(SPEEDS[_speed_index]))
var farm := "Scarecrow %d/%d · Crops %d/%d" % [s.scarecrow_hp, s.scarecrow_max_hp, s.crops, s.crops_total]
if s.animals_total > 0:
farm += " · Animals %d/%d" % [s.animals, s.animals_total]
if s.supplies_total > 0:
farm += " · Supplies %d%s" % [s.supplies, " (raided)" if s.shed_raided else ""]
lines.append(farm)
if sim != null and sim.loot != null:
lines.append("Thieves %d · carried %d, dropped %d, following %d · pen %s" % [sim.enemies.alive_count(),
sim.loot.count(LootSystem.Status.CARRIED), sim.loot.count(LootSystem.Status.DROPPED),
sim.loot.followers(), "open" if sim.animals.pen_open else "closed"])
match s.phase:
CampaignController.Phase.GAME_OVER:
lines.append(ENDINGS[campaign.outcome] + " · [R] retry the night")
CampaignController.Phase.FARMERS_RETURN:
lines.append(ENDINGS[campaign.outcome] + " · [R] new vacation")
_:
if campaign.can_start_night_early():
lines.append("[N] start the night early")
if sim != null and sim.waves.debug_plan != null:
lines.append("Scenario: %s (F2 next)" % sim.waves.debug_plan.title)
lines.append("F1 hide · F2 scenario · F6 next phase · F7 speed · F9 scarecrow to 0 HP · F10 strip farm · T/G/H thief/crow/breaker")
return "\n".join(lines)