tassaron / dnd-character

library for making Dungeons & Dragons 5e characters as serializable data
https://pypi.org/project/dnd-character/
Eclipse Public License 2.0
45 stars 17 forks source link

Serialization #8

Closed gergo-szabo closed 1 year ago

gergo-szabo commented 1 year ago

The markdown states: Characters are serializable into Python dicts so they can be saved and loaded however you wish.

The uid: UUID and the experience: Union[int, None, Experience] variables in the Character class make serialization problematic.

Also class features get into the dictionary (dict) which bloat the size so large it gets inconvenient for database storage (my usecase).

I recommend to implement two function (eg.: dump_to_dict, restore_from_dict) for the Character class.

gergo-szabo commented 1 year ago

Incorrectly used. Well done

tassaron commented 1 year ago

If you need some help using this, feel free to ask. I agree that the size of the dictionaries is a bit excessively large.

Truthfully I doubt UUID is necessary at all (I believe it would be the responsibility of an app using this library to disambiguate identical characters). So that may be something I remove in a future version when I get around to reducing the dictionary size.

You technically don't have to store class features -- if you delete them by setting class_features to None then they should be regenerated when the Character is deserialized. However this might be a minor savings, since the class_features are also stored inside class_levels.

The logic behind saving everything is that D&D is not a rules-bound game, so it's possible that you might want to tweak something about your character that would get deleted if we assume that every character perfectly follows the SRD. Feedback about how people are actually the library would be helpful in regards to design decisions like that :)

gergo-szabo commented 1 year ago

UUID is a useful feature in my case. And the serialization of it works well. I just messed it up.

I am building an LLM based storytelling app. I use a database to store the game state. A record must be below 400 kb. So over ~15 character it gets problematic to store the whole state in one record. I am leveraging the fact that the LLM already kinda knows the general gist of the game (class features, etc.). The LLM will homebrew it anyway so there is no need to store these in my case. So I made a wrapper around your Character class which handles my custom lightweight save/load.

At the moment the Character class is mainly used as a data storage. Charater generation mechanisms are used but others are not. I might start to other mechanisms later. Short and long rest mechanisms would be nice to have.