Skip to content

Conversation

@mathrick
Copy link

@mathrick mathrick commented Jun 2, 2024

This splits the card database loading into a separate component (CardDB) which can be implemented however the user wishes, with JSONFileCardDB being a built-in option provided. CardCollection has also undergone a similar treatment (unfortunately, in Godot 4.2 it's not possible to provide a drop-in replacement object which can be iterated like a simple array whilst also allowing custom logic, because of godotengine/godot#74686). They are coupled to CardPileUI through a very simple protocol which imposes a minimal amount of requirements on the user code.

For backwards compatibility, JSON loading will still happen as a fallback if no card_database or card_collection has been provided, so existing code will continue to work unchanged. This has been tested using the examples: example 1 (ie. main scene) has been ported to use JSONFileCardDB explicitly, whereas example 2 uses the old deprecated *_file_path properties. Both work without issues.

All of the changes have been fully documented in the README.

Fixes #4.

mathrick added 3 commits June 2, 2024 00:01
CardDB is now a generic loading/lookup mechanism with two built-in
implementations:

* NullCardDB, which doesn't do any loading or lookup. It simply acts
  as a pass-through for cards supplied by external means
* JSONFileCardDB, which implements loading/lookup compatible with the
  previous interface. It can also be subclassed to implemented any
  required custom transformation during loading

Setting json_card_database_path and json_card_collection_path is now
deprecated, but still supported for backwards compatibility. New code
should use card_database and card_collection directly instead, and
pick a CardDB implementation to use.
Unfortunately it's not possible to simply use custom iterables to
mimic a plain Array, because of a bug in the iteration protocol
implementation currently present in 4.2 that's not fixed before 4.3,
which would require calling a function
anyway (godotengine/godot#74686)
@mathrick
Copy link
Author

mathrick commented Jun 2, 2024

Marking it as a draft for now, since I haven't fully integrated CardPileUI into my project yet, and I want to make sure I'm not overlooking something. As soon as I have that working, I will mark this PR as ready.

@mathrick mathrick force-pushed the decouple-json-card-db branch from fd8cf2c to 6eaff8d Compare June 3, 2024 00:38
@mathrick mathrick marked this pull request as ready for review June 3, 2024 22:09
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.

CardPileUI should not hardcode JSON files for the card DB

1 participant