Modding:Variants: Difference between revisions

From Vintage Story Wiki
mNo edit summary
Line 54: Line 54:


=== Wildcards ===
=== Wildcards ===
Wildcards are very important when using variants, and they can be used to reference collections of objects easily.  
When referencing asset locations from a json file, wildcards can be used to reference any number of assets. By using the wildcard character ('''*''') inside an asset location, any matching code with satisfy the wildcard. The use and purpose of a wildcard depends on where it is being used.  


Technically, wildcards use a "''matching''" system, rather than creating a collection of objects.
Some examples of wildcards are:


Some examples of wildcards are:
* '''hammer-*''' - Any hammer will satisfy this condition.
* '''seashell-scallop-*''' - Any seashell with the type ''scallop''.
* '''seashell-*-latte''' - Any seashell with the color ''latte''.
* '''*-copper''' - Any item, block, or entity who's last variant state is ''copper''.
Wildcards are very versatile and are used commonly throughout json files. Wildcards can be used in, but not including:


* '''hammer-*''' - This will  
* SkipVariants and AllowedVariants when creating an object.
* ByType variant groups. Any matching code will use the byType property.
* Recipe ingredients. Any matching code will work as a valid ingredient for the recipe.


=== {Variant Groups} ===
=== {Variant Groups} ===
Line 89: Line 95:
Any property in a json file can be defined as '<nowiki/>''byType''', except from the ''code'' and variant properties. The ByType properties are analysed based on the provided wildcards, and properties that do not match the variant are removed.
Any property in a json file can be defined as '<nowiki/>''byType''', except from the ''code'' and variant properties. The ByType properties are analysed based on the provided wildcards, and properties that do not match the variant are removed.


After the '<nowiki/>''byType''' is analysed, any variant groups referenced in curly braces ('''{ }''') are substituted with their appropriate variant state.
After the ''byType'' is analysed, any variant groups referenced in curly braces ('''{ }''') are substituted with their appropriate variant state.


When all the variants, byTypes, and variant groups are resolved, the cloned json properties are loaded as a unique object.
When all the variants, byTypes, and variant groups are resolved, the cloned json properties are loaded as a unique object.