Kryzeth Standard Library

data.data

Methods57

function Data.is_valid(type: nil | string) -> valid boolean

Returns whether this wrapper contains a valid prototype.

Parameters
typenil | string

Prototype type to require

Returns
validboolean
function Data.is_class(class: nil | string) -> matches boolean

Returns whether this wrapper is an instance of the requested class.

Parameters
classnil | string

Class name to require

Returns
matchesboolean
function Data.print(...: string) -> self

Prints selected fields from this wrapper.

Parameters
...string

Field names

Returns
self
function Data.log(tbl: any) -> self

Logs this wrapper or a supplied value using the inspect formatter.

Parameters
tblany

Value to log; defaults to this wrapper

Returns
self
function Data.serpent() -> self

Logs this wrapper using Serpent.

function Data.error(msg: nil | string) -> unknown

Raises an error.

Parameters
msgnil | string

Error message

Returns
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.

Parameters
boolboolean

Whether the wrapper should remain valid

Returns
self
function Data.continue_if(func: fun(self: self, ...: any) -> any, ...: any) -> self

Retains validity only when the supplied predicate returns a truthy value.

Parameters
funcfun(self: self, ...: any) -> any

Predicate that receives this wrapper and any additional arguments

...any

Additional predicate arguments

Returns
self
function Data.extend(force: nil | boolean) -> self

Adds the wrapped prototype to data.raw.

Parameters
forcenil | boolean

Extend even if the prototype is already extended

Returns
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.

Parameters
new_namestring

The new name for the data object.

resultnil | string

Replacement name for result-related fields; defaults to new_name

opts{string, boolean} | nil

Options for the copied wrapper

Returns
self
function Data.krycopy(new_name: string, result: nil | string, opts: {string, boolean} | nil) -> self
Parameters
new_namestring

The new name for the data object.

resultnil | string

Replacement name for result-related fields; defaults to new_name

opts{string, boolean} | nil

Options for the copied wrapper

Returns
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.

Parameters
new_namestring

The new name for the data object.

resultnil | string

Name for fields such as minable.result or place_result

opts{string, boolean} | nil

Options for the copied wrapper

Returns
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.

Parameters
new_typestring

The new prototype type

opts{string, boolean} | nil

Options for the copied wrapper; defaults to self.options

Returns
new_dataself

The newly wrapped prototype

function Data.Flags(create: nil | boolean) -> flags StdLib.UniqueArray

(( Flags ))-- Returns this prototype's flags as a unique array.

Parameters
createnil | boolean

Assign the unique-array wrapper back to self.flags

Returns
function Data.add_flag(flag: string) -> self

Adds a prototype flag.

Parameters
flagstring

Flag to add

Returns
self
function Data.remove_flag(flag: string) -> self

Removes a prototype flag.

Parameters
flagstring

Flag to remove

Returns
self
function Data.has_flag(flag: string | string[]) -> present boolean

Returns whether all requested flags are present.

Parameters
flagstring | string[]

Flag or flags to check

Returns
presentboolean
function Data.any_flag(flag: string | string[]) -> present boolean

Returns whether any requested flag is present.

Parameters
flagstring | string[]

Flag or flags to check

Returns
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.

Parameters
funcfun(self: self, ...: any) -> any

Function to run

...any

Additional function arguments

Returns
self
function Data.execute(func: fun(self: self, ...: any) -> any, ...: any) -> self
Parameters
funcfun(self: self, ...: any) -> any

Function to run

...any

Additional function arguments

Returns
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.

Parameters
funcfun(self: self, ...: any) -> any

Function to run

...any

Additional function arguments

Returns
validboolean

Whether the wrapper was valid

resultsany

Values 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.

Parameters
tabnil | table

table to update

Returns
self
function Data.set_field(field: string, value: any) -> self

Adds or changes a field.

Parameters
fieldstring

Field to change

valueany

Value to assign

Returns
self
function Data.set(field: string, value: any) -> self
Parameters
fieldstring

Field to change

valueany

Value to assign

Returns
self
function Data.set_fields(tab: {string, any}) -> self

Sets fields from a dictionary, overwriting existing values.

Parameters
tab{string, any}

Fields to set

Returns
self
function Data.get_field(field: string, default_value: any) -> value any

Gets a field from this wrapper.

Parameters
fieldstring

Field to retrieve

default_valueany

Value returned when the field is nil

Returns
valueany
function Data.get_fields(arr: string[], as_dictionary: nil | boolean) -> values any

Gets multiple fields as separate return values or as a dictionary.

Parameters
arrstring[]

Field names

as_dictionarynil | boolean

Return a dictionary instead of separate values

Returns
valuesany

Field values, or a dictionary when as_dictionary is 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.

Parameters
fieldstring

Field to remove

Returns
self
function Data.remove_fields(arr: string[]) -> self

Removes an array of fields from this wrapper.

Parameters
arrstring[]

Fields to remove

Returns
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.

Parameters
copy_namestring

Name of the prototype to copy from

fieldsstring[] | {string, any}

Fields to copy or replacement values

Returns
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.

Parameters
copy_namestring

Name of the prototype to copy from

exceptionsstring[] | nil

Fields not to copy

Returns
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.

Parameters
subgroupnil | string

Subgroup to assign when valid

ordernil | string

Order string to assign

Returns
self
function Data.set_subgroup(subgroup: string) -> self

Changes the item subgroup without affecting order.

Parameters
subgroupstring

Valid item-subgroup name

Returns
self
function Data.set_order(order: string) -> self

Changes the order string without affecting the subgroup.

Parameters
orderstring

Order string to assign

Returns
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.

Parameters
order_suffixstring

String to append to self.order

Returns
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.

Parameters
iconstring | IconData[]

Icon path or layered icon definitions

sizenil | integer

Icon size in pixels

Returns
self
function Data.get_icons(copy: nil | boolean) -> icons IconData[] | nil

Gets the layered icon definitions.

Parameters
copynil | boolean

Return a deep copy

Returns
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.

Parameters
...IconData

Icon layers to append

Returns
self
function Data.set_icon_at(index: integer, values: {string, any}) -> self

Updates fields on a layered icon at the given index.

Parameters
indexinteger

Layer index

values{string, any}

Fields to update

Returns
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.

Parameters
valueLocalisedString

Value to append

separatorLocalisedString | nil

Separator between the existing and appended names

Returns
self
function Data.append_localized_name(value: LocalisedString, separator: LocalisedString | nil) -> self
Parameters
valueLocalisedString

Value to append

separatorLocalisedString | nil

Separator between the existing and appended names

Returns
self
function Data.prepend_localised_name(value: LocalisedString, separator: LocalisedString | nil) -> self

Prepends a LocalisedString to this prototype's effective localised name.

Parameters
valueLocalisedString

Value to prepend

separatorLocalisedString | nil

Separator between the prepended and existing names

Returns
self
function Data.prepend_localized_name(value: LocalisedString, separator: LocalisedString | nil) -> self
Parameters
valueLocalisedString

Value to prepend

separatorLocalisedString | nil

Separator between the prepended and existing names

Returns
self
function Data.append_localised_description(value: LocalisedString, separator: LocalisedString | nil) -> self

Appends a LocalisedString to this prototype's effective localised description.

Parameters
valueLocalisedString

Value to append

separatorLocalisedString | nil

Separator between the existing and appended descriptions

Returns
self
function Data.append_localized_description(value: LocalisedString, separator: LocalisedString | nil) -> self
Parameters
valueLocalisedString

Value to append

separatorLocalisedString | nil

Separator between the existing and appended descriptions

Returns
self
function Data.prepend_localised_description(value: LocalisedString, separator: LocalisedString | nil) -> self

Prepends a LocalisedString to this prototype's effective localised description.

Parameters
valueLocalisedString

Value to prepend

separatorLocalisedString | nil

Separator between the prepended and existing descriptions

Returns
self
function Data.prepend_localized_description(value: LocalisedString, separator: LocalisedString | nil) -> self
Parameters
valueLocalisedString

Value to prepend

separatorLocalisedString | nil

Separator between the prepended and existing descriptions

Returns
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.

Parameters
sourcenil | table | string

Prototype type or dictionary; defaults to this wrapper's type

opts{string, boolean} | nil

Options for yielded wrappers

Returns
iteratorfun() -> ...any
initial_keynil
initial_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.

Parameters
objecttable | string

Prototype name or prototype table

object_typenil | string

data.raw type; required for names except item wrappers

opts{string, boolean} | nil

Wrapper options

Returns
wrappedself
function Data.__call(object: table | string, object_type: nil | string, opts: {string, boolean} | nil) -> wrapped self
Parameters
objecttable | string

Prototype name or prototype table

object_typenil | string

data.raw type; required for names except item wrappers

opts{string, boolean} | nil

Wrapper options

Returns
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