Data classmod

Data

Methods

Data:is_valid([type]) Is this a valid object
Data:continue(bool) Changes the validity of the object.
Data:continue_if(func) Changes the validity of the object if the passed function is true.
Data:extend([force]) Extend object into the data table
Data:copy(new_name, result[, opts]) Copies a recipe to a new recipe.
Data:run_function(func) Run a function if the object is valid.
Data:get_function_results(func) Run a function on a valid object and return its results.
Data:set_unique_array(tab) Set the unique array class to the field if the field is present
Data:set_field(field, value) Add or change a field.
Data:set_fields(tab) Iterate a dictionary table and set fields on the object.
Data:get_field(field, default_value) Get a field.
Data:get_fields(arr, as_dictionary) Iterate an array of fields and return the values as paramaters
Data:remove_field(field) Remove an indiviual field from the the object
Data:remove_fields(arr) Iterate a string array and set to nil.
Data:subgroup_order([subgroup=nil][, order=nil]) Change the item-subgroup and/or order.
Data:replace_icon(icon, size) Replace an icon
Data:get_icons([copy=false]) Get the icons
Data:tostring() Get the objects name.
Data:get(object[, object_type][, opts]) Returns a valid thing object reference.

Methods

# Data:is_valid([type])

Is this a valid object

Parameters:
  • type : (string) if present is the object this type (optional)
Returns:
  • (self)
# Data:continue(bool)

Changes the validity of the object.

Parameters: Returns:
  • (self)
# Data:continue_if(func)

Changes the validity of the object if the passed function is true.

Parameters:
  • func : (function) the function to test, self is passed as the first paramater
Returns:
  • (self)
# Data:extend([force])

Extend object into the data table

Parameters:
  • force : (boolean) Extend even if it is already extended (optional)
Returns:
  • (self)
# Data:copy(new_name, result[, opts])

Copies a recipe to a new recipe.

Parameters:
  • new_name : (string) The new name for the recipe.
  • result : (string)
  • opts : (table) (optional)
Returns:
  • (self)
# Data:run_function(func)

Run a function if the object is valid.

The object and any additional paramaters are passed to the function.

Parameters:
  • func : (function) then function to run.
Returns:
  • (self)
# Data:get_function_results(func)

Run a function on a valid object and return its results.

Parameters:
  • func : (function) the function to run. self is passed as the first paramter
Returns:
  • (boolean) if the object was valid
  • (the) results from the passed function
# Data:set_unique_array(tab)

Set the unique array class to the field if the field is present

Parameters: Returns:
  • (self)
# Data:set_field(field, value)

Add or change a field.

Parameters:
  • field : (string) the field to change.
  • value : (mixed) the value to set on the field.
Returns:
  • (self)
# Data:set_fields(tab)

Iterate a dictionary table and set fields on the object.

Existing fields are overwritten.

Parameters:
  • tab : (table) dictionary table of fields to set.
Returns:
  • (self)
# Data:get_field(field, default_value)

Get a field.

Parameters:
  • field : (string)
  • default_value : (mixed) return this if the field doesn’t exist
Returns:
  • (nil or mixed) the value of the field
# Data:get_fields(arr, as_dictionary)

Iterate an array of fields and return the values as paramaters

Parameters:
  • arr : (array)
  • as_dictionary : (boolean) Return the results as a dictionary table instead of parameters
Returns:
  • (mixed) the parameters
Usage:
local icon, name = Data('stone-furnace', 'furnace'):get_fields({icon, name})
# Data:remove_field(field)

Remove an indiviual field from the the object

Parameters:
  • field : (string) The field to remove
Returns:
  • (self)
# Data:remove_fields(arr)

Iterate a string array and set to nil.

Parameters:
  • arr : (table) string array of fields to remove.
Returns:
  • (self)
# Data:subgroup_order([subgroup=nil][, order=nil])

Change the item-subgroup and/or order.

Parameters:
  • subgroup : (string) , The subgroup to change to if valid. (default: nil)
  • order : (string) The order string to use note if subgroup is non nil and subgroub is not valid order wil not be changed. (default: nil)
Returns:
  • (self)
# Data:replace_icon(icon, size)

Replace an icon

Parameters:
# Data:get_icons([copy=false])

Get the icons

Parameters:
  • copy : (boolean) return a copy of the icons table (default: false)
Returns:
# Data:tostring()

Get the objects name.

Returns:
# Data:get(object[, object_type][, opts])

Returns a valid thing object reference.

This is the main getter.

Parameters:
  • object : (string or table) The thing to use, if string the thing must be in data.raw[type], tables are not verified
  • object_type : (string) the raw type. Required if object is a string (optional)
  • opts : (table) options to pass (optional)
Returns:
  • (Object)