Data Structures - JanSharp/JanSharpsGuiLibrary GitHub Wiki
This defines a GuiClassInst
. In the end this will get converted to a GuiClassInst
.
{
type = string, -- see basic-class-names.lua
children = nil | {
GuiClassInstChildDefinition,
...
-- before LuaGuiElement.add(...) get's called, this table
-- will be removed from the GuiClassInstDefinition.
-- this is to make dealing with circular references easier
-- (basically don't worry about them inside children).
-- afterwards, for every item
-- add_child_definition(parent, child) will be called.
-- where parent = inst
-- and child = the respective GuiClassInstChildDefinition
},
elem_mods = nil | {
[string] = any, -- after the inst.elem has been created, for every
... -- item in this list inst.elem[key] = value will be executed
},
style_mods = nil | {
[string] = any, -- just like elem_mods, but for inst.elem.style
...
},
[any] = any,
...
-- this table will be passed to the LuaGuiElement.add(...) function
-- so any parameters dependent on the type will be used by the api
-- every other key-value pair will also persist in the GuiClassInst
}
This defines a child of an inst.
{
class_name = string,
name = nil | string,
parent_pass_count = nil | integer,
-- every continuous integer key starting at 1 ascending
-- will be passed to GuiClass.create(...) in that order
}
Instance of a GuiClass
. Gets created using a GuiClassInstDefinition
.
All GuiClassInst
s are stored in factorio's global
. They are the only data structure stored in said gobal
.
{
class_name = string,
name = nil | string,
parent = nil | GuiClassInst,
children = {
[string] = GuiClassInst, -- all named children
...
[integer] = GuiClassInst, -- all unnamed children
...
},
elem = LuaGuiElement,
[string] = GuiClassInst, -- all named children
...
[any] = any,
...
-- everything that was in the GuiClassinstDefinition
-- plus the "passed_data", which is the optional second
-- return value of GuiClass.create(...)
<metatable> = GuiClass, -- the class of the inst
}
A definition for a GuiClass
(which it will turn into when registered).
Relevant references:
{
class_name = string, -- unique
create = function(...) ->
(GuiClassInstDefinition, nil | {[any] = any, ...}),
-- called whenever a new instance of the class gets created
-- the second return value simply contains data that
-- will end up in the GuiClassInst.
-- this is required whenever a value cannot be passed to
-- the LuaGuiElement.add function,
-- like when having circular references
-- the class events
-- https://github.com/JanSharp/JanSharpsGuiLibrary/wiki/Terms#class-events
on_elem_created = function(GuiClassInst self),
on_create = function(GuiClassInst self),
on_destroy = function(GuiClassInst self),
event_conditions = nil | {
[event_name] = any | function(self) -> bool,
...
-- if these are literals, they will get evaluated upon registering the class
-- (i only see this being useful for debugging)
-- if it is a function, the function will be called when an inst gets created
-- if it returns true, the event handler gets subscribed, otherwise it does not
-- these also get evaluated on_load, so make sure this is deterministic
},
[event_name] = function(self, event),
...
-- event handlers. on_click would be one for example
-- https://github.com/JanSharp/JanSharpsGuiLibrary/wiki/Terms#gui-events
[any] = any,
...
-- you can throw anything into this table,
-- remember it'll be a metatable for GuiClassInst s
}
GuiClassDefinition
s get converted to GuiClasse
s when registered.
Relevant references:
{
-- <everything that was in the GuiClassDefinition
-- used to create the GuiClass>
__index = GuiClass, -- self
-- see respective functions for documentation
-- https://github.com/JanSharp/JanSharpsGuiLibrary/wiki/Gui-Handler
add = function(parent, class_name, name, ...) -> inst, -- gui_handler.add_child
add_definition = function(parent, child) -> inst, -- gui_handler.add_child_definition
add_children = function(parent, children), -- gui_handler.add_children
destroy = function(inst), -- gui_handler.destroy
got_destroyed = function(inst), -- gui_handler.got_destroyed
}