data.data
Methods57
function Data.is_valid(type: nil | string) -> valid boolean
Returns whether this wrapper contains a valid prototype.
typenil | stringPrototype type to require
validboolean
function Data.is_class(class: nil | string) -> matches boolean
Returns whether this wrapper is an instance of the requested class.
classnil | stringClass name to require
matchesboolean
function Data.print(...: string) -> self
Prints selected fields from this wrapper.
...stringField names
- self
function Data.log(tbl: any) -> self
Logs this wrapper or a supplied value using the inspect formatter.
tblanyValue to log; defaults to this wrapper
- self
function Data.serpent() -> self
Logs this wrapper using Serpent.
function Data.error(msg: nil | string) -> unknown
Raises an error.
msgnil | stringError message
- unknown
function Data.serpent_error() -> unknown
Raises an error containing a Serpent dump of the wrapped prototype.
function Data.continue(bool: boolean) -> self
Changes the validity of this wrapper.
boolbooleanWhether the wrapper should remain valid
- self
function Data.continue_if(func: fun(self: self, ...: any) -> any, ...: any) -> self
Retains validity only when the supplied predicate returns a truthy value.
funcfun(self: self, ...: any) -> anyPredicate that receives this wrapper and any additional arguments
...anyAdditional predicate arguments
- self
function Data.extend(force: nil | boolean) -> self
Adds the wrapped prototype to data.raw.
forcenil | booleanExtend even if the prototype is already extended
- self
function Data.copy(new_name: string, result: nil | string, opts: {string, boolean} | nil) -> self
Copies a data object (recipe, item, entity, etc) under a new name.
new_namestringThe new name for the data object.
resultnil | stringReplacement name for result-related fields; defaults to
new_nameopts{string, boolean} | nilOptions for the copied wrapper
- self
function Data.krycopy(new_name: string, result: nil | string, opts: {string, boolean} | nil) -> self
new_namestringThe new name for the data object.
resultnil | stringReplacement name for result-related fields; defaults to
new_nameopts{string, boolean} | nilOptions for the copied wrapper
- self
function Data.replace_name(new_name: string, result: nil | string, opts: {string, boolean} | nil) -> self
Renames a data object (recipe, item, entity, etc) by copying and removing the original.
new_namestringThe new name for the data object.
resultnil | stringName for fields such as
minable.resultorplace_resultopts{string, boolean} | nilOptions for the copied wrapper
- self
function Data.change_type(new_type: string, opts: {string, boolean} | nil) -> new_data self
Changes the type of a data object by copying it and removing the original.
The original prototype is removed from data.raw after the copy is created.
new_typestringThe new prototype type
opts{string, boolean} | nilOptions for the copied wrapper; defaults to
self.options
new_dataselfThe newly wrapped prototype
function Data.Flags(create: nil | boolean) -> flags StdLib.UniqueArray
(( Flags ))-- Returns this prototype's flags as a unique array.
createnil | booleanAssign the unique-array wrapper back to
self.flags
flagsStdLib.UniqueArray
function Data.add_flag(flag: string) -> self
Adds a prototype flag.
flagstringFlag to add
- self
function Data.remove_flag(flag: string) -> self
Removes a prototype flag.
flagstringFlag to remove
- self
function Data.has_flag(flag: string | string[]) -> present boolean
Returns whether all requested flags are present.
flagstring | string[]Flag or flags to check
presentboolean
function Data.any_flag(flag: string | string[]) -> present boolean
Returns whether any requested flag is present.
flagstring | string[]Flag or flags to check
presentboolean
function Data.run_function(func: fun(self: self, ...: any) -> any, ...: any) -> self
Runs a function if this wrapper is valid. This wrapper and any additional parameters are passed to the function.
funcfun(self: self, ...: any) -> anyFunction to run
...anyAdditional function arguments
- self
function Data.execute(func: fun(self: self, ...: any) -> any, ...: any) -> self
funcfun(self: self, ...: any) -> anyFunction to run
...anyAdditional function arguments
- self
function Data.get_function_results(func: fun(self: self, ...: any) -> any, ...: any) -> (valid boolean, results any)
Runs a function on a valid wrapper and returns its results.
funcfun(self: self, ...: any) -> anyFunction to run
...anyAdditional function arguments
validbooleanWhether the wrapper was valid
resultsanyValues returned by
func
function Data.set_unique_array(tab: nil | table) -> self
Applies the unique-array metatable to a table when this wrapper is valid.
tabnil | tabletable to update
- self
function Data.set_field(field: string, value: any) -> self
Adds or changes a field.
fieldstringField to change
valueanyValue to assign
- self
function Data.set(field: string, value: any) -> self
fieldstringField to change
valueanyValue to assign
- self
function Data.set_fields(tab: {string, any}) -> self
Sets fields from a dictionary, overwriting existing values.
tab{string, any}Fields to set
- self
function Data.get_field(field: string, default_value: any) -> value any
Gets a field from this wrapper.
fieldstringField to retrieve
default_valueanyValue returned when the field is
nil
valueany
function Data.get_fields(arr: string[], as_dictionary: nil | boolean) -> values any
Gets multiple fields as separate return values or as a dictionary.
arrstring[]Field names
as_dictionarynil | booleanReturn a dictionary instead of separate values
valuesanyField values, or a dictionary when
as_dictionaryis true
@usage local icon, name = Data('stone-furnace', 'furnace'):get_fields({'icon', 'name'})
function Data.remove_field(field: string) -> self
Removes an individual field from this wrapper.
fieldstringField to remove
- self
function Data.remove_fields(arr: string[]) -> self
Removes an array of fields from this wrapper.
arrstring[]Fields to remove
- self
function Data.copy_fields(copy_name: string, fields: string[] | {string, any}) -> self
Copies fields from another prototype of the same type. A dictionary can provide replacement values instead of copying those fields.
copy_namestringName of the prototype to copy from
fieldsstring[] | {string, any}Fields to copy or replacement values
- self
function Data.copy_all_fields(copy_name: string, exceptions: string[] | nil) -> self
Copies all existing fields from another prototype of the same type. The name and type fields are always excluded. An optional array can specify additional fields not to copy.
copy_namestringName of the prototype to copy from
exceptionsstring[] | nilFields not to copy
- self
function Data.subgroup_order(subgroup: nil | string, order: nil | string) -> self
Changes the item subgroup and/or order. If subgroup is invalid, order is not changed.
subgroupnil | stringSubgroup to assign when valid
ordernil | stringOrder string to assign
- self
function Data.set_subgroup(subgroup: string) -> self
Changes the item subgroup without affecting order.
subgroupstringValid item-subgroup name
- self
function Data.set_order(order: string) -> self
Changes the order string without affecting the subgroup.
orderstringOrder string to assign
- self
function Data.append_order(order_suffix: string) -> self
Appends a string to the current order string. Does nothing if self.order does not exist.
order_suffixstringString to append to
self.order
- self
function Data.replace_icon(icon: string | IconData[], size: nil | integer) -> self
Replaces the prototype icon or layered icons. Removes icons when a single icon path is supplied.
iconstring | IconData[]Icon path or layered icon definitions
sizenil | integerIcon size in pixels
- self
function Data.get_icons(copy: nil | boolean) -> icons IconData[] | nil
Gets the layered icon definitions.
copynil | booleanReturn a deep copy
iconsIconData[] | nil
function Data.get_icon() -> icon nil | string
Gets the single icon path.
function Data.make_icons(...: IconData) -> self
Converts a single icon to layered icons and appends additional layers.
...IconDataIcon layers to append
- self
function Data.set_icon_at(index: integer, values: {string, any}) -> self
Updates fields on a layered icon at the given index.
indexintegerLayer index
values{string, any}Fields to update
- self
function Data.get_localised_name() -> LocalisedString | nil
Gets the effective localised name of this prototype. Resolves prototype-specific inherited names, such as an item's placed entity or a recipe's main product, before falling back to its locale key.
function Data.get_localized_name() -> LocalisedString | nil
function Data.get_localised_description() -> LocalisedString | nil
Gets the effective localised description of this prototype. Explicit localised descriptions take priority. Otherwise returns the standard locale description with an empty fallback when none exists.
function Data.get_localized_description() -> LocalisedString | nil
function Data.append_localised_name(value: LocalisedString, separator: LocalisedString | nil) -> self
Appends a LocalisedString to this prototype's effective localised name.
valueLocalisedStringValue to append
separatorLocalisedString | nilSeparator between the existing and appended names
- self
function Data.append_localized_name(value: LocalisedString, separator: LocalisedString | nil) -> self
valueLocalisedStringValue to append
separatorLocalisedString | nilSeparator between the existing and appended names
- self
function Data.prepend_localised_name(value: LocalisedString, separator: LocalisedString | nil) -> self
Prepends a LocalisedString to this prototype's effective localised name.
valueLocalisedStringValue to prepend
separatorLocalisedString | nilSeparator between the prepended and existing names
- self
function Data.prepend_localized_name(value: LocalisedString, separator: LocalisedString | nil) -> self
valueLocalisedStringValue to prepend
separatorLocalisedString | nilSeparator between the prepended and existing names
- self
function Data.append_localised_description(value: LocalisedString, separator: LocalisedString | nil) -> self
Appends a LocalisedString to this prototype's effective localised description.
valueLocalisedStringValue to append
separatorLocalisedString | nilSeparator between the existing and appended descriptions
- self
function Data.append_localized_description(value: LocalisedString, separator: LocalisedString | nil) -> self
valueLocalisedStringValue to append
separatorLocalisedString | nilSeparator between the existing and appended descriptions
- self
function Data.prepend_localised_description(value: LocalisedString, separator: LocalisedString | nil) -> self
Prepends a LocalisedString to this prototype's effective localised description.
valueLocalisedStringValue to prepend
separatorLocalisedString | nilSeparator between the prepended and existing descriptions
- self
function Data.prepend_localized_description(value: LocalisedString, separator: LocalisedString | nil) -> self
valueLocalisedStringValue to prepend
separatorLocalisedString | nilSeparator between the prepended and existing descriptions
- self
function Data.tostring() -> identifier string
Gets a printable type/name identifier for this wrapper.
function Data.pairs(source: nil | table | string, opts: {string, boolean} | nil) -> (iterator fun() -> ...any, initial_key nil, initial_value nil)
Iterates wrapped prototypes from a data.raw type or prototype dictionary.
sourcenil | table | stringPrototype type or dictionary; defaults to this wrapper's type
opts{string, boolean} | nilOptions for yielded wrappers
iteratorfun() -> ...anyinitial_keynilinitial_valuenil
function Data.get(object: table | string, object_type: nil | string, opts: {string, boolean} | nil) -> wrapped self
Wraps a prototype table or looks up and wraps a prototype by name.
objecttable | stringPrototype name or prototype table
object_typenil | stringdata.rawtype; required for names except item wrappersopts{string, boolean} | nilWrapper options
wrappedself
function Data.__call(object: table | string, object_type: nil | string, opts: {string, boolean} | nil) -> wrapped self
objecttable | stringPrototype name or prototype table
object_typenil | stringdata.rawtype; required for names except item wrappersopts{string, boolean} | nilWrapper options
wrappedself
Fields27
Data.name : nil | string
Data.type : nil | string
Data._raw : nil | table
Data._products : nil | table
Data._parent : StdLib.Data | nil
Data._requested_object : nil | table | string
Data._requested_type : nil | string
Data.valid : string | false
Data.extended : boolean
Data.overwrite : boolean
Data.class : table
Data.options : {string, boolean}
Data.__class: string = "Data"
Data.__index : unknown
Data.Sprites : unknown
Data.Pipes : unknown
Data.Util : unknown
Data._default_options: table
Data.flags : unknown
Data.subgroup : string
Data.order : string
Data.icons : IconData[]
Data.icon : nil
Data.icon_size : any
Data.localised_name : LocalisedString
Data.localised_description : LocalisedString
Data._object_mt: table
This is the table set on new objects