Closed paddywaan closed 3 years ago
My proposal would be to get rid of the CustomRecipe and add the recipe generation into the CustomItem.
Item with a config class: new CustomItem(prefab, new ItemConfig())
Item with mocked Recipe: new CustomItem(prefab, RecipeInstance)
Piece with config class new CustomPiece(prefab, new PieceConfig())
PieceRequirements can be just Requirements
During documentation, there was an inconsistency which has jumped out at me, and we must resolve before we release to the public as this will be a "now or never" change which will affect all documentation, examples, and dependant plugins going forward.
I will preface this issue by detailing the vanilla game's implementation for two similar object interfaces.
First, we have two individual component systems within valheim, that live in the ObjectDB. We have the
m_recipes
collection, and them_items
collection.Recipe
is comprised of two notable attributes:public ItemDrop m_item;
, andpublic Piece.Requirement[] m_resources = new Piece.Requirement[0];
. Meanwhile, them_items
collection is of generic GameObjects, which may have anItemDrop
component, the same ItemDrop which can be referenced from a recipe.Secondly, we have Pieces, that short of their piecetables do not have a objectDB style collection. Pieces, have a subclass named
Requirement
, which is a basic structure that defines anpublic ItemDrop m_resItem;
and a quantity as an ingredient.At this point, its clear to see some similarities in these implementations. Now lets look forward at how we interface with these libraries within our JVL abstractions:
Item
In the above, we create a
CustomItem
, and aCustomRecipe
which can take aRecipeConfig
as a parameter, that also requires aPieceRequirementConfig
property to define its ingredient list.Piece
Inconsistency
In the above, we create a
CustomPiece
, which takesPieceConfig
as a parameter, that also requires aPieceRequirementConfig
property to define its ingredient list.If we compare this to the item example:
In the above, we create a
CustomItem
, and aCustomRecipe
which can take aRecipeConfig
as a parameter, that also requires aPieceRequirementConfig
property to define its ingredient list.The problem:
The problem here is inconsistency. We are obfuscating native implementations via our abstractions using inconsistent naming schemas to accomplish the same operations, not to mention potentially having some redundant nesting of tightly coupled objects/types when we could just abstract them away with parameters, but that's a problem for another time.
We can see that if we were to apply consistent naming schema, then the
CustomItem
should have anItemConfig
, not aCustomRecipe
as a component parameter.Furthermore,
PieceRequirementConfig
is a misnaming within the vanilla libraries, and just further adds to the confusing as now items have piece requirements, which makes 0 sense at all either.We are better than this, there is no need to make this mistake and we can correct it before we release. I suggest that we do as such.