diff --git a/README.md b/README.md index 1630cf0..3865d7e 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Godot 4 tactical RPG prototype inspired by classic turn-based Romance of the Thr - Pre-battle Roster can move optional officers between sortie and reserve within scenario limits. - Pre-battle Formation lets deployed officers swap starting positions inside scenario-defined cells. - Pre-battle briefing shows the campaign chapter, chapter battle number, location, and victory/defeat summary. +- Pre-battle Chapters overview shows story-arc progress and the current battle. - Escort scenarios can include required, non-controllable protected units. - Campaign saves joined officers, future deployments can require prior recruitment, and choices can make officers leave. - Completed saves reconcile officer join/leave rewards on load without replaying gold or items. diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 10b2854..130123c 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -35,7 +35,7 @@ 1. Load battle data. 2. Hydrate deployments through `DataCatalog`. 3. Dispatch battle-start scenario events. -4. Show scenario briefing with the campaign chapter header, battle header, objective summary, and optional pre-battle shop, Armory, Roster, and Formation setup. +4. Show scenario briefing with the campaign chapter header, battle header, objective summary, chapter overview, and optional pre-battle shop, Armory, Roster, and Formation setup. 5. Player selects a unit. 6. Briefing completion dispatches battle-begin events, including opening dialogue. 7. Unit moves, attacks, chooses a tactic or consumable item from the side menu, changes equipment, counters, gains EXP, levels up, promotes at class thresholds, or waits. Tactic buttons show MP cost, kind, range, and power or support effect. Physical attacks roll hit chance from unit agility and target terrain avoid; misses give reduced EXP. The scene plays placeholder SFX, a short movement slide, low-HP warning rings, hover target preview badges, and floating combat text for core action and UI feedback. @@ -56,7 +56,7 @@ Joined officers gate whether `requires_joined` player deployments are loaded at all. Rewards and post-battle choices can add or remove joined officers without deleting their saved roster snapshot, so a later rejoin can preserve progression. When a save loads, `CampaignState` scans completed scenarios in campaign order and reapplies only officer join/leave transitions from rewards and the saved `applied_post_battle_choices` ledger, allowing added recruitment rewards to reach older saves without replaying gold or items. Old saves without the ledger can backfill a choice id only when exactly one completed scenario choice matches saved flags. Roster entries are keyed by `officer_id` when available, so future scenarios can deploy the same joined officer under different scenario-specific `unit_id` values. Saved progression overlays final battle stats for now; a later equipment refactor should split base stats from equipment bonuses before adding item leveling or stat recalculation. New battles currently start player units healed to their saved maximum HP/MP. Skill access is carried in roster snapshots, with class defaults still applied for old saves that do not include skills. Promoted class ids are saved in the roster, and the next battle rehydrates class-derived movement, growth, skills, and range from the saved class id before equipment range is recalculated. -Inventory and campaign flags are copied from `CampaignState` into `BattleState` when a scenario starts. Pre-battle shop stock comes from the loaded scenario's `shop.items` list plus matching `shop.conditional_items` blocks. Shop purchases and 50% sell-back are campaign transactions: they update saved gold and unequipped inventory immediately, write the save file, and refresh the already-loaded battle inventory before the player begins the battle. Pre-battle Armory equipment changes use the same equipment rules as battle HUD equipment changes, then immediately save merged roster equipment/stat snapshots and inventory stock. Pre-battle Roster uses scenario `roster.max_units`, `roster.required_officers`, and `roster.required_units` to mark optional player deployments as sortie or reserve; reserve units remain in the candidate list but are excluded from board occupancy, drawing, selection, AI targeting, and living-unit victory checks. Non-controllable player units can act as protected escort targets: enemies can attack them and conditions can reference them, but they are skipped by player selection, Armory, Formation, counterattacks, and campaign roster progression snapshots when `persist_progression` is false. Scenario `ai_target_priority` nudges enemy movement and damage-skill scoring toward important targets such as envoys without overriding defeat bonuses or range checks. Pre-battle Formation uses the loaded scenario's `formation.cells` and only mutates current battle unit positions before battle-begin events fire. Destination victory cells from `unit_reaches_tile` conditions are exposed to the scene for objective overlays and tile info. Movement-triggered `unit_reaches_tile` events receive the unit that just moved, so ambushes fire on entry rather than from units already standing on a marker. Briefing data can append matching `briefing.conditional_lines`, and scenario events can use `when.campaign_flags` to branch dialogue, objective changes, and reinforcements from saved campaign choices. Consumable use can restore HP or MP, and in-battle item use plus equipment swaps mutate only the battle copy until victory; defeats and restarts do not spend saved items or preserve in-battle gear changes. Post-battle choices write campaign `flags` only after the result-panel button is pressed; if the player reloads after rewards are saved but before selecting, the pending scenario id restores the victory choice panel without replaying rewards. The next battle button stays locked until the campaign choice save succeeds. Equipment rewards share the same `item_id -> count` inventory stock, cover weapon, armor, and accessory slots, can be equipped from the side HUD before the selected unit moves or acts, and do not appear in the consumable action menu. Already completed scenarios can be replayed without granting duplicate rewards, choices, or replay inventory consumption; pre-battle Shop, Armory, Roster, and Formation are disabled on completed-scenario replays to avoid side effects. +Inventory and campaign flags are copied from `CampaignState` into `BattleState` when a scenario starts. The pre-battle Chapters overview reads `CampaignState` chapter progress without mutating the save. Pre-battle shop stock comes from the loaded scenario's `shop.items` list plus matching `shop.conditional_items` blocks. Shop purchases and 50% sell-back are campaign transactions: they update saved gold and unequipped inventory immediately, write the save file, and refresh the already-loaded battle inventory before the player begins the battle. Pre-battle Armory equipment changes use the same equipment rules as battle HUD equipment changes, then immediately save merged roster equipment/stat snapshots and inventory stock. Pre-battle Roster uses scenario `roster.max_units`, `roster.required_officers`, and `roster.required_units` to mark optional player deployments as sortie or reserve; reserve units remain in the candidate list but are excluded from board occupancy, drawing, selection, AI targeting, and living-unit victory checks. Non-controllable player units can act as protected escort targets: enemies can attack them and conditions can reference them, but they are skipped by player selection, Armory, Formation, counterattacks, and campaign roster progression snapshots when `persist_progression` is false. Scenario `ai_target_priority` nudges enemy movement and damage-skill scoring toward important targets such as envoys without overriding defeat bonuses or range checks. Pre-battle Formation uses the loaded scenario's `formation.cells` and only mutates current battle unit positions before battle-begin events fire. Destination victory cells from `unit_reaches_tile` conditions are exposed to the scene for objective overlays and tile info. Movement-triggered `unit_reaches_tile` events receive the unit that just moved, so ambushes fire on entry rather than from units already standing on a marker. Briefing data can append matching `briefing.conditional_lines`, and scenario events can use `when.campaign_flags` to branch dialogue, objective changes, and reinforcements from saved campaign choices. Consumable use can restore HP or MP, and in-battle item use plus equipment swaps mutate only the battle copy until victory; defeats and restarts do not spend saved items or preserve in-battle gear changes. Post-battle choices write campaign `flags` only after the result-panel button is pressed; if the player reloads after rewards are saved but before selecting, the pending scenario id restores the victory choice panel without replaying rewards. The next battle button stays locked until the campaign choice save succeeds. Equipment rewards share the same `item_id -> count` inventory stock, cover weapon, armor, and accessory slots, can be equipped from the side HUD before the selected unit moves or acts, and do not appear in the consumable action menu. Already completed scenarios can be replayed without granting duplicate rewards, choices, or replay inventory consumption; pre-battle Shop, Armory, Roster, and Formation are disabled on completed-scenario replays to avoid side effects. The battle scene owns presentation feedback: briefing and result states use menu BGM, briefing headers combine `CampaignState` chapter ranges, campaign order, and title data with `BattleState` briefing and objective text, active battles use battle BGM, dialogue lines can show optional portrait textures or speaker-initial fallback panels and can place the portrait on the left or right side of the dialogue panel, board units render low-HP warning rings and HP bar color states from battle state fields, hover previews are rendered as target badges from existing `BattleState` forecast APIs, log/result hooks trigger placeholder SFX, `BattleState.unit_motion_requested` asks the scene to interpolate a unit's draw position during movement, and `BattleState.combat_feedback_requested` asks the scene to draw transient floating combat text without changing battle rules. diff --git a/docs/DATA_MODEL.md b/docs/DATA_MODEL.md index 245ad9b..5d86c0e 100644 --- a/docs/DATA_MODEL.md +++ b/docs/DATA_MODEL.md @@ -170,7 +170,7 @@ The campaign file defines chapter ranges, scenario order, resource paths, and of } ``` -`chapters` are display metadata for campaign presentation. Each chapter has a stable lowercase `id`, non-empty `title`, and inclusive `start_scenario`/`end_scenario` ids from the linear scenario order. When chapters are present, the validator requires the ranges to cover every campaign scenario exactly once, without overlaps or gaps. `CampaignState` uses them for briefing headers and chapter-local battle numbering; save files still store scenario ids, not chapter ids. +`chapters` are display metadata for campaign presentation. Each chapter has a stable lowercase `id`, non-empty `title`, and inclusive `start_scenario`/`end_scenario` ids from the linear scenario order. When chapters are present, the validator requires the ranges to cover every campaign scenario exactly once, without overlaps or gaps. `CampaignState` uses them for briefing headers, chapter-local battle numbering, and pre-battle chapter progress overview entries; save files still store scenario ids, not chapter ids. ## Officers diff --git a/docs/GODOT_4_6_MIGRATION.md b/docs/GODOT_4_6_MIGRATION.md index 1e0c441..a79ff94 100644 --- a/docs/GODOT_4_6_MIGRATION.md +++ b/docs/GODOT_4_6_MIGRATION.md @@ -42,7 +42,7 @@ powershell -NoProfile -ExecutionPolicy Bypass -File tools\check_godot46_readines - Main scene starts without script errors. - Current campaign save loads or a new campaign starts cleanly. - Briefing opens and can enter battle. -- Shop, Armory, Roster, and Formation open and close. +- Chapters, Shop, Armory, Roster, and Formation open and close. - A player unit can move, attack, wait, use a tactic, use an item, and equip compatible gear. - Enemy turn advances and AI acts. - Victory and defeat panels still appear. diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 46f256d..1bb64ad 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -51,7 +51,7 @@ - Party roster persistence has a first save-file skeleton. - Level, experience, and equipment persistence. -- Chapter selection and save/load. +- Chapter overview exists in pre-battle briefing. Chapter selection and manual save/load are still planned. - Linear sixty-seven-scenario campaign order exists with chapter ranges for story arcs. - Save reset exists. - Victory rewards, consumable counts, equipment stock, and equipped gear persist. @@ -134,7 +134,7 @@ - Unit sprites and animations. Board movement now has a short slide animation, and board units show low-HP warning rings. - Battle effects. First floating combat text now covers damage, recovery, misses, support effects, level-ups, and promotions. Hover target preview badges summarize attacks, tactics, and items. - Music and sound. Basic placeholder BGM and SFX now play for menus, battle flow, unit actions, tactics, items, and result states. -- Chapter UI and visual novel scenes. Pre-battle briefing now uses campaign chapter ranges for chapter-aware numbering, and dialogue lines can choose left or right portrait placement. +- Chapter UI and visual novel scenes. Pre-battle briefing now uses campaign chapter ranges for chapter-aware numbering, has a chapter progress overview, and dialogue lines can choose left or right portrait placement. ## Milestone 6: Content Expansion diff --git a/scripts/core/campaign_state.gd b/scripts/core/campaign_state.gd index 5a8de39..a2de022 100644 --- a/scripts/core/campaign_state.gd +++ b/scripts/core/campaign_state.gd @@ -650,6 +650,33 @@ func get_scenario_count_in_chapter(scenario_id: String) -> int: return scenario_ids.size() +func get_chapter_progress_entries() -> Array: + var entries := [] + for chapter_index in range(chapter_order.size()): + var chapter_id := chapter_order[chapter_index] + var scenario_ids: Array = chapter_scenario_ids.get(chapter_id, []) + var completed_count := 0 + var current_in_chapter := false + var current_scenario_title := "" + for scenario_id in scenario_ids: + if completed_scenarios.has(scenario_id): + completed_count += 1 + if scenario_id == current_scenario_id: + current_in_chapter = true + current_scenario_title = get_scenario_title(scenario_id) + entries.append({ + "id": chapter_id, + "title": str(chapter_titles.get(chapter_id, chapter_id)), + "position": chapter_index + 1, + "chapter_count": chapter_order.size(), + "completed": completed_count, + "total": scenario_ids.size(), + "current": current_in_chapter, + "current_scenario_title": current_scenario_title + }) + return entries + + func get_next_scenario_id(scenario_id: String) -> String: var index := scenario_order.find(scenario_id) if index == -1 or index + 1 >= scenario_order.size(): diff --git a/scripts/scenes/battle_scene.gd b/scripts/scenes/battle_scene.gd index a083b0d..2be5c93 100644 --- a/scripts/scenes/battle_scene.gd +++ b/scripts/scenes/battle_scene.gd @@ -65,6 +65,10 @@ var briefing_title_label: Label var briefing_location_label: Label var briefing_objective_label: Label var briefing_label: Label +var chapter_button: Button +var chapter_menu: VBoxContainer +var chapter_list: VBoxContainer +var chapter_status_label: Label var shop_button: Button var shop_menu: VBoxContainer var shop_buy_button: Button @@ -354,6 +358,11 @@ func _create_hud() -> void: prep_button_row.add_theme_constant_override("separation", 8) briefing_column.add_child(prep_button_row) + chapter_button = Button.new() + chapter_button.text = "Chapters" + chapter_button.pressed.connect(_on_chapter_pressed) + prep_button_row.add_child(chapter_button) + shop_button = Button.new() shop_button.text = "Shop" shop_button.pressed.connect(_on_shop_pressed) @@ -374,6 +383,25 @@ func _create_hud() -> void: formation_button.pressed.connect(_on_formation_pressed) prep_button_row.add_child(formation_button) + chapter_menu = VBoxContainer.new() + chapter_menu.visible = false + chapter_menu.add_theme_constant_override("separation", 6) + briefing_column.add_child(chapter_menu) + + chapter_status_label = Label.new() + chapter_status_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART + chapter_status_label.custom_minimum_size = Vector2(600, 22) + chapter_menu.add_child(chapter_status_label) + + var chapter_scroll := ScrollContainer.new() + chapter_scroll.custom_minimum_size = Vector2(600, 190) + chapter_menu.add_child(chapter_scroll) + + chapter_list = VBoxContainer.new() + chapter_list.custom_minimum_size = Vector2(580, 0) + chapter_list.add_theme_constant_override("separation", 4) + chapter_scroll.add_child(chapter_list) + shop_menu = VBoxContainer.new() shop_menu.visible = false shop_menu.add_theme_constant_override("separation", 6) @@ -757,7 +785,9 @@ func _handle_key(event: InputEventKey) -> void: return _on_begin_battle_pressed() elif event.keycode == KEY_ESCAPE: - if shop_menu != null and shop_menu.visible: + if chapter_menu != null and chapter_menu.visible: + _hide_chapter_menu() + elif shop_menu != null and shop_menu.visible: _hide_shop_menu() elif armory_menu != null and armory_menu.visible: _hide_armory_menu() @@ -1823,6 +1853,7 @@ func _load_scenario(scenario_id: String) -> void: _hide_tactic_menu() _hide_item_menu() _hide_equip_menu() + _hide_chapter_menu() _hide_shop_menu() _hide_armory_menu() _hide_roster_menu() @@ -1915,11 +1946,14 @@ func _show_briefing() -> void: briefing_label.text = body briefing_panel.visible = true battle_started = false + _hide_chapter_menu() _hide_shop_menu() _hide_armory_menu() _hide_roster_menu() _hide_formation_menu() var prep_locked := _is_prebattle_prep_locked() + if chapter_button != null: + chapter_button.disabled = campaign_state.get_chapter_progress_entries().is_empty() if shop_button != null: shop_button.disabled = prep_locked or (state.get_shop_item_ids().is_empty() and _get_sellable_item_ids().is_empty()) if armory_button != null: @@ -1940,6 +1974,7 @@ func _start_battle_from_briefing() -> void: _play_bgm("battle") if briefing_panel != null: briefing_panel.visible = false + _hide_chapter_menu() _hide_shop_menu() _hide_armory_menu() _hide_roster_menu() @@ -1949,6 +1984,69 @@ func _start_battle_from_briefing() -> void: _update_hud() +func _on_chapter_pressed() -> void: + if battle_started or briefing_panel == null or not briefing_panel.visible: + return + _play_ui_click() + if chapter_menu != null and chapter_menu.visible: + _hide_chapter_menu() + else: + _hide_shop_menu() + _hide_armory_menu() + _hide_roster_menu() + _hide_formation_menu() + _rebuild_chapter_menu() + chapter_menu.visible = true + _update_hud() + + +func _hide_chapter_menu() -> void: + if chapter_menu == null: + return + chapter_menu.visible = false + + +func _rebuild_chapter_menu() -> void: + if chapter_list == null: + return + for child in chapter_list.get_children(): + chapter_list.remove_child(child) + child.queue_free() + var entries := campaign_state.get_chapter_progress_entries() + if chapter_status_label != null: + chapter_status_label.text = "%s chapters | %d/%d battles complete" % [ + campaign_state.campaign_title, + campaign_state.completed_scenarios.size(), + campaign_state.get_scenario_count() + ] + if entries.is_empty(): + var empty_label := Label.new() + empty_label.text = "No campaign chapters are defined." + chapter_list.add_child(empty_label) + return + for entry in entries: + var completed := int(entry.get("completed", 0)) + var total := int(entry.get("total", 0)) + var current := bool(entry.get("current", false)) + var status := "Current" if current else ("Complete" if total > 0 and completed >= total else "Upcoming") + var current_title := str(entry.get("current_scenario_title", "")) + var line := "Chapter %02d/%02d - %s [%s] %d/%d" % [ + int(entry.get("position", 0)), + int(entry.get("chapter_count", 0)), + entry.get("title", ""), + status, + completed, + total + ] + if current and not current_title.is_empty(): + line += "\nCurrent battle: %s" % current_title + var chapter_label := Label.new() + chapter_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART + chapter_label.custom_minimum_size = Vector2(560, 0) + chapter_label.text = line + chapter_list.add_child(chapter_label) + + func _on_shop_pressed() -> void: if battle_started or _is_prebattle_prep_locked() or briefing_panel == null or not briefing_panel.visible: return @@ -1957,6 +2055,7 @@ func _on_shop_pressed() -> void: _hide_shop_menu() else: shop_sell_mode = state.get_shop_item_ids().is_empty() and not _get_sellable_item_ids().is_empty() + _hide_chapter_menu() _hide_armory_menu() _hide_roster_menu() _hide_formation_menu() @@ -1978,6 +2077,7 @@ func _on_armory_pressed() -> void: if armory_menu != null and armory_menu.visible: _hide_armory_menu() else: + _hide_chapter_menu() _hide_shop_menu() _hide_roster_menu() _hide_formation_menu() @@ -1999,6 +2099,7 @@ func _on_roster_pressed() -> void: if roster_menu != null and roster_menu.visible: _hide_roster_menu() else: + _hide_chapter_menu() _hide_shop_menu() _hide_armory_menu() _hide_formation_menu() @@ -2020,6 +2121,7 @@ func _on_formation_pressed() -> void: if formation_menu != null and formation_menu.visible: _hide_formation_menu() else: + _hide_chapter_menu() _hide_shop_menu() _hide_armory_menu() _hide_roster_menu() @@ -2037,7 +2139,8 @@ func _hide_formation_menu() -> void: func _is_prep_menu_visible() -> bool: return ( - (shop_menu != null and shop_menu.visible) + (chapter_menu != null and chapter_menu.visible) + or (shop_menu != null and shop_menu.visible) or (armory_menu != null and armory_menu.visible) or (roster_menu != null and roster_menu.visible) or (formation_menu != null and formation_menu.visible) @@ -2764,6 +2867,7 @@ func _show_campaign_complete() -> void: _hide_tactic_menu() _hide_item_menu() _hide_equip_menu() + _hide_chapter_menu() _hide_shop_menu() _hide_armory_menu() _hide_roster_menu() @@ -2799,6 +2903,7 @@ func _on_new_campaign_pressed() -> void: _hide_tactic_menu() _hide_item_menu() _hide_equip_menu() + _hide_chapter_menu() _hide_roster_menu() _load_current_battle() _show_briefing()