-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Generate category enums from category heirarchy #169
Conversation
Discussion point: What's interesting is the way I got around this without generating the enums was to create a new category for each equipment slot (as an example) and set it as the resource default on the parent category. Ie. EquipmentSlots: Hands That way it was a property lookup rather than caring what the category was. I'm not sure which is better, the enums use less disk space since you're not having to serialize a reference on every single item. My guess is that a true category enum system is more flexible and easier to maintain since the inheritance is defined by the category structure and not a bunch of hard coded fields. That said, one of the ways the embedded reference was nicer was you could merge multiple categories more easily, right now the way we generate enums I don't have every child of Equipment in a single enum (I wonder if I should add that) or have a boolean for "only direct children" or "all children" ie. Items.Equipment.Armor and Items.Equipment.Wield.Tools doesn't share a single type but my equipment system has slots you can equip items in for both sets and ideally the interface would be equip_item(item: Item, Slot: PandoraCategories.Equipment) |
I added in a recursive bool to the code that produces something like
The other option is to have two enums, one for the top level category and one like category_nested or category_all so you can reference either the single depth or multi-depth enum. Thoughts? |
Oh one other thing I noticed, since enums write out as ints the category lookup needs a cast from the value to string so there's likely something to be considered for consistency sake on how we want to manage that. |
Any thoughts on the direction you'd want to take this? Can convert into a discussion instead of using this PR |
@imothee sorry for the late reply - I have been rather busy this week. I will check out this PR and will provide my feedback after. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally a good approach. A few things need improvement:
- entities/categories may have different id types (number or string), depending on the ID generator. Hence, we cannot rely on enums but we probably have to generate constants/classes. For example, something like this:
# Do not modify! Auto-generated file.
class_name PandoraCategories
class Items:
const SWORDS = "2"
const SHIELDS = "3"
class Swords:
const GREAT_SWORDS = "4"
const SMALL_SWORDS = "5"
# root categories can be on the top level as const
const ITEMS = "1"
- Secondly, we may want to update the docs, too describing the new behaviour https://github.com/bitbrain/pandora/blob/godot-4.x/docs/mastery/id-constants.md
Updated generator. I had to append Categories to the classes because they usually conflicted with the generated entity file names. Naming conflicts is going to be tough regardless, I tried to handle non-unique category names. Pandora will also generate a PandoraCategories file that contains the Category IDs of all categories and subcategories in your tree. It will generate a file called # Do not modify! Auto-generated file.
class_name PandoraCategories
const ITEMS = "3"
const RARITY = "7"
const ENCHANTMENTS = "48"
const SKILLS = "66"
const ANIMATIONS = "70"
const CHARACTERS = "71"
const BODY_TYPES = "72"
const LOOT = "73"
const HAIR_TYPES = "120"
const RESOURCES = "135"
const RESOURCE_STATES = "142"
const GAMECONFIG = "177"
class ItemsCategories:
const EQUIPMENT = "4"
const CONSUMABLE = "37"
const RESOURCE = "38"
const LITERARY = "39"
const QUESTS = "40"
const MISC = "41"
class EquipmentCategories:
const WIELD = "35"
const ARMOR = "50"
const ACCESSORIES = "51"
This allows you to do something like this: if entity.is_category(ItemsCategories.EQUIPMENT):
# entity is under the Equipment category |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work.
Description
This attempts to create a PandoraCategories file that contains all the enum heirarchy written out.
Addressed issues
Attempts to close #63
Change
Outputs a pandora/categories.gd containing