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 ## F3 / Shift+F3 in the morning review: jump to the next / previous day's morning, farm as ## it is (jump_morning; debug builds only, not on a co-op partner's machine) ## 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_F3: jump_morning(-1 if key.shift_pressed else 1) 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() ## Debug builds, in the morning review only: to the morning of the next (step 1) or previous ## (step -1) day, within the vacation. The farm stays as it is and nights_survived follows as ## night - 1. It's the campaign's own new-morning path (CampaignController.load_state with the ## current state), so everything a real morning does happens: dormant crop fields sprout (or go ## dormant again) by nights_survived, the Workbench is granted from nights_survived 1 on, the ## retry snapshot is retaken, and the review panel refreshes. As at a real night's end, the ## Workbench and the sprouted crops are in the state before that snapshot. The save file is left ## alone. Returns whether it moved. func jump_morning(step: int) -> bool: var s := campaign.state if not OS.is_debug_build() or s.phase != CampaignController.Phase.MORNING or campaign.remote_request.is_valid(): return false var night := clampi(s.night + step, 1, campaign.config.campaign_nights) if night == s.night: return false s.night = night s.nights_survived = night - 1 if sim != null: # what the night's end does first (CampaignController.night_ending) if s.nights_survived >= 1: sim.structures.grant_workbench() sim.loot.grow_crops_total(s.nights_survived) var path := campaign.save_path campaign.save_path = "" # no autosave: a jump isn't a morning the player reached campaign.load_state(s) campaign.save_path = path return true ## 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 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 · F3 / Shift+F3 next / previous morning · F6 next phase · F7 speed · F9 scarecrow to 0 HP · F10 strip farm · T/G/H thief/crow/breaker") return "\n".join(lines)