Modding:Variants: Difference between revisions

From Vintage Story Wiki
m
Line 80: Line 80:


=== ByType Properties ===
=== ByType Properties ===
Another way to add differences to variants is by adding '''byType''<nowiki/>' onto the end of ''any'' property in a file that has defined variants.
When using a '''key''' with byType, the '''value''' becomes a new dictionary, with the keys being asset locations and the values being whatever the original property was.
For example, the following code would set all hammers to have the same durability:<syntaxhighlight lang="json">
durability: 60,
</syntaxhighlight>However, hammers different durabilities based on their variant type. The following code sets different durabilities for each hammer type:<syntaxhighlight lang="json">
durabilitybytype: {
"hammer-stone": 60,
"hammer-gold": 250,
"hammer-silver": 250,
"hammer-copper": 500,
"hammer-tinbronze": 750,
"hammer-bismuthbronze": 900,
"hammer-blackbronze": 1100,
"hammer-iron": 1800,
"hammer-meteoriciron": 2100,
"hammer-steel": 4500
},
</syntaxhighlight>Our durability property has now become durability''bytype'', and accepts a dictionary of all the hammers to each have their own durability.
By using a combination of ByType Properties, wildcards, and Variant Substitutions, objects can be created much more efficiently. The following code is an excerpt from the ''blade.json'' tool.<syntaxhighlight lang="json">
shapeByType: {
"blade-falx-*": { base: "item/tool/blade/falx/{metal}" },
"blade-longsword-admin": { base: "item/tool/blade/admin" },
"blade-*-ruined": { base: "item/tool/blade/ruined/{type}" },
"*": { base: "item/tool/blade/{type}" }
},
</syntaxhighlight>There's a few important things to note here:
* All JSON properties are case-insensitive in content mods, including the ByType suffix.
* The ByType keys can use wildcards to group variants together by their type.
* The values in ByType can still use variant substitutions.
* A wildcard of "'''*'''" will simply satisfy ''every'' object.
* ByType keys are analysed from top to bottom - If an object's code satisfies more than one key in byType, it will always use the topmost entry.


== Detailed Understanding ==
== Detailed Understanding ==
Confirmedusers
566

edits