Externalize card database and fusion recipes to JSON #1
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Card data (~50 cards) and fusion recipes (~40) are currently hardcoded as Rust struct literals in source files:
crates/card-data/src/card_db.rs(494 lines of inlineMonsterCard { ... }andSpellCard { ... }declarations)crates/fusion-engine/src/fusion_table.rs(555 lines of inlineFusionRecipe { ... }declarations)This makes it impossible to expand the dataset (target: 722 cards, ~700 fusion recipes) without recompiling the entire Rust codebase. Designers cannot add cards without touching Rust code.
Goal
Move 100% of card and fusion data out of
.rsfiles into external JSON files that are loaded at runtime. The Rust code should only contain loading logic, not data.Files to Create
assets/cards.jsonTop-level structure:
Monster types must match
MonsterTypeenum variants exactly (Dragon,Warrior,Machine,Zombie,Thunder,Aqua,Fiend,Spellcaster,Beast,BeastWarrior,Insect,Plant,Dinosaur,Rock,Fish,SeaSerpent,Pyro,Fairy,Reptile,WingedBeast).Spell types must match
SpellTypeenum variants exactly (Normal,Field,Equip,Ritual).Guardian stars must match
GuardianStarenum variants exactly (Sun,Mercury,Venus,Moon,Mars,Jupiter,Saturn,Uranus,Neptune,Pluto).assets/fusions.jsonTop-level structure:
FusionMaterialuses externally tagged enum representation:{"Type": "Dragon"}for type-based material{"Specific": "Blue-Eyes White Dragon"}for specific card materialFusionResultuses externally tagged enum representation:{"Monster": {...}}for monster result{"Spell": {...}}for spell resultFiles to Modify
crates/card-data/Cargo.tomlAdd
serde_json = "1.0"dependency.crates/card-data/src/card_db.rsvec![...]inline data fromnew()pub fn from_file(path: &str) -> Result<Self, CardDbError>pub fn from_str(json: &str) -> Result<Self, CardDbError>pub fn test_data() -> Selfwith ~10 cards for unit tests (or load from test fixture)new()should attempt to load fromassets/cards.jsonat runtime, returning empty on error (or panicking with a clear message)crates/fusion-engine/Cargo.tomlAdd
serde_json = "1.0"dependency.crates/fusion-engine/src/recipe.rsSerialize, Deserializederives toFusionMaterial,FusionResult, andFusionRecipeFusionMaterialandFusionResultcurrently only deriveClone, Debug, PartialEq, Eqcrates/fusion-engine/src/fusion_table.rsvec![...]inline recipes fromnew()pub fn from_file(path: &str) -> Result<Self, FusionError>pub fn from_str(json: &str) -> Result<Self, FusionError>new()should attempt to load fromassets/fusions.jsoncrates/cli/src/main.rsand/orcrates/cli/src/game.rsassets/directory at startupassets/cards.jsonandassets/fusions.jsonrelative to the working directorycrates/duel-engine/src/duel.rs(tests only)FusionTable::new()directly to use a test helperError Types
Use
thiserrorto define:CardDbErrorincard-data(IO, Parse, InvalidMonsterType, etc.)FusionErrorinfusion-engine(IO, Parse, etc.)Data Preservation
Every single card and fusion recipe currently in the codebase must be preserved in the JSON files. Do not drop any data.
Testing Strategy
card-datashould useCardDatabase::test_data()(small embedded set)fusion-engineshould useFusionTable::test_data()(small embedded set)from_fileloads the fullassets/correctlyAcceptance Criteria
assets/cards.jsonexists with all 50+ current cards exactly preservedassets/fusions.jsonexists with all ~40 current recipes exactly preservedCardDatabase::from_file("assets/cards.json")loads successfullyFusionTable::from_file("assets/fusions.json")loads successfullycard-dataandfusion-enginehaveserde_jsonin Cargo.tomlFusionMaterial,FusionResult,FusionRecipederiveDeserializeassets/at startup and workscargo test --workspace)cargo clippy --workspaceclean (zero warnings)cargo check --workspaceclean