Skip to content

Refactor code such that Card info can be loaded from an external JSON file#21

Merged
apmnt merged 10 commits intoapmnt:mainfrom
KFSPC8:main
Oct 24, 2025
Merged

Refactor code such that Card info can be loaded from an external JSON file#21
apmnt merged 10 commits intoapmnt:mainfrom
KFSPC8:main

Conversation

@KFSPC8
Copy link
Contributor

@KFSPC8 KFSPC8 commented Oct 24, 2025

Moved Card Data to a JSON file

Changes

  1. Moved card definitions from inline Python to database.json:

    • The eventual goal is to make use of database.json from deckgym to save LOTS of manual importing and duplicated maintenance work
  2. Enhanced card data parsing:

    • Added _parse_card_data() to convert JSON strings to Python types
    • Creates Ability instances from string names
    • Supports both numeric and list-based retreat costs (e.g., ["Colorless", "Colorless"]2)
  3. Code cleanup:

    • Removed inline CARDS_DICT, replaced with loaded CARDS_DATA
    • Added proper type hints and docstrings
    • Improved error handling in card data loading

Technical Details

  • Card loading happens when the module is imported via _load_cards()
  • JSON format example:
    {
      "Pokemon": {
        "id": "A1 129",
        "name": "Mewtwo EX",
        "hp": 150,
        "energy_type": "PSYCHIC",
        "attacks": ["psydrive", "psychic_sphere"],
        "retreat_cost": ["Colorless", "Colorless"],
        ...
      }
    }

Copy link
Owner

@apmnt apmnt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, sensible change. Also drives collaboration. Thanks!

self.test_deck2.add(Card.create_card(Cards.RALTS))
self.test_deck2.add(Card.create_card(Cards.RALTS))
self.test_deck2.add(Card.create_card(Cards.RALTS))
self.test_deck2.add(Card.create_card(Cards.RALTS))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could still be an option for an enum just for developer experience when building decks like this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understandable. Although I'm not sure what is the best way to do it without incurring maintenance effort of populating the enum. Perhaps we need a separate script to parse the json and generate the enum through a build pipeline.

@apmnt apmnt merged commit b3a13af into apmnt:main Oct 24, 2025
1 check failed
@KFSPC8
Copy link
Contributor Author

KFSPC8 commented Oct 25, 2025

Thanks for the merge. I hope it didn't result in too much merge conflicts!

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