Skip to content

Codex (Civilopedia) Phase 1: data layer — parse Civilopedia.txt and attach pedia keys - #999

Open
Billytifft wants to merge 2 commits into
C7-Game:Developmentfrom
Billytifft:billy/codex-phase-1-data
Open

Billytifft wants to merge 2 commits into
C7-Game:Developmentfrom
Billytifft:billy/codex-phase-1-data

Conversation

@Billytifft

Copy link
Copy Markdown
Contributor

Summary

Phase 1 (data layer) of the Civilopedia/Codex epic (#997): parse Text/Civilopedia.txt into a queryable model, attach civilopedia keys to all game objects during BIQ/SAV import, and load the text beside PediaIcons during import.

What's included

  • C7Engine/C7GameData/Codex.cs — new parser producing Codex (entry dictionary + game-concept keys), CodexEntry, CodexPage.
    • Windows-1252 decoding of the legacy file.
    • #KEY headers → entries; #DESC_<KEY> headers → additional pages; {Title} lines → page titles; ^-prefixed lines → paragraphs (wrapped lines are rejoined).
    • #GAME_CONCEPTS_KEYSGameConceptKeys list; empty placeholder markers (GAME_CONCEPTS, EOF) are filtered.
    • Inline $LINK<Text=Key> converted to markdown [Text](key:Key); keys are trimmed on lookup (the real file has trailing-space keys like GCON_Enslavement ).
  • Keys attached during import for units, buildings, and civilizations (civilopediaEntry on SaveUnitPrototype/UnitPrototype, SaveBuilding/Building, Civilization). Techs/resources/governments/terrain already had them.
  • Load pipeline — a new GetCivilopediaTextPath func mirrors the existing GetPediaIconsPath pattern through GameParams, CreateGame, SaveManager.LoadSave, ImportCiv3.ImportSav/Biq, SaveGame.Load, Game.cs, ScenarioSetup, and BuildDevSave.
  • StorageCodex lives on SaveGame / GameData. It is [JsonIgnore] on SaveGame and regenerated from the scenario search path on load, so C7 saves stay portable and text is never duplicated into JSON.
  • TestsEngineTests/GameData/CodexTest.cs (11 tests): parser semantics, Windows-1252, key trimming, game-concept keys, a real-file smoke test against the actual install, and an import integration test (2 Rise of Rome.biq) verifying keys attach and resolve.

Design decisions

  1. Legacy Civilopedia.txt parsed as-is, not a native format. Matches the legacy-mode direction and keeps mods working (per issue open question 1). Revisit native prose only if/when standalone content is authored.
  2. Naming: Codex* for our feature, Civilopedia kept for legacy artifacts. The new model/API is Codex/CodexEntry/CodexPage; Civilopedia naming remains only where it refers to the Civ3 files/content (Civilopedia.txt, civilopediaEntry keys, path lambdas).
  3. Markdown bodies. The parser emits markdown ([Text](key:Key) links, \n\n paragraph breaks, {Title} pages) so Phase 2/3 UI can render with a stock markdown-capable control and the key: links give deep-linking for free.
  4. Codex is not part of saves. It is regenerated on load ([JsonIgnore]), resolving issue open question 2: keeps the dictionary on GameData/SaveGame for convenient access, but keeps saves small and language-agnostic.
  5. Null-safe for missing keys. Scenario-only objects (e.g. Rise of Rome's PRTO_Fire_Catapult) legitimately have no entry in the installed text. GetEntry returns null rather than throwing; the integration test asserts graceful handling. UI must render a fallback (name + stats) for these.
  6. Path resolves to the base ruleset text. Scenarios ship only an override PediaIcons.txt today; there is exactly one Civilopedia.txt in a Complete install, so the path resolves to Conquests/Text/Civilopedia.txt (via the same Util.Civ3MediaPath / scenario-search convention as GetPediaIconsPath), keeping mod override support for any future mod-provided file.

Verified

  • dotnet build C7/C7.sln — 0 errors
  • dotnet test C7/C7.sln — 83/83 passed (with CIV3_HOME set)
  • dotnet format C7/C7.sln whitespace --verify-no-changes — clean

Out of scope (later phases)

UI shell, stat blocks, rendering key: links, deep-linking, and search are Phase 2/3 per #997. Standalone-mode fallback when no text file exists is covered by a Codex warning path (renders empty, callers must handle null).

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.

1 participant