Valheim-Modding / Jotunn

Jötunn, the Valheim Library.
https://valheim-modding.github.io/Jotunn/
MIT License
126 stars 40 forks source link

Added feature to help resolve mocks based off same type search. #417

Closed OrianaVenture closed 10 months ago

OrianaVenture commented 10 months ago

Since there are many unnamed Mesh objects used the current mocking system can not replace them. This is the required changes to get a functioning mesh mocking system, but should work for other types too.

Examples of usage:

  1. Create a mocked mesh called JVLmock_Pickable_Thistle__default, this will find the first Mesh on the Pickable_Thistle prefab under the child "default" for a replacement.
  2. Create a mocked mesh named JVLmock_TrollCave02__dirtfloor (11), this will find the first Mesh on the TrollCave02 prefab under the child "dirtfloor (11)" for a replacement.
MSchmoecker commented 10 months ago

Thanks, it looks really good. Especially using the ClassMember to find fields on the child, which makes it much more generic. Using __ as a separator instead of a single underscore is also a good idea to keep the names intact and feels natural to use.

While testing with the VikingShip, a child name can be ambiguous, e.g. mast is used for both the mesh and the interactive child. The interactive child is nested shallower and therefore found first. Intermediate children could be a solution, so maybe JVLmock_VikingShip__ship__mast to match the ship child first and then the mast child.

With more complex matching, the warnings should also be more specific. For example, if a child wasn't found should print a different warning than if the type on the child wasn't found. If you don't want to worry about this, I can also do this later.

There are a few minor comments I will make on the code but this won't be a blocker.

OrianaVenture commented 10 months ago

Current minor suggestions have been implemented. I will look into making the pathing more dynamic to accept more nesting for cases like: JVLmock_VikingShipshipmast and work on better error logging for that case.

OrianaVenture commented 10 months ago

Testing this on my current mocked locations the startup time is significantly slower than my stand alone solution which had caching. Next improvement will be to add in the ability to cache all instances with the longer path finding names after finding them once.