harvest/game/scripts/campaign_debug.gd
2026-10-03 12:14:28 -04:00

97 lines
3.4 KiB
GDScript

class_name CampaignDebug
extends CanvasLayer
## Temporary campaign readout and debug keys, until the phase HUD (Step 7) and menus (Step 11)
## replace it.
## Enter / Space / A begin the day (ends the untimed morning review)
## N start the night early (only when GameConfig.allow_early_night is on)
## R / Start 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
const SPEEDS: Array[float] = [1.0, 5.0, 20.0]
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
var _label: Label
var _speed_index: int = 0
func _ready() -> void:
_label = Label.new()
_label.position = Vector2(24.0, 20.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)
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("ui_accept") and s.phase == CampaignController.Phase.MORNING:
campaign.begin_day()
elif event.is_action_pressed("restart"):
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_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.crops = 0
s.animals = 0
s.supplies = 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.supplies
lines.append(farm)
match s.phase:
CampaignController.Phase.MORNING:
lines.append("[Enter] begin the day")
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")
lines.append("F6 next phase · F7 speed · F9 scarecrow to 0 HP · F10 strip farm")
return "\n".join(lines)