Skip to content

Refactor monsters to have a well-defined structure #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2025

Conversation

ben-githubs
Copy link
Owner

Summary

Previously we've been importing the monsters from JSON files using json and writing our app logic to accommodate the inconsistencies on the JSON data, but this is becoming unmanageable. I've introduced a Monster class with a well-defined structure and some tooling to convert the JSON files to this. The conversion script is ugly as all hell and it gives me serious ark of the covenant vibes, but it means all that spaghetti is contained to one file and the rest of our code can be simpler and easier to read/maintain.

I've also moved the backed code which manages monsters to the dmtoolkit.api sub-package to make it more consistent with the overarching organization of the app.

Changes

  • created a migration script to download JSON files containing D&D monster data and convert it to a normalized structure
  • created several dataclass "models"
  • created serialization methods for the models
  • migrated monster-management functions to the api package
  • updated the statblock display template to work with the new Monster model

Testing

At some point I'll have to make actual unit tests for these, but for now, I did some manual testing.

  • all the serialized Monster objects can be loaded
  • spot checking statblock rendering with Archmage-MM and Veteran-MM statblocks

@ben-githubs ben-githubs merged commit 4424f15 into main Apr 6, 2025
@ben-githubs ben-githubs deleted the ben/ref/consistant-monsters branch April 6, 2025 23:11
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.

None yet

1 participant