metadata_util¶
Source: base/tealdef/scripts/metadata_util.d.tl
Notes
Types of /scripts/metadata_util.tl (MetadataUtil): typed accessors for the free-form metadata
tables of construction descriptions, construction instances, subconstruction instances and savegame
scripts. Each feature registers its own key and reads/writes only that key.
Example
-- register an accessor (base/content/game_mechanics/game_mechanics/emission/emission_config_metadata.tl)
constructionDesc = metadata_util.constructionDesc.register("emissionConfig") as MetadataAccessor<ConstructionDescMetadata, EmissionConfigMeta>,
-- build a metadata table from several accessors (base/content/gui/gui/construction/construction_react_util.tl)
metadata = metadata_util.constructionDesc.make({company_metadata.constructionDesc.make(companyMeta)}),
Globals¶
Types
| Name | Definition | Description |
|---|---|---|
ConstructionDescMetadata |
declared here, defined in ConstructionDescMetadata |
Opaque type of the metadata table of a construction description. |
ConstructionInstanceMetadata |
declared here, defined in ConstructionInstanceMetadata |
Opaque type of the metadata stored with a built construction. |
SubconstructionInstanceMetadata |
declared here, defined in SubconstructionInstanceMetadata |
Opaque type of the metadata stored with a subconstruction instance. |
SavegameScriptMetadata |
declared here, defined in SavegameScriptMetadata |
Opaque type of the metadata a game script stores in the savegame (returned from the storeSavegameMetadata event). |
MetadataAccessor¶
record global base/tealdef/scripts/metadata_util.d.tl:3
global record MetadataAccessor<C, T>
Notes
Typed access to one key of a metadata table, obtained from MetadataTypeUtil.register(key).
C is the kind of metadata table, T the type stored under the key.
Functions
set(container : C, value : T) base/tealdef/scripts/metadata_util.d.tl:4
Notes
Stores value under this accessor's key in the metadata table container.
get(container : C) : T base/tealdef/scripts/metadata_util.d.tl:5
Notes
Reads this accessor's key from the metadata table container.
Returns T: The stored value, or nil if container is nil or has no value under the key.
make(value : T) : function(C) base/tealdef/scripts/metadata_util.d.tl:8
creates a function that will insert into the container
Returns function(C)
MetadataUtil¶
record global base/tealdef/scripts/metadata_util.d.tl:16
global record MetadataUtil
Load: local metadata_util = ug_require "/scripts/metadata_util.tl"
Notes
Accessor factories for the four kinds of metadata tables; returned by ug_require "/scripts/metadata_util.tl".
Fields
| Name | Type | Description |
|---|---|---|
constructionDesc |
MetadataTypeUtil<ConstructionDescMetadata> |
Accessor factory for construction description metadata. used 19× in the base game |
constructionInstance |
MetadataTypeUtil<ConstructionInstanceMetadata> |
Accessor factory for construction instance metadata. used 3× in the base game |
subconstructionInstance |
MetadataTypeUtil<SubconstructionInstanceMetadata> |
Accessor factory for subconstruction instance metadata. used 2× in the base game |
savegameScript |
MetadataTypeUtil<SavegameScriptMetadata> |
Accessor factory for savegame script metadata. used 2× in the base game |
MetadataUtil.MetadataTypeUtil¶
record base/tealdef/scripts/metadata_util.d.tl:17
record MetadataTypeUtil<C>
Notes
Accessor factory for one kind of metadata table C.
Used in the base game: 5 times in 1 file
base/content/scripts/scripts/metadata_util.tl:35
Functions
register<T>(key : string) : MetadataAccessor<C, T> base/tealdef/scripts/metadata_util.d.tl:18
Notes
Creates an accessor that reads and writes the given key of metadata tables of this kind.
| Parameter | Type | Description |
|---|---|---|
key |
string |
The key under which the feature stores its data, for example "emissionConfig". |
Returns MetadataAccessor<C, T>: An accessor with get, set and make.
make(uses : {function(C)}) : C base/tealdef/scripts/metadata_util.d.tl:19
Notes
Builds a new metadata table by calling each function (usually from accessor.make(value)) on it.
| Parameter | Type | Description |
|---|---|---|
uses |
{function(C)} |
Functions that each insert one value into the table. |
Returns C: The filled metadata table.