Module:Item/doc: Difference between revisions
(added resolvers link to used json files) |
(rewrite to fit the new reality) |
||
Line 8: | Line 8: | ||
To add more items, go to [[Module:Item/item names by item id.json]]. | To add more items, go to [[Module:Item/item names by item id.json]]. | ||
It is a JSON file containing an object with keys being the item in-game IDs, but also allows custom IDs for displaying items such as coil variations. | It is a JSON file containing an object with keys being the item in-game IDs, but also allows custom IDs for displaying items such as coil variations. | ||
Values are the names for these items - the first being the "display name" used in-game, and the rest are aliases. | |||
Currently, there's no process for adding new items or keeping existing ones up to date automatically or, so it's all manual work. | |||
=== Adding new item to the list of items === | |||
First, get the item ID. It can be found in the `Resources` directory. | |||
Second, get the item display name. It can be found in locale files in the same `Resources` directory. | |||
After you got both, add a new entry to the end of the file. | |||
{{Callout|Example | |||
|For instance, if you want to add {{c|omega soap}} with ID {{c|SoapOmega}}, the entry will look like this: | |||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
" | "SoapOmega": [ | ||
" | "omega soap" | ||
] | |||
] | |||
</syntaxhighlight> | </syntaxhighlight> | ||
{{c| | More names can be added - these will be aliases - you can add as many as you want, e.g. {{c|osoap}}. | ||
}} | }} | ||
== | === Linking a texture to the item === | ||
To add images for items, go to [[Module:Item/item image files by item id.json]]. | To add images for items, go to [[Module:Item/item image files by item id.json]]. | ||
It is a JSON file containing an object with keys being the item in-game IDs, but also allows custom IDs for displaying items such as coil variations. | It is a JSON file containing an object with keys being the item in-game IDs, but also allows custom IDs for displaying items such as coil variations. | ||
{{ | Values are the texture file names, uploaded to the wiki. | ||
{{Callout|Example | |||
|First, upload a texture to the wiki. | |||
Following the previous example for {{c|omega soap}}, let's say that the texture uploaded is called {{kbd|OmegaSoapIcon.png}}. Now, add a new entry: | |||
<syntaxhighlight lang="json"> | |||
"SoapOmega": "OmegaSoapIcon.png" | |||
</syntaxhighlight> | |||
}} | |||
=== Adding multiple textures for an item === | |||
Let's say, we want to upload textures for a new shiny material called Brass. In-game, the material has the ID {{c|SheetBrass}}. But since we can only make a single item → texture connection, there's no way to add multiple textures for one element. | |||
For such cases, the solution is to add more items to the list of items and link extra textures to them. These "fake" items can have any IDs you want. | |||
After that is done, now it's time to make a link between item amount and its texture. This is done in https://wiki.spacestation14.com/wiki/Module:Item/item_lookup_conflicts_resolvers.json | |||
Each entry in that file has the following schema: | |||
<syntaxhighlight lang="json> | |||
{ | |||
"match": "An array of item IDs that match with this entry. If an item ID doesn't appear here, this entry will be skipped.", | |||
"fallbackItemId": "Item ID used when no amount is specified or when no condition from below matches", | |||
"resolvers": [ | |||
{ | |||
"itemId": "Item ID used when if the condition below satisfies.", | |||
"conditions": { | |||
"min": "At least what amount should be specified for this condition to be satisfied." | |||
} | |||
}, | |||
... | |||
] | |||
} | |||
</syntaxhighlight> | |||
{{Callout|Example | {{Callout|Example | ||
| | |For Brass, the schema will look like this: | ||
<syntaxhighlight lang="json> | <syntaxhighlight lang="json> | ||
{ | |||
"match": [ | |||
"SheetBrass", | |||
"SheetBrass10", | |||
"SheetBrass1" | |||
], | |||
"fallbackItemId": "SheetBrass", | |||
"resolvers": [ | |||
{ | |||
"itemId": "SheetBrass", | |||
"conditions": { | |||
"min": 20 | |||
} | |||
}, | |||
{ | |||
"itemId": "SheetBrass10", | |||
"conditions": { | |||
"min": 10 | |||
} | |||
}, | |||
{ | |||
"itemId": "SheetBrass1" | |||
} | |||
] | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
# We add all Brass item IDs to {{c|match}}, so that the whole entry doesn't get skipped. | |||
# We pick a fallback item ID in {{c|fallbackItemId}} to use when no amount is specified in the template, or when no condition is satisfied. | |||
# We set up "resolvers" - when satisfied, the specified ID will be used as a result. Each resolver must have an {{c|itemId}}. If a resolver doesn't have {{c|conditions}}, it automatically "wins". If it DOES have it, then the listed conditions are checked. | |||
# For Brass, we set up 3 resolvers: | |||
* Use item with ID {{c|SheetBrass}} when there are at least 20 items in stack. | |||
* Use item with ID {{c|SheetBrass10}} when there are at least 10 items in stack. | |||
* Use item with ID {{c|SheetBrass1}} in other cases (i.e. when there are 9 or less items in stack). | |||
The specified resolvers will be checked in sequence, until a resolver with proper conditions is found. If that doensn't happen, the fallback item ID is used. | |||
}} | }} | ||
Revision as of 23:39, 17 August 2024
Module documentation
|
---|
View or edit this documentation • (about module documentation) |
Contains utilities for working with in-game items.
Adding items
To add more items, go to Module:Item/item names by item id.json.
It is a JSON file containing an object with keys being the item in-game IDs, but also allows custom IDs for displaying items such as coil variations.
Values are the names for these items - the first being the "display name" used in-game, and the rest are aliases.
Currently, there's no process for adding new items or keeping existing ones up to date automatically or, so it's all manual work.
Adding new item to the list of items
First, get the item ID. It can be found in the `Resources` directory. Second, get the item display name. It can be found in locale files in the same `Resources` directory.
After you got both, add a new entry to the end of the file.
omega soap
with ID SoapOmega
, the entry will look like this:
"SoapOmega": [
"omega soap"
]
osoap
.Linking a texture to the item
To add images for items, go to Module:Item/item image files by item id.json.
It is a JSON file containing an object with keys being the item in-game IDs, but also allows custom IDs for displaying items such as coil variations.
Values are the texture file names, uploaded to the wiki.
Following the previous example for omega soap
, let's say that the texture uploaded is called OmegaSoapIcon.png. Now, add a new entry:
"SoapOmega": "OmegaSoapIcon.png"
Adding multiple textures for an item
Let's say, we want to upload textures for a new shiny material called Brass. In-game, the material has the ID SheetBrass
. But since we can only make a single item → texture connection, there's no way to add multiple textures for one element.
For such cases, the solution is to add more items to the list of items and link extra textures to them. These "fake" items can have any IDs you want.
After that is done, now it's time to make a link between item amount and its texture. This is done in https://wiki.spacestation14.com/wiki/Module:Item/item_lookup_conflicts_resolvers.json
Each entry in that file has the following schema:
{
"match": "An array of item IDs that match with this entry. If an item ID doesn't appear here, this entry will be skipped.",
"fallbackItemId": "Item ID used when no amount is specified or when no condition from below matches",
"resolvers": [
{
"itemId": "Item ID used when if the condition below satisfies.",
"conditions": {
"min": "At least what amount should be specified for this condition to be satisfied."
}
},
...
]
}
{
"match": [
"SheetBrass",
"SheetBrass10",
"SheetBrass1"
],
"fallbackItemId": "SheetBrass",
"resolvers": [
{
"itemId": "SheetBrass",
"conditions": {
"min": 20
}
},
{
"itemId": "SheetBrass10",
"conditions": {
"min": 10
}
},
{
"itemId": "SheetBrass1"
}
]
}
- We add all Brass item IDs to
match
, so that the whole entry doesn't get skipped. - We pick a fallback item ID in
fallbackItemId
to use when no amount is specified in the template, or when no condition is satisfied. - We set up "resolvers" - when satisfied, the specified ID will be used as a result. Each resolver must have an
itemId
. If a resolver doesn't haveconditions
, it automatically "wins". If it DOES have it, then the listed conditions are checked. - For Brass, we set up 3 resolvers:
- Use item with ID
SheetBrass
when there are at least 20 items in stack. - Use item with ID
SheetBrass10
when there are at least 10 items in stack. - Use item with ID
SheetBrass1
in other cases (i.e. when there are 9 or less items in stack).