From 645b98fbe1fb8e22a058b884e23f5bd508a5c2cb Mon Sep 17 00:00:00 2001
From: Cooldude2606
Date: Tue, 29 May 2018 16:11:31 +0100
Subject: [PATCH 001/231] Module: ExpGamingLib
---
ExpLib.lua | 126 --------
FactorioSoftmodManager.lua | 474 ++++++++++++++++++++++++++++++
control.lua | 88 +-----
modules/ExpGamingLib/control.lua | 144 +++++++++
modules/ExpGamingLib/softmod.json | 14 +
modules/index.lua | 3 +
6 files changed, 648 insertions(+), 201 deletions(-)
delete mode 100644 ExpLib.lua
create mode 100644 FactorioSoftmodManager.lua
create mode 100644 modules/ExpGamingLib/control.lua
create mode 100644 modules/ExpGamingLib/softmod.json
create mode 100644 modules/index.lua
diff --git a/ExpLib.lua b/ExpLib.lua
deleted file mode 100644
index 7c6751f0..00000000
--- a/ExpLib.lua
+++ /dev/null
@@ -1,126 +0,0 @@
---[[
-Explosive Gaming
-
-This file can be used with permission but this and the credit below must remain in the file.
-Contact a member of management on our discord to seek permission to use our code.
-Any changes that you may make to the code are yours but that does not make the script yours.
-Discord: https://discord.gg/r6dC2uK
-]]
---Please Only Edit Below This Line-----------------------------------------------------------
-
--- @module ExpLib
--- @usage require('/ExpLib')
-
-local ExpLib = {}
---- Loads a table into the global lua table
--- @usage a = {k1='foo',k2='bar'}
--- _load_to_G(a)
--- @tparam table tbl table to add to the global lua table
-function ExpLib._unpack_to_G(tbl)
- if not type(tbl) == 'table' or game then return end
- for name,value in pairs(tbl) do
- if not _G[name] then _G[name] = value end
- end
-end
-
---- Returns a bolean based on the type of v matching the test type
--- @usage a = 'foo'
--- is_type(a,'string') -- return true
--- @param v the value to be tested
--- @tparam[opt=nil] string test_type the type to test for if nil then it tests for nil
--- @treturn bolean is v a matching type
-function ExpLib.is_type(v,test_type)
- return test_type and v and type(v) == test_type or not test_type and not v or false
-end
-
---- Returns a value to the player or if no player then log the return
--- @usage a = 'to return'
--- player_return(a)
--- @param rtn the value to return
--- @param player the player to print to
-function ExpLib.player_return(rtn,colour,player)
- local colour = colour or defines.color.white
- local player = player or game.player
- if player then
- local player = Game.get_player(player)
- if not player then return end
- player.play_sound{path='utility/scenario_message'}
- if is_type(rtn,'table') then
- -- test if its a localised string
- if is_type(rtn.__self,'userdata') then player.print('Cant Display Userdata',colour)
- elseif is_type(rtn[1],'string') and string.find(rtn[1],'.+[.].+') and not string.find(rtn[1],'%s') then pcall(player.print,rtn,colour)
- else player.print(table.to_string(rtn),colour)
- end
- elseif is_type(rtn,'function') then player.print('Cant Display Functions',colour)
- else player.print(tostring(rtn),colour)
- end
- else
- local _return = 'Invalid'
- if is_type(rtn,'table') then _return = table.to_string(rtn)
- elseif is_type(rtn,'function') then _return = 'Cant Display Functions'
- elseif is_type(rtn,'userdata') then _return = 'Cant Display Userdata'
- else _return = tostring(rtn)
- end log(_return) rcon.print(_return)
- end
-end
-
---- Convert ticks to hours
--- @usage a = 216001
--- tick_to_hour(a) -- return 1
--- @tparam number tick to convert to hours
--- @treturn number the number of whole hours from this tick
-function ExpLib.tick_to_hour(tick)
- if not is_type(tick,'number') then return 0 end
- return math.floor(tick/(216000*game.speed))
-end
-
---- Convert ticks to minutes
--- @usage a = 3601
--- tick_to_hour(a) -- return 1
--- @tparam number tick to convert to minutes
--- @treturn number the number of whole minutes from this tick
-function ExpLib.tick_to_min (tick)
- if not is_type(tick,'number') then return 0 end
- return math.floor(tick/(3600*game.speed))
-end
-
---- Returns a tick in a displayable format
--- @usage a = 3600
--- tick_to_display_format(a) -- return '1.00 M'
--- @usage a = 234000
--- tick_to_display_format(a) -- return '1 H 5 M'
--- @tparam number tick to convert
--- @treturn string the formated string
-function ExpLib.tick_to_display_format(tick)
- if not is_type(tick,'number') then return '0H 0M' end
- if tick_to_min(tick) < 10 then
- return string.format('%.2f M',tick/(3600*game.speed))
- else
- return string.format('%d H %d M',
- tick_to_hour(tick),
- tick_to_min(tick)-60*tick_to_hour(tick)
- )
- end
-end
-
-function ExpLib.Gui_tree(root)
- local tree = {}
- for _,child in pairs(root.children) do
- if #child.children > 0 then
- if child.name then
- tree[child.name] = ExpLib.Gui_tree(child)
- else
- table.insert(tree,ExpLib.Gui_tree(child))
- end
- else
- if child.name then
- tree[child.name] = child.type
- else
- table.insert(tree,child.type)
- end
- end
- end
- return tree
-end
-
-return ExpLib
\ No newline at end of file
diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua
new file mode 100644
index 00000000..34580b2c
--- /dev/null
+++ b/FactorioSoftmodManager.lua
@@ -0,0 +1,474 @@
+-- Used to load all other modules that are indexed in index.lua
+local moduleIndex = require("/modules/index")
+local Manager = {}
+--- Setup for metatable of the Manager to force read only nature
+-- @usage Manager() -- runs Manager.loadModdules()
+-- @usage Manager[name] -- returns module by that name
+-- @usage tostring(Manager) -- returns formated list of loaded modules
+local ReadOnlyManager = setmetatable({},{
+ __metatable=false,
+ __index=function(tbl,key)
+ -- first looks in manager and then looks in mander.loadModules
+ return rawget(Manager,key) ~= nil and rawget(Manager,key) or rawget(Manager.loadModules,key)
+ end,
+ __call=function(tbl)
+ -- if there are no modules loaded then it loads them
+ if #tbl.loadModules == 0 then
+ tbl.loadModules()
+ end
+ end,
+ __newindex=function(tbl,key,value)
+ -- provents the changing of any key that is not currentState
+ if key == 'currentState' then
+ -- provides a verbose that is always emited describing the change in state
+ Manager.verbose('Current state is now: "'..value.. '"; The verbose state is now: '..tostring(Manager.setVerbose[value]),true)
+ rawset(Manager,key,value)
+ else error('Manager is read only please use included methods',2) end
+ end,
+ __tostring=function(tbl)
+ -- acts as a redirect
+ return tostring(Manager.loadModules)
+ end
+})
+local function setupModuleName(name)
+ -- creates a table that acts like a string but is read only
+ return setmetatable({},{
+ __index=function(tbl,key) return name end,
+ __newindex=function(tbl,key,value) error('Module Name Is Read Only') end,
+ __tostring=function(tbl) return name end,
+ __concat=function(val1,val2) return type(val1) == 'string' and val1..name or name..val2 end,
+ __metatable=false,
+ })
+end
+
+Manager.currentState = 'selfInit'
+-- selfInit > moduleLoad > moduleInit > moduleEnv
+
+--- Default output for the verbose
+-- @usage Manager.verbose('Hello, World!')
+-- @tparm rtn string the value that will be returned though verbose output
+Manager._verbose = function(rtn)
+ -- creates one file per game, ie clears file on reset
+ if game and Manager.setVerbose._output ~= true then Manager.setVerbose._output=true game.write_file('verbose.log',rtn)
+ elseif game then game.write_file('verbose.log','\n'..rtn,true) end
+ -- standard print and log, _log is a version of log which is ln1 of control.lua for shorter log lines
+ if print then print(rtn) end
+ if _log then _log(rtn) end
+end
+
+--- Used to call the output of the verbose when the current state allows it
+-- @usage Manager.verbose('Hello, World!')
+-- @tparm rtn string the value that will be returned though verbose output
+-- @tparm action string is used to decide which verbose this is error || event etc
+Manager.verbose = function(rtn,action)
+ local settings = Manager.setVerbose
+ local state = Manager.currentState
+ -- if ran in a module the the global module_name is present
+ if module_name then rtn='['..module_name..'] '..rtn
+ else rtn='[FSM] '..rtn end
+ -- module_verbose is a local override for a file, action is used in the manager to describe an extra type, state is the current state
+ -- if action is true then it will always trigger verbose
+ if module_verbose or action and (action == true or settings[action]) or settings[state] then
+ if type(settings.output) == 'function' then
+ -- calls the output function, not pcalled as if this fails some thing is very wrong
+ settings.output(rtn)
+ else
+ error('Verbose set for: '..state..' but output can not be called',2)
+ end
+ end
+end
+
+--- Main logic for allowing verbose at different stages though out the script
+-- @usage Manager.setVerbose{output=log}
+-- @tparam newTbl table the table that will be searched for settings to be updated
+-- @usage Manager.setVerbose[setting] -- returns the value of that setting
+-- @usage tostring(Manager.setVerbose) -- returns a formated list of the current settings
+Manager.setVerbose = setmetatable(
+ {
+ selfInit=true, -- called while the manager is being set up
+ moduleLoad=false, -- when a module is required by the manager
+ moduleInit=false, -- when and within the initation of a module
+ moduleEnv=false, -- during module runtime, this is a global option set within each module(module_verbose=true ln:1) for fine control
+ eventRegistered=false, -- when a module registers its event handlers
+ errorCaught=true, -- when an error is caught during runtime
+ output=Manager._verbose, -- can be: print || log || or other function
+ _output={} -- a constant value that can used to store output data
+ },
+ {
+ __metatable=false,
+ __call=function(tbl,newTbl)
+ -- does not allow any new keys, but will override any existing ones
+ for key,value in pairs(newTbl) do
+ if rawget(tbl,key) ~= nil then
+ Manager.verbose('Verbose for: "'..key..'" has been set to: '..tostring(value))
+ rawset(tbl,key,value)
+ end
+ end
+ end,
+ __newindex=function(tbl,key,value)
+ -- stops creationg of new keys
+ error('New settings cannot be added during runtime',2)
+ end,
+ __index=function(tbl,key)
+ -- will always return a value, never nil
+ return rawget(tbl,key) or false
+ end,
+ __tostring=function(tbl)
+ -- a simple concat function for the settings
+ local rtn = ''
+ for key,value in pairs(tbl) do
+ if type(value) == 'boolean' then
+ rtn=rtn..key..': '..tostring(value)..', '
+ end
+ end
+ return rtn:sub(1,-3)
+ end
+ }
+)
+-- call to verbose to show start up, will always be present
+Manager.verbose('Current state is now: "selfInit"; The verbose state is: '..tostring(Manager.setVerbose.selfInit),true)
+
+--- Creates a sand box envorment and runs a callback in that sand box; provents global pollution
+-- @usage Manager.sandbox(callback) -- return sandbox, success, other returns from callback
+-- @tparam callback function the function that will be ran in the sandbox
+-- @param[opt] any other params that the function will use
+-- @usage Manager.sandbox() -- returns and empty sandbox
+-- @usage Manager.sandbox[key] -- returns the sand box value in that key
+Manager.sandbox = setmetatable({
+ -- can not use existing keys of _G
+ verbose=Manager.verbose,
+ module_verbose=false,
+ module_exports=false
+},{
+ __metatable=false,
+ __call=function(tbl,callback,env,...)
+ if type(callback) == 'function' then
+ -- creates a new sandbox env
+ local sandbox = tbl()
+ -- new indexs are saved into sandbox and if _G does not have the index then look in sandbox
+ setmetatable(env,{__index=sandbox})
+ setmetatable(_G,{__index=env,__newindex=sandbox})
+ -- runs the callback
+ local rtn = {pcall(callback,...)}
+ local success = table.remove(rtn,1)
+ -- this is to allow modules to be access with out the need of using Mangaer[name] also keeps global clean
+ setmetatable(_G,{__index=ReadOnlyManager})
+ if success then return sandbox, success, rtn
+ else return sandbox, success, rtn[1] end
+ else return setmetatable({},{__index=tbl}) end
+ end
+})
+
+--- Loads the modules that are present in the index list
+-- @usage Manager.loadModules() -- loads all moddules in the index list
+-- @usage #Manager.loadModules -- returns the number of modules loaded
+-- @usage tostring(Manager.loadModules) -- returns a formatted list of all modules loaded
+-- @usage pairs(Manager.loadModules) -- loops over the loaded modules moduleName, module
+Manager.loadModules = setmetatable({},
+ {
+ __metatable=false,
+ __call=function(tbl)
+ -- ReadOnlyManager used to trigger verbose change
+ ReadOnlyManager.currentState = 'moduleLoad'
+ -- goes though the index looking for modules
+ for module_name,location in pairs (moduleIndex) do
+ Manager.verbose('Loading module: "'..module_name..'"; Location: '..location)
+ -- runs the module in a sandbox env
+ local sandbox, success, module = Manager.sandbox(require,{module_name=setupModuleName(module_name),module_location=location},location)
+ -- extracts the module into a global index table for later use
+ if success then
+ -- verbose to notifie of any globals that were attempted to be created
+ local globals = ''
+ for key,value in pairs(sandbox) do globals = globals..key..', ' end
+ if globals ~= '' then Manager.verbose('Globals caught in "'..module_name..'": '..globals:sub(1,-3),'errorCaught') end
+ Manager.verbose('Successfully loaded: "'..module_name..'"; Location: '..location)
+ -- sets that it has been loaded and adds to the loaded index
+ -- if you prefere module_exports can be used rather than returning the module
+ if type(tbl[module_name]) == 'nil' then
+ -- if it is a new module then creat the new index
+ if sandbox.module_exports and type(sandbox.module_exports) == 'table'
+ then tbl[module_name] = sandbox.module_exports
+ else tbl[module_name] = table.remove(module,1) end
+ elseif type(tbl[module_name]) == 'table' then
+ -- if this module adds onto an existing one then append the keys
+ if sandbox.module_exports and type(sandbox.module_exports) == 'table'
+ then for key,value in pairs(sandbox.module_exports) do tbl[module_name][key] = value end
+ else for key,value in pairs(table.remove(module,1)) do tbl[module_name][key] = value end end
+ else
+ -- if it is a function then it is still able to be called even if more keys are going to be added
+ -- if it is a string then it will act like one; if it is a number well thats too many metatable indexs
+ tbl[module_name] = setmetatable({__old=tbl[module_name]},{
+ __call=function(tbl,...) if type(tbl.__old) == 'function' then tbl.__old(...) else return tbl.__old end end,
+ __tostring=function(tbl) return tbl.__old end,
+ __concat=function(tbl,val) return tbl.__old..val end
+ })
+ -- same as above for adding the keys to the table
+ if sandbox.module_exports and type(sandbox.module_exports) == 'table'
+ then for key,value in pairs(sandbox.module_exports) do tbl[module_name][key] = value end
+ else for key,value in pairs(table.remove(module,1)) do tbl[module_name][key] = value end end
+ end
+ -- if there is a module by this name in _G ex table then it will be indexed to the new module
+ if rawget(_G,module_name) then setmetatable(rawget(_G,module_name),{__index=tbl[module_name]}) end
+ else
+ Manager.verbose('Failed load: "'..module_name..'"; Location: '..location..' ('..module..')','errorCaught')
+ end
+ end
+ -- new state for the manager to allow control of verbose
+ ReadOnlyManager.currentState = 'moduleInit'
+ -- runs though all loaded modules looking for on_init function; all other modules have been loaded
+ for module_name,data in pairs(tbl) do
+ -- looks for init so that init or on_init can be used
+ if type(data) == 'table' and data.init and data.on_init == nil then data.on_init = data.init data.init = nil end
+ if type(data) == 'table' and data.on_init and type(data.on_init) == 'function' then
+ Manager.verbose('Initiating module: "'..module_name)
+ local sandbox, success, err = Manager.sandbox(data.on_init,{module_name=setupModuleName(module_name)},data)
+ if success then
+ Manager.verbose('Successfully Initiated: "'..module_name..'"')
+ else
+ Manager.verbose('Failed Initiation: "'..module_name..'" ('..err..')','errorCaught')
+ end
+ -- clears the init function so it cant be used in runtime
+ data.on_init = nil
+ end
+ end
+ -- this could also be called runtime
+ ReadOnlyManager.currentState = 'moduleEnv'
+ end,
+ __len=function(tbl)
+ -- counts the number of loaded modules
+ local rtn = 0
+ for key,value in pairs(tbl) do
+ rtn = rtn + 1
+ end
+ return rtn
+ end,
+ __tostring=function(tbl)
+ -- a concat of all the loaded modules
+ local rtn = 'Load Modules: '
+ for key,value in pairs(tbl) do
+ rtn=rtn..key..', '
+ end
+ return rtn:sub(1,-3)
+ end
+ }
+)
+
+--- A more detailed replacement for the lua error function to allow for handlers to be added; repleaces default error so error can be used instead of Manager.error
+-- @usage Manager.error(err) -- calls all error handlers that are set or if none then prints to game and if that fails crashs game
+-- @tparam err string the err string that will be passed to the handlers
+-- @usage Manager.error() -- returns an error constant that can be used to crash game
+-- @usage Manager.error(Manager.error()) -- crashs the game
+-- @usage Manager.error.addHandler(name,callback) -- adds a new handler if handler returns Manager.error() then game will crash
+-- @tparam name string || fucntion the name that is given to the callback || the callback that will be used
+-- @tparam[opt:type(name)=='function'] callback function if name is given as a string this will be the callback used
+-- @usage Manager.error[name] -- returns the handler of that name if present
+-- @usage #Manager.error -- returns the number of error handlers that are present
+-- @usage pairs(Manager.error) -- loops over only the error handlers handler_name,hander
+Manager.error = setmetatable({
+ __error_call=error,
+ __error_const={},
+ __error_handler=function(handler_name,callback)
+ -- when handler_name is a string it is expeced that callback is a function; other wise handler_name must be a function
+ if type(handler_name) == 'string' and type(callback) == 'function' then Manager.error[handler_name]=callback
+ elseif type(handler_name) == 'function' then table.insert(Manager.error,handler_name)
+ else Manager.error('Handler is not a function',2) end
+ end
+},{
+ __metatalbe=false,
+ __call=function(tbl,err,...)
+ -- if no params then return the error constant
+ if err == nil then return rawget(tbl,'__error_const') end
+ -- if the error constant is given crash game
+ if err == rawget(tbl,'__error_const') then Manager.verbose('Force Stop','errorCaught') rawget(tbl,'__error_call')('Force Stop',2) end
+ -- other wise treat the call as if its been passed an err string
+ if #tbl > 0 then
+ -- there is at least one error handler loaded; loops over the error handlers
+ for handler_name,callback in pairs(tbl) do
+ local success, err = pcall(callback,err,...)
+ if not success then Manager.verbose('Error handler: "'..handler_name..'" failed to run ('..err..')','errorCaught') end
+ -- if the error constant is returned from the handler then crash the game
+ if err == rawget(tbl,'__error_const') then Manager.verbose('Force Stop by: '..handler_name,'errorCaught') rawget(tbl,'__error_call')('Force Stop by: '..handler_name) end
+ end
+ elseif game then
+ -- there are no handlers loaded so it will print to the game if loaded
+ Manager.verbose('No error handlers loaded; Default game print used','errorCaught')
+ game.print(err)
+ else
+ -- all else fails it will crash the game with the error code
+ Manager.verbose('No error handlers loaded; Game not loaded; Forced crash: '..err,'errorCaught')
+ rawget(tbl,'__error_call')(err,2)
+ end
+ end,
+ __index=function(tbl,key)
+ -- this allows the __error_handler to be called from many different names
+ if key:lower() == 'addhandler' or key:lower() == 'sethandler' or key:lower() == 'handler' or key:lower() == 'register' then return rawget(tbl,'__error_handler')
+ else rawget(tbl,'__error_call')('Invalid index for error handler; please use build in methods.') end
+ end,
+ __newindex=function(tbl,key,value)
+ -- making a new index adds it as a handler
+ if type(value) == 'function' then
+ Manager.verbose('Added Error Handler: "'..key..'"','eventRegistered')
+ rawset(tbl,key,value)
+ end
+ end,
+ __len=function(tbl)
+ -- counts the number of handlers there are
+ local rtn=0
+ for handler_name,callback in pairs(tbl) do
+ rtn=rtn+1
+ end
+ return rtn
+ end,
+ __pairs=function(tbl)
+ -- will not return any of the three core values as part of pairs
+ local function next_pair(tbl,k)
+ local v
+ k, v = next(tbl, k)
+ if k == '__error_call' or k == '__error_const' or k == '__error_handler' then return next_pair(tbl,k) end
+ if type(v) == 'function' then return k,v end
+ end
+ return next_pair, tbl, nil
+ end
+})
+-- overrides the default error function
+error=Manager.error
+
+-- event does work a bit differnt from error, and if event breaks error is the fallback
+--- Event handler that modules can use, each module can register one function per event
+-- @usage Manager.event[event_name] = callback -- sets the callback for that event
+-- @usage Manager.event[event_name] = nil -- clears the callback for that event
+-- @usage Manager.event(event_name,callback) -- sets the callback for that event
+-- @usage Manager.event[event_name] -- returns the callback for that event or the event id if not registered
+-- @usage Manager.event(event_name) -- runs all the call backs for that event
+-- @tparam event_name int|string index that referes to an event
+-- @tparam callback function the function that will be set for that event
+-- @usage Manager.event() -- returns the stop value for the event proccessor, if returned during an event will stop all other callbacks
+-- @usage #Manager.event -- returns the number of callbacks that are registered
+-- @usage pairs(Manager.events) -- returns event_id,table of callbacks
+Manager.event = setmetatable({
+ __stop={},
+ __events={},
+ __event=script.on_event,
+ __generate=script.generate_event_name,
+ __get_handler=script.get_event_handler,
+ __raise=script.raise_event,
+ __init=script.on_init,
+ __load=script.on_load,
+ __config=script.on_configuration_changed,
+ events=defines.events
+},{
+ __metatable=false,
+ __call=function(tbl,event_name,new_callback,...)
+ -- if no params then return the stop constant
+ if event_name == nil then return rawget(tbl,'__stop') end
+ -- if the event name is a table then loop over each value in that table
+ if type(event_name) == 'table' then
+ for key,_event_name in pairs(event_name) do tbl(_event_name,new_callback,...) end return
+ end
+ -- convert the event name to a number index
+ event_name = tonumber(event_name) or tbl.names[event_name]
+ -- if there is a callback present then set new callback rather than raise the event
+ if type(new_callback) == 'function' then
+ Manager.event[event_name] = new_callback return
+ end
+ -- other wise raise the event and call every callback; no use of script.raise_event due to override
+ if type(tbl[event_name]) == 'table' then
+ for module_name,callback in pairs(tbl[event_name]) do
+ -- loops over the call backs and which module it is from
+ if type(callback) ~= 'function' then error('Invalid Event Callback: "'..event_name..'/'..module_name..'"') end
+ local sandbox, success, err = Manager.sandbox(callback,{module_name=setupModuleName(module_name)},new_callback,...)
+ if not success then Manager.verbose('Event Failed: "'..tbl.names[event_name]..'/'..module_name..'" ('..err..')','errorCaught') error('Event Failed: "'..event_name..'/'..module_name..'" ('..err..')') end
+ -- if stop constant is returned then stop further processing
+ if err == rawget(tbl,'__stop') then Manager.verbose('Event Haulted By: "'..module_name..'"','errorCaught') break end
+ end
+ end
+ end,
+ __newindex=function(tbl,key,value)
+ -- handles the creation of new event handlers
+ if type(value) ~= 'function' and type(value) ~= nil then error('Attempted to set a non function value to an event',2) end
+ -- checks for a global module name that is present
+ local module_name = module_name or 'FSM'
+ -- converts the key to a number index for the event
+ key = tonumber(key) or tbl.names[key]
+ Manager.verbose('Added Handler: "'..tbl.names[key]..'"','errorCaught')
+ -- checks that the event has a valid table to store callbacks; if its not valid it will creat it and register a real event handler
+ if not rawget(rawget(tbl,'__events'),key) then rawget(tbl,'__event')(key,function(...) tbl(...) end) rawset(rawget(tbl,'__events'),key,{}) end
+ -- adds callback to Manager.event.__events[event_id][module_name]
+ rawset(rawget(rawget(tbl,'__events'),key),module_name,value)
+ end,
+ __index=function(tbl,key)
+ -- proforms different look ups depentding weather the current module has an event handler registered
+ if module_name then
+ -- first looks for the event callback table and then under the module name; does same but converts the key to a number; no handler regisered so returns the converted event id
+ return rawget(rawget(tbl,'__events'),key) and rawget(rawget(rawget(tbl,'__events'),key),module_name)
+ or rawget(rawget(tbl,'__events'),rawget(tbl,'names')[key]) and rawget(rawget(rawget(tbl,'__events'),rawget(tbl,'names')[key]),module_name)
+ or rawget(tbl,'names')[key]
+ else
+ -- if there is no module present then it will return the full list of regisered handlers; or other wise the converted event id
+ return rawget(rawget(tbl,'__events'),key) or rawget(rawget(tbl,'__events'),rawget(tbl,'names')[key]) or rawget(tbl,'names')[key]
+ end
+ end,
+ __len=function(tbl)
+ -- counts every handler that is regised not just the the number of events with handlers
+ local rtn=0
+ for event,callbacks in pairs(tbl) do
+ for module,callback in pairs(callbacks) do
+ rtn=rtn+1
+ end
+ end
+ return rtn
+ end,
+ __pairs=function(tbl)
+ -- will loops over the event handlers and not Manager.event
+ local function next_pair(tbl,k)
+ k, v = next(rawget(tbl,'__events'), k)
+ if type(v) == 'table' then return k,v end
+ end
+ return next_pair, tbl, nil
+ end
+})
+--- Sub set to Manger.event and acts as a coverter between event_name and event_id
+-- @usage Manager.event[event_name] -- see above, can not be accessed via Manager.event.names
+rawset(Manager.event,'names',setmetatable({},{
+ __index=function(tbl,key)
+ if type(key) == 'number' or tonumber(key) then
+ -- if it is a number then it will first look in the chache
+ if rawget(tbl,key) then return rawget(tbl,key) end
+ -- if it is a core event then it will simply return
+ if key == 'on_init' or key == 'init' then
+ rawset(tbl,key,-1)
+ elseif key == 'on_load' or key == 'load' then
+ rawset(tbl,key,-2)
+ elseif key == 'on_configuration_changed' or key == 'configuration_changed' then
+ rawset(tbl,key,-3)
+ else
+ -- if it is not a core event then it does a value look up on Manager.events aka defines.events
+ for event,id in pairs(rawget(Manager.event,'events')) do
+ if id == key then rawset(tbl,key,event) end
+ end
+ end
+ -- returns the value from the chache after being loaded in
+ return rawget(tbl,key)
+ -- if it is a string then no reverse look up is required
+ else return rawget(rawget(Manager.event,'events'),key) end
+ end
+}))
+--over rides for the base values; can be called though Event
+Event=setmetatable({},{__index=function(tbl,key) return Manager.event[key] or script[key] or error('Invalid Index To Table Event') end})
+script.mod_name = setmetatable({},{
+ __index=function(tbl,key) return _G.module_name end,
+ __newindex=function(tbl,key,value) error('Module Name Is Read Only') end,
+ __tostring=function(tbl) return _G.module_name end,
+ __concat=function(tbl,val) return _G.module_name..val end,
+ __metatable=false,
+})
+script.on_event=Manager.event
+script.raise_event=Manager.event
+script.on_init=function(callback) Manager.event(-1,callback) end
+script.on_load=function(callback) Manager.event(-2,callback) end
+script.on_configuration_changed=function(callback) Manager.event(-3,callback) end
+script.get_event_handler=function(event_name) return type(Manager.event[event_name]) == 'function' and Manager.event[event_name] or nil end
+script.generate_event_name=function(event_name) local event_id = Manager.event.__generate() local event_name = event_name or event_id Manager.event.events[event_name]=event_id return event_id end
+-- to do set up nth tick
+
+return ReadOnlyManager
\ No newline at end of file
diff --git a/control.lua b/control.lua
index 90226fbb..fe3b3285 100644
--- a/control.lua
+++ b/control.lua
@@ -1,3 +1,4 @@
+function _log(...) log(...) end
--[[
Explosive Gaming
@@ -8,78 +9,15 @@ Discord: https://discord.gg/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
--- Replaces the base error function
-_error = error
-error = function(err)
- verbose('Error Called: '..err)
- if _G.error_handle and type(error_handle) == 'function' then
- verbose('Exception Caught By Error Handle')
- local success, _err = pcall(error_handle,err)
- if not success then _error({handle=_err,err=err}) end
- elseif _G.Game and game then
- verbose('Exception Caught By Game Print')
- if Game.print_all(err) == 0 then
- _error(err)
- end
- else
- verbose('Failed to catch error')
- _error(err)
- end
-end
--- Replaces the base require function and verbose function
-_verbose = false -- Set to true for more on the loading of the files
-function verbose(str) if _verbose then log(str) print(str) end end
-verbose('============================= START =============================')
-require_return_err = false -- Set to false when removing files; set to true for debuging
-_require = require
-require = function(path)
- local _path = path
- if string.sub(path,1) ~= '/' then path = '/'..path end
- local _return = {pcall(_require,path)}
- if not table.remove(_return, 1) then
- local __return = {pcall(_require,'/Addons'..path)}
- if not table.remove(__return, 1) then
- verbose('Failed to load: '.._path..' ('.._return[1]..')')
- verbose('Also Attemped: /Addons'..path..' ('..__return[1]..')')
- if require_return_err then error(unpack(_return)) end
- else verbose('Loaded: '.._path) return unpack(__return) end
- else verbose('Loaded: '.._path) end
- return unpack(_return)
-end
-
-verbose('Begain Base Lib Loading')
-require('mod-gui')
--- Loads the stdlib and allows Core Game and Event
-Color, Game, Event = require('StdLib/load'){'Color','Game','Event'}
-
--- loads the ExpLib, functions are placed into the lua global
-local ExpLib = require 'ExpLib'
-verbose('ExpLib Extraction')
-ExpLib._unpack_to_G(ExpLib)
-
-verbose('Begain Core File Loading')
--- Loads the ExpCore files. These are need in order to run the other addons
-Ranking, Sync, Server, Gui = require('ExpCore/load'){'Ranking','Sync','Server','Gui'}
-verbose('Gui Test Initiation')
-local success,err = require('ExpCore/GuiParts/test')
-if success then Gui.test = err else verbose('No Test Present') end
-if Gui.popup then verbose('Gui Popup Initiation') Gui.popup._load() end
-if Sync._load then verbose('Sync Initiation') Sync._load() end
--- Loads the ranks that Ranking uses
-verbose('Base Ranks Initiation')
-require('ExpCore/ranks')
--- Loads any edits that are not need in core pcall as file may not be present
-verbose('Extented Ranks Initiation')
-require('Addons/playerRanks')
--- Makes sure that all the little details are cleaned up
-verbose('Ranking Initiation')
-Ranking._auto_edit_ranks()
--- Loads all the addons
-verbose('Begain Addons Loading')
-local success,err = pcall(require,'Addons/load')
-if not success then error(err) end
--- Loads anything that does not use ExpCore (source given in the file)
-verbose('Begain Stand Alone Loading')
-local success,err = pcall(require,'StandAlone/load')
-if not success then error(err) end
-verbose('============================== END ==============================')
\ No newline at end of file
+-- File Which Factorio Will Call
+Manager = require("FactorioSoftmodManager")
+Manager.setVerbose{
+ selfInit=true, -- called while the manager is being set up
+ moduleLoad=true, -- when a module is required by the manager
+ moduleInit=true, -- when and within the initation of a module
+ moduleEnv=true, -- during module runtime, this is a global option set within each module for fine control
+ eventRegistered=true, -- when a module registers its event handlers
+ errorCaught=true, -- when an error is caught during runtime
+ output=Manager._verbose -- can be: can be: print || log || other function
+}
+Manager() -- can be Manager.loadModules() if called else where
\ No newline at end of file
diff --git a/modules/ExpGamingLib/control.lua b/modules/ExpGamingLib/control.lua
new file mode 100644
index 00000000..bc691e93
--- /dev/null
+++ b/modules/ExpGamingLib/control.lua
@@ -0,0 +1,144 @@
+--[[
+Explosive Gaming
+
+This file can be used with permission but this and the credit below must remain in the file.
+Contact a member of management on our discord to seek permission to use our code.
+Any changes that you may make to the code are yours but that does not make the script yours.
+Discord: https://discord.gg/r6dC2uK
+]]
+--Please Only Edit Below This Line-----------------------------------------------------------
+local module_verbose = false -- there is no verbose in this file so true will do nothing
+local ExpLib = {}
+
+--- Loads a table into _G even when sandboxed; will not overwrite values or append to tables; will not work during runtime to avoid desyncs
+-- @usage unpack_to_G{key1='foo',key2='bar'}
+-- @tparam table tbl -- table to be unpacked
+function ExpLib.unpack_to_G(tbl)
+ if not type(tbl) == 'table' or game then return end
+ for key,value in pairs(tbl) do
+ if not _G[key] then rawset(_G,key,value) end
+ end
+end
+
+--- Used to get the current ENV with all _G keys removed; useful when saving function to global
+-- @usage get_env() -- returns current ENV with _G keys removed
+-- @treturn table -- the env table with _G keys removed
+function ExpLib.get_env()
+ local level = 2
+ local env = setmetatable({},{__index=_G})
+ while true do
+ if not debug.getinfo(level-1) then break end
+ local i = 1
+ while true do
+ local name, value = debug.getlocal(level,i)
+ if not name then break else env[name] = value end
+ i=i+1
+ end
+ level=level+1
+ if debug.getinfo(level-1).namewhat == 'global' then break end
+ end
+ return env
+end
+
+--- Compear types faster for faster valadation of prams
+-- @usage is_type('foo','string') -- return true
+-- @usage is_type('foo') -- return false
+-- @param v -- the value to be tested
+-- @tparam[opt=nil] string test_type -- the type to test for if not given then it tests for nil
+-- @treturn bolean -- is v of type test_type
+function ExpLib.is_type(v,test_type)
+ return test_type and v and type(v) == test_type or not test_type and not v or false
+end
+
+--- Will return a value of any type to the player/server console, allows colour for in-game players
+-- @usage player_return('Hello, World!') -- returns 'Hello, World!' to game.player or server console
+-- @usage player_return('Hello, World!','green') -- returns 'Hello, World!' to game.player with colour green or server console
+-- @usage player_return('Hello, World!',nil,player) -- returns 'Hello, World!' to the given player
+-- @param rtn -- any value of any type that will be returned to the player or console
+-- @tparam[opt=defines.colour.white] defines.color || string colour -- the colour of the text for the player, ingroned when printing to console
+-- @tparam[opt=game.player] LuaPlayer player -- the player that return will go to, if no game.player then returns to server
+function ExpLib.player_return(rtn,colour,player)
+ local colour = ExpLib.is_type(colour) == 'table' and colour or defines.color[colour]
+ local player = player or game.player
+ local function _return(callback,rtn)
+ if ExpLib.is_type(rtn,'table') then
+ -- test for: userdata, locale string, table with __tostring meta method, any other table
+ if ExpLib.is_type(rtn.__self,'userdata') then callback('Cant Display Userdata',colour)
+ elseif ExpLib.is_type(rtn[1],'string') and string.find(rtn[1],'.+[.].+') and not string.find(rtn[1],'%s') then callback(rtn,colour)
+ elseif getmetatable(rtn) ~= nil and not tostring(rtn):find('table: 0x') then callback(tostring(rtn),colour)
+ else callback(table.tostring(rtn),colour) end
+ -- test for: function
+ elseif ExpLib.is_type(rtn,'function') then callback('Cant Display Functions',colour)
+ -- else just call tostring
+ else callback(tostring(rtn),colour) end
+ end
+ if player then
+ -- allows any vaild player identifier to be used
+ local player = Game.get_player(player)
+ if not player then error('Invalid Player given to player_return',2) end
+ -- plays a nice sound that is different to normal message sound
+ player.play_sound{path='utility/scenario_message'}
+ _return(player.print,rtn)
+ else _return(rcon.print,rtn) end
+end
+
+--- Convert ticks to hours
+-- @usage tick_to_hour(216001) -- return 1
+-- @tparam number tick -- tick to convert to hours
+-- @treturn number -- the number of whole hours from this tick
+function ExpLib.tick_to_hour(tick)
+ if not ExpLib.is_type(tick,'number') then return 0 end
+ return math.floor(tick/(216000*game.speed))
+end
+
+--- Convert ticks to minutes
+-- @usage tick_to_hour(3601) -- return 1
+-- @tparam number tick -- tick to convert to minutes
+-- @treturn number -- the number of whole minutes from this tick
+function ExpLib.tick_to_min (tick)
+ if not ExpLib.is_type(tick,'number') then return 0 end
+ return math.floor(tick/(3600*game.speed))
+end
+
+--- Converts a tick into a clean format for end user
+-- @usage tick_to_display_format(3600) -- return '1.00 M'
+-- @usage tick_to_display_format(234000) -- return '1 H 5 M'
+-- @tparam number tick -- the tick to convert
+-- @treturn string -- the formated string
+function ExpLib.tick_to_display_format(tick)
+ if not ExpLib.is_type(tick,'number') then return '0H 0M' end
+ if ExpLib.tick_to_min(tick) < 10 then
+ return string.format('%.2f M',tick/(3600*game.speed))
+ else
+ return string.format('%d H %d M',
+ ExpLib.tick_to_hour(tick),
+ ExpLib.tick_to_min(tick)-60*ExpLib.tick_to_hour(tick)
+ )
+ end
+end
+
+--- Used as a way to view the structure of a gui, used for debuging
+-- @usage Gui_tree(root) -- returns all children of gui recusivly
+-- @tparam LuaGuiElement root -- the root to start the tree from
+-- @treturn table -- the table that describes the gui
+function ExpLib.gui_tree(root)
+ if not ExpLib.is_type(root,'table') or not root.valid then error('Invalid Gui Element given to gui_tree',2) end
+ local tree = {}
+ for _,child in pairs(root.children) do
+ if #child.children > 0 then
+ if child.name then tree[child.name] = ExpLib.gui_tree(child)
+ else table.insert(tree,ExpLib.gui_tree(child)) end
+ else
+ if child.name then tree[child.name] = child.type
+ else table.insert(tree,child.type) end
+ end
+ end
+ return tree
+end
+
+-- unpacks lib to _G on module init
+function ExpLib.on_init(self)
+ self:unpack_to_G()
+end
+
+return ExpLib
\ No newline at end of file
diff --git a/modules/ExpGamingLib/softmod.json b/modules/ExpGamingLib/softmod.json
new file mode 100644
index 00000000..54669d82
--- /dev/null
+++ b/modules/ExpGamingLib/softmod.json
@@ -0,0 +1,14 @@
+{
+ "name": "ExpGamingLib",
+ "module": "ExpLib",
+ "description": "Adds some common functions used though out all ExpGaming modules",
+ "keywords": ["ExpGaming","Lib"],
+ "version": "1.0.0",
+ "location": "nil",
+ "main": "control",
+ "dependencies": {},
+ "author": "Cooldude2606",
+ "contact": "Discord: Cooldude2606#5241",
+ "license": "https://github.com/badgamernl/explosivegaming-main/blob/master/LICENSE"
+}
+
\ No newline at end of file
diff --git a/modules/index.lua b/modules/index.lua
new file mode 100644
index 00000000..da98a4a0
--- /dev/null
+++ b/modules/index.lua
@@ -0,0 +1,3 @@
+return {
+ ['ExpLib']='/modules/ExpGamingLib/control',
+}
\ No newline at end of file
From 7dafb4ea7f6ff09ae78c093e8d3b394f35007950 Mon Sep 17 00:00:00 2001
From: Cooldude2606
Date: Tue, 29 May 2018 16:13:39 +0100
Subject: [PATCH 002/231] Forgot the dependencies
---
modules/ExpGamingLib/softmod.json | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/modules/ExpGamingLib/softmod.json b/modules/ExpGamingLib/softmod.json
index 54669d82..9b86aee9 100644
--- a/modules/ExpGamingLib/softmod.json
+++ b/modules/ExpGamingLib/softmod.json
@@ -6,7 +6,10 @@
"version": "1.0.0",
"location": "nil",
"main": "control",
- "dependencies": {},
+ "dependencies": {
+ "StdLib/Game": ">=1.0.0",
+ "StdLib/Color": ">=1.0.0"
+ },
"author": "Cooldude2606",
"contact": "Discord: Cooldude2606#5241",
"license": "https://github.com/badgamernl/explosivegaming-main/blob/master/LICENSE"
From f5153f368684e91a44fba8d515a8eb7d4b4d8a5b Mon Sep 17 00:00:00 2001
From: Cooldude2606
Date: Tue, 29 May 2018 20:15:20 +0100
Subject: [PATCH 003/231] Doc Added
---
ExpCore/GuiParts/center.lua | 6 +-
ExpCore/GuiParts/inputs.lua | 19 +-
ExpCore/GuiParts/toolbar.lua | 2 +-
ExpCore/commands.lua | 2 +-
ExpCore/gui.lua | 17 +-
ExpCore/ranking.lua | 5 +-
ExpCore/server.lua | 8 +-
ExpCore/sync.lua | 24 +-
FactorioSoftmodManager.lua | 13 +-
StdLib/event.lua | 172 ---
control.lua | 4 +-
doc/index.html | 155 +++
doc/ldoc.css | 303 +++++
doc/modules/Event.html | 210 +++
doc/modules/FSM.html | 337 +++++
doc/modules/Game.html | 231 ++++
doc/modules/defines.color.html | 519 ++++++++
doc/modules/defines.time.html | 148 +++
doc/modules/expcore.commands.html | 136 ++
doc/modules/expcore.gui.html | 172 +++
doc/modules/expcore.guiparts.center.html | 290 +++++
doc/modules/expcore.guiparts.inputs.html | 446 +++++++
doc/modules/expcore.guiparts.left.html | 193 +++
doc/modules/expcore.guiparts.popup.html | 138 ++
doc/modules/expcore.guiparts.toolbar.html | 129 ++
doc/modules/expcore.ranking.html | 386 ++++++
doc/modules/expcore.server.html | 571 ++++++++
doc/modules/expcore.sync.html | 542 ++++++++
doc/modules/modules.expgaminglib.control.html | 350 +++++
doc/modules/string.html | 310 +++++
doc/modules/table.html | 1145 +++++++++++++++++
doc/scripts/control.lua.html | 85 ++
doc/scripts/index.lua.html | 85 ++
modules/ExpGamingLib/control.lua | 40 +-
{StdLib => modules/FactorioStdLib}/LICENSE | 0
{StdLib => modules/FactorioStdLib}/color.lua | 7 +-
{StdLib => modules/FactorioStdLib}/game.lua | 0
{StdLib => modules/FactorioStdLib}/load.lua | 0
modules/FactorioStdLib/softmod.json | 14 +
{StdLib => modules/FactorioStdLib}/string.lua | 0
{StdLib => modules/FactorioStdLib}/table.lua | 4 +-
{StdLib => modules/FactorioStdLib}/time.lua | 0
modules/index.lua | 2 +
43 files changed, 6979 insertions(+), 241 deletions(-)
delete mode 100644 StdLib/event.lua
create mode 100644 doc/index.html
create mode 100644 doc/ldoc.css
create mode 100644 doc/modules/Event.html
create mode 100644 doc/modules/FSM.html
create mode 100644 doc/modules/Game.html
create mode 100644 doc/modules/defines.color.html
create mode 100644 doc/modules/defines.time.html
create mode 100644 doc/modules/expcore.commands.html
create mode 100644 doc/modules/expcore.gui.html
create mode 100644 doc/modules/expcore.guiparts.center.html
create mode 100644 doc/modules/expcore.guiparts.inputs.html
create mode 100644 doc/modules/expcore.guiparts.left.html
create mode 100644 doc/modules/expcore.guiparts.popup.html
create mode 100644 doc/modules/expcore.guiparts.toolbar.html
create mode 100644 doc/modules/expcore.ranking.html
create mode 100644 doc/modules/expcore.server.html
create mode 100644 doc/modules/expcore.sync.html
create mode 100644 doc/modules/modules.expgaminglib.control.html
create mode 100644 doc/modules/string.html
create mode 100644 doc/modules/table.html
create mode 100644 doc/scripts/control.lua.html
create mode 100644 doc/scripts/index.lua.html
rename {StdLib => modules/FactorioStdLib}/LICENSE (100%)
rename {StdLib => modules/FactorioStdLib}/color.lua (97%)
rename {StdLib => modules/FactorioStdLib}/game.lua (100%)
rename {StdLib => modules/FactorioStdLib}/load.lua (100%)
create mode 100644 modules/FactorioStdLib/softmod.json
rename {StdLib => modules/FactorioStdLib}/string.lua (100%)
rename {StdLib => modules/FactorioStdLib}/table.lua (99%)
rename {StdLib => modules/FactorioStdLib}/time.lua (100%)
diff --git a/ExpCore/GuiParts/center.lua b/ExpCore/GuiParts/center.lua
index 0cf0f107..9179df26 100644
--- a/ExpCore/GuiParts/center.lua
+++ b/ExpCore/GuiParts/center.lua
@@ -38,7 +38,7 @@ end
--- Used to open a center frame for a player
-- @usage Gui.center.open(player,'server-info') -- return true
-- @param player a player indifier to get the flow for
--- @tparam center string the name of the center frame to open
+-- @tparam string center the name of the center frame to open
-- @treturn boelon based on if it successed or not
function center.open(player,center)
local player = Game.get_player(player)
@@ -54,8 +54,8 @@ end
--- Used to open a center frame for a player
-- @usage Gui.center.open_tab(player,'readme','rules') -- return true
-- @param player a player indifier to get the flow for
--- @tparam center string the name of the center frame to open
--- @tparam tab string the name of the tab to open
+-- @tparam string center the name of the center frame to open
+-- @tparam string tab the name of the tab to open
-- @treturn boelon based on if it successed or not
function center.open_tab(player,center,tab)
local player = Game.get_player(player)
diff --git a/ExpCore/GuiParts/inputs.lua b/ExpCore/GuiParts/inputs.lua
index 73e249e1..605a7518 100644
--- a/ExpCore/GuiParts/inputs.lua
+++ b/ExpCore/GuiParts/inputs.lua
@@ -182,9 +182,9 @@ end
--- Used to define a choose-elem-button callback only on elem_changed
-- @usage Gui.inputs.add_elem_button('test','Test','Just for testing',function)
-- @tparam string name the name of this button
--- @tparam string the display for this button, either text or sprite path
+-- @tparam string elem_type the display for this button, either text or sprite path
-- @tparam string tooltip the tooltip to show on the button
--- @tparam function the callback to call on change function(player,element,elem)
+-- @tparam function callback the callback to call on change function(player,element,elem)
-- @treturn table the button object that was made, to allow a custom error event if wanted
function inputs.add_elem_button(name,elem_type,tooltip,callback)
local button = inputs.add{
@@ -210,9 +210,11 @@ end
--- Used to define a checkbox callback only on state_changed
-- @usage Gui.inputs.add_checkbox('test',false,'Just for testing',function,function,funvtion)
-- @tparam string name the name of this button
--- @tparam string the display for this button, either text or sprite path
--- @tparam string tooltip the tooltip to show on the button
--- @tparam function the callback to call on change function(player,element,elem)
+-- @tparam boolean radio if this is a radio button
+-- @tparam string display the display for this button, either text or sprite path
+-- @tparam function default the callback which choses the default check state
+-- @tparam function callback_true the callback to call when changed to true
+-- @tparam function callback_false the callback to call when changed to false
-- @treturn table the button object that was made, to allow a custom error event if wanted
function inputs.add_checkbox(name,radio,display,default,callback_true,callback_false)
local type = 'checkbox'; if radio then type='radiobutton' end
@@ -279,7 +281,7 @@ end
-- @tparam string name the name of this button
-- @tparam boolean box is it a text box rather than a text field
-- @tparam string text the starting text
--- @tparam function the callback to call on change function(player,text,element)
+-- @tparam function callback the callback to call on change function(player,text,element)
-- @treturn table the text object that was made, to allow a custom error event if wanted
function inputs.add_text(name,box,text,callback)
local type = 'textfield'; if box then type='text-box' end
@@ -305,10 +307,10 @@ end
--- Used to define a slider callback only on value_changed
-- @usage Gui.inputs.add_slider('test','horizontal',1,10,5,function)
-- @tparam string name the name of this button
--- @tapram string text the caption to go with the slider
+-- @tparam string orientation direction of the slider
-- @tparam number min the lowest number
-- @tparam number max the highest number
--- @param start_callback either a number or a function to return a number
+-- @tparam function start_callback either a number or a function to return a number
-- @tparam function callback the function to be called on value_changed function(player,value,percent,element)
-- @treturn table the slider object that was made, to allow a custom error event if wanted
function inputs.add_slider(name,orientation,min,max,start_callback,callback)
@@ -338,6 +340,7 @@ end
--- Used to define a drop down callback only on value_changed
-- @usage Gui.inputs.add_drop_down('test',{1,2,3},1,function)
+-- @tparam string name name of the drop down
-- @param items either a list or a function which returns a list
-- @param index either a number or a function which returns a number
-- @tparam function callback the callback which is called when a new index is selected function(player,selected,items,element)
diff --git a/ExpCore/GuiParts/toolbar.lua b/ExpCore/GuiParts/toolbar.lua
index f197312e..7c515f9d 100644
--- a/ExpCore/GuiParts/toolbar.lua
+++ b/ExpCore/GuiParts/toolbar.lua
@@ -13,7 +13,7 @@ local toolbar = {}
-- @usage toolbar.add('foo','Foo','Test',function() game.print('test') end)
-- @tparam string name the name of the button
-- @tparam string caption can be a sprite path or text to show
--- @tparma string tooltip the help to show for the button
+-- @tparam string tooltip the help to show for the button
-- @tparam function callback the function which is called on_click
-- @treturn table the button object that was made
function toolbar.add(name,caption,tooltip,callback)
diff --git a/ExpCore/commands.lua b/ExpCore/commands.lua
index 8b6ca10e..f8e9de87 100644
--- a/ExpCore/commands.lua
+++ b/ExpCore/commands.lua
@@ -76,7 +76,7 @@ end
--- Used to call the custom commands
-- @usage You dont its an internal command
--- @tparam defines.events.on_console_command event the event rasied by the command=
+-- @tparam defines.events.on_console_command command the event rasied by the command
local function run_custom_command(command)
local command_data = command_data[command.name]
local player_name = Game.get_player(command) and Game.get_player(command).name or 'server'
diff --git a/ExpCore/gui.lua b/ExpCore/gui.lua
index d5649e79..a3ee80da 100644
--- a/ExpCore/gui.lua
+++ b/ExpCore/gui.lua
@@ -97,14 +97,15 @@ end)
--- Adds a camera that updates every tick (or less depeading on how many are opening) it will move to follow an entity
-- @usage Gui.cam_link{entity=game.player.character,frame=frame,width=50,hight=50,zoom=1}
-- @usage Gui.cam_link{entity=game.player.character,cam=frame.camera,surface=game.surfaces['testing']}
--- @param entity this is the entity that the camera will follow
--- @param[opt] cam a camera that you already have in the gui
--- @param[opt] frame the frame to add the camera to, no effect if cam param is given
--- @param[chain=frame] zoom the zoom to give the new camera
--- @param[chain=frame] width the width to give the new camera
--- @param[chain=frame] height the height to give the new camera
--- @param[opt] surface this will over ride the surface that the camera follows on, allowing for a 'ghost surface' while keeping same position
--- @param[opt] respawn_open if set to true then the camera will auto re link to the player after a respawn
+-- @tparam table data contains all other params given below
+-- @field entity this is the entity that the camera will follow
+-- @field cam a camera that you already have in the gui
+-- @field frame the frame to add the camera to, no effect if cam param is given
+-- @field zoom the zoom to give the new camera
+-- @field width the width to give the new camera
+-- @field height the height to give the new camera
+-- @field surface this will over ride the surface that the camera follows on, allowing for a 'ghost surface' while keeping same position
+-- @field respawn_open if set to true then the camera will auto re link to the player after a respawn
-- @return the camera that the function used be it made or given as a param
function Gui.cam_link(data)
if not data.entity or not data.entity.valid then return end
diff --git a/ExpCore/ranking.lua b/ExpCore/ranking.lua
index bad35ad0..8d0549d2 100644
--- a/ExpCore/ranking.lua
+++ b/ExpCore/ranking.lua
@@ -97,6 +97,7 @@ end
-- @usage Ranking.print('admin','We got a grifer')
-- @param rank_base the rank that acts as the cut off point (rank is always included)
-- @param rtn what do you want to return to the players
+-- @tparam defines.color colour the colour that will be used to print
-- @tparam bolean below if true rank below base are printed to
function Ranking.print(rank_base,rtn,colour,below)
local colour = colour or defines.color.white
@@ -185,7 +186,7 @@ end
--- Given the player has a rank in the preset table it is given
-- @usage Ranking.find_preset(1)
-- @param player the player to test for an auto rank
--- @tparam[opt=nil] tick the tick it happens on
+-- @tparam[opt=nil] number tick the tick it happens on
function Ranking.find_preset(player,tick)
local presets = Ranking._presets().current
local meta_data = Ranking._presets().meta
@@ -250,6 +251,8 @@ end
--- Print a message to all players of this rank
-- @usage rank:print('foo')
-- @param rtn any value you want to return
+-- @tparam define.color colour the colour that will be used to print
+-- @tparam boolean show_default weather to use the default rank name for the print
function Ranking._rank:print(rtn,colour,show_default)
local colour = colour or defines.color.white
local meta_data = Ranking._presets().meta
diff --git a/ExpCore/server.lua b/ExpCore/server.lua
index ed79419c..c765c428 100644
--- a/ExpCore/server.lua
+++ b/ExpCore/server.lua
@@ -63,8 +63,8 @@ end
--- Adds a thread into the resolve queue, can be used to lower lag
-- @usage Server.queue_thread(thread) -- return true/false
--- @tparam table the thread to add to the queue must have a resolve function (must be open)
--- @treturn bolean was the thread added
+-- @tparam table thread_to_queue the thread to add to the queue must have a resolve function (must be open)
+-- @treturn boolean was the thread added
function Server.queue_thread(thread_to_queue)
if not thread_to_queue and not thread_to_queue.valid and not thread_to_queue:valid() then return false end
if not thread_to_queue._resolve then return false end
@@ -87,7 +87,7 @@ function Server.close_all_threads(with_force)
end
--- Runs all the theads which have opened with an on_tick event
--- @ussage Server.run_tick_threads()
+-- @usage Server.run_tick_threads()
function Server.run_tick_threads()
table.each(Server._threads().tick,function(uuid)
local next_thread = Server.get_thread(uuid)
@@ -99,7 +99,7 @@ function Server.run_tick_threads()
end
--- Checks the timeout on all active timeout threads
--- @ussage Server.check_timeouts()
+-- @usage Server.check_timeouts()
function Server.check_timeouts()
table.each(Server._threads().timeout,function(uuid)
local next_thread = Server.get_thread(uuid)
diff --git a/ExpCore/sync.lua b/ExpCore/sync.lua
index dec82cf8..4cfb4aa2 100644
--- a/ExpCore/sync.lua
+++ b/ExpCore/sync.lua
@@ -29,7 +29,7 @@ end
-- @param player_message the message to be printed in chat
-- @param player_name the name of the player sending the message
-- @param[opt] player_tag the tag apllied to the player's name
--- @param[opt] plyaer_colour the colour of the message
+-- @param[opt] player_colour the colour of the message
-- @param[opt] prefix add a prefix before the chat eg [IRC]
function Sync.print(player_message,player_name,player_tag,player_colour,prefix)
if not player_message then return 'No Message Found' end
@@ -53,13 +53,13 @@ end
--- Logs an embed to the json.data we use a js script to add things we cant here
-- @usage Sync.emit_embeded{title='BAN',color='0x0',description='A player was banned' ... }
--- @tparam table arg a table which contains everything that the embeded will use
--- @param[opt=''] title the tile of the embed
--- @param[opt='0x0'] color the color given in hex you can use Color.to_hex{r=0,g=0,b=0}
--- @param[opt=''] description the description of the embed
--- @param[opt=''] server_detail sting to add onto the pre-set server detail
--- @param[opt] fieldone the filed to add to the embed (key is name) (value is text) (start value with <> to make inline)
--- @param[optchain] fieldtwo
+-- @tparam table args a table which contains everything that the embeded will use
+-- @field title the tile of the embed
+-- @field color the color given in hex you can use Color.to_hex{r=0,g=0,b=0}
+-- @field description the description of the embed
+-- @field server_detail sting to add onto the pre-set server detail
+-- @field fieldone the filed to add to the embed (key is name) (value is text) (start value with <> to make inline)
+-- @field fieldtwo the filed to add to the embed (key is name) (value is text) (start value with <> to make inline)
function Sync.emit_embeded(args)
if not is_type(args,'table') then return end
local title = is_type(args.title,'string') and args.title or ''
@@ -166,7 +166,7 @@ end
--- used to return the global list and set values in it
-- @usage Sync.info{server_name='Factorio Server 2'}
--- @tparam[opt=nil] table keys to be replaced in the server info
+-- @tparam[opt=nil] table set keys to be replaced in the server info
-- @return either returns success when setting or the info when not setting
function Sync.info(set)
if not global.exp_core then global.exp_core = {} end
@@ -203,7 +203,7 @@ end
--- used to return the global time and set its value
-- @usage Sync.time('Sun Apr 1 18:44:30 UTC 2018')
--- @tparam[opt=nil] string the date time to be set
+-- @tparam[opt=nil] string set the date time to be set
-- @return either true false if setting or the date time and tick off set
function Sync.time(set)
local info = Sync.info()
@@ -242,8 +242,8 @@ end
--- Adds a callback to be called when the info is updated
-- @usage Sync.add_update('players',function() return #game.players end)
--- @tparam key string the key that the value will be stored in
--- @tparam callback function the function which will return this value
+-- @tparam string key the key that the value will be stored in
+-- @tparam function callback the function which will return this value
function Sync.add_update(key,callback)
if game then return end
if not is_type(callback,'function') then return end
diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua
index 34580b2c..cb1137fb 100644
--- a/FactorioSoftmodManager.lua
+++ b/FactorioSoftmodManager.lua
@@ -1,3 +1,8 @@
+--- Factorio Softmod Manager
+-- @module FSM
+-- @alias Manager
+-- @author Cooldude2606
+-- @usage Manager = require("FactorioSoftmodManager")
-- Used to load all other modules that are indexed in index.lua
local moduleIndex = require("/modules/index")
local Manager = {}
@@ -46,7 +51,7 @@ Manager.currentState = 'selfInit'
--- Default output for the verbose
-- @usage Manager.verbose('Hello, World!')
--- @tparm rtn string the value that will be returned though verbose output
+-- @tparam string rtn the value that will be returned though verbose output
Manager._verbose = function(rtn)
-- creates one file per game, ie clears file on reset
if game and Manager.setVerbose._output ~= true then Manager.setVerbose._output=true game.write_file('verbose.log',rtn)
@@ -58,8 +63,8 @@ end
--- Used to call the output of the verbose when the current state allows it
-- @usage Manager.verbose('Hello, World!')
--- @tparm rtn string the value that will be returned though verbose output
--- @tparm action string is used to decide which verbose this is error || event etc
+-- @tparam string rtn the value that will be returned though verbose output
+-- @tparam string action is used to decide which verbose this is error || event etc
Manager.verbose = function(rtn,action)
local settings = Manager.setVerbose
local state = Manager.currentState
@@ -428,7 +433,9 @@ Manager.event = setmetatable({
end
})
--- Sub set to Manger.event and acts as a coverter between event_name and event_id
+-- @field names
-- @usage Manager.event[event_name] -- see above, can not be accessed via Manager.event.names
+-- @see Manager.event
rawset(Manager.event,'names',setmetatable({},{
__index=function(tbl,key)
if type(key) == 'number' or tonumber(key) then
diff --git a/StdLib/event.lua b/StdLib/event.lua
deleted file mode 100644
index 9a4a380b..00000000
--- a/StdLib/event.lua
+++ /dev/null
@@ -1,172 +0,0 @@
---- Makes working with events in factorio a lot more simple.
---
Factorio can only have one handler registered per event. This module
--- allows you to easily register multiple handlers for each event.
--- Using this module is as simple as replacing script.on_event(...) with Event.register(...)
--- @module Event
--- @usage require('stdlib/event/event')
-
-local Event = { --luacheck: allow defined top
- _registry = {},
- core_events = {
- init = -1,
- load = -2,
- configuration_changed = -3,
- _register = function(id)
- if id == Event.core_events.init then
- script.on_init(
- function()
- Event.dispatch({name = Event.core_events.init, tick = game.tick})
- end
- )
- elseif id == Event.core_events.load then
- script.on_load(
- function()
- Event.dispatch({name = Event.core_events.load, tick = -1})
- end
- )
- elseif id == Event.core_events.configuration_changed then
- script.on_configuration_changed(
- function(event)
- event.name = Event.core_events.configuration_changed
- event.data = event -- for backwards compatibilty
- Event.dispatch(event)
- end
- )
- end
- end
- }
-}
-
---[[ edit by cooldude2606 to allow change during run-time without desyncs -- still going to use this but FACTORIO NO LIKE
-Event.__registry = Event._registry
-Event._registry = function()
- if game and global then
- if not global.event_registry then global.event_registry = Event.__registry end
- return global.event_registry
- end
- return Event.__registry
-end]]
-
---- Registers a function for a given event. If a nil handler is passed remove all events and stop listening for that event.
--- Events are dispatched in the order they are registered.
--- @usage Event.register(defines.events.on_tick, function(event) print event.tick end)
--- -- creates an event that prints the current tick every tick.
--- @tparam defines.events|{defines.events,...} event events to register
--- @tparam function handler Function to call when event is triggered
--- @treturn Event
-function Event.register(event, handler)
- if not _G.Game then error('StdLib/Game not loaded') end
- _G.Game.fail_if_missing(event, "missing event argument")
-
- event = (type(event) == "table" and event) or {event}
-
- for _, event_id in pairs(event) do
- if not (type(event_id) == "number" or type(event_id) == "string") then
- error("Invalid Event Id, Must be string or int, or array of strings and/or ints", 2)
- end
- if handler == nil then
- Event._registry[event_id] = nil
- script.on_event(event_id, nil)
- else
- if not Event._registry[event_id] then
- Event._registry[event_id] = {}
-
- if type(event_id) == "string" or event_id >= 0 then
- script.on_event(event_id, Event.dispatch)
- elseif event_id < 0 then
- Event.core_events._register(event_id)
- end
- end
- table.insert(Event._registry[event_id], handler)
- end
- end
- return Event
-end
-
---- Calls the registerd handlers
--- Will stop dispatching remaning handlers if any handler passes invalid event userdata.
--- Handlers are dispatched in the order they were created
--- @tparam table event LuaEvent as created by script.raise_event
--- @see https://forums.factorio.com/viewtopic.php?t=32039#p202158 Invalid Event Objects
-function Event.dispatch(event)
- if event then
- local _registry = event.name and Event._registry[event.name] or event.input_name and Event._registry[event.input_name]
- if _registry then
- local force_crc = Event.force_crc
- for idx, handler in ipairs(_registry) do
-
- -- Check for userdata and stop processing further handlers if not valid
- for _, val in pairs(event) do
- if type(val) == "table" and val.__self == "userdata" and not val.valid then
- return
- end
- end
-
- setmetatable(event, { __index = { _handler = handler } })
-
- -- Call the handler
- local success, err = pcall(handler, event)
-
- -- If the handler errors lets make sure someone notices
- if not success then
- if _G.game then -- may be nil in on_load
- -- edit by cooldude2606 custom error haddle
- --if Game.print_all(err) == 0 then
- --error(err) -- no players received the message, force a real error so someone notices
- --end
- error(err)
- else
- error(err) -- no way to handle errors cleanly when the game is not up
- end
- -- continue processing the remaning handlers. In most cases they won't be related to the failed code.
- end
-
- -- force a crc check if option is enabled. This is a debug option and will hamper perfomance if enabled
- if (force_crc or event.force_crc) and _G.game then
- local msg = 'CRC check called for event '..event.name..' handler #'..idx
- log(msg) -- log the message to factorio-current.log
- game.force_crc()
- end
-
- -- if present stop further handlers for this event
- if event.stop_processing then
- return
- end
- end
- end
- else
- error('missing event argument')
- end
-end
-
---- Removes the handler from the event. If it removes the last handler for an event stop listening for that event.
--- @tparam defines.events|{defines.events,...} event events to remove the handler for
--- @tparam function handler to remove
--- @return Event
-function Event.remove(event, handler)
- if not _G.Game then error('StdLib/Game not loaded') end
- _G.Game.fail_if_missing(event, "missing event argument")
- _G.Game.fail_if_missing(handler, "missing handler argument")
-
- event = (type(event) == "table" and event) or {event}
-
- for _, event_id in pairs(event) do
- if not (type(event_id) == "number" or type(event_id) == "string") then
- error("Invalid Event Id, Must be string or int, or array of strings and/or ints", 2)
- end
- if Event._registry[event_id] then
- for i=#Event._registry[event_id], 1, -1 do
- if Event._registry[event_id][i] == handler then
- table.remove(Event._registry[event_id], i)
- end
- end
- if #Event._registry[event_id] == 0 then
- Event._registry[event_id] = nil
- script.on_event(event_id, nil)
- end
- end
- end
- return Event
-end
-
-return Event
\ No newline at end of file
diff --git a/control.lua b/control.lua
index fe3b3285..9aba66bc 100644
--- a/control.lua
+++ b/control.lua
@@ -1,3 +1,5 @@
+--- Root Script File
+-- @script control.lua
function _log(...) log(...) end
--[[
Explosive Gaming
@@ -8,8 +10,6 @@ Any changes that you may make to the code are yours but that does not make the s
Discord: https://discord.gg/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
-
--- File Which Factorio Will Call
Manager = require("FactorioSoftmodManager")
Manager.setVerbose{
selfInit=true, -- called while the manager is being set up
diff --git a/doc/index.html b/doc/index.html
new file mode 100644
index 00000000..a9153abb
--- /dev/null
+++ b/doc/index.html
@@ -0,0 +1,155 @@
+
+
+
+
+ Reference
+
+
+
+
+
Makes working with events in factorio a lot more simple.
+
+
Factorio can only have one handler registered per event. This module
+ allows you to easily register multiple handlers for each event.
+ Using this module is as simple as replacing script.on_event(...) with Event.register(...)
+ Registers a function for a given event. If a nil handler is passed remove all events and stop listening for that event.
+ Events are dispatched in the order they are registered.
+
+
+
Parameters:
+
+
event
+ defines.events or {defines.events,...}
+ events to register
+
+
handler
+ function
+ Function to call when event is triggered
+
+
+
+
Returns:
+
+
+ Event
+
+
+
+
+
+
Usage:
+
+
Event.register(defines.events.on_tick, function(event) print event.tick end)
+ -- creates an event that prints the current tick every tick.
+
+
+
+
+
+ dispatch (event)
+
+
+ Calls the registerd handlers
+ Will stop dispatching remaning handlers if any handler passes invalid event userdata.
+ Handlers are dispatched in the order they were created
+
+
+
Parameters:
+
+
event
+ table
+ LuaEvent as created by script.raise_event
+
+
+
+
+
+
See also:
+
+
+
+
+
+
+
+ remove (event, handler)
+
+
+ Removes the handler from the event. If it removes the last handler for an event stop listening for that event.
+
+
+
Parameters:
+
+
event
+ defines.events or {defines.events,...}
+ events to remove the handler for
+
+
handler
+ function
+ to remove
+
+
+
+
Returns:
+
+
+ Event
+
+
+
+
+
+
+
+
+
+
+
+
+generated by LDoc 1.4.6
+Last updated 2018-05-29 20:06:55
+
A more detailed replacement for the lua error function to allow for handlers to be added; repleaces default error so error can be used instead of Manager.error
Sub set to Manger.event and acts as a coverter between event_name and event_id
+
+
+
+
+
+
+
+
Functions
+
+
+
+
+ _verbose (rtn)
+
+
+ Default output for the verbose
+
+
+
Parameters:
+
+
rtn
+ string
+ the value that will be returned though verbose output
+
+
+
+
+
+
+
Usage:
+
+
Manager.verbose('Hello, World!')
+
+
+
+
+
+ verbose (rtn, action)
+
+
+ Used to call the output of the verbose when the current state allows it
+
+
+
Parameters:
+
+
rtn
+ string
+ the value that will be returned though verbose output
+
+
action
+ string
+ is used to decide which verbose this is error || event etc
+
+
+
+
+
+
+
Usage:
+
+
Manager.verbose('Hello, World!')
+
+
+
+
+
Fields
+
+
+
+
+ setVerbose
+
+
+ Main logic for allowing verbose at different stages though out the script
+
+
+
+
table
+ newTbl
+ the table that will be searched for settings to be updated
+
+
+
+
+
+
+
Usage:
+
+
Manager.setVerbose{output=log}
+
Manager.setVerbose[setting] -- returns the value of that setting
+
tostring(Manager.setVerbose) -- returns a formated list of the current settings
+
+
+
+
+
+ sandbox
+
+
+ Creates a sand box envorment and runs a callback in that sand box; provents global pollution
+
+
+
+
function
+ callback
+ the function that will be ran in the sandbox
+
+
any
+ other params that the function will use
+ (optional)
+
+
+
+
+
+
+
Usage:
+
+
Manager.sandbox(callback) -- return sandbox, success, other returns from callback
+
Manager.sandbox() -- returns and empty sandbox
+
Manager.sandbox[key] -- returns the sand box value in that key
+
+
+
+
+
+ loadModules
+
+
+ Loads the modules that are present in the index list
+
+
+
+
+
+
+
Usage:
+
+
Manager.loadModules() -- loads all moddules in the index list
+
#Manager.loadModules -- returns the number of modules loaded
+
tostring(Manager.loadModules) -- returns a formatted list of all modules loaded
+
pairs(Manager.loadModules) -- loops over the loaded modules moduleName, module
+
+
+
+
+
+ error
+
+
+ A more detailed replacement for the lua error function to allow for handlers to be added; repleaces default error so error can be used instead of Manager.error
+
+
+
+
string
+ name
+ || fucntion the name that is given to the callback || the callback that will be used
+
+
string
+ name
+ || fucntion the name that is given to the callback || the callback that will be used
+
+
function
+ callback
+ if name is given as a string this will be the callback used
+
+
+
+
+
+
+
Usage:
+
+
Manager.error(err) -- calls all error handlers that are set or if none then prints to game and if that fails crashs game
+
Manager.error() -- returns an error constant that can be used to crash game
+
Manager.error(Manager.error()) -- crashs the game
+
Manager.error.addHandler(name,callback) -- adds a new handler if handler returns Manager.error() then game will crash
+
Manager.error[name] -- returns the handler of that name if present
+
#Manager.error-- returns the number of error handlers that are present
+
pairs(Manager.error) -- loops over only the error handlers handler_name,hander
+
+
+
+
+
+ names
+
+
+ Sub set to Manger.event and acts as a coverter between event_name and event_id
+
+
+
+
names
+
+
+
+
+
+
+
See also:
+
+
+
+
Usage:
+
+
Manager.event[event_name] -- see above, can not be accessed via Manager.event.names
+
+
+
+
+
+
+
+
+
+generated by LDoc 1.4.6
+Last updated 2018-05-29 20:15:05
+
+ Messages all players currently connected to the game.
+> Offline players are not counted as having received the message.
+ If no players exist msg is stored in the `global._print_queue` table.
+
+
+
+ Given a string or function it will run that function and return any values
+
+
+
Parameters:
+
+
callback
+ either a function or string which will be ran via pcall
+
+
use_thread
+ give a thread for the interface to run on (does not need to be open, but cant use on_resolve)
+ (optional)
+
+
...
+ any args you want to pass to the function
+ (optional)
+
+
+
+
+
+
+
Usage:
+
+
Server.interface('local x = 1+1 print(x) return x') -- return 2
+ Server.interface('local x = 1+1 print(x)',thread) -- no return
+
+
+
+
+
+ Server._thread:valid (skip_location_check)
+
+
+ Test if the thread has all requied parts
+
+
+
Parameters:
+
+
skip_location_check
+ bolean
+ true to skip the location check
+
+
+
+
Returns:
+
+
+ bolean
+ is the thread valid
+
+
+
+
+
Usage:
+
+
if thread:valid() thenend
+
+
+
+
+
+ Server._thread:open ()
+
+
+ Opens the thread by storing it in a place the server object can find it
+
+
+
+
Returns:
+
+
+ bolean
+ if the thread was opened
+
+
+
+
+
Usage:
+
+
thread:open() -- return true
+
+
+
+
+
+ Server._thread:close ()
+
+
+ Inverse of thread:open() - it removes the thread and calles on_close
+
+
+
+
Returns:
+
+
+ bolean
+ if the thread had a on_close function
+
+
+
+
+
Usage:
+
+
thread:close() -- return true
+
+
+
+
+
+ Server._thread:resolve ([...])
+
+
+ Trigger the on_resolve function and closes the thread - error and success called based on result of pcall (useful for async)
+
+
+
Parameters:
+
+
...
+ any arguments you want to pass to the resolve function
+ (optional)
+
+
+
+
Returns:
+
+
+ bolean
+ true if the thread called on_success or on_error
+
+
+
+
+
Usage:
+
+
thread:resolve(x,y,z) -- return true
+
+
+
+
+
+ Server._thread:check_timeout ()
+
+
+ Checks the timeout on a thread - if timedout then it calles on_timeout and closes
+
+
+
+
Returns:
+
+
+ bolean
+ if the thread timedout
+
+
+
+
+
Usage:
+
+
thread:check_timeout() -- return true
+
+
+
+
+
+ Server._thread:error (err)
+
+
+ Rasies an error on this thread
+
+
+
Parameters:
+
+
err
+ the err to be rasied
+
+
+
+
Returns:
+
+
+ bolean
+ did the thread handdle the error
+
+
+
+
+
Usage:
+
+
thread:error(err) -- return true
+
+
+
+
+
+ Server._thread:on_event (event, callback)
+
+
+ Set function to run then an event is called on a thread, none of them are 'needed' but you are advised to have atleast one
+
+
+
Parameters:
+
+
event
+ string
+ the name of the event that it is called on
+
+
callback
+ function
+ the function which is called on the event
+
+
+
+
Returns:
+
+
+ table
+ returns self so that there can be chained
+
+
+
+
+
Usage:
+
+
thread:on_event('close',function) -- return true
+events = ['close','timeout','tick','resolve','success','error']
+if event is a number then it is asumed to be a game event
+
+
+
+
+
+
+
+
+
+generated by LDoc 1.4.6
+Last updated 2018-05-29 20:15:05
+
Given a mapping function, creates a transformed copy of the table
+ by calling the function for each element in the table, and using
+ the result as the new value for the key.
Given a filter function, creates a filtered copy of the table
+ by calling the function for each element in the table, and
+ filtering out any key-value pairs for non-true results.
Given a candidate search function, iterates over the table, calling the function
+ for each element in the table, and returns the first element the search function returned true.
Given a candidate search function, iterates over the table, calling the function
+ for each element in the table, and returns true if search function returned true.
Returns the list is a sorted way that would be expected by people (this is by key) (faster alterative than above)
+
+
+
+
+
+
+
+
Functions
+
+
+
+
+ map (tbl, func[, ...])
+
+
+ Given a mapping function, creates a transformed copy of the table
+ by calling the function for each element in the table, and using
+ the result as the new value for the key. Passes the index as second argument to the function.
+
+
+
Parameters:
+
+
tbl
+ table
+ the table to be mapped to the transform
+
+
func
+ function
+ the function to transform values
+
+
...
+ additional arguments passed to the function
+ (optional)
+
+
+
+
Returns:
+
+
+ table
+ a new table containing the keys and mapped values
+
+
+
+
+
a = {1, 2, 3, 4, 5}
+table.map(a, function(v, k, x) return v * k + x end, 100) --produces { 101, 104, 109, 116, 125}
+
+
+
+
+
+ filter (tbl, func[, ...])
+
+
+ Given a filter function, creates a filtered copy of the table
+ by calling the function for each element in the table, and
+ filtering out any key-value pairs for non-true results. Passes the index as second argument to the function.
+
+
+
+ Given a candidate search function, iterates over the table, calling the function
+ for each element in the table, and returns the first element the search function returned true.
+ Passes the index as second argument to the function.
+
+
+
a = {1, 2, 3, 4, 5}
+table.find(a, function(v, k, x) return k % 2 == 1end) --produces: 1
+
+
+
+
+
+ any (tbl, func[, ...])
+
+
+ Given a candidate search function, iterates over the table, calling the function
+ for each element in the table, and returns true if search function returned true.
+ Passes the index as second argument to the function.
+
+
+
+ Returns a new array that is a one-dimensional recursive flattening of the given array.
+ For every element that is an array, extract its elements into the new array.
+
The optional level argument determines the level of recursion to flatten.
+> This function flattens an integer-indexed array, but not an associative array.
+
+
+
Parameters:
+
+
tbl
+ array
+ the array to be flattened
+
+
level
+ uint
+ recursive levels, or no limit to recursion if not supplied
+ (optional)
+
+
+
+
Returns:
+
+
+ array
+ a new array that represents the flattened contents of the given array
+
+
+
+
+
+
+
+
+ first (tbl)
+
+
+ Given an array, returns the first element or nil if no element exists.
+
+
+
Parameters:
+
+
tbl
+ array
+ the array
+
+
+
+
Returns:
+
+
+ nil or Mixed
+ the first element
+
+
+
+
+
+
+
+
+ last (tbl)
+
+
+ Given an array, returns the last element or nil if no elements exist.
+
+
+
Parameters:
+
+
tbl
+ array
+ the array
+
+
+
+
Returns:
+
+
+ nil or Mixed
+ the last element or nil
+
+
+
+
+
+
+
+
+ min (tbl)
+
+
+ Given an array of only numeric values, returns the minimum or nil if no element exists.
+
+
+
Parameters:
+
+
tbl
+ {number,...}
+ the array with only numeric values
+
+
+
+
Returns:
+
+
+ nil or number
+ the minimum value
+
+
+
+
+
+
+
+
+ max (tbl)
+
+
+ Given an array of only numeric values, returns the maximum or nil if no element exists.
+
+
+
Parameters:
+
+
tbl
+ {number,...}
+ the array with only numeric values
+
+
+
+
Returns:
+
+
+ nil or number
+ the maximum value
+
+
+
+
+
+
+
+
+ sum (tbl)
+
+
+ Given an array of only numeric values, return the sum of all values, or 0 for empty arrays.
+
+
+
Parameters:
+
+
tbl
+ {number,...}
+ the array with only numeric values
+
+
+
+
Returns:
+
+
+ number
+ the sum of the numbers or zero if the given array was empty
+
+
+
+
+
+
+
+
+ avg (tbl)
+
+
+ Given an array of only numeric values, returns the average or nil if no element exists.
+
+
+
Parameters:
+
+
tbl
+ {number,...}
+ the array with only numeric values
+
+
+
+
Returns:
+
+
+ nil or number
+ the average value
+
+
+
+
+
+
+
+
+ merge (tblA, tblB[, array_merge=false])
+
+
+ Merges two tables — values from first get overwritten by the second.
+
+
+
array_merge
+ boolean
+ set to true to merge the tables as an array or false for an associative array
+ (default false)
+
+
+
+
Returns:
+
+
+ array or table
+ an array or an associated array where tblA and tblB have been merged
+
+
+
+
+
Usage:
+
+
function some_func(x, y, args)
+ args = table.merge({option1=false}, args)
+ if opts.option1 == truethenreturn x elsereturn y end
+end
+some_func(1,2) -- returns 2
+some_func(1,2,{option1=true}) -- returns 1
+
+
+
+
+
+ deepcopy (object)
+
+
+ Creates a deep copy of table without copying Factorio objects.
+
+
+
func
+ function
+ to incremement counter
+ (optional)
+
+
...
+ additional arguments passed to the function
+ (optional)
+
+
+
+
Returns:
+
+
+ number
+ The number of keys matching the function or the number of all keys if func isn't passed
+
+ number
+ The total number of keys
+
+
+
+
+
Usage:
+
+
local a = { 1, 2, 3, 4, 5}
+ table.count_keys(a) -- produces: 5, 5
+
local a = {1, 2, 3, 4, 5}
+ table.count_keys(a, function(v, k) return k % 2 == 1end) -- produces: 3, 5
+
+
+
+
+
+ invert (tbl)
+
+
+ Returns an inverted (***{[value] = key,...}***) copy of the given table. If the values are not unique, the assigned key depends on the order of pairs().
+
+
+
+generated by LDoc 1.4.6
+Last updated 2018-05-29 20:15:05
+
+
+
+
diff --git a/modules/ExpGamingLib/control.lua b/modules/ExpGamingLib/control.lua
index bc691e93..8be5f427 100644
--- a/modules/ExpGamingLib/control.lua
+++ b/modules/ExpGamingLib/control.lua
@@ -7,12 +7,16 @@ Any changes that you may make to the code are yours but that does not make the s
Discord: https://discord.gg/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
+--- Adds some common functions used though out all ExpGaming modules
+-- @module ExpGamingLib
+-- @alias ExpLib
+-- @author Cooldude2606
local module_verbose = false -- there is no verbose in this file so true will do nothing
local ExpLib = {}
--- Loads a table into _G even when sandboxed; will not overwrite values or append to tables; will not work during runtime to avoid desyncs
-- @usage unpack_to_G{key1='foo',key2='bar'}
--- @tparam table tbl -- table to be unpacked
+-- @tparam table tbl table to be unpacked
function ExpLib.unpack_to_G(tbl)
if not type(tbl) == 'table' or game then return end
for key,value in pairs(tbl) do
@@ -21,8 +25,8 @@ function ExpLib.unpack_to_G(tbl)
end
--- Used to get the current ENV with all _G keys removed; useful when saving function to global
--- @usage get_env() -- returns current ENV with _G keys removed
--- @treturn table -- the env table with _G keys removed
+-- @usage get_env() returns current ENV with _G keys removed
+-- @treturn table the env table with _G keys removed
function ExpLib.get_env()
local level = 2
local env = setmetatable({},{__index=_G})
@@ -43,9 +47,9 @@ end
--- Compear types faster for faster valadation of prams
-- @usage is_type('foo','string') -- return true
-- @usage is_type('foo') -- return false
--- @param v -- the value to be tested
--- @tparam[opt=nil] string test_type -- the type to test for if not given then it tests for nil
--- @treturn bolean -- is v of type test_type
+-- @param v the value to be tested
+-- @tparam[opt=nil] string test_type the type to test for if not given then it tests for nil
+-- @treturn bolean is v of type test_type
function ExpLib.is_type(v,test_type)
return test_type and v and type(v) == test_type or not test_type and not v or false
end
@@ -54,9 +58,9 @@ end
-- @usage player_return('Hello, World!') -- returns 'Hello, World!' to game.player or server console
-- @usage player_return('Hello, World!','green') -- returns 'Hello, World!' to game.player with colour green or server console
-- @usage player_return('Hello, World!',nil,player) -- returns 'Hello, World!' to the given player
--- @param rtn -- any value of any type that will be returned to the player or console
--- @tparam[opt=defines.colour.white] defines.color || string colour -- the colour of the text for the player, ingroned when printing to console
--- @tparam[opt=game.player] LuaPlayer player -- the player that return will go to, if no game.player then returns to server
+-- @param rtn any value of any type that will be returned to the player or console
+-- @tparam[opt=defines.colour.white] ?defines.color|string colour the colour of the text for the player, ingroned when printing to console
+-- @tparam[opt=game.player] LuaPlayer player the player that return will go to, if no game.player then returns to server
function ExpLib.player_return(rtn,colour,player)
local colour = ExpLib.is_type(colour) == 'table' and colour or defines.color[colour]
local player = player or game.player
@@ -84,8 +88,8 @@ end
--- Convert ticks to hours
-- @usage tick_to_hour(216001) -- return 1
--- @tparam number tick -- tick to convert to hours
--- @treturn number -- the number of whole hours from this tick
+-- @tparam number tick tick to convert to hours
+-- @treturn number the number of whole hours from this tick
function ExpLib.tick_to_hour(tick)
if not ExpLib.is_type(tick,'number') then return 0 end
return math.floor(tick/(216000*game.speed))
@@ -93,8 +97,8 @@ end
--- Convert ticks to minutes
-- @usage tick_to_hour(3601) -- return 1
--- @tparam number tick -- tick to convert to minutes
--- @treturn number -- the number of whole minutes from this tick
+-- @tparam number tick tick to convert to minutes
+-- @treturn number the number of whole minutes from this tick
function ExpLib.tick_to_min (tick)
if not ExpLib.is_type(tick,'number') then return 0 end
return math.floor(tick/(3600*game.speed))
@@ -103,8 +107,8 @@ end
--- Converts a tick into a clean format for end user
-- @usage tick_to_display_format(3600) -- return '1.00 M'
-- @usage tick_to_display_format(234000) -- return '1 H 5 M'
--- @tparam number tick -- the tick to convert
--- @treturn string -- the formated string
+-- @tparam number tick the tick to convert
+-- @treturn string the formated string
function ExpLib.tick_to_display_format(tick)
if not ExpLib.is_type(tick,'number') then return '0H 0M' end
if ExpLib.tick_to_min(tick) < 10 then
@@ -118,9 +122,9 @@ function ExpLib.tick_to_display_format(tick)
end
--- Used as a way to view the structure of a gui, used for debuging
--- @usage Gui_tree(root) -- returns all children of gui recusivly
--- @tparam LuaGuiElement root -- the root to start the tree from
--- @treturn table -- the table that describes the gui
+-- @usage Gui_tree(root) returns all children of gui recusivly
+-- @tparam LuaGuiElement root the root to start the tree from
+-- @treturn table the table that describes the gui
function ExpLib.gui_tree(root)
if not ExpLib.is_type(root,'table') or not root.valid then error('Invalid Gui Element given to gui_tree',2) end
local tree = {}
diff --git a/StdLib/LICENSE b/modules/FactorioStdLib/LICENSE
similarity index 100%
rename from StdLib/LICENSE
rename to modules/FactorioStdLib/LICENSE
diff --git a/StdLib/color.lua b/modules/FactorioStdLib/color.lua
similarity index 97%
rename from StdLib/color.lua
rename to modules/FactorioStdLib/color.lua
index 54aa9376..6daa0d1b 100644
--- a/StdLib/color.lua
+++ b/modules/FactorioStdLib/color.lua
@@ -2,7 +2,6 @@
-- Extends the Factorio defines table.
-- @usage require('stdlib/defines/color')
-- @module defines.color
--- @see Concepts.Color
-- defines table is automatically required in all mod loading stages.
-- luacheck: ignore 122/defines
@@ -210,10 +209,6 @@ setmetatable(defines.anticolor, _mt.anticolor)
setmetatable(defines.text_color, _mt.text_color)
setmetatable(defines.lightcolor, _mt.lightcolor)
---- For playing with colors.
--- @module Color
--- @usage local Color = require('stdlib/color/color')
-
local Color = {} --luacheck: allow defined top
--- Set a value for the alpha channel in the given color table.
@@ -234,7 +229,7 @@ function Color.set(color, alpha)
end
--- Converts a color in the array format to a color in the table format.
--- @tparam array c_arr the color to convert — { [1] = @{float}, [2] = @{float}, [3] = @{float}, [4] = @{float} }
+-- @tparam table c_arr the color to convert
-- @treturn Concepts.Color a converted color — { r = c\_arr[1], g = c\_arr[2], b = c\_arr[3], a = c\_arr[4] }
function Color.to_table(c_arr)
if #c_arr > 0 then
diff --git a/StdLib/game.lua b/modules/FactorioStdLib/game.lua
similarity index 100%
rename from StdLib/game.lua
rename to modules/FactorioStdLib/game.lua
diff --git a/StdLib/load.lua b/modules/FactorioStdLib/load.lua
similarity index 100%
rename from StdLib/load.lua
rename to modules/FactorioStdLib/load.lua
diff --git a/modules/FactorioStdLib/softmod.json b/modules/FactorioStdLib/softmod.json
new file mode 100644
index 00000000..db47a8a3
--- /dev/null
+++ b/modules/FactorioStdLib/softmod.json
@@ -0,0 +1,14 @@
+{
+ "name": "FactorioStdLib",
+ "module": "StdLib",
+ "description": "Factorio Standard Library Projects",
+ "keywords": ["Standard Library","Lib","StdLib"],
+ "version": "0.8.0",
+ "location": "nil",
+ "submodules": {
+
+ },
+ "author": "Afforess",
+ "contact": "https://github.com/Afforess/Factorio-Stdlib/issues",
+ "license": "https://github.com/Afforess/Factorio-Stdlib/blob/master/LICENSE"
+}
\ No newline at end of file
diff --git a/StdLib/string.lua b/modules/FactorioStdLib/string.lua
similarity index 100%
rename from StdLib/string.lua
rename to modules/FactorioStdLib/string.lua
diff --git a/StdLib/table.lua b/modules/FactorioStdLib/table.lua
similarity index 99%
rename from StdLib/table.lua
rename to modules/FactorioStdLib/table.lua
index 783507b6..958cb21b 100644
--- a/StdLib/table.lua
+++ b/modules/FactorioStdLib/table.lua
@@ -498,7 +498,7 @@ end
--- Returns the list is a sorted way that would be expected by people (this is by key)
-- @usage tbl = table.alphanumsort(tbl)
--- @tparam tbl table the table to be sorted
+-- @tparam table tbl the table to be sorted
-- @treturn table the sorted table
function table.alphanumsort(tbl)
local o = table.keys(tbl)
@@ -514,7 +514,7 @@ end
--- Returns the list is a sorted way that would be expected by people (this is by key) (faster alterative than above)
-- @usage tbl = table.alphanumsort(tbl)
--- @tparam tbl table the table to be sorted
+-- @tparam table tbl the table to be sorted
-- @treturn table the sorted table
function table.keysort(tbl)
local o = table.keys(tbl,true)
diff --git a/StdLib/time.lua b/modules/FactorioStdLib/time.lua
similarity index 100%
rename from StdLib/time.lua
rename to modules/FactorioStdLib/time.lua
diff --git a/modules/index.lua b/modules/index.lua
index da98a4a0..2dabc4dc 100644
--- a/modules/index.lua
+++ b/modules/index.lua
@@ -1,3 +1,5 @@
+--- Used to index the files to be loaded
+-- @script index.lua
return {
['ExpLib']='/modules/ExpGamingLib/control',
}
\ No newline at end of file
From 0ec7bb919eba62d3a276f0b99ddceced05f8b971 Mon Sep 17 00:00:00 2001
From: Cooldude2606
Date: Tue, 29 May 2018 20:57:30 +0100
Subject: [PATCH 004/231] Code Doc Changes
---
FactorioSoftmodManager.lua | 34 ++++++++++++++++++++------------
modules/ExpGamingLib/control.lua | 1 +
modules/FactorioStdLib/color.lua | 3 ++-
3 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua
index cb1137fb..2644ace4 100644
--- a/FactorioSoftmodManager.lua
+++ b/FactorioSoftmodManager.lua
@@ -3,9 +3,9 @@
-- @alias Manager
-- @author Cooldude2606
-- @usage Manager = require("FactorioSoftmodManager")
--- Used to load all other modules that are indexed in index.lua
local moduleIndex = require("/modules/index")
local Manager = {}
+
--- Setup for metatable of the Manager to force read only nature
-- @usage Manager() -- runs Manager.loadModdules()
-- @usage Manager[name] -- returns module by that name
@@ -35,6 +35,7 @@ local ReadOnlyManager = setmetatable({},{
return tostring(Manager.loadModules)
end
})
+
local function setupModuleName(name)
-- creates a table that acts like a string but is read only
return setmetatable({},{
@@ -84,8 +85,9 @@ Manager.verbose = function(rtn,action)
end
--- Main logic for allowing verbose at different stages though out the script
+-- @function Manager.setVerbose
-- @usage Manager.setVerbose{output=log}
--- @tparam newTbl table the table that will be searched for settings to be updated
+-- @tparam newTbl settings the table that will be searched for settings to be updated
-- @usage Manager.setVerbose[setting] -- returns the value of that setting
-- @usage tostring(Manager.setVerbose) -- returns a formated list of the current settings
Manager.setVerbose = setmetatable(
@@ -101,9 +103,9 @@ Manager.setVerbose = setmetatable(
},
{
__metatable=false,
- __call=function(tbl,newTbl)
+ __call=function(tbl,settings)
-- does not allow any new keys, but will override any existing ones
- for key,value in pairs(newTbl) do
+ for key,value in pairs(settings) do
if rawget(tbl,key) ~= nil then
Manager.verbose('Verbose for: "'..key..'" has been set to: '..tostring(value))
rawset(tbl,key,value)
@@ -134,9 +136,10 @@ Manager.setVerbose = setmetatable(
Manager.verbose('Current state is now: "selfInit"; The verbose state is: '..tostring(Manager.setVerbose.selfInit),true)
--- Creates a sand box envorment and runs a callback in that sand box; provents global pollution
+-- @function Manager.sandbox
-- @usage Manager.sandbox(callback) -- return sandbox, success, other returns from callback
--- @tparam callback function the function that will be ran in the sandbox
--- @param[opt] any other params that the function will use
+-- @tparam function callback the function that will be ran in the sandbox
+-- @param[opt] env any other params that the function will use
-- @usage Manager.sandbox() -- returns and empty sandbox
-- @usage Manager.sandbox[key] -- returns the sand box value in that key
Manager.sandbox = setmetatable({
@@ -165,6 +168,7 @@ Manager.sandbox = setmetatable({
})
--- Loads the modules that are present in the index list
+-- @function Manager.loadModules
-- @usage Manager.loadModules() -- loads all moddules in the index list
-- @usage #Manager.loadModules -- returns the number of modules loaded
-- @usage tostring(Manager.loadModules) -- returns a formatted list of all modules loaded
@@ -259,13 +263,13 @@ Manager.loadModules = setmetatable({},
)
--- A more detailed replacement for the lua error function to allow for handlers to be added; repleaces default error so error can be used instead of Manager.error
+-- @function Manager.error
-- @usage Manager.error(err) -- calls all error handlers that are set or if none then prints to game and if that fails crashs game
--- @tparam err string the err string that will be passed to the handlers
-- @usage Manager.error() -- returns an error constant that can be used to crash game
-- @usage Manager.error(Manager.error()) -- crashs the game
-- @usage Manager.error.addHandler(name,callback) -- adds a new handler if handler returns Manager.error() then game will crash
--- @tparam name string || fucntion the name that is given to the callback || the callback that will be used
--- @tparam[opt:type(name)=='function'] callback function if name is given as a string this will be the callback used
+-- @tparam[2] ?string|fucntion err the string to be passed to handlers; if a function it will register a handler
+-- @tparam[2] function callback if given the err param will be used to given the handler a name
-- @usage Manager.error[name] -- returns the handler of that name if present
-- @usage #Manager.error -- returns the number of error handlers that are present
-- @usage pairs(Manager.error) -- loops over only the error handlers handler_name,hander
@@ -339,14 +343,16 @@ Manager.error = setmetatable({
error=Manager.error
-- event does work a bit differnt from error, and if event breaks error is the fallback
+
--- Event handler that modules can use, each module can register one function per event
+-- @function Manager.event
-- @usage Manager.event[event_name] = callback -- sets the callback for that event
-- @usage Manager.event[event_name] = nil -- clears the callback for that event
-- @usage Manager.event(event_name,callback) -- sets the callback for that event
-- @usage Manager.event[event_name] -- returns the callback for that event or the event id if not registered
-- @usage Manager.event(event_name) -- runs all the call backs for that event
--- @tparam event_name int|string index that referes to an event
--- @tparam callback function the function that will be set for that event
+-- @tparam ?int|string event_name that referes to an event
+-- @tparam function callback the function that will be set for that event
-- @usage Manager.event() -- returns the stop value for the event proccessor, if returned during an event will stop all other callbacks
-- @usage #Manager.event -- returns the number of callbacks that are registered
-- @usage pairs(Manager.events) -- returns event_id,table of callbacks
@@ -432,9 +438,10 @@ Manager.event = setmetatable({
return next_pair, tbl, nil
end
})
+
--- Sub set to Manger.event and acts as a coverter between event_name and event_id
--- @field names
--- @usage Manager.event[event_name] -- see above, can not be accessed via Manager.event.names
+-- @table Manager.event.names
+-- @usage Manager.event[event_name]
-- @see Manager.event
rawset(Manager.event,'names',setmetatable({},{
__index=function(tbl,key)
@@ -460,6 +467,7 @@ rawset(Manager.event,'names',setmetatable({},{
else return rawget(rawget(Manager.event,'events'),key) end
end
}))
+
--over rides for the base values; can be called though Event
Event=setmetatable({},{__index=function(tbl,key) return Manager.event[key] or script[key] or error('Invalid Index To Table Event') end})
script.mod_name = setmetatable({},{
diff --git a/modules/ExpGamingLib/control.lua b/modules/ExpGamingLib/control.lua
index 8be5f427..8be81b65 100644
--- a/modules/ExpGamingLib/control.lua
+++ b/modules/ExpGamingLib/control.lua
@@ -7,6 +7,7 @@ Any changes that you may make to the code are yours but that does not make the s
Discord: https://discord.gg/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
+
--- Adds some common functions used though out all ExpGaming modules
-- @module ExpGamingLib
-- @alias ExpLib
diff --git a/modules/FactorioStdLib/color.lua b/modules/FactorioStdLib/color.lua
index 6daa0d1b..e2c32318 100644
--- a/modules/FactorioStdLib/color.lua
+++ b/modules/FactorioStdLib/color.lua
@@ -1,7 +1,8 @@
--- A defines module for retrieving colors by name.
-- Extends the Factorio defines table.
-- @usage require('stdlib/defines/color')
--- @module defines.color
+-- @module Color
+-- @alias defines.color
-- defines table is automatically required in all mod loading stages.
-- luacheck: ignore 122/defines
From 3939b137594ac96a798360c15bf0302b417bccdc Mon Sep 17 00:00:00 2001
From: Cooldude2606
Date: Tue, 29 May 2018 22:00:25 +0100
Subject: [PATCH 005/231] Added Module: FactorioStdLib
---
FactorioSoftmodManager.lua | 4 +-
doc/index.html | 12 +-
doc/ldoc.css | 501 ++++++++---------
doc/modules/Color.html | 519 ++++++++++++++++++
...minglib.control.html => ExpGamingLib.html} | 86 ++-
doc/modules/FSM.html | 121 ++--
doc/modules/Game.html | 6 +-
doc/modules/defines.color.html | 4 +-
doc/modules/defines.time.html | 6 +-
doc/modules/expcore.commands.html | 6 +-
doc/modules/expcore.gui.html | 6 +-
doc/modules/expcore.guiparts.center.html | 6 +-
doc/modules/expcore.guiparts.inputs.html | 6 +-
doc/modules/expcore.guiparts.left.html | 6 +-
doc/modules/expcore.guiparts.popup.html | 6 +-
doc/modules/expcore.guiparts.toolbar.html | 6 +-
doc/modules/expcore.ranking.html | 6 +-
doc/modules/expcore.server.html | 6 +-
doc/modules/expcore.sync.html | 6 +-
doc/modules/string.html | 6 +-
doc/modules/table.html | 6 +-
doc/scripts/control.lua.html | 6 +-
doc/scripts/index.lua.html | 6 +-
modules/ExpGamingLib/control.lua | 2 +-
modules/FactorioStdLib/color.lua | 103 +---
modules/FactorioStdLib/load.lua | 36 --
modules/FactorioStdLib/softmod.json | 46 +-
modules/FactorioStdLib/string.lua | 4 +-
modules/FactorioStdLib/table.lua | 4 +-
modules/FactorioStdLib/time.lua | 3 +-
modules/index.lua | 5 +
31 files changed, 1013 insertions(+), 533 deletions(-)
create mode 100644 doc/modules/Color.html
rename doc/modules/{modules.expgaminglib.control.html => ExpGamingLib.html} (78%)
delete mode 100644 modules/FactorioStdLib/load.lua
diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua
index 2644ace4..c3660234 100644
--- a/FactorioSoftmodManager.lua
+++ b/FactorioSoftmodManager.lua
@@ -70,8 +70,8 @@ Manager.verbose = function(rtn,action)
local settings = Manager.setVerbose
local state = Manager.currentState
-- if ran in a module the the global module_name is present
- if module_name then rtn='['..module_name..'] '..rtn
- else rtn='[FSM] '..rtn end
+ if module_name then rtn='['..module_name..'] '..tostring(rtn)
+ else rtn='[FSM] '..tostring(rtn) end
-- module_verbose is a local override for a file, action is used in the manager to describe an extra type, state is the current state
-- if action is true then it will always trigger verbose
if module_verbose or action and (action == true or settings[action]) or settings[state] then
diff --git a/doc/index.html b/doc/index.html
index a9153abb..3856ff87 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -42,8 +42,8 @@