Skip to content

Refactor narrative_nodes.json: 57.7% line reduction via templates, merged actions, inline end nodes - #8

Open
mimi99528 with Copilot wants to merge 4 commits into
masterfrom
copilot/optimize-narrative-nodes
Open

Refactor narrative_nodes.json: 57.7% line reduction via templates, merged actions, inline end nodes#8
mimi99528 with Copilot wants to merge 4 commits into
masterfrom
copilot/optimize-narrative-nodes

Conversation

Copilot AI commented Jul 12, 2026

Copy link
Copy Markdown

narrative_nodes.json had grown to 1139 lines in prototype stage due to redundant per-action five-level result sets, 4 near-identical fire distraction actions, and 5 content-free _end placeholder nodes. This PR restructures the data and updates all consuming code.

Data file (narrative_nodes.json): 1139 → 482 lines (−57.7%)

New top-level structure:

{
  "outcome_templates": {
    "fire_distraction": { "大成功": {...}, "成功": {...}, ... }
  },
  "nodes": [ ... ]
}
  • Merged fire actions: 火焰箭 / 火球术 / 点火术 → single 点燃类 action referencing shared template via {"$template": "fire_distraction"}. Key matches action name directly — no fallback lookup needed.
  • Removed 5 _end nodes: altar_site_001_end etc. replaced by "__end__" sentinel in next_nodes + end_summary field on the parent node.
  • Compact results_pool format: outcome level as dict key instead of list of objects, effects inline — eliminates ~5 lines per result down to 1.

narrative_system.py

  • NarrativeNode.from_dict accepts templates: Optional[Dict] param; detects and handles three results_pool formats: legacy list, new compact dict, and {"$template": "..."} reference.
  • New _resolve_template static method for {param} substitution in template text.
  • load_from_file detects new {outcome_templates, nodes} top-level dict vs. old flat list (backward compatible).
  • Added end_summary: Optional[str] field to NarrativeNode.
  • NarrativeResult docstring documents the full effects field schema (30+ effect types) as canonical reference.

scene_manager.py / game_view.py

_handle_narrative_confirm now checks next_node_id == "__end__" to return to map, replacing the old is_end_node lookup against a now-removed node object.

Copilot AI changed the title [WIP] Optimize narrative nodes data file for clarity and maintenance Refactor narrative_nodes.json: 57.7% line reduction via templates, merged actions, inline end nodes Jul 12, 2026
Copilot AI requested a review from mimi99528 July 12, 2026 05:21
@mimi99528
mimi99528 marked this pull request as ready for review July 13, 2026 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants