Custom Classes by Item Type?

Hello Everyone, I’m trying to set up custom document classes for items based on their type. For example, a Weapon class if type === "weapon", Armor class if type === "armor", etc. I know it’s pretty straightforward to assign different sheets using Items.registerSheet(..., { types: [...] }), but I wanted to know if the document itself could be a custom class, not just the sheet. Any guidance is appreciated.
4 Replies
Ethaks
Ethaks2w ago
To keep in line with modern Foundry: don't use polymorphic document classes, use type-specific TypeDataModels in the documents' system instead. For reference, there's a general DataModel page in the wiki, which amongst other things also links to Foundry's KB entry on System Data Models.
Foundry VTT Community Wiki
Data Model
The abstract base class which defines the data schema contained within a Document.
Foundry Virtual Tabletop | Foundry Virtual Tabletop
The official website and community for Foundry Virtual Tabletop.
Dark
DarkOP2w ago
Alright, thank you for your response!
Ethaks
Ethaks2w ago
Nowadays you can attach most any functionality to the type models, with only a few things requiring handling in the document class. And even then, delegating to the type data model is still an option if that fits your purposes better.
Dark
DarkOP2w ago
Interesting, I appreciate you telling me. I was looking for hours for a solution

Did you find this page helpful?