feat: add generic singleton Instance pattern for CustomItem and CustomRole#775
feat: add generic singleton Instance pattern for CustomItem and CustomRole#775MS-crew wants to merge 3 commits intoExMod-Team:devfrom
Conversation
|
I love this change it may introduce few issues with reflection, but it's just addition between the item being done and the item above. It makes easier getting custom items and in between not removing the functionality to get by Id. |
Someone-193
left a comment
There was a problem hiding this comment.
Please add the generic constraint ", new()" onto all the other ones. It means that all the inheritors of the class have to have a parameterless constructor, which is necessary for CI / CR
done @Someone-193 |
Someone-193
left a comment
There was a problem hiding this comment.
Looks good to go I guess. If you want another suggestion, maybe make Instance not nullable, but if you call the getter while it's null, the item auto-registers. Idk though
9c57b2f to
84c5d50
Compare
84c5d50 to
9c57b2f
Compare
9c57b2f to
ced753a
Compare
Description
Describe the changes
Adds CustomItem, CustomRole and typed wrappers for all subclasses (CustomWeapon, CustomKeycard, CustomArmor, CustomGrenade, CustomGoggles). Instead of fetching instances via Get(id) or Get(name) which are fragile since ids and names can change at any time with configs, other plugins can now reference a custom item or role directly via example MyCustomGoggles.Instance or MyCustomRole.Instance, getting full strongly typed access to all properties and methods without any casting. This makes cross plugin integrations simpler, less error prone, and more accessible to developers who aren't deeply familiar with the codebase.
What is the current behavior? (You can also link to an open issue here)
What is the new behavior? (if this is a feature change)
Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
No
Other information:

Example usage
on another plugin via referance or another class
Types of changes
Submission checklist
Patches (if there are any changes related to Harmony patches)
Other