Module:Item/doc: Difference between revisions

From Space Station 14 Wiki
(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.


Each item has a list of names. These are used for various lookups.
Currently, there's no process for adding new items or keeping existing ones up to date automatically or, so it's all manual work.
An item can have as many names as you wish, but it must have at least two.
* The first name listed must the one used in-game. It will be used as a «main» name in various lookups.
* The rest are aliases and can be anything. But be aware that duplicate names '''will''' screw up the lookups.  


{{Callout|Example
=== Adding new item to the list of items ===
|h=Example - adding items with the same main name
First, get the item ID. It can be found in the `Resources` directory.
|For coils, the game has 3 item IDs: {{c|CableHVStack}} (hv), {{c|CableMVStack}} (mv), {{c|CableApcStack}} (lv).
Second, get the item display name. It can be found in locale files in the same `Resources` directory.


These three allow to configure a single icon for each coil variation, but the game has more variations per type of coil depending on how many coils are left in stack. For instance, for less than 20 HV coils the icon will change to {{item|hv10|l=}}, and when there are less than 10 - to {{item|hv1|l=}}.
After you got both, add a new entry to the end of the file.


To support more icons per item, we can just add more "fake" item IDs, give them any name we want and then define icons for them. For the "10" variation of HV we can add:
{{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">
"CableHV10": [
"SoapOmega": [
"HV cable coil",
"omega soap"
"HV10"
]
],
</syntaxhighlight>
</syntaxhighlight>


{{c|HV cable coil}} would be the «main» name, and the rest below are aliases.
More names can be added - these will be aliases - you can add as many as you want, e.g. {{c|osoap}}.  
}}
}}


== Adding images for items ==
=== 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.


{{callout|Warning|For items to show up, they must also be added as items.}}
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.


The value of an item is its icon filename.
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
|To add an icon for a newly added {{c|CableHV10}} item from the previous example, we would have to add a new line to the JSON file. For instance, if the icon filename is {{c|Coilhv-10.png}}, the line would be:
|For Brass, the schema will look like this:
<syntaxhighlight lang="json>
<syntaxhighlight lang="json>
    "CableHV10": "Coilhv-10.png"
{
"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.
}}
}}
To see if icons do work, look at newly-added items in the list of items in {{t|item}}.

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.

Example
For instance, if you want to add omega soap with ID SoapOmega, the entry will look like this:
	"SoapOmega": [
		"omega soap"
	]
More names can be added - these will be aliases - you can add as many as you want, e.g. 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.

Example
First, upload a texture 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."
				}
			},
            ...
		]
	}
Example
For Brass, the schema will look like this:
	{
		"match": [
			"SheetBrass",
			"SheetBrass10",
			"SheetBrass1"
		],
		"fallbackItemId": "SheetBrass",
		"resolvers": [
			{
				"itemId": "SheetBrass",
				"conditions": {
					"min": 20
				}
			},
			{
				"itemId": "SheetBrass10",
				"conditions": {
					"min": 10
				}
			},
			{
				"itemId": "SheetBrass1"
			}
		]
	}
  1. We add all Brass item IDs to match, so that the whole entry doesn't get skipped.
  2. We pick a fallback item ID in fallbackItemId to use when no amount is specified in the template, or when no condition is satisfied.
  3. 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 have conditions, it automatically "wins". If it DOES have it, then the listed conditions are checked.
  4. 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).
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.