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 + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ + + +

Modules

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
expcore.guiparts.centerAdds a new obj to the center gui
expcore.guiparts.inputsSets the input to trigger on an certain event
expcore.guiparts.leftUsed to add a left gui frame
expcore.guiparts.popupUsed to add a popup gui style
expcore.guiparts.toolbarAdd a button to the toolbar, ranks need to be allowed to use these buttons if ranks is preset
expcore.commandsUses a commands data to return the inputs as a string
expcore.guiAdd a white bar to any gui frame
expcore.rankingReturns a rank object given a player or rank name
expcore.serverReturns a un-used uuid (better system needed)
expcore.syncUsed as a faster way to get to the ranking function, overrides previous
FSMFactorio Softmod Manager
modules.expgaminglib.controlLoads a table into _G even when sandboxed; will not overwrite values or append to tables; will not work during runtime to avoid desyncs
defines.colorA defines module for retrieving colors by name.
GameThe game module.
stringExtends Lua 5.2 string.
tableExtends Lua 5.2 table.
defines.timeA defines module for retrieving the number of ticks in 1 unit of time.
+

Scripts

+ + + + + + + + + +
control.luaRoot Script File
index.luaUsed to index the files to be loaded
+ +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/ldoc.css b/doc/ldoc.css new file mode 100644 index 00000000..52c4ad2b --- /dev/null +++ b/doc/ldoc.css @@ -0,0 +1,303 @@ +/* BEGIN RESET + +Copyright (c) 2010, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.com/yui/license.html +version: 2.8.2r1 +*/ +html { + color: #000; + background: #FFF; +} +body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td { + margin: 0; + padding: 0; +} +table { + border-collapse: collapse; + border-spacing: 0; +} +fieldset,img { + border: 0; +} +address,caption,cite,code,dfn,em,strong,th,var,optgroup { + font-style: inherit; + font-weight: inherit; +} +del,ins { + text-decoration: none; +} +li { + margin-left: 20px; +} +caption,th { + text-align: left; +} +h1,h2,h3,h4,h5,h6 { + font-size: 100%; + font-weight: bold; +} +q:before,q:after { + content: ''; +} +abbr,acronym { + border: 0; + font-variant: normal; +} +sup { + vertical-align: baseline; +} +sub { + vertical-align: baseline; +} +legend { + color: #000; +} +input,button,textarea,select,optgroup,option { + font-family: inherit; + font-size: inherit; + font-style: inherit; + font-weight: inherit; +} +input,button,textarea,select {*font-size:100%; +} +/* END RESET */ + +body { + margin-left: 1em; + margin-right: 1em; + font-family: arial, helvetica, geneva, sans-serif; + background-color: #ffffff; margin: 0px; +} + +code, tt { font-family: monospace; font-size: 1.1em; } +span.parameter { font-family:monospace; } +span.parameter:after { content:":"; } +span.types:before { content:"("; } +span.types:after { content:")"; } +.type { font-weight: bold; font-style:italic } + +body, p, td, th { font-size: .95em; line-height: 1.2em;} + +p, ul { margin: 10px 0 0 0px;} + +strong { font-weight: bold;} + +em { font-style: italic;} + +h1 { + font-size: 1.5em; + margin: 20px 0 20px 0; +} +h2, h3, h4 { margin: 15px 0 10px 0; } +h2 { font-size: 1.25em; } +h3 { font-size: 1.15em; } +h4 { font-size: 1.06em; } + +a:link { font-weight: bold; color: #004080; text-decoration: none; } +a:visited { font-weight: bold; color: #006699; text-decoration: none; } +a:link:hover { text-decoration: underline; } + +hr { + color:#cccccc; + background: #00007f; + height: 1px; +} + +blockquote { margin-left: 3em; } + +ul { list-style-type: disc; } + +p.name { + font-family: "Andale Mono", monospace; + padding-top: 1em; +} + +pre { + background-color: rgb(245, 245, 245); + border: 1px solid #C0C0C0; /* silver */ + padding: 10px; + margin: 10px 0 10px 0; + overflow: auto; + font-family: "Andale Mono", monospace; +} + +pre.example { + font-size: .85em; +} + +table.index { border: 1px #00007f; } +table.index td { text-align: left; vertical-align: top; } + +#container { + margin-left: 1em; + margin-right: 1em; + background-color: #f0f0f0; +} + +#product { + text-align: center; + border-bottom: 1px solid #cccccc; + background-color: #ffffff; +} + +#product big { + font-size: 2em; +} + +#main { + background-color: #f0f0f0; + border-left: 2px solid #cccccc; +} + +#navigation { + float: left; + width: 14em; + vertical-align: top; + background-color: #f0f0f0; + overflow: visible; +} + +#navigation h2 { + background-color:#e7e7e7; + font-size:1.1em; + color:#000000; + text-align: left; + padding:0.2em; + border-top:1px solid #dddddd; + border-bottom:1px solid #dddddd; +} + +#navigation ul +{ + font-size:1em; + list-style-type: none; + margin: 1px 1px 10px 1px; +} + +#navigation li { + text-indent: -1em; + display: block; + margin: 3px 0px 0px 22px; +} + +#navigation li li a { + margin: 0px 3px 0px -1em; +} + +#content { + margin-left: 14em; + padding: 1em; + width: 700px; + border-left: 2px solid #cccccc; + border-right: 2px solid #cccccc; + background-color: #ffffff; +} + +#about { + clear: both; + padding: 5px; + border-top: 2px solid #cccccc; + background-color: #ffffff; +} + +@media print { + body { + font: 12pt "Times New Roman", "TimeNR", Times, serif; + } + a { font-weight: bold; color: #004080; text-decoration: underline; } + + #main { + background-color: #ffffff; + border-left: 0px; + } + + #container { + margin-left: 2%; + margin-right: 2%; + background-color: #ffffff; + } + + #content { + padding: 1em; + background-color: #ffffff; + } + + #navigation { + display: none; + } + pre.example { + font-family: "Andale Mono", monospace; + font-size: 10pt; + page-break-inside: avoid; + } +} + +table.module_list { + border-width: 1px; + border-style: solid; + border-color: #cccccc; + border-collapse: collapse; +} +table.module_list td { + border-width: 1px; + padding: 3px; + border-style: solid; + border-color: #cccccc; +} +table.module_list td.name { background-color: #f0f0f0; min-width: 200px; } +table.module_list td.summary { width: 100%; } + + +table.function_list { + border-width: 1px; + border-style: solid; + border-color: #cccccc; + border-collapse: collapse; +} +table.function_list td { + border-width: 1px; + padding: 3px; + border-style: solid; + border-color: #cccccc; +} +table.function_list td.name { background-color: #f0f0f0; min-width: 200px; } +table.function_list td.summary { width: 100%; } + +ul.nowrap { + overflow:auto; + white-space:nowrap; +} + +dl.table dt, dl.function dt {border-top: 1px solid #ccc; padding-top: 1em;} +dl.table dd, dl.function dd {padding-bottom: 1em; margin: 10px 0 0 20px;} +dl.table h3, dl.function h3 {font-size: .95em;} + +/* stop sublists from having initial vertical space */ +ul ul { margin-top: 0px; } +ol ul { margin-top: 0px; } +ol ol { margin-top: 0px; } +ul ol { margin-top: 0px; } + +/* make the target distinct; helps when we're navigating to a function */ +a:target + * { + background-color: #FF9; +} + + +/* styles for prettification of source */ +pre .comment { color: #558817; } +pre .constant { color: #a8660d; } +pre .escape { color: #844631; } +pre .keyword { color: #aa5050; font-weight: bold; } +pre .library { color: #0e7c6b; } +pre .marker { color: #512b1e; background: #fedc56; font-weight: bold; } +pre .string { color: #8080ff; } +pre .number { color: #f8660d; } +pre .operator { color: #2239a8; font-weight: bold; } +pre .preprocessor, pre .prepro { color: #a33243; } +pre .global { color: #800080; } +pre .user-keyword { color: #800080; } +pre .prompt { color: #558817; } +pre .url { color: #272fc2; text-decoration: underline; } + diff --git a/doc/modules/Event.html b/doc/modules/Event.html new file mode 100644 index 00000000..85168be6 --- /dev/null +++ b/doc/modules/Event.html @@ -0,0 +1,210 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module Event

+

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(...)

+

Usage:

+
    +
    require('stdlib/event/event')
    +
    +
+ + +

Functions

+ + + + + + + + + + + + + +
register (event, handler)Registers a function for a given event.
dispatch (event)Calls the registerd handlers + Will stop dispatching remaning handlers if any handler passes invalid event userdata.
remove (event, handler)Removes the handler from the event.
+ +
+
+ + +

Functions

+ +
+
+ + register (event, handler) +
+
+ 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 +
+
+ + diff --git a/doc/modules/FSM.html b/doc/modules/FSM.html new file mode 100644 index 00000000..1c9fd6bf --- /dev/null +++ b/doc/modules/FSM.html @@ -0,0 +1,337 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module FSM

+

Factorio Softmod Manager

+

+

Usage:

+
    +
    Manager = require("FactorioSoftmodManager")
    + Used to load all other modules that are indexed in index.lua
    +
    +
+

Info:

+
    +
  • Author: Cooldude2606
  • +
+ + +

Functions

+ + + + + + + + + +
_verbose (rtn)Default output for the verbose
verbose (rtn, action)Used to call the output of the verbose when the current state allows it
+

Fields

+ + + + + + + + + + + + + + + + + + + + + +
setVerboseMain logic for allowing verbose at different stages though out the script
sandboxCreates a sand box envorment and runs a callback in that sand box; provents global pollution
loadModulesLoads the modules that are present in the index list
errorA 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
namesSub 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 +
+
+ + diff --git a/doc/modules/Game.html b/doc/modules/Game.html new file mode 100644 index 00000000..27aa7ddb --- /dev/null +++ b/doc/modules/Game.html @@ -0,0 +1,231 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module Game

+

The game module.

+

+

Usage:

+
    +
    local Game = require('stdlib/game')
    +
    +
+ + +

Functions

+ + + + + + + + + + + + + + + + + +
fail_if_missing (var[, msg="missing value"])Print msg if specified var evaluates to false.
get_player (mixed)Return a valid player object from event, index, string, or userdata
get_force (mixed)Return a valid force object from event, string, or userdata
print_all (msg[, condition])Messages all players currently connected to the game.
+ +
+
+ + +

Functions

+ +
+
+ + fail_if_missing (var[, msg="missing value"]) +
+
+ Print msg if specified var evaluates to false. + + +

Parameters:

+
    +
  • var + Mixed + variable to evaluate +
  • +
  • msg + string + message + (default "missing value") +
  • +
+ + + + + +
+
+ + get_player (mixed) +
+
+ Return a valid player object from event, index, string, or userdata + + +

Parameters:

+
    +
  • mixed + string, number, LuaPlayer or event + +
  • +
+ +

Returns:

+
    + + LuaPlayer + a valid player or nil +
+ + + + +
+
+ + get_force (mixed) +
+
+ Return a valid force object from event, string, or userdata + + +

Parameters:

+
    +
  • mixed + string, LuaForce or event + +
  • +
+ +

Returns:

+
    + + LuaForce + a valid force or nil +
+ + + + +
+
+ + print_all (msg[, condition]) +
+
+ 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. + + +

Parameters:

+
    +
  • msg + string + the message to send to players +
  • +
  • condition + nil or boolean + the condition to be true for a player to be messaged + (optional) +
  • +
+ +

Returns:

+
    + + uint + the number of players who received the message. +
+ + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/modules/defines.color.html b/doc/modules/defines.color.html new file mode 100644 index 00000000..38dc3a04 --- /dev/null +++ b/doc/modules/defines.color.html @@ -0,0 +1,519 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module defines.color

+

A defines module for retrieving colors by name.

+

+ Extends the Factorio defines table.

+

Usage:

+
    +
    require('stdlib/defines/color')
    +
    +
+ + +

Functions

+ + + + + + + + + + + + + + + + + +
Color.set ([color=white[, alpha=1]])Set a value for the alpha channel in the given color table.
Color.to_table (c_arr)Converts a color in the array format to a color in the table format.
Color.from_rgb ([r=0[, g=0[, b=0[, a=255]]]])Converts a color in the rgb format to a color table
Color.from_hex (hex[, alpha=1])Get a color table with a hexadecimal string.
+

Tables

+ + + + + + + + + + + + + +
defines.colorA table of colors allowing retrieval by color name.
defines.anticolorReturns white for dark colors or black for lighter colors.
defines.lightcolorReturns a lighter color of a named color.
+ +
+
+ + +

Functions

+ +
+
+ + Color.set ([color=white[, alpha=1]]) +
+
+ Set a value for the alpha channel in the given color table. + `color.a` represents the alpha channel in the given color table. +
    +
  • If ***alpha*** is given, set `color.a` to it. +
  • If ***alpha*** is not given, and if the given color table does not have a value for `color.a`, set `color.a` to 1. +
  • If ***alpha*** is not given, and if the given color table already has a value for `color.a`, then leave `color.a` alone. +
+ + +

Parameters:

+
    +
  • color + defines.color or Concepts.Color + the color to configure + (default white) +
  • +
  • alpha + float + the alpha value (*[0 - 1]*) to set for the given color + (default 1) +
  • +
+ +

Returns:

+
    + + Concepts.Color + a color table that has the specified value for the alpha channel +
+ + + + +
+
+ + Color.to_table (c_arr) +
+
+ Converts a color in the array format to a color in the table format. + + +

Parameters:

+
    +
  • c_arr + table + the color to convert +
  • +
+ +

Returns:

+
    + + Concepts.Color + a converted color — { r = c\_arr[1], g = c\_arr[2], b = c\_arr[3], a = c\_arr[4] } +
+ + + + +
+
+ + Color.from_rgb ([r=0[, g=0[, b=0[, a=255]]]]) +
+
+ Converts a color in the rgb format to a color table + + +

Parameters:

+
    +
  • r + int + 0-255 red + (default 0) +
  • +
  • g + int + 0-255 green + (default 0) +
  • +
  • b + int + 0-255 blue + (default 0) +
  • +
  • a + int + 0-255 alpha + (default 255) +
  • +
+ +

Returns:

+
    + + Concepts.Color + +
+ + + + +
+
+ + Color.from_hex (hex[, alpha=1]) +
+
+ Get a color table with a hexadecimal string. + Optionally provide the value for the alpha channel. + + +

Parameters:

+
    +
  • hex + string + hexadecimal color string (#ffffff, not #fff) +
  • +
  • alpha + float + the alpha value to set; such that ***[ 0 ⋜ value ⋜ 1 ]*** + (default 1) +
  • +
+ +

Returns:

+
    + + Concepts.Color + a color table with RGB converted from Hex and with alpha +
+ + + + +
+
+

Tables

+ +
+
+ + defines.color +
+
+ A table of colors allowing retrieval by color name. + + +

Fields:

+
    +
  • white + Concepts.Color + +
  • +
  • black + Concepts.Color + +
  • +
  • darkgrey + Concepts.Color + +
  • +
  • grey + Concepts.Color + +
  • +
  • lightgrey + Concepts.Color + +
  • +
  • red + Concepts.Color + +
  • +
  • darkred + Concepts.Color + +
  • +
  • lightred + Concepts.Color + +
  • +
  • green + Concepts.Color + +
  • +
  • darkgreen + Concepts.Color + +
  • +
  • lightgreen + Concepts.Color + +
  • +
  • blue + Concepts.Color + +
  • +
  • darkblue + Concepts.Color + +
  • +
  • lightblue + Concepts.Color + +
  • +
  • orange + Concepts.Color + +
  • +
  • yellow + Concepts.Color + +
  • +
  • pink + Concepts.Color + +
  • +
  • purple + Concepts.Color + +
  • +
  • brown + Concepts.Color + +
  • +
+ + + + +

Usage:

+
    +
    color = defines.color.red
    +
+ +
+
+ + defines.anticolor +
+
+ Returns white for dark colors or black for lighter colors. + + +

Fields:

+
    +
  • green + Concepts.Color + defines.color.black +
  • +
  • grey + Concepts.Color + defines.color.black +
  • +
  • lightblue + Concepts.Color + defines.color.black +
  • +
  • lightgreen + Concepts.Color + defines.color.black +
  • +
  • lightgrey + Concepts.Color + defines.color.black +
  • +
  • lightred + Concepts.Color + defines.color.black +
  • +
  • orange + Concepts.Color + defines.color.black +
  • +
  • white + Concepts.Color + defines.color.black +
  • +
  • yellow + Concepts.Color + defines.color.black +
  • +
  • black + Concepts.Color + defines.color.white +
  • +
  • blue + Concepts.Color + defines.color.white +
  • +
  • brown + Concepts.Color + defines.color.white +
  • +
  • darkblue + Concepts.Color + defines.color.white +
  • +
  • darkgreen + Concepts.Color + defines.color.white +
  • +
  • darkgrey + Concepts.Color + defines.color.white +
  • +
  • darkred + Concepts.Color + defines.color.white +
  • +
  • pink + Concepts.Color + defines.color.white +
  • +
  • purple + Concepts.Color + defines.color.white +
  • +
  • red + Concepts.Color + defines.color.white +
  • +
+ + + + + +
+
+ + defines.lightcolor +
+
+ Returns a lighter color of a named color. + + +

Fields:

+
    +
  • white + Concepts.Color + defines.color.lightgrey +
  • +
  • grey + Concepts.Color + defines.color.darkgrey +
  • +
  • lightgrey + Concepts.Color + defines.color.grey +
  • +
  • red + Concepts.Color + defines.color.lightred +
  • +
  • green + Concepts.Color + defines.color.lightgreen +
  • +
  • blue + Concepts.Color + defines.color.lightblue +
  • +
  • yellow + Concepts.Color + defines.color.orange +
  • +
  • pink + Concepts.Color + defines.color.purple +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/modules/defines.time.html b/doc/modules/defines.time.html new file mode 100644 index 00000000..fd176df3 --- /dev/null +++ b/doc/modules/defines.time.html @@ -0,0 +1,148 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module defines.time

+

A defines module for retrieving the number of ticks in 1 unit of time.

+

+ Extends the Factorio defines table.

+

Usage:

+
    +
    require('stdlib/defines/time')
    +
    +
+ + +

Tables

+ + + + + +
defines.timeReturns the number of ticks in a second, minute, hour, day, week, month, or year.
+ +
+
+ + +

Tables

+ +
+
+ + defines.time +
+
+ Returns the number of ticks in a second, minute, hour, day, week, month, or year. + + +

Fields:

+
    +
  • second + the number of Factorio ticks in a second +
  • +
  • minute + the number of Factorio ticks in a second +
  • +
  • hour + the number of Factorio ticks in an hour +
  • +
  • day + the number of Factorio ticks in an day +
  • +
  • week + the number of Factorio ticks in a week +
  • +
  • month + the number of Factorio ticks in a month (30 days) +
  • +
  • year + the number of Factorio ticks in a year (365 days) +
  • +
+ + + + +

Usage:

+
    +
    local ten_seconds = defines.time.second * 10
    +
+ +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/modules/expcore.commands.html b/doc/modules/expcore.commands.html new file mode 100644 index 00000000..a553e593 --- /dev/null +++ b/doc/modules/expcore.commands.html @@ -0,0 +1,136 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module expcore.commands

+

Uses a commands data to return the inputs as a string

+

+

Usage:

+
    +
    command = command_data[command_name]
    + command_inputs(command) -- returns "<input1> <input2> "
    +
    +
+ + +

Functions

+ + + + + +
get_commands (player)Used to return all the commands a player can use
+ +
+
+ + +

Functions

+ +
+
+ + get_commands (player) +
+
+ Used to return all the commands a player can use + + +

Parameters:

+
    +
  • player + the player refreced by string|number|LuaPlayer|event +
  • +
+ +

Returns:

+
    + + table + a table containg all the commands the player can use +
+ + + +

Usage:

+
    +
    get_commands(1) -- return {{command data},{command data}}
    +
+ +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/modules/expcore.gui.html b/doc/modules/expcore.gui.html new file mode 100644 index 00000000..a6368064 --- /dev/null +++ b/doc/modules/expcore.gui.html @@ -0,0 +1,172 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module expcore.gui

+

Add a white bar to any gui frame

+

+

Usage:

+
    +
    Gui.bar(frame,100)
    +
    +
+ + +

Functions

+ + + + + + + + + +
Gui.set_dropdown_index (dropdown, _item)Used to set the index of a drop down to a certian item
Gui.cam_link (data)Adds a camera that updates every tick (or less depeading on how many are opening) it will move to follow an entity
+ +
+
+ + +

Functions

+ +
+
+ + Gui.set_dropdown_index (dropdown, _item) +
+
+ Used to set the index of a drop down to a certian item + + +

Parameters:

+
    +
  • dropdown + the dropdown that is to be effected +
  • +
  • _item + this is the item to look for +
  • +
+ +

Returns:

+
    + + returns the dropdown if it was successful +
+ + + +

Usage:

+
    +
    Gui.set_dropdown_index(dropdown,player.name)
    +
+ +
+
+ + Gui.cam_link (data) +
+
+ Adds a camera that updates every tick (or less depeading on how many are opening) it will move to follow an entity + + +

Parameters:

+
    +
  • data + table + contains all other params given below +
  • +
+ +

Returns:

+
    + + the camera that the function used be it made or given as a param +
+ + + +

Usage:

+
    +
  • Gui.cam_link{entity=game.player.character,frame=frame,width=50,hight=50,zoom=1}
  • +
  • Gui.cam_link{entity=game.player.character,cam=frame.camera,surface=game.surfaces['testing']}
  • +
+ +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/modules/expcore.guiparts.center.html b/doc/modules/expcore.guiparts.center.html new file mode 100644 index 00000000..ed110104 --- /dev/null +++ b/doc/modules/expcore.guiparts.center.html @@ -0,0 +1,290 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module expcore.guiparts.center

+

Adds a new obj to the center gui

+

+

Usage:

+
    +
    Gui.center.add{name='foo',caption='Foo',tooltip='Testing',draw=function}
    +
    +
+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + +
get_flow (player)Used to get the center frame of the player, used mainly in script
open (player, center)Used to open a center frame for a player
open_tab (player, center, tab)Used to open a center frame for a player
clear (player)Used to clear the center frame of the player, used mainly in script
center._center:add_tab (name, caption[, tooltip], callback)If deafult draw is used then you can add tabs to the gui with this function
+ +
+
+ + +

Functions

+ +
+
+ + get_flow (player) +
+
+ Used to get the center frame of the player, used mainly in script + + +

Parameters:

+
    +
  • player + a player indifier to get the flow for +
  • +
+ +

Returns:

+
    + + table + the gui element flow +
+ + + +

Usage:

+
    +
    Gui.center.get_flow(player) -- returns gui emelemt
    +
+ +
+
+ + open (player, center) +
+
+ Used to open a center frame for a player + + +

Parameters:

+
    +
  • player + a player indifier to get the flow for +
  • +
  • center + string + the name of the center frame to open +
  • +
+ +

Returns:

+
    + + boelon + based on if it successed or not +
+ + + +

Usage:

+
    +
    Gui.center.open(player,'server-info') -- return true
    +
+ +
+
+ + open_tab (player, center, tab) +
+
+ Used to open a center frame for a player + + +

Parameters:

+
    +
  • player + a player indifier to get the flow for +
  • +
  • center + string + the name of the center frame to open +
  • +
  • tab + string + the name of the tab to open +
  • +
+ +

Returns:

+
    + + boelon + based on if it successed or not +
+ + + +

Usage:

+
    +
    Gui.center.open_tab(player,'readme','rules') -- return true
    +
+ +
+
+ + clear (player) +
+
+ Used to clear the center frame of the player, used mainly in script + + +

Parameters:

+
    +
  • player + a player indifier to get the flow for +
  • +
+ + + + +

Usage:

+
    +
    Gui.center.clear(player)
    +
+ +
+
+ + center._center:add_tab (name, caption[, tooltip], callback) +
+
+ If deafult draw is used then you can add tabs to the gui with this function + + +

Parameters:

+
    +
  • name + string + this is the name of the tab +
  • +
  • caption + string + this is the words that appear on the tab button +
  • +
  • tooltip + string + the tooltip that is on the button + (optional) +
  • +
  • callback + function + this is called when button is pressed with function(root_frame) +
  • +
+ +

Returns:

+
    + + self to allow chaining of _center:add_tab +
+ + + +

Usage:

+
    +
    _center:add_tab('foo','Foo','Just a tab',function)
    +
+ +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/modules/expcore.guiparts.inputs.html b/doc/modules/expcore.guiparts.inputs.html new file mode 100644 index 00000000..f8de31de --- /dev/null +++ b/doc/modules/expcore.guiparts.inputs.html @@ -0,0 +1,446 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module expcore.guiparts.inputs

+

Sets the input to trigger on an certain event

+

+

Usage:

+
    +
    button:on_event(defines.events.on_gui_click,player_return)
    +
    +
+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
inputs._input:draw (root)Draw the input into the root element
add (obj)Add a new input, this is the same as doing frame.add{} but returns a diffrent object
add_elem_button (name, elem_type, tooltip, callback)Used to define a choose-elem-button callback only on elem_changed
add_checkbox (name, radio, display, default, callback_true, callback_false)Used to define a checkbox callback only on state_changed
reset_radio (elements)Used to reset the state of radio buttons, recomened to be called on_state_change to reset any radio buttons it is ment to work with.
add_text (name, box, text, callback)Used to define a text callback only on text_changed
add_slider (name, orientation, min, max, start_callback, callback)Used to define a slider callback only on value_changed
add_drop_down (name, items, index, callback)Used to define a drop down callback only on value_changed
+ +
+
+ + +

Functions

+ +
+
+ + inputs._input:draw (root) +
+
+ Draw the input into the root element + + +

Parameters:

+
    +
  • root + the element you want to add the input to +
  • +
+ +

Returns:

+
    + + returns the element that was added +
+ + + +

Usage:

+
    +
    button:draw(frame)
    +
+ +
+
+ + add (obj) +
+
+ Add a new input, this is the same as doing frame.add{} but returns a diffrent object + + +

Parameters:

+
    +
  • obj + table + the new element to add if caption is a sprite path then sprite is used +
  • +
+ +

Returns:

+
    + + table + the custom input object +
+ + + +

Usage:

+
    +
    Gui.inputs.add{type='button',name='test',caption='Test'}
    +
+ +
+
+ + add_elem_button (name, elem_type, tooltip, callback) +
+
+ Used to define a choose-elem-button callback only on elem_changed + + +

Parameters:

+
    +
  • name + string + the name of this button +
  • +
  • elem_type + string + the display for this button, either text or sprite path +
  • +
  • tooltip + string + the tooltip to show on the button +
  • +
  • callback + function + the callback to call on change function(player,element,elem) +
  • +
+ +

Returns:

+
    + + table + the button object that was made, to allow a custom error event if wanted +
+ + + +

Usage:

+
    +
    Gui.inputs.add_elem_button('test','Test','Just for testing',function)
    +
+ +
+
+ + add_checkbox (name, radio, display, default, callback_true, callback_false) +
+
+ Used to define a checkbox callback only on state_changed + + +

Parameters:

+
    +
  • name + string + the name of this button +
  • +
  • radio + boolean + if this is a radio button +
  • +
  • display + string + the display for this button, either text or sprite path +
  • +
  • default + function + the callback which choses the default check state +
  • +
  • callback_true + function + the callback to call when changed to true +
  • +
  • callback_false + function + the callback to call when changed to false +
  • +
+ +

Returns:

+
    + + table + the button object that was made, to allow a custom error event if wanted +
+ + + +

Usage:

+
    +
    Gui.inputs.add_checkbox('test',false,'Just for testing',function,function,funvtion)
    +
+ +
+
+ + reset_radio (elements) +
+
+ Used to reset the state of radio buttons, recomened to be called on_state_change to reset any radio buttons it is ment to work with. + + +

Parameters:

+
    +
  • elements + can be a list of elements or a single element +
  • +
+ + + + +

Usage:

+
    +
    Gui.inputs.reset_radio{radio1,radio2,...}
    +
+ +
+
+ + add_text (name, box, text, callback) +
+
+ Used to define a text callback only on text_changed + + +

Parameters:

+
    +
  • name + string + the name of this button +
  • +
  • box + boolean + is it a text box rather than a text field +
  • +
  • text + string + the starting text +
  • +
  • callback + function + the callback to call on change function(player,text,element) +
  • +
+ +

Returns:

+
    + + table + the text object that was made, to allow a custom error event if wanted +
+ + + +

Usage:

+
    +
    Gui.inputs.add_text('test',false,'Just for testing',function)
    +
+ +
+
+ + add_slider (name, orientation, min, max, start_callback, callback) +
+
+ Used to define a slider callback only on value_changed + + +

Parameters:

+
    +
  • name + string + the name of this button +
  • +
  • orientation + string + direction of the slider +
  • +
  • min + number + the lowest number +
  • +
  • max + number + the highest number +
  • +
  • start_callback + function + either a number or a function to return a number +
  • +
  • callback + function + the function to be called on value_changed function(player,value,percent,element) +
  • +
+ +

Returns:

+
    + + table + the slider object that was made, to allow a custom error event if wanted +
+ + + +

Usage:

+
    +
    Gui.inputs.add_slider('test','horizontal',1,10,5,function)
    +
+ +
+
+ + add_drop_down (name, items, index, callback) +
+
+ Used to define a drop down callback only on value_changed + + +

Parameters:

+
    +
  • name + string + name of the drop down +
  • +
  • items + either a list or a function which returns a list +
  • +
  • index + either a number or a function which returns a number +
  • +
  • callback + function + the callback which is called when a new index is selected function(player,selected,items,element) +
  • +
+ +

Returns:

+
    + + table + the drop-down object that was made, to allow a custom error event if wanted +
+ + + +

Usage:

+
    +
    Gui.inputs.add_drop_down('test',{1,2,3},1,function)
    +
+ +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/modules/expcore.guiparts.left.html b/doc/modules/expcore.guiparts.left.html new file mode 100644 index 00000000..ce4257f8 --- /dev/null +++ b/doc/modules/expcore.guiparts.left.html @@ -0,0 +1,193 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module expcore.guiparts.left

+

Used to add a left gui frame

+

+

Usage:

+
    +
    Gui.left.add{name='foo',caption='Foo',tooltip='just testing',open_on_join=true,can_open=function,draw=function}
    +
    +
+ + +

Functions

+ + + + + + + + + + + + + +
update ([frame[, players]])This is used to update all the guis of conected players, good idea to use our thread system as it as nested for loops
open (left_name)Used to open the left gui of every player
close (left_name)Used to close the left gui of every player
+ +
+
+ + +

Functions

+ +
+
+ + update ([frame[, players]]) +
+
+ This is used to update all the guis of conected players, good idea to use our thread system as it as nested for loops + + +

Parameters:

+
    +
  • frame + string + this is the name of a frame if you only want to update one + (optional) +
  • +
  • players + the player to update for, if not given all players are updated, can be one player + (optional) +
  • +
+ + + + +

Usage:

+
    +
    Gui.left.update()
    +
+ +
+
+ + open (left_name) +
+
+ Used to open the left gui of every player + + +

Parameters:

+
    +
  • left_name + string + this is the gui that you want to open +
  • +
+ + + + +

Usage:

+
    +
    Gui.left.open('foo')
    +
+ +
+
+ + close (left_name) +
+
+ Used to close the left gui of every player + + +

Parameters:

+
    +
  • left_name + string + this is the gui that you want to close +
  • +
+ + + + +

Usage:

+
    +
    Gui.left.close('foo')
    +
+ +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/modules/expcore.guiparts.popup.html b/doc/modules/expcore.guiparts.popup.html new file mode 100644 index 00000000..987917ff --- /dev/null +++ b/doc/modules/expcore.guiparts.popup.html @@ -0,0 +1,138 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module expcore.guiparts.popup

+

Used to add a popup gui style

+

+

Usage:

+
    +
    Gui.left.add{name='foo',caption='Foo',draw=function}
    +
    +
+ + +

Functions

+ + + + + +
open (style, data[, players=game.connected_players])Use to open a popup for these players
+ +
+
+ + +

Functions

+ +
+
+ + open (style, data[, players=game.connected_players]) +
+
+ Use to open a popup for these players + + +

Parameters:

+
    +
  • style + string + this is the name you gave to the popup when added +
  • +
  • data + this is the data that is sent to the draw function +
  • +
  • players + table + the players to open the popup for + (default game.connected_players) +
  • +
+ + + + +

Usage:

+
    +
    Gui.popup.open('ban',nil,{player=1,reason='foo'})
    +
+ +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/modules/expcore.guiparts.toolbar.html b/doc/modules/expcore.guiparts.toolbar.html new file mode 100644 index 00000000..cdbf2952 --- /dev/null +++ b/doc/modules/expcore.guiparts.toolbar.html @@ -0,0 +1,129 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module expcore.guiparts.toolbar

+

Add a button to the toolbar, ranks need to be allowed to use these buttons if ranks is preset

+

+

Usage:

+
    +
    toolbar.add('foo','Foo','Test',function() game.print('test') end)
    +
    +
+ + +

Functions

+ + + + + +
draw (player)Draws the toolbar for a certain player
+ +
+
+ + +

Functions

+ +
+
+ + draw (player) +
+
+ Draws the toolbar for a certain player + + +

Parameters:

+
    +
  • player + the player to draw the tool bar of +
  • +
+ + + + +

Usage:

+
    +
    toolbar.draw(1)
    +
+ +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/modules/expcore.ranking.html b/doc/modules/expcore.ranking.html new file mode 100644 index 00000000..d1d22f6e --- /dev/null +++ b/doc/modules/expcore.ranking.html @@ -0,0 +1,386 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module expcore.ranking

+

Returns a rank object given a player or rank name

+

+

Usage:

+
    +
    Ranking.get_rank(game.player)
    + Ranking.get_rank('admin')
    +
    +
+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Ranking.get_group (mixed)Returns the group object used to sort ranks given group name or see Ranking.get_rank
Ranking.print (rank_base, rtn, colour, below)Prints to all rank of greater/lower power of the rank given
Ranking.give_rank (player, rank[, by_player='server'[, tick=game.tick]])Gives a user a rank
Ranking.revert (player[, by_player=nil])Revert the last change to a players rank
Ranking.find_preset (player[, tick=nil])Given the player has a rank in the preset table it is given
Ranking._rank:allowed (action)Is this rank allowed to open this gui or use this command etc.
Ranking._rank:get_players (online)Get all the players in this rank
Ranking._rank:print (rtn, colour, show_default)Print a message to all players of this rank
+ +
+
+ + +

Functions

+ +
+
+ + Ranking.get_group (mixed) +
+
+ Returns the group object used to sort ranks given group name or see Ranking.get_rank + + +

Parameters:

+
    +
  • mixed + player|player index|player name|rank name|rank|'server'|'root'|group name|group what group to get +
  • +
+ +

Returns:

+
    + + table + the group that is linked to mixed +
+ + + +

Usage:

+
    +
    Ranking.get_group(game.player)
    + Ranking.get_group('root')
    +
+ +
+
+ + Ranking.print (rank_base, rtn, colour, below) +
+
+ Prints to all rank of greater/lower power of the rank given + + +

Parameters:

+
    +
  • rank_base + the rank that acts as the cut off point (rank is always included) +
  • +
  • rtn + what do you want to return to the players +
  • +
  • colour + defines.color + the colour that will be used to print +
  • +
  • below + bolean + if true rank below base are printed to +
  • +
+ + + + +

Usage:

+
    +
    Ranking.print('admin','We got a grifer')
    +
+ +
+
+ + Ranking.give_rank (player, rank[, by_player='server'[, tick=game.tick]]) +
+
+ Gives a user a rank + + +

Parameters:

+
    +
  • player + the player to give the rank to +
  • +
  • rank + the rank to give to the player +
  • +
  • by_player + the player who is giving the rank + (default 'server') +
  • +
  • tick + the tick that the rank is being given on + (default game.tick) +
  • +
+ + + + +

Usage:

+
    +
    Ranking.give_rank(1,'admin')
    +
+ +
+
+ + Ranking.revert (player[, by_player=nil]) +
+
+ Revert the last change to a players rank + + +

Parameters:

+
    +
  • player + the player to revert the rank of +
  • +
  • by_player + the player who is doing the revert + (default nil) +
  • +
+ + + + +

Usage:

+
    +
    Ranking.revert(1)
    +
+ +
+
+ + Ranking.find_preset (player[, tick=nil]) +
+
+ Given the player has a rank in the preset table it is given + + +

Parameters:

+
    +
  • player + the player to test for an auto rank +
  • +
  • tick + number + the tick it happens on + (default nil) +
  • +
+ + + + +

Usage:

+
    +
    Ranking.find_preset(1)
    +
+ +
+
+ + Ranking._rank:allowed (action) +
+
+ Is this rank allowed to open this gui or use this command etc. + + +

Parameters:

+
    +
  • action + teh + to test for +
  • +
+ +

Returns:

+
    + + bolean + is it allowed +
+ + + +

Usage:

+
    +
    rank:allowed('server-interface')
    +
+ +
+
+ + Ranking._rank:get_players (online) +
+
+ Get all the players in this rank + + +

Parameters:

+
    +
  • online + bolean + get only online players +
  • +
+ +

Returns:

+
    + + table + a table of all players in this rank +
+ + + +

Usage:

+
    +
    rank:get_players()
    +
+ +
+
+ + Ranking._rank:print (rtn, colour, show_default) +
+
+ Print a message to all players of this rank + + +

Parameters:

+
    +
  • rtn + any value you want to return +
  • +
  • colour + define.color + the colour that will be used to print +
  • +
  • show_default + boolean + weather to use the default rank name for the print +
  • +
+ + + + +

Usage:

+
    +
    rank:print('foo')
    +
+ +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/modules/expcore.server.html b/doc/modules/expcore.server.html new file mode 100644 index 00000000..4dec0cb5 --- /dev/null +++ b/doc/modules/expcore.server.html @@ -0,0 +1,571 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module expcore.server

+

Returns a un-used uuid (better system needed)

+

+

Usage:

+
    +
    obj.uuid = Server.new_uuid()
    +
    +
+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Server.threads ([count=nil])Returns either the number of threads or a able of threads
Server.get_thread (mixed)Used to get a thread via it's uuid or by name if one is given
Server.queue_thread (thread_to_queue)Adds a thread into the resolve queue, can be used to lower lag
Server.close_all_threads (with_force)Closes all active threads, can use force if it causes errors
Server.run_tick_threads ()Runs all the theads which have opened with an on_tick event
Server.check_timeouts ()Checks the timeout on all active timeout threads
Server._thread_handler (event)Calles all threads on a certain game event (used with script.on_event)
Server.interface (callback[, use_thread[, ...]])Given a string or function it will run that function and return any values
Server._thread:valid (skip_location_check)Test if the thread has all requied parts
Server._thread:open ()Opens the thread by storing it in a place the server object can find it
Server._thread:close ()Inverse of thread:open() - it removes the thread and calles on_close
Server._thread:resolve ([...])Trigger the on_resolve function and closes the thread - error and success called based on result of pcall (useful for async)
Server._thread:check_timeout ()Checks the timeout on a thread - if timedout then it calles on_timeout and closes
Server._thread:error (err)Rasies an error on this thread
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
+ +
+
+ + +

Functions

+ +
+
+ + Server.threads ([count=nil]) +
+
+ Returns either the number of threads or a able of threads + + +

Parameters:

+
    +
  • count + bolean + true to return the number of threads + (default nil) +
  • +
+ +

Returns:

+
    + + either a list of threads or a number +
+ + + +

Usage:

+
    +
    Server.threads() -- return {...}
    + Server.threads(true) -- return int
    +
+ +
+
+ + Server.get_thread (mixed) +
+
+ Used to get a thread via it's uuid or by name if one is given + + +

Parameters:

+
    +
  • mixed + either a uuid or the name given to a thread +
  • +
+ +

Returns:

+
    + + table + the thread by that name or uuid +
+ + + +

Usage:

+
    +
    Server.get_thread('decon') -- return thread
    +
+ +
+
+ + Server.queue_thread (thread_to_queue) +
+
+ Adds a thread into the resolve queue, can be used to lower lag + + +

Parameters:

+
    +
  • thread_to_queue + table + the thread to add to the queue must have a resolve function (must be open) +
  • +
+ +

Returns:

+
    + + boolean + was the thread added +
+ + + +

Usage:

+
    +
    Server.queue_thread(thread) -- return true/false
    +
+ +
+
+ + Server.close_all_threads (with_force) +
+
+ Closes all active threads, can use force if it causes errors + + +

Parameters:

+
    +
  • with_force + bolean + use force when closing +
  • +
+ + + + +

Usage:

+
    +
    Server.close_all_threads()
    + Server.close_all_threads(true) -- use if no force makes errors
    +
+ +
+
+ + Server.run_tick_threads () +
+
+ Runs all the theads which have opened with an on_tick event + + + + + + +

Usage:

+
    +
    Server.run_tick_threads()
    +
+ +
+
+ + Server.check_timeouts () +
+
+ Checks the timeout on all active timeout threads + + + + + + +

Usage:

+
    +
    Server.check_timeouts()
    +
+ +
+
+ + Server._thread_handler (event) +
+
+ Calles all threads on a certain game event (used with script.on_event) + + +

Parameters:

+
    +
  • event + table + the event that is called +
  • +
+ + + + + +
+
+ + Server.interface (callback[, use_thread[, ...]]) +
+
+ 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() then end
    +
+ +
+
+ + 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 +
+
+ + diff --git a/doc/modules/expcore.sync.html b/doc/modules/expcore.sync.html new file mode 100644 index 00000000..74f4dd89 --- /dev/null +++ b/doc/modules/expcore.sync.html @@ -0,0 +1,542 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module expcore.sync

+

Used as a faster way to get to the ranking function, overrides previous

+

+

Usage:

+
    +
    Sync.set_ranks{name=rank_name}
    +
    +
+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Sync.tick_format (tick)Used to standidise the tick format for any sync info
Sync.print (player_message, player_name[, player_tag[, player_colour[, prefix]]])Prints to chat as if it were a player
Sync.emit_embeded (args)Logs an embed to the json.data we use a js script to add things we cant here
Sync.count_admins ()used to get the number of admins currently online
Sync.count_afk ([time=7200])used to get the number of afk players defined by 2 min by default
Sync.count_ranks ()used to get the number of players in each rank and currently online
Sync.count_players (online)used to get the number of players either online or all
Sync.count_player_times ()used to get the number of players resulting in there play times
Sync.info ([set=nil])used to return the global list and set values in it
Sync.time ([set=nil])used to return the global time and set its value
Sync.update ()called to update values inside of the info
Sync.add_update (key, callback)Adds a callback to be called when the info is updated
Sync.emit_data ()outputs the curent server info into a file
Sync.add_to_gui (element)Adds a emeltent to the sever info gui
+ +
+
+ + +

Functions

+ +
+
+ + Sync.tick_format (tick) +
+
+ Used to standidise the tick format for any sync info + + +

Parameters:

+
    +
  • tick + +
  • +
+ + + + +

Usage:

+
    +
    Sync.tick_format(60) -- return {60,'1.00M'}
    +
+ +
+
+ + Sync.print (player_message, player_name[, player_tag[, player_colour[, prefix]]]) +
+
+ Prints to chat as if it were a player + + +

Parameters:

+
    +
  • player_message + the message to be printed in chat +
  • +
  • player_name + the name of the player sending the message +
  • +
  • player_tag + the tag apllied to the player's name + (optional) +
  • +
  • player_colour + the colour of the message + (optional) +
  • +
  • prefix + add a prefix before the chat eg [IRC] + (optional) +
  • +
+ + + + +

Usage:

+
    +
    Sync.print('Test','Cooldude2606')
    +
+ +
+
+ + Sync.emit_embeded (args) +
+
+ Logs an embed to the json.data we use a js script to add things we cant here + + +

Parameters:

+
    +
  • args + table + a table which contains everything that the embeded will use +
  • +
+ + + + +

Usage:

+
    +
    Sync.emit_embeded{title='BAN',color='0x0',description='A player was banned' ... }
    +
+ +
+
+ + Sync.count_admins () +
+
+ used to get the number of admins currently online + + + +

Returns:

+
    + + int + the number of admins online +
+ + + +

Usage:

+
    +
    Sync.count_admins()
    +
+ +
+
+ + Sync.count_afk ([time=7200]) +
+
+ used to get the number of afk players defined by 2 min by default + + +

Parameters:

+
    +
  • time + int + in ticks that a player is called afk + (default 7200) +
  • +
+ +

Returns:

+
    + + int + the number of afk players +
+ + + +

Usage:

+
    +
    Sync.count_afk()
    +
+ +
+
+ + Sync.count_ranks () +
+
+ used to get the number of players in each rank and currently online + + + +

Returns:

+
    + + table + contains the ranks and the players in that rank +
+ + + +

Usage:

+
    +
    Sync.count_ranks()
    +
+ +
+
+ + Sync.count_players (online) +
+
+ used to get the number of players either online or all + + +

Parameters:

+
    +
  • online + bolean + if true only get online players +
  • +
+ +

Returns:

+
    + + table + contains player names +
+ + + +

Usage:

+
    +
    Sync.count_players()
    +
+ +
+
+ + Sync.count_player_times () +
+
+ used to get the number of players resulting in there play times + + + +

Returns:

+
    + + table + contains players and each player is given a tick amount and a formated string +
+ + + +

Usage:

+
    +
    Sync.count_player_times()
    +
+ +
+
+ + Sync.info ([set=nil]) +
+
+ used to return the global list and set values in it + + +

Parameters:

+
    +
  • set + table + keys to be replaced in the server info + (default nil) +
  • +
+ +

Returns:

+
    + + either returns success when setting or the info when not setting +
+ + + +

Usage:

+
    +
    Sync.info{server_name='Factorio Server 2'}
    +
+ +
+
+ + Sync.time ([set=nil]) +
+
+ used to return the global time and set its value + + +

Parameters:

+
    +
  • set + string + the date time to be set + (default nil) +
  • +
+ +

Returns:

+
    + + either true false if setting or the date time and tick off set +
+ + + +

Usage:

+
    +
    Sync.time('Sun Apr  1 18:44:30 UTC 2018')
    +
+ +
+
+ + Sync.update () +
+
+ called to update values inside of the info + + + +

Returns:

+
    + + all of the new info +
+ + + +

Usage:

+
    +
    Sync.update()
    +
+ +
+
+ + Sync.add_update (key, callback) +
+
+ Adds a callback to be called when the info is updated + + +

Parameters:

+
    +
  • key + string + the key that the value will be stored in +
  • +
  • callback + function + the function which will return this value +
  • +
+ + + + +

Usage:

+
    +
    Sync.add_update('players',function() return #game.players end)
    +
+ +
+
+ + Sync.emit_data () +
+
+ outputs the curent server info into a file + + + + + + +

Usage:

+
    +
    Sync.emit_data()
    +
+ +
+
+ + Sync.add_to_gui (element) +
+
+ Adds a emeltent to the sever info gui + + +

Parameters:

+
    +
  • element + see examples before for what can be used, it can also be a return from Gui.inputs.add +
  • +
+ +

Returns:

+
    + + bolean + based on weather it was successful or not +
+ + + +

Usage:

+
    +
    Sync.add_to_gui('string') -- return trues
    +
+ +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/modules/modules.expgaminglib.control.html b/doc/modules/modules.expgaminglib.control.html new file mode 100644 index 00000000..63260c90 --- /dev/null +++ b/doc/modules/modules.expgaminglib.control.html @@ -0,0 +1,350 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module modules.expgaminglib.control

+

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'}
    +
    +
+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ExpLib.get_env ()Used to get the current ENV with all _G keys removed; useful when saving function to global
ExpLib.is_type (v[, test_type=nil])Compear types faster for faster valadation of prams
ExpLib.player_return (rtn[, colour=defines.colour.white[, player=game.player]])Will return a value of any type to the player/server console, allows colour for in-game players
ExpLib.tick_to_hour (tick)Convert ticks to hours
ExpLib.tick_to_min (tick)Convert ticks to minutes
ExpLib.tick_to_display_format (tick)Converts a tick into a clean format for end user
ExpLib.gui_tree (root)Used as a way to view the structure of a gui, used for debuging
+ +
+
+ + +

Functions

+ +
+
+ + ExpLib.get_env () +
+
+ Used to get the current ENV with all _G keys removed; useful when saving function to global + + + +

Returns:

+
    + + table + the env table with _G keys removed +
+ + + +

Usage:

+
    +
    get_env() returns current ENV with _G keys removed
    +
+ +
+
+ + ExpLib.is_type (v[, test_type=nil]) +
+
+ Compear types faster for faster valadation of prams + + +

Parameters:

+
    +
  • v + the value to be tested +
  • +
  • test_type + string + the type to test for if not given then it tests for nil + (default nil) +
  • +
+ +

Returns:

+
    + + bolean + is v of type test_type +
+ + + +

Usage:

+
    +
  • is_type('foo','string') -- return true
  • +
  • is_type('foo') -- return false
  • +
+ +
+
+ + ExpLib.player_return (rtn[, colour=defines.colour.white[, player=game.player]]) +
+
+ Will return a value of any type to the player/server console, allows colour for in-game players + + +

Parameters:

+
    +
  • rtn + any value of any type that will be returned to the player or console +
  • +
  • colour + defines.color or string + the colour of the text for the player, ingroned when printing to console + (default defines.colour.white) +
  • +
  • player + LuaPlayer + the player that return will go to, if no game.player then returns to server + (default game.player) +
  • +
+ + + + +

Usage:

+
    +
  • player_return('Hello, World!') -- returns 'Hello, World!' to game.player or server console
  • +
  • player_return('Hello, World!','green') -- returns 'Hello, World!' to game.player with colour green or server console
  • +
  • player_return('Hello, World!',nil,player) -- returns 'Hello, World!' to the given player
  • +
+ +
+
+ + ExpLib.tick_to_hour (tick) +
+
+ Convert ticks to hours + + +

Parameters:

+
    +
  • tick + number + tick to convert to hours +
  • +
+ +

Returns:

+
    + + number + the number of whole hours from this tick +
+ + + +

Usage:

+
    +
    tick_to_hour(216001) -- return 1
    +
+ +
+
+ + ExpLib.tick_to_min (tick) +
+
+ Convert ticks to minutes + + +

Parameters:

+
    +
  • tick + number + tick to convert to minutes +
  • +
+ +

Returns:

+
    + + number + the number of whole minutes from this tick +
+ + + +

Usage:

+
    +
    tick_to_hour(3601) -- return 1
    +
+ +
+
+ + ExpLib.tick_to_display_format (tick) +
+
+ Converts a tick into a clean format for end user + + +

Parameters:

+
    +
  • tick + number + the tick to convert +
  • +
+ +

Returns:

+
    + + string + the formated string +
+ + + +

Usage:

+
    +
  • tick_to_display_format(3600) -- return '1.00 M'
  • +
  • tick_to_display_format(234000) -- return '1 H 5 M'
  • +
+ +
+
+ + ExpLib.gui_tree (root) +
+
+ Used as a way to view the structure of a gui, used for debuging + + +

Parameters:

+
    +
  • root + LuaGuiElement + the root to start the tree from +
  • +
+ +

Returns:

+
    + + table + the table that describes the gui +
+ + + +

Usage:

+
    +
    Gui_tree(root) returns all children of gui recusivly
    +
+ +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/modules/string.html b/doc/modules/string.html new file mode 100644 index 00000000..2f757761 --- /dev/null +++ b/doc/modules/string.html @@ -0,0 +1,310 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module string

+

Extends Lua 5.2 string.

+

+

See also:

+ + + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + +
trim (s)Returns a copy of the string with any leading or trailing whitespace from the string removed.
starts_with (s, start)Tests if a string starts with a given substring.
ends_with (s, ends)Tests if a string ends with a given substring.
contains (s, contains)Tests if a string contains a given substring.
is_empty (s)Tests whether a string is empty.
split (s[, sep="."[, pattern=false]])Splits a string into an array.
+ +
+
+ + +

Functions

+ +
+
+ + trim (s) +
+
+ Returns a copy of the string with any leading or trailing whitespace from the string removed. + + +

Parameters:

+
    +
  • s + string + the string to remove leading or trailing whitespace from +
  • +
+ +

Returns:

+
    + + string + a copy of the string without leading or trailing whitespace +
+ + + + +
+
+ + starts_with (s, start) +
+
+ Tests if a string starts with a given substring. + + +

Parameters:

+
    +
  • s + string + the string to check for the start substring +
  • +
  • start + string + the substring to test for +
  • +
+ +

Returns:

+
    + + boolean + true if the start substring was found in the string +
+ + + + +
+
+ + ends_with (s, ends) +
+
+ Tests if a string ends with a given substring. + + +

Parameters:

+
    +
  • s + string + the string to check for the end substring +
  • +
  • ends + string + the substring to test for +
  • +
+ +

Returns:

+
    + + boolean + true if the end substring was found in the string +
+ + + + +
+
+ + contains (s, contains) +
+
+ Tests if a string contains a given substring. + + +

Parameters:

+
    +
  • s + string + the string to check for the substring +
  • +
  • contains + string + the substring to test for +
  • +
+ +

Returns:

+
    + + boolean + true if the substring was found in the string +
+ + + + +
+
+ + is_empty (s) +
+
+ Tests whether a string is empty. + + +

Parameters:

+
    +
  • s + string + the string to test +
  • +
+ +

Returns:

+
    + + boolean + true if the string is empty +
+ + + + +
+
+ + split (s[, sep="."[, pattern=false]]) +
+
+ Splits a string into an array. + *Note:* Empty split substrings are not included in the resulting table. +

For example, `string.split("foo.bar...", ".", false)` results in the table `{"foo", "bar"}`. + + +

Parameters:

+
    +
  • s + string + the string to split +
  • +
  • sep + string + the separator to use. + (default ".") +
  • +
  • pattern + boolean + whether to interpret the separator as a lua pattern or plaintext for the string split + (default false) +
  • +
+ +

Returns:

+
    + + {string,...} + an array of strings +
+ + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/modules/table.html b/doc/modules/table.html new file mode 100644 index 00000000..ccf6d405 --- /dev/null +++ b/doc/modules/table.html @@ -0,0 +1,1145 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module table

+

Extends Lua 5.2 table.

+

+

See also:

+ + + +

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.
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.
find (tbl, func[, ...])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.
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.
each (tbl, func[, ...])Given a function, apply it to each element in the table.
flatten (tbl[, level])Returns a new array that is a one-dimensional recursive flattening of the given array.
first (tbl)Given an array, returns the first element or nil if no element exists.
last (tbl)Given an array, returns the last element or nil if no elements exist.
min (tbl)Given an array of only numeric values, returns the minimum or nil if no element exists.
max (tbl)Given an array of only numeric values, returns the maximum or nil if no element exists.
sum (tbl)Given an array of only numeric values, return the sum of all values, or 0 for empty arrays.
avg (tbl)Given an array of only numeric values, returns the average or nil if no element exists.
merge (tblA, tblB[, array_merge=false])Merges two tables — values from first get overwritten by the second.
deepcopy (object)Creates a deep copy of table without copying Factorio objects.
values (tbl[, sorted[, as_string]])Returns a copy of all of the values in the table.
keys (tbl[, sorted[, as_string]])Returns a copy of all of the keys in the table.
remove_keys (tbl, keys)Removes keys from a table by setting the values associated with the keys to nil.
count_keys (tbl[, func[, ...]])Returns the number of keys in a table, if func is passed only count keys when the function is true.
invert (tbl)Returns an inverted (***{[value] = key,...}***) copy of the given table.
size (table)Return the size of a table using built in table_size function
arr_to_bool (tbl)For all string or number values in an array map them to a key = true table
key_to_str (k)Returns a value in a form able to be read as a key
to_string (tbl)Returns a table in a form able to be read as a table
json (lua_table)Simmilar to table.to_string but converts a lua table to a json one
autokey (tbl, str)Returns the closest match to a key
alphanumsort (tbl)Returns the list is a sorted way that would be expected by people (this is by key)
keysort (tbl)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 +
+ + + +

Usage:

+
    +
  • a= { 1, 2, 3, 4, 5}
    +table.map(a, function(v) return v * 10 end) --produces: { 10, 20, 30, 40, 50 }
  • +
  • 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. + + +

Parameters:

+
    +
  • tbl + table + the table to be filtered +
  • +
  • func + function + the function to filter values +
  • +
  • ... + additional arguments passed to the function + (optional) +
  • +
+ +

Returns:

+
    + + table + a new table containing the filtered key-value pairs +
+ + + +

Usage:

+
    +
  • a= { 1, 2, 3, 4, 5}
    +table.filter(a, function(v) return v % 2 == 0 end) --produces: { 2, 4 }
  • +
  • a = {1, 2, 3, 4, 5}
    +table.filter(a, function(v, k, x) return k % 2 == 1 end) --produces: { 1, 3, 5 }
  • +
+ +
+
+ + find (tbl, func[, ...]) +
+
+ 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. + + +

Parameters:

+
    +
  • tbl + table + the table to be searched +
  • +
  • func + function + the function to use to search for any matching element +
  • +
  • ... + additional arguments passed to the function + (optional) +
  • +
+ +

Returns:

+
    + + nil or Mixed + the first found value, or nil if none was found +
+ + + +

Usage:

+
    +
  • a= { 1, 2, 3, 4, 5}
    +table.find(a, function(v) return v % 2 == 0 end) --produces: 2
  • +
  • a = {1, 2, 3, 4, 5}
    +table.find(a, function(v, k, x) return k % 2 == 1 end) --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. + + +

Parameters:

+
    +
  • tbl + table + the table to be searched +
  • +
  • func + function + the function to use to search for any matching element +
  • +
  • ... + additional arguments passed to the function + (optional) +
  • +
+ +

Returns:

+
    + + boolean + true if an element was found, false if none was found +
+ + +

See also:

+ + +

Usage:

+
    +
  • a= { 1, 2, 3, 4, 5}
    +table.any(a, function(v) return v % 2 == 0 end) --produces: true
  • +
  • a = {1, 2, 3, 4, 5}
    +table.any(a, function(v, k, x) return k % 2 == 1 end) --produces: true
  • +
+ +
+
+ + each (tbl, func[, ...]) +
+
+ Given a function, apply it to each element in the table. + Passes the index as the second argument to the function. +

Iteration is aborted if the applied function returns true for any element during iteration. + + +

Parameters:

+
    +
  • tbl + table + the table to be iterated +
  • +
  • func + function + the function to apply to elements +
  • +
  • ... + additional arguments passed to the function + (optional) +
  • +
+ +

Returns:

+
    + + table + the table where the given function has been applied to its elements +
+ + + +

Usage:

+
    +
    a = {10, 20, 30, 40}
    +table.each(a, function(v) game.print(v) end) --prints 10, 20, 30, 40, 50
    +
+ +
+
+ + flatten (tbl[, level]) +
+
+ 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. + + +

Parameters:

+
    +
  • tblA + table + first table +
  • +
  • tblB + table + second table +
  • +
  • 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 == true then return x else return 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. + + +

Parameters:

+
    +
  • object + table + the table to copy +
  • +
+ +

Returns:

+
    + + table + a copy of the table +
+ + + +

Usage:

+
    +
    local copy = table.deepcopy[data.raw.["stone-furnace"]["stone-furnace"]] -- returns a copy of the stone furnace entity
    +
+ +
+
+ + values (tbl[, sorted[, as_string]]) +
+
+ Returns a copy of all of the values in the table. + + +

Parameters:

+
    +
  • tbl + table + the table to copy the keys from, or an empty table if tbl is nil +
  • +
  • sorted + boolean + whether to sort the keys (slower) or keep the random order from pairs() + (optional) +
  • +
  • as_string + boolean + whether to try and parse the values as strings, or leave them as their existing type + (optional) +
  • +
+ +

Returns:

+
    + + array + an array with a copy of all the values in the table +
+ + + + +
+
+ + keys (tbl[, sorted[, as_string]]) +
+
+ Returns a copy of all of the keys in the table. + + +

Parameters:

+
    +
  • tbl + table + the table to copy the keys from, or an empty table if tbl is nil +
  • +
  • sorted + boolean + whether to sort the keys (slower) or keep the random order from pairs() + (optional) +
  • +
  • as_string + boolean + whether to try and parse the keys as strings, or leave them as their existing type + (optional) +
  • +
+ +

Returns:

+
    + + array + an array with a copy of all the keys in the table +
+ + + + +
+
+ + remove_keys (tbl, keys) +
+
+ Removes keys from a table by setting the values associated with the keys to nil. + + +

Parameters:

+
    +
  • tbl + table + the table to remove the keys from +
  • +
  • keys + {Mixed,...} + an array of keys that exist in the given table +
  • +
+ +

Returns:

+
    + + table + tbl without the specified keys +
+ + + +

Usage:

+
    +
  • local a = {1, 2, 3, 4}
    +table.remove_keys(a, {1,3}) --returns {nil, 2, nil, 4}
  • +
  • local b = {k1 = 1, k2 = 'foo', old_key = 'bar'}
    +table.remove_keys(b, {'old_key'}) --returns {k1 = 1, k2 = 'foo'}
  • +
+ +
+
+ + count_keys (tbl[, func[, ...]]) +
+
+ Returns the number of keys in a table, if func is passed only count keys when the function is true. + + +

Parameters:

+
    +
  • tbl + table + to count keys +
  • +
  • func + function + to incremement counter + (optional) +
  • +
  • ... + additional arguments passed to the function + (optional) +
  • +
+ +

Returns:

+
    +
  1. + number + The number of keys matching the function or the number of all keys if func isn't passed
  2. +
  3. + number + The total number of keys
  4. +
+ + + +

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 == 1 end) -- 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(). + + +

Parameters:

+
    +
  • tbl + table + the table to invert +
  • +
+ +

Returns:

+
    + + table + a new table with inverted mapping +
+ + + +

Usage:

+
    +
  • local a = {k1 = 'foo', k2 = 'bar'}
    +table.invert(a) --returns {'foo' = k1, 'bar' = k2}
  • +
  • local b = {k1 = 'foo', k2 = 'bar', k3 = 'bar'}
    +table.invert(b) --returns {'foo' = k1, 'bar' = ?}
  • +
+ +
+
+ + size (table) +
+
+ Return the size of a table using built in table_size function + + +

Parameters:

+
    +
  • table + table + to use +
  • +
+ +

Returns:

+
    + + int + size of the table +
+ + + + +
+
+ + arr_to_bool (tbl) +
+
+ For all string or number values in an array map them to a key = true table + + +

Parameters:

+
    +
  • tbl + table + the table to convert +
  • +
+ +

Returns:

+
    + + table + the converted table +
+ + + +

Usage:

+
    +
    local a = {"v1", "v2"}
    + table.array_to_dict_bool(a) -- return {["v1"] = true, ["v2"]= true}
    +
+ +
+
+ + key_to_str (k) +
+
+ Returns a value in a form able to be read as a key + + +

Parameters:

+
    +
  • k + key to convert +
  • +
+ +

Returns:

+
    + + string + the converted key +
+ + + +

Usage:

+
    +
    local a = 'key'
    + table.key_to_str(a) -- return '["key"]'
    +
+ +
+
+ + to_string (tbl) +
+
+ Returns a table in a form able to be read as a table + + +

Parameters:

+
    +
  • tbl + table + table to convert +
  • +
+ +

Returns:

+
    + + string + the converted table +
+ + + +

Usage:

+
    +
    local a = {k1='foo',k2='bar'}
    + table.tostring(a) -- return '{["k1"]="foo",["k2"]="bar"}'
    +
+ +
+
+ + json (lua_table) +
+
+ Simmilar to table.to_string but converts a lua table to a json one + + +

Parameters:

+
    +
  • lua_table + table + the table to convert +
  • +
+ +

Returns:

+
    + + string + the table in a json format +
+ + + +

Usage:

+
    +
    local a = {k1='foo',k2='bar'}
    + talbe.json(a) -- return '{"k1":"foo","k2":"bar"}'
    +
+ +
+
+ + autokey (tbl, str) +
+
+ Returns the closest match to a key + + +

Parameters:

+
    +
  • tbl + +
  • +
  • str + +
  • +
+ + + + +

Usage:

+
    +
    tbl = {foo=1,bar=2}
    + table.autokey(tbl,'f') -- return 1
    +
+ +
+
+ + alphanumsort (tbl) +
+
+ Returns the list is a sorted way that would be expected by people (this is by key) + + +

Parameters:

+
    +
  • tbl + table + the table to be sorted +
  • +
+ +

Returns:

+
    + + table + the sorted table +
+ + + +

Usage:

+
    +
    tbl = table.alphanumsort(tbl)
    +
+ +
+
+ + keysort (tbl) +
+
+ Returns the list is a sorted way that would be expected by people (this is by key) (faster alterative than above) + + +

Parameters:

+
    +
  • tbl + table + the table to be sorted +
  • +
+ +

Returns:

+
    + + table + the sorted table +
+ + + +

Usage:

+
    +
    tbl = table.alphanumsort(tbl)
    +
+ +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/scripts/control.lua.html b/doc/scripts/control.lua.html new file mode 100644 index 00000000..ad99953a --- /dev/null +++ b/doc/scripts/control.lua.html @@ -0,0 +1,85 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Script control.lua

+

Root Script File

+

+ + + +
+
+ + + + +
+
+
+generated by LDoc 1.4.6 +Last updated 2018-05-29 20:15:05 +
+
+ + diff --git a/doc/scripts/index.lua.html b/doc/scripts/index.lua.html new file mode 100644 index 00000000..888d05bc --- /dev/null +++ b/doc/scripts/index.lua.html @@ -0,0 +1,85 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Script index.lua

+

Used to index the files to be loaded

+

+ + + +
+
+ + + + +
+
+
+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 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -108,11 +108,11 @@ Factorio Softmod Manager - modules.expgaminglib.control - Loads a table into _G even when sandboxed; will not overwrite values or append to tables; will not work during runtime to avoid desyncs + ExpGamingLib + Adds some common functions used though out all ExpGaming modules - defines.color + Color A defines module for retrieving colors by name. @@ -148,7 +148,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/ldoc.css b/doc/ldoc.css index 52c4ad2b..809ab237 100644 --- a/doc/ldoc.css +++ b/doc/ldoc.css @@ -1,303 +1,244 @@ -/* BEGIN RESET +/* universal */ -Copyright (c) 2010, Yahoo! Inc. All rights reserved. -Code licensed under the BSD License: -http://developer.yahoo.com/yui/license.html -version: 2.8.2r1 -*/ -html { - color: #000; - background: #FFF; -} -body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td { - margin: 0; - padding: 0; -} -table { - border-collapse: collapse; - border-spacing: 0; -} -fieldset,img { - border: 0; -} -address,caption,cite,code,dfn,em,strong,th,var,optgroup { - font-style: inherit; - font-weight: inherit; -} -del,ins { - text-decoration: none; -} -li { - margin-left: 20px; -} -caption,th { - text-align: left; -} -h1,h2,h3,h4,h5,h6 { - font-size: 100%; - font-weight: bold; -} -q:before,q:after { - content: ''; -} -abbr,acronym { - border: 0; - font-variant: normal; -} -sup { - vertical-align: baseline; -} -sub { - vertical-align: baseline; -} -legend { - color: #000; -} -input,button,textarea,select,optgroup,option { - font-family: inherit; - font-size: inherit; - font-style: inherit; - font-weight: inherit; -} -input,button,textarea,select {*font-size:100%; -} -/* END RESET */ +body{background-color:#0F0F0F;color:#C8C8C8;font-family:'Lucida Grande',Arial,sans-serif} +a{text-decoration:none;border-style:none;outline:none!important} +a:link{color:#FF7200;text-decoration:none} +a:visited{color:#FF7200;text-decoration:none} +a:hover{color:#C8C8C8;text-decoration:none} +a:active{color:#C8C8C8;text-decoration:none} +h1{font-size:2.5rem} +h2{font-size:2.3rem} +h3{font-size:2rem} +h4{font-size:1.8rem} +h5{font-size:1.6rem} -body { - margin-left: 1em; - margin-right: 1em; - font-family: arial, helvetica, geneva, sans-serif; - background-color: #ffffff; margin: 0px; + +/* table */ + +table,thead{text-align:left} +table,th,td{padding:2px} + + +/* sidebar */ + +.sidebar {height: 100%} + +.sidebar-custom { + border-right: 1px solid #2C2C2C; + padding-right: 1.4rem; + bottom: 0rem; } -code, tt { font-family: monospace; font-size: 1.1em; } -span.parameter { font-family:monospace; } -span.parameter:after { content:":"; } -span.types:before { content:"("; } -span.types:after { content:")"; } -.type { font-weight: bold; font-style:italic } - -body, p, td, th { font-size: .95em; line-height: 1.2em;} - -p, ul { margin: 10px 0 0 0px;} - -strong { font-weight: bold;} - -em { font-style: italic;} - -h1 { - font-size: 1.5em; - margin: 20px 0 20px 0; -} -h2, h3, h4 { margin: 15px 0 10px 0; } -h2 { font-size: 1.25em; } -h3 { font-size: 1.15em; } -h4 { font-size: 1.06em; } - -a:link { font-weight: bold; color: #004080; text-decoration: none; } -a:visited { font-weight: bold; color: #006699; text-decoration: none; } -a:link:hover { text-decoration: underline; } - -hr { - color:#cccccc; - background: #00007f; - height: 1px; -} - -blockquote { margin-left: 3em; } - -ul { list-style-type: disc; } - -p.name { - font-family: "Andale Mono", monospace; - padding-top: 1em; -} - -pre { - background-color: rgb(245, 245, 245); - border: 1px solid #C0C0C0; /* silver */ - padding: 10px; - margin: 10px 0 10px 0; - overflow: auto; - font-family: "Andale Mono", monospace; -} - -pre.example { - font-size: .85em; -} - -table.index { border: 1px #00007f; } -table.index td { text-align: left; vertical-align: top; } - -#container { - margin-left: 1em; - margin-right: 1em; - background-color: #f0f0f0; -} - -#product { - text-align: center; - border-bottom: 1px solid #cccccc; - background-color: #ffffff; -} - -#product big { - font-size: 2em; -} - -#main { - background-color: #f0f0f0; - border-left: 2px solid #cccccc; -} - -#navigation { - float: left; - width: 14em; - vertical-align: top; - background-color: #f0f0f0; - overflow: visible; -} - -#navigation h2 { - background-color:#e7e7e7; - font-size:1.1em; - color:#000000; - text-align: left; - padding:0.2em; - border-top:1px solid #dddddd; - border-bottom:1px solid #dddddd; -} - -#navigation ul -{ - font-size:1em; - list-style-type: none; - margin: 1px 1px 10px 1px; -} - -#navigation li { - text-indent: -1em; - display: block; - margin: 3px 0px 0px 22px; -} - -#navigation li li a { - margin: 0px 3px 0px -1em; -} - -#content { - margin-left: 14em; - padding: 1em; - width: 700px; - border-left: 2px solid #cccccc; - border-right: 2px solid #cccccc; - background-color: #ffffff; -} - -#about { - clear: both; - padding: 5px; - border-top: 2px solid #cccccc; - background-color: #ffffff; -} - -@media print { - body { - font: 12pt "Times New Roman", "TimeNR", Times, serif; - } - a { font-weight: bold; color: #004080; text-decoration: underline; } - - #main { - background-color: #ffffff; - border-left: 0px; - } - - #container { - margin-left: 2%; - margin-right: 2%; - background-color: #ffffff; - } - - #content { - padding: 1em; - background-color: #ffffff; - } - - #navigation { - display: none; - } - pre.example { - font-family: "Andale Mono", monospace; - font-size: 10pt; - page-break-inside: avoid; +@supports (-ms-ime-align:auto) { + .sidebar-custom { + height: 99%; } } +.up-to-top { + top: 1.5rem; + position: -webkit-sticky; + position: sticky; + text-align: right; + margin-right: 0.2rem; +} + +.up-to-top a{padding:20px} +.up-to-top a:link{color:#FF7200} +.up-to-top a:hover{color:#C8C8C8} +.icon-arrow-right-custom{margin-bottom:3px} +.project-infobox{text-align:right} +.project-infobox .project-desc{font-style:italic} +.nav-modules{text-align:right} +.nav-module-contents{text-align:right} + + +/* navigation */ + +.nav .nav a{color:#FF7200} +.nav .nav a:link{color:#FF7200} +.nav .nav a:visited{color:#FF7200} +.nav .nav a:hover{color:#C8C8C8;text-decoration:none} +.nav .nav-item.active>a:hover{color:#C8C8C8;text-decoration:none} +.nav .nav-item.active{margin-left:0} +.nav .nav a:active{color:#C8C8C8} + + +/* main page module list */ + +.body-module-name {font-weight: 500} + table.module_list { - border-width: 1px; - border-style: solid; - border-color: #cccccc; + border-spacing: 0; + display: table; border-collapse: collapse; + margin-bottom: 2.0rem; } + table.module_list td { - border-width: 1px; - padding: 3px; - border-style: solid; - border-color: #cccccc; + border-top: 1px solid #2C2C2C; + border-bottom: 1px solid #2C2C2C; + padding: 3px 7px 3px 7px; } -table.module_list td.name { background-color: #f0f0f0; min-width: 200px; } -table.module_list td.summary { width: 100%; } +table.module_list td.name { + vertical-align: top; + min-width: 125px; + background-color: #0D0D0D; +} -table.function_list { - border-width: 1px; - border-style: solid; - border-color: #cccccc; +table.module_list td.summary {vertical-align: top} + +.module_list p {margin:0px} + +/* section */ + +.module-see-also li { + margin-top: 0.5rem; +} + +.section-title a:link{color:#C8C8C8} +.section-title a:visited{color:#C8C8C8} +.section-title a:hover{color:#FF7200} +.section-title a:active{color:#FF7200} + +.section-body-container dd { + margin: 1.0rem 0 1.5rem 0; +} + +table.section-content-list { + border-spacing: 0; + display: table; border-collapse: collapse; -} -table.function_list td { - border-width: 1px; - padding: 3px; - border-style: solid; - border-color: #cccccc; -} -table.function_list td.name { background-color: #f0f0f0; min-width: 200px; } -table.function_list td.summary { width: 100%; } - -ul.nowrap { - overflow:auto; - white-space:nowrap; + margin-bottom: 1.5rem; } -dl.table dt, dl.function dt {border-top: 1px solid #ccc; padding-top: 1em;} -dl.table dd, dl.function dd {padding-bottom: 1em; margin: 10px 0 0 20px;} -dl.table h3, dl.function h3 {font-size: .95em;} +table.section-content-list td { + border-top: 1px solid #2C2C2C; + border-bottom: 1px solid #2C2C2C; + padding: 3px 7px 3px 7px; +} -/* stop sublists from having initial vertical space */ -ul ul { margin-top: 0px; } -ol ul { margin-top: 0px; } -ol ol { margin-top: 0px; } -ul ol { margin-top: 0px; } +table.section-content-list td.name { + background-color: #0D0D0D; + vertical-align: top; + white-space: nowrap; +} -/* make the target distinct; helps when we're navigating to a function */ -a:target + * { - background-color: #FF9; +table.section-content-list td.summary { + min-width: 200px; + vertical-align: top; +} + +.section-content-list p {margin: 0px} + +div.section-item-header .section-item-title { + font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; + font-size: 1.5rem; + margin-left: 3px; +} + +.section-title:target { + padding-left: 7px; + border-left: 5px solid #FF7200; + text-decoration: none; +} + +.section-item-title:target { + padding: 3px 5px 3px 5px; + background-color: #FF7200; + color: #000000; + text-decoration: none; +} + +.section-item-body {margin-left: 4rem} + +/*.section-subitem-li { + padding-left: 1.28571429em; + text-indent: -1.28571429em; +}*/ + +/*.section-subitem-module-field-li { + margin-left: -1.28571429em; + padding-left: 1.28571429em; + text-indent: -1.28571429em; +}*/ + +/* example pages */ + +pre.code.example{margin:0 0 1em} +pre.code.example code h2{display:none} +pre.code.example code pre{margin:0} + + +/* usage code */ + +code{background-color:#181818;color:#C8C8C8;font-size:1.3rem} +pre.code code{background-color:#282828;color:#C8C8C8;font-size:1.3rem} +pre.code .comment{color:#998d70} +pre.code .constant{color:#a8660d} +pre.code .escape{color:#844631} +pre.code .keyword{color:#c43724;font-weight:700} +pre.code .library{color:#0e7c6b} +pre.code .marker{color:#512b1e;background:#fedc56;font-weight:700} +pre.code .string{color:#99ca3c} +pre.code .number{color:#f8660d} +pre.code .operator{color:#2239a8;font-weight:700} +pre.code .preprocessor,pre .prepro{color:#a33243} +pre.code .global{color:#5798da} +pre.code .user-keyword{color:purple} +pre.code .prompt{color:#998d70} +pre.code .url{color:#272fc2;text-decoration:underline} + + +/* footer */ + +.footer{height:65px} +.sidebar-footer{text-align:left;padding-right:33px} +.content-footer{text-align:right} + + +/* misc */ + +.types {font-weight:bold;font-style:italic} + +.divider[data-content]::after,.divider-vert[data-content]::after{background:#262626;color:#C8C8C8} +.divider-custom{border-width:1px;border-color:#585959} + + +/* fragment hashtag */ + +.fragment-hashtag{color:#3C3C3C} +a.fragment-hashtag{color:#3C3C3C} +a.fragment-hashtag:hover{color:#FF7200} + + +/* mobile */ + +@media screen and (max-width: 540px) { + .up-to-top {display: none} + .sidebar-custom { + border-right: 1px solid #2C2C2C; + padding-right: 1.4rem; + bottom: 0rem; + margin-right: 0px; + } + .sidebar-footer { + text-align: right; + padding-right: 10px; + white-space: nowrap; + } + table.function_list td.name { + background-color: #0D0D0D; + vertical-align: top; + white-space: normal; + } + .function-item-spec-body-wrap {margin-left: 1.5rem} } -/* styles for prettification of source */ -pre .comment { color: #558817; } -pre .constant { color: #a8660d; } -pre .escape { color: #844631; } -pre .keyword { color: #aa5050; font-weight: bold; } -pre .library { color: #0e7c6b; } -pre .marker { color: #512b1e; background: #fedc56; font-weight: bold; } -pre .string { color: #8080ff; } -pre .number { color: #f8660d; } -pre .operator { color: #2239a8; font-weight: bold; } -pre .preprocessor, pre .prepro { color: #a33243; } -pre .global { color: #800080; } -pre .user-keyword { color: #800080; } -pre .prompt { color: #558817; } -pre .url { color: #272fc2; text-decoration: underline; } +/* tablets */ +@media screen and (min-width: 540px) and (max-width: 780px) { + .sidebar-footer {white-space: nowrap} +} diff --git a/doc/modules/Color.html b/doc/modules/Color.html new file mode 100644 index 00000000..94f0acff --- /dev/null +++ b/doc/modules/Color.html @@ -0,0 +1,519 @@ + + + + + Reference + + + + +
    + +
    + +
    +
    +
    + + +
    + + + + + + +
    + +

    Module Color

    +

    A defines module for retrieving colors by name.

    +

    + Extends the Factorio defines table.

    +

    Usage:

    +
      +
      require('stdlib/defines/color')
      +
      +
    + + +

    Functions

    + + + + + + + + + + + + + + + + + +
    set ([color=white[, alpha=1]])Set a value for the alpha channel in the given color table.
    to_table (c_arr)Converts a color in the array format to a color in the table format.
    from_rgb ([r=0[, g=0[, b=0[, a=255]]]])Converts a color in the rgb format to a color table
    from_hex (hex[, alpha=1])Get a color table with a hexadecimal string.
    +

    Tables

    + + + + + + + + + + + + + +
    defines.colorA table of colors allowing retrieval by color name.
    defines.anticolorReturns white for dark colors or black for lighter colors.
    defines.lightcolorReturns a lighter color of a named color.
    + +
    +
    + + +

    Functions

    + +
    +
    + + set ([color=white[, alpha=1]]) +
    +
    + Set a value for the alpha channel in the given color table. + `color.a` represents the alpha channel in the given color table. +
      +
    • If ***alpha*** is given, set `color.a` to it. +
    • If ***alpha*** is not given, and if the given color table does not have a value for `color.a`, set `color.a` to 1. +
    • If ***alpha*** is not given, and if the given color table already has a value for `color.a`, then leave `color.a` alone. +
    + + +

    Parameters:

    +
      +
    • color + defines.color or Concepts.Color + the color to configure + (default white) +
    • +
    • alpha + float + the alpha value (*[0 - 1]*) to set for the given color + (default 1) +
    • +
    + +

    Returns:

    +
      + + Concepts.Color + a color table that has the specified value for the alpha channel +
    + + + + +
    +
    + + to_table (c_arr) +
    +
    + Converts a color in the array format to a color in the table format. + + +

    Parameters:

    +
      +
    • c_arr + table + the color to convert +
    • +
    + +

    Returns:

    +
      + + Concepts.Color + a converted color — { r = c\_arr[1], g = c\_arr[2], b = c\_arr[3], a = c\_arr[4] } +
    + + + + +
    +
    + + from_rgb ([r=0[, g=0[, b=0[, a=255]]]]) +
    +
    + Converts a color in the rgb format to a color table + + +

    Parameters:

    +
      +
    • r + int + 0-255 red + (default 0) +
    • +
    • g + int + 0-255 green + (default 0) +
    • +
    • b + int + 0-255 blue + (default 0) +
    • +
    • a + int + 0-255 alpha + (default 255) +
    • +
    + +

    Returns:

    +
      + + Concepts.Color + +
    + + + + +
    +
    + + from_hex (hex[, alpha=1]) +
    +
    + Get a color table with a hexadecimal string. + Optionally provide the value for the alpha channel. + + +

    Parameters:

    +
      +
    • hex + string + hexadecimal color string (#ffffff, not #fff) +
    • +
    • alpha + float + the alpha value to set; such that ***[ 0 ⋜ value ⋜ 1 ]*** + (default 1) +
    • +
    + +

    Returns:

    +
      + + Concepts.Color + a color table with RGB converted from Hex and with alpha +
    + + + + +
    +
    +

    Tables

    + +
    +
    + + defines.color +
    +
    + A table of colors allowing retrieval by color name. + + +

    Fields:

    +
      +
    • white + Concepts.Color + +
    • +
    • black + Concepts.Color + +
    • +
    • darkgrey + Concepts.Color + +
    • +
    • grey + Concepts.Color + +
    • +
    • lightgrey + Concepts.Color + +
    • +
    • red + Concepts.Color + +
    • +
    • darkred + Concepts.Color + +
    • +
    • lightred + Concepts.Color + +
    • +
    • green + Concepts.Color + +
    • +
    • darkgreen + Concepts.Color + +
    • +
    • lightgreen + Concepts.Color + +
    • +
    • blue + Concepts.Color + +
    • +
    • darkblue + Concepts.Color + +
    • +
    • lightblue + Concepts.Color + +
    • +
    • orange + Concepts.Color + +
    • +
    • yellow + Concepts.Color + +
    • +
    • pink + Concepts.Color + +
    • +
    • purple + Concepts.Color + +
    • +
    • brown + Concepts.Color + +
    • +
    + + + + +

    Usage:

    +
      +
      color = defines.color.red
      +
    + +
    +
    + + defines.anticolor +
    +
    + Returns white for dark colors or black for lighter colors. + + +

    Fields:

    +
      +
    • green + Concepts.Color + defines.color.black +
    • +
    • grey + Concepts.Color + defines.color.black +
    • +
    • lightblue + Concepts.Color + defines.color.black +
    • +
    • lightgreen + Concepts.Color + defines.color.black +
    • +
    • lightgrey + Concepts.Color + defines.color.black +
    • +
    • lightred + Concepts.Color + defines.color.black +
    • +
    • orange + Concepts.Color + defines.color.black +
    • +
    • white + Concepts.Color + defines.color.black +
    • +
    • yellow + Concepts.Color + defines.color.black +
    • +
    • black + Concepts.Color + defines.color.white +
    • +
    • blue + Concepts.Color + defines.color.white +
    • +
    • brown + Concepts.Color + defines.color.white +
    • +
    • darkblue + Concepts.Color + defines.color.white +
    • +
    • darkgreen + Concepts.Color + defines.color.white +
    • +
    • darkgrey + Concepts.Color + defines.color.white +
    • +
    • darkred + Concepts.Color + defines.color.white +
    • +
    • pink + Concepts.Color + defines.color.white +
    • +
    • purple + Concepts.Color + defines.color.white +
    • +
    • red + Concepts.Color + defines.color.white +
    • +
    + + + + + +
    +
    + + defines.lightcolor +
    +
    + Returns a lighter color of a named color. + + +

    Fields:

    +
      +
    • white + Concepts.Color + defines.color.lightgrey +
    • +
    • grey + Concepts.Color + defines.color.darkgrey +
    • +
    • lightgrey + Concepts.Color + defines.color.grey +
    • +
    • red + Concepts.Color + defines.color.lightred +
    • +
    • green + Concepts.Color + defines.color.lightgreen +
    • +
    • blue + Concepts.Color + defines.color.lightblue +
    • +
    • yellow + Concepts.Color + defines.color.orange +
    • +
    • pink + Concepts.Color + defines.color.purple +
    • +
    + + + + + +
    +
    + + +
    +
    +
    +generated by LDoc 1.4.6 +Last updated 2018-05-29 20:54:20 +
    +
    + + diff --git a/doc/modules/modules.expgaminglib.control.html b/doc/modules/ExpGamingLib.html similarity index 78% rename from doc/modules/modules.expgaminglib.control.html rename to doc/modules/ExpGamingLib.html index 63260c90..f5ea6be6 100644 --- a/doc/modules/modules.expgaminglib.control.html +++ b/doc/modules/ExpGamingLib.html @@ -49,8 +49,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -66,44 +66,47 @@
    -

    Module modules.expgaminglib.control

    -

    Loads a table into _G even when sandboxed; will not overwrite values or append to tables; will not work during runtime to avoid desyncs

    +

    Module ExpGamingLib

    +

    Adds some common functions used though out all ExpGaming modules

    -

    Usage:

    +

    Info:

      -
      unpack_to_G{key1='foo',key2='bar'}
      -
      +
    • Author: Cooldude2606

    Functions

    - + + + + + - + - + - + - + - + - +
    ExpLib.get_env ()unpack_to_G (tbl)Loads a table into _G even when sandboxed; will not overwrite values or append to tables; will not work during runtime to avoid desyncs
    get_env () Used to get the current ENV with all _G keys removed; useful when saving function to global
    ExpLib.is_type (v[, test_type=nil])is_type (v[, test_type=nil]) Compear types faster for faster valadation of prams
    ExpLib.player_return (rtn[, colour=defines.colour.white[, player=game.player]])player_return (rtn[, colour=defines.colour.white[, player=game.player]]) Will return a value of any type to the player/server console, allows colour for in-game players
    ExpLib.tick_to_hour (tick)tick_to_hour (tick) Convert ticks to hours
    ExpLib.tick_to_min (tick)tick_to_min (tick) Convert ticks to minutes
    ExpLib.tick_to_display_format (tick)tick_to_display_format (tick) Converts a tick into a clean format for end user
    ExpLib.gui_tree (root)gui_tree (root) Used as a way to view the structure of a gui, used for debuging
    @@ -116,8 +119,33 @@
    - - ExpLib.get_env () + + unpack_to_G (tbl) +
    +
    + Loads a table into _G even when sandboxed; will not overwrite values or append to tables; will not work during runtime to avoid desyncs + + +

    Parameters:

    +
      +
    • tbl + table + table to be unpacked +
    • +
    + + + + +

    Usage:

    +
      +
      unpack_to_G{key1='foo',key2='bar'}
      +
    + +
    +
    + + get_env ()
    Used to get the current ENV with all _G keys removed; useful when saving function to global @@ -140,8 +168,8 @@
    - - ExpLib.is_type (v[, test_type=nil]) + + is_type (v[, test_type=nil])
    Compear types faster for faster valadation of prams @@ -176,8 +204,8 @@
    - - ExpLib.player_return (rtn[, colour=defines.colour.white[, player=game.player]]) + + player_return (rtn[, colour=defines.colour.white[, player=game.player]])
    Will return a value of any type to the player/server console, allows colour for in-game players @@ -212,8 +240,8 @@
    - - ExpLib.tick_to_hour (tick) + + tick_to_hour (tick)
    Convert ticks to hours @@ -243,8 +271,8 @@
    - - ExpLib.tick_to_min (tick) + + tick_to_min (tick)
    Convert ticks to minutes @@ -274,8 +302,8 @@
    - - ExpLib.tick_to_display_format (tick) + + tick_to_display_format (tick)
    Converts a tick into a clean format for end user @@ -306,8 +334,8 @@
    - - ExpLib.gui_tree (root) + + gui_tree (root)
    Used as a way to view the structure of a gui, used for debuging @@ -343,7 +371,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/modules/FSM.html b/doc/modules/FSM.html index 1c9fd6bf..4d8b6ca0 100644 --- a/doc/modules/FSM.html +++ b/doc/modules/FSM.html @@ -33,7 +33,7 @@

    Contents

    @@ -50,8 +50,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -73,7 +73,6 @@

    Usage:

      Manager = require("FactorioSoftmodManager")
      - Used to load all other modules that are indexed in index.lua
       

    Info:

    @@ -92,27 +91,31 @@ verbose (rtn, action) Used to call the output of the verbose when the current state allows it - -

    Fields

    - - + - + - + - + - + + + +
    setVerbosesetVerbose (settings) Main logic for allowing verbose at different stages though out the script
    sandboxsandbox (callback[, env]) Creates a sand box envorment and runs a callback in that sand box; provents global pollution
    loadModulesloadModules () Loads the modules that are present in the index list
    errorerror (err, callback) 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
    namesevent (event_name, callback)Event handler that modules can use, each module can register one function per event
    +

    Tables

    + + +
    Manager.event.names Sub set to Manger.event and acts as a coverter between event_name and event_id
    @@ -178,20 +181,17 @@ - -

    Fields

    - -
    - setVerbose + setVerbose (settings)
    Main logic for allowing verbose at different stages though out the script +

    Parameters:

      -
    • table +
    • settings newTbl the table that will be searched for settings to be updated
    • @@ -210,19 +210,20 @@
    - sandbox + sandbox (callback[, env])
    Creates a sand box envorment and runs a callback in that sand box; provents global pollution +

    Parameters:

      -
    • function - callback +
    • callback + function the function that will be ran in the sandbox
    • -
    • any - other params that the function will use +
    • env + any other params that the function will use (optional)
    @@ -240,7 +241,7 @@
    - loadModules + loadModules ()
    Loads the modules that are present in the index list @@ -261,24 +262,21 @@
    - error + error (err, callback)
    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 +

    Parameters:

      -
    • string - name - || fucntion the name that is given to the callback || the callback that will be used +
    • err + string or fucntion + the string to be passed to handlers; if a function it will register a handler
    • -
    • 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 +
    • callback + function + if given the err param will be used to given the handler a name
    @@ -298,18 +296,53 @@
    - - names + + event (event_name, callback) +
    +
    + Event handler that modules can use, each module can register one function per event + + +

    Parameters:

    +
      +
    • event_name + int or string + that referes to an event +
    • +
    • callback + function + the function that will be set for that event +
    • +
    + + + + +

    Usage:

    +
      +
    • Manager.event[event_name] = callback -- sets the callback for that event
    • +
    • Manager.event[event_name] = nil -- clears the callback for that event
    • +
    • Manager.event(event_name,callback) -- sets the callback for that event
    • +
    • Manager.event[event_name] -- returns the callback for that event or the event id if not registered
    • +
    • Manager.event(event_name) -- runs all the call backs for that event
    • +
    • Manager.event() -- returns the stop value for the event proccessor, if returned during an event will stop all other callbacks
    • +
    • #Manager.event -- returns the number of callbacks that are registered
    • +
    • pairs(Manager.events) -- returns event_id,table of callbacks
    • +
    + +
    +
    +

    Tables

    + +
    +
    + + Manager.event.names
    Sub set to Manger.event and acts as a coverter between event_name and event_id -
      -
    • names - -
    • -
    @@ -319,7 +352,7 @@

    Usage:

      -
      Manager.event[event_name] -- see above, can not be accessed via Manager.event.names
      +
      Manager.event[event_name]
    @@ -330,7 +363,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/modules/Game.html b/doc/modules/Game.html index 27aa7ddb..480765da 100644 --- a/doc/modules/Game.html +++ b/doc/modules/Game.html @@ -49,8 +49,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -224,7 +224,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/modules/defines.color.html b/doc/modules/defines.color.html index 38dc3a04..f30e1639 100644 --- a/doc/modules/defines.color.html +++ b/doc/modules/defines.color.html @@ -50,7 +50,7 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • +
  • ExpGamingLib
  • defines.color
  • Game
  • string
  • @@ -512,7 +512,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:19:50
    diff --git a/doc/modules/defines.time.html b/doc/modules/defines.time.html index fd176df3..a3200293 100644 --- a/doc/modules/defines.time.html +++ b/doc/modules/defines.time.html @@ -49,8 +49,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -141,7 +141,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/modules/expcore.commands.html b/doc/modules/expcore.commands.html index a553e593..ab6186c5 100644 --- a/doc/modules/expcore.commands.html +++ b/doc/modules/expcore.commands.html @@ -49,8 +49,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -129,7 +129,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/modules/expcore.gui.html b/doc/modules/expcore.gui.html index a6368064..afff68dd 100644 --- a/doc/modules/expcore.gui.html +++ b/doc/modules/expcore.gui.html @@ -49,8 +49,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -165,7 +165,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/modules/expcore.guiparts.center.html b/doc/modules/expcore.guiparts.center.html index ed110104..f57a9762 100644 --- a/doc/modules/expcore.guiparts.center.html +++ b/doc/modules/expcore.guiparts.center.html @@ -49,8 +49,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -283,7 +283,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/modules/expcore.guiparts.inputs.html b/doc/modules/expcore.guiparts.inputs.html index f8de31de..de43e3f5 100644 --- a/doc/modules/expcore.guiparts.inputs.html +++ b/doc/modules/expcore.guiparts.inputs.html @@ -49,8 +49,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -439,7 +439,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/modules/expcore.guiparts.left.html b/doc/modules/expcore.guiparts.left.html index ce4257f8..5fceed56 100644 --- a/doc/modules/expcore.guiparts.left.html +++ b/doc/modules/expcore.guiparts.left.html @@ -49,8 +49,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -186,7 +186,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/modules/expcore.guiparts.popup.html b/doc/modules/expcore.guiparts.popup.html index 987917ff..035361f7 100644 --- a/doc/modules/expcore.guiparts.popup.html +++ b/doc/modules/expcore.guiparts.popup.html @@ -49,8 +49,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -131,7 +131,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/modules/expcore.guiparts.toolbar.html b/doc/modules/expcore.guiparts.toolbar.html index cdbf2952..a2ee5fd1 100644 --- a/doc/modules/expcore.guiparts.toolbar.html +++ b/doc/modules/expcore.guiparts.toolbar.html @@ -49,8 +49,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -122,7 +122,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/modules/expcore.ranking.html b/doc/modules/expcore.ranking.html index d1d22f6e..dba445c8 100644 --- a/doc/modules/expcore.ranking.html +++ b/doc/modules/expcore.ranking.html @@ -49,8 +49,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -379,7 +379,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/modules/expcore.server.html b/doc/modules/expcore.server.html index 4dec0cb5..d79511d4 100644 --- a/doc/modules/expcore.server.html +++ b/doc/modules/expcore.server.html @@ -49,8 +49,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -564,7 +564,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/modules/expcore.sync.html b/doc/modules/expcore.sync.html index 74f4dd89..dc46d448 100644 --- a/doc/modules/expcore.sync.html +++ b/doc/modules/expcore.sync.html @@ -49,8 +49,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -535,7 +535,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/modules/string.html b/doc/modules/string.html index 2f757761..8119a1e6 100644 --- a/doc/modules/string.html +++ b/doc/modules/string.html @@ -49,8 +49,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -303,7 +303,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/modules/table.html b/doc/modules/table.html index ccf6d405..09446462 100644 --- a/doc/modules/table.html +++ b/doc/modules/table.html @@ -49,8 +49,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -1138,7 +1138,7 @@ some_func(1,2)
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/scripts/control.lua.html b/doc/scripts/control.lua.html index ad99953a..d638ec17 100644 --- a/doc/scripts/control.lua.html +++ b/doc/scripts/control.lua.html @@ -50,8 +50,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -78,7 +78,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/doc/scripts/index.lua.html b/doc/scripts/index.lua.html index 888d05bc..ac0f9c3b 100644 --- a/doc/scripts/index.lua.html +++ b/doc/scripts/index.lua.html @@ -50,8 +50,8 @@
  • expcore.server
  • expcore.sync
  • FSM
  • -
  • modules.expgaminglib.control
  • -
  • defines.color
  • +
  • ExpGamingLib
  • +
  • Color
  • Game
  • string
  • table
  • @@ -78,7 +78,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:15:05 +Last updated 2018-05-29 20:54:20
    diff --git a/modules/ExpGamingLib/control.lua b/modules/ExpGamingLib/control.lua index 8be81b65..efd40bd5 100644 --- a/modules/ExpGamingLib/control.lua +++ b/modules/ExpGamingLib/control.lua @@ -63,7 +63,7 @@ end -- @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 colour = ExpLib.is_type(colour) == 'table' and colour or defines.text_color[colour] ~= defines.color.white and defines.text_color[colour] or defines.color[colour] local player = player or game.player local function _return(callback,rtn) if ExpLib.is_type(rtn,'table') then diff --git a/modules/FactorioStdLib/color.lua b/modules/FactorioStdLib/color.lua index e2c32318..2fe1e8e8 100644 --- a/modules/FactorioStdLib/color.lua +++ b/modules/FactorioStdLib/color.lua @@ -32,9 +32,7 @@ defines = defines or {} --luacheck: ignore defines (This is used for testing loc -- @tfield Concepts.Color pink -- @tfield Concepts.Color purple -- @tfield Concepts.Color brown -defines.color = {} - -local colors = { +defines.color = { white = {r = 1.00, g = 1.00, b = 1.00}, black = {r = 0.00, g = 0.00, b = 0.00}, darkgrey = {r = 0.25, g = 0.25, b = 0.25}, @@ -55,7 +53,7 @@ local colors = { purple = {r = 0.60, g = 0.10, b = 0.60}, brown = {r = 0.60, g = 0.40, b = 0.10} } - +local colors = defines.color --- Returns white for dark colors or black for lighter colors. -- @tfield Concepts.Color green defines.color.black -- @tfield Concepts.Color grey defines.color.black @@ -76,9 +74,7 @@ local colors = { -- @tfield Concepts.Color pink defines.color.white -- @tfield Concepts.Color purple defines.color.white -- @tfield Concepts.Color red defines.color.white -defines.anticolor = {} - -local anticolors = { +defines.anticolor = { green = colors.black, grey = colors.black, lightblue = colors.black, @@ -109,8 +105,7 @@ local anticolors = { -- @tfield Concepts.Color blue defines.color.lightblue -- @tfield Concepts.Color yellow defines.color.orange -- @tfield Concepts.Color pink defines.color.purple -defines.lightcolor = {} -local lightcolors = { +defines.lightcolor = { white = colors.lightgrey, grey = colors.darkgrey, lightgrey = colors.grey, @@ -129,8 +124,7 @@ local lightcolors = { -- @tfield Concepts.Color med -- @tfield Concepts.Color high -- @tfield Concepts.Color crit -defines.text_color = {} -local text_color = { +defines.text_color = { info = {r = 0.21, g = 0.95, b = 1.00}, bg = {r = 0.00, g = 0.00, b = 0.00}, low = {r = 0.18, g = 0.77, b = 0.18}, @@ -139,76 +133,27 @@ local text_color = { crit = {r = 1.00, g = 0.00, b = 0.00} } +-- metatable remade by cooldude local _mt = { - color = { - __index = function(_, c) - return colors[c] - and { r = colors[c]['r'], g=colors[c]['g'], b=colors[c]['b'], a = colors[c]['a'] } - or { r = 1, g = 1, b = 1, a = 1 } - end, - __pairs = function() - local k = nil - local c = colors - return function() - local v - k, v = next(c, k) - return k, (v and {r = v['r'], g = v['g'], b = v['b'], a = v['a']}) or nil - end - end - }, - anticolor = { - __index = function(_, c) - return anticolors[c] - and { r = anticolors[c]['r'], g=anticolors[c]['g'], b=anticolors[c]['b'], a = anticolors[c]['a'] } - or { r = 1, g = 1, b = 1, a = 1 } - end, - __pairs = function() - local k = nil - local c = anticolors - return function() - local v - k, v = next(c, k) - return k, (v and {r = v['r'], g = v['g'], b = v['b'], a = v['a']}) or nil - end - end - }, - lightcolor = { - __index = function(_, c) - return lightcolors[c] - and { r = lightcolors[c]['r'], g=lightcolors[c]['g'], b=lightcolors[c]['b'], a = lightcolors[c]['a'] } - or { r = 1, g = 1, b = 1, a = 1 } - end, - __pairs = function() - local k = nil - local c = lightcolors - return function() - local v - k, v = next(c, k) - return k, (v and {r = v['r'], g = v['g'], b = v['b'], a = v['a']}) or nil - end - end - }, - text_color = { -- added by cooldude2606 - __index = function(_, c) - return text_color[c] - and { r = text_color[c]['r'], g=text_color[c]['g'], b=text_color[c]['b'], a = text_color[c]['a'] } - or { r = 1, g = 1, b = 1, a = 1 } - end, - __pairs = function() - local k = nil - local c = text_color - return function() - local v - k, v = next(c, k) - return k, (v and {r = v['r'], g = v['g'], b = v['b'], a = v['a']}) or nil - end - end - } + __index=function(tbl,key) + return rawget(tbl,tostring(key):lower()) or rawget(defines.color,'white') + end, + __pairs=function(tbl) + return function() + local v + k, v = next(tbl, k) + return k, (v and {r = v['r'], g = v['g'], b = v['b'], a = v['a']}) or nil + end, tbl, nil + end, + __eq=function(tbl1,tbl2) + return tbl1.r == tbl2.r and tbl1.g == tbl2.g and tbl1.b == tbl2.b and tbl1.a == tbl2.a + end } -setmetatable(defines.color, _mt.color) -setmetatable(defines.anticolor, _mt.anticolor) -setmetatable(defines.text_color, _mt.text_color) -setmetatable(defines.lightcolor, _mt.lightcolor) + +setmetatable(defines.color, _mt) +setmetatable(defines.anticolor, _mt) +setmetatable(defines.text_color, _mt) +setmetatable(defines.lightcolor, _mt) local Color = {} --luacheck: allow defined top diff --git a/modules/FactorioStdLib/load.lua b/modules/FactorioStdLib/load.lua deleted file mode 100644 index 0ee0dc47..00000000 --- a/modules/FactorioStdLib/load.lua +++ /dev/null @@ -1,36 +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 -]] - ---[[ -StdLib - -This file allow you to only require this one file to return the diffent libarys. -This file will return a function which can be used to access only the part you want. -Pass a table with the names of the objects you want and it will be return in that order -]] - -local StdLib = {} - -require('table') -require('string') -require('time') -StdLib.Color = require('color') -StdLib.Game = require('game') -StdLib.Event = require('event') - -return function(rtn) - local _return = {} - for _,name in pairs(rtn) do - if StdLib[name] then - verbose('StdLib Extraction: '..name) - table.insert(_return,StdLib[name]) - end - end - return unpack(_return) -end \ No newline at end of file diff --git a/modules/FactorioStdLib/softmod.json b/modules/FactorioStdLib/softmod.json index db47a8a3..98acc3a7 100644 --- a/modules/FactorioStdLib/softmod.json +++ b/modules/FactorioStdLib/softmod.json @@ -6,7 +6,51 @@ "version": "0.8.0", "location": "nil", "submodules": { - + "Color": { + "name": "Color", + "module": "Color", + "description": "A defines module for retrieving colors by name.", + "keywords": ["Standard Library","Lib","StdLib","Color","Extends"], + "version": "0.8.0", + "location": "color", + "dependencies": {} + }, + "Game": { + "name": "Game", + "module": "game", + "description": "The game module.", + "keywords": ["Standard Library","Lib","StdLib","Game","Extends"], + "version": "0.8.0", + "location": "game", + "dependencies": {} + }, + "String": { + "name": "String", + "module": "string", + "description": "Extends Lua 5.2 string.", + "keywords": ["Standard Library","Lib","StdLib","String","Extends"], + "version": "0.8.0", + "location": "string", + "dependencies": {} + }, + "Table": { + "name": "Table", + "module": "table", + "description": "Extends Lua 5.2 table.", + "keywords": ["Standard Library","Lib","StdLib","Table","Extends"], + "version": "0.8.0", + "location": "table", + "dependencies": {} + }, + "Time": { + "name": "Time", + "module": "Time", + "description": "A defines module for retrieving the number of ticks in 1 unit of time.", + "keywords": ["Standard Library","Lib","StdLib","Time","Extends"], + "version": "0.8.0", + "location": "time", + "dependencies": {} + } }, "author": "Afforess", "contact": "https://github.com/Afforess/Factorio-Stdlib/issues", diff --git a/modules/FactorioStdLib/string.lua b/modules/FactorioStdLib/string.lua index b151e34a..27a3aaed 100644 --- a/modules/FactorioStdLib/string.lua +++ b/modules/FactorioStdLib/string.lua @@ -1,6 +1,6 @@ --- Extends Lua 5.2 string. --- @module string --- @see string +-- @module String +-- @alias string -- luacheck: globals string (Allow mutating string) diff --git a/modules/FactorioStdLib/table.lua b/modules/FactorioStdLib/table.lua index 958cb21b..b3229d1f 100644 --- a/modules/FactorioStdLib/table.lua +++ b/modules/FactorioStdLib/table.lua @@ -1,6 +1,6 @@ --- Extends Lua 5.2 table. --- @module table --- @see table +-- @module Table +-- @alias table -- luacheck: globals table (Allow mutating global table) diff --git a/modules/FactorioStdLib/time.lua b/modules/FactorioStdLib/time.lua index b3b520cb..a7d9a128 100644 --- a/modules/FactorioStdLib/time.lua +++ b/modules/FactorioStdLib/time.lua @@ -1,6 +1,7 @@ --- A defines module for retrieving the number of ticks in 1 unit of time. -- Extends the Factorio defines table. --- @module defines.time +-- @module Time +-- @alias defines.time -- @usage require('stdlib/defines/time') -- defines table is automatically required in all mod loading stages. diff --git a/modules/index.lua b/modules/index.lua index 2dabc4dc..6fd4b693 100644 --- a/modules/index.lua +++ b/modules/index.lua @@ -2,4 +2,9 @@ -- @script index.lua return { ['ExpLib']='/modules/ExpGamingLib/control', + ['Game']='/modules/FactorioStdLib/game', + ['Time']='/modules/FactorioStdLib/time', + ['Color']='/modules/FactorioStdLib/color', + ['table']='/modules/FactorioStdLib/table', + ['string']='/modules/FactorioStdLib/string', } \ No newline at end of file From 98481696f03a4453123eda2d2e4fb8c6e0f1293f Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 29 May 2018 22:03:32 +0100 Subject: [PATCH 006/231] Fixed table.tostring --- modules/FactorioStdLib/table.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/FactorioStdLib/table.lua b/modules/FactorioStdLib/table.lua index b3229d1f..1c8acd30 100644 --- a/modules/FactorioStdLib/table.lua +++ b/modules/FactorioStdLib/table.lua @@ -438,7 +438,7 @@ end -- table.tostring(a) -- return '{["k1"]="foo",["k2"]="bar"}' -- @tparam table tbl table to convert -- @treturn string the converted table -function table.to_string(tbl) +function table.tostring(tbl) local result, done = {}, {} for k, v in ipairs(tbl) do table.insert(result,table.val_to_str(v)) From 9b80e8d8fe2dfa562560f006fb250e6ba8c9aef8 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 29 May 2018 22:15:22 +0100 Subject: [PATCH 007/231] Fixed index bug for _G modules --- FactorioSoftmodManager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index c3660234..4daef9f1 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -217,7 +217,7 @@ Manager.loadModules = setmetatable({}, 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 + if rawget(_G,module_name) and type(tbl[module_name]) == 'table' then setmetatable(rawget(_G,module_name),{__index=tbl[module_name]}) end else Manager.verbose('Failed load: "'..module_name..'"; Location: '..location..' ('..module..')','errorCaught') end From 310d9599b83de225f7953bc46c16c8bb3294b86c Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 29 May 2018 22:56:54 +0100 Subject: [PATCH 008/231] Many Changes To Doc --- ExpCore/GuiParts/left.lua | 4 +- ExpCore/commands.lua | 6 +- ExpCore/ranking.lua | 4 +- ExpCore/server.lua | 2 +- ExpCore/sync.lua | 2 +- FactorioSoftmodManager.lua | 27 +- doc/index.html | 14 +- doc/ldoc.css | 501 ++++++++++++---------- doc/modules/Color.html | 201 ++++----- doc/modules/ExpGamingLib.html | 8 +- doc/modules/FSM.html | 63 ++- doc/modules/Game.html | 8 +- doc/modules/Time.html | 166 +++++++ doc/modules/expcore.commands.html | 8 +- doc/modules/expcore.gui.html | 8 +- doc/modules/expcore.guiparts.center.html | 8 +- doc/modules/expcore.guiparts.inputs.html | 8 +- doc/modules/expcore.guiparts.left.html | 8 +- doc/modules/expcore.guiparts.popup.html | 8 +- doc/modules/expcore.guiparts.toolbar.html | 8 +- doc/modules/expcore.ranking.html | 8 +- doc/modules/expcore.server.html | 8 +- doc/modules/expcore.sync.html | 8 +- doc/modules/string.html | 14 +- doc/modules/table.html | 30 +- doc/scripts/control.lua.html | 8 +- doc/scripts/index.lua.html | 8 +- modules/ExpGamingLib/control.lua | 2 +- modules/FactorioStdLib/color.lua | 200 ++++----- modules/FactorioStdLib/table.lua | 7 +- modules/FactorioStdLib/time.lua | 4 + 31 files changed, 798 insertions(+), 561 deletions(-) create mode 100644 doc/modules/Time.html diff --git a/ExpCore/GuiParts/left.lua b/ExpCore/GuiParts/left.lua index 372f0289..ef42a7c6 100644 --- a/ExpCore/GuiParts/left.lua +++ b/ExpCore/GuiParts/left.lua @@ -160,8 +160,8 @@ function left._left.toggle(event) else left.style.visible = false end - if open == false then player_return({'gui.cant-open-no-reason'},defines.text_color.crit,player) player.play_sound{path='utility/cannot_build'} - elseif open ~= true then player_return({'gui.cant-open',open},defines.text_color.crit,player) player.play_sound{path='utility/cannot_build'} end + if open == false then player_return({'gui.cant-open-no-reason'},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} + elseif open ~= true then player_return({'gui.cant-open',open},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} end end -- draws the left guis when a player first joins, fake_event is just because i am lazy diff --git a/ExpCore/commands.lua b/ExpCore/commands.lua index f8e9de87..05986d75 100644 --- a/ExpCore/commands.lua +++ b/ExpCore/commands.lua @@ -82,7 +82,7 @@ local function run_custom_command(command) local player_name = Game.get_player(command) and Game.get_player(command).name or 'server' -- is the player allowed to use this command if is_type(Ranking,'table') and Ranking._presets and Ranking._presets().meta.rank_count > 0 and not Ranking.get_rank(player_name):allowed(command.name) then - player_return({'commands.unauthorized'},defines.text_color.crit) + player_return({'commands.unauthorized'},defines.textcolor.crit) if game.player then game.player.play_sound{path='utility/cannot_build'} end game.write_file('commands.log', game.tick @@ -96,7 +96,7 @@ local function run_custom_command(command) -- gets the args for the command local args, valid = command_args(command,command_data) if not valid then - player_return({'commands.invalid-inputs',command.name,command_inputs(command_data)},defines.text_color.high) + player_return({'commands.invalid-inputs',command.name,command_inputs(command_data)},defines.textcolor.high) if game.player then game.player.play_sound{path='utility/deconstruct_big'} end game.write_file('commands.log', game.tick @@ -110,7 +110,7 @@ local function run_custom_command(command) -- runs the command local success, err = pcall(command_calls[command.name],command,args) if not success then error(err) end - if err ~= commands.error and player_name ~= 'server' then player_return({'commands.command-ran'},defines.text_color.info) end + if err ~= commands.error and player_name ~= 'server' then player_return({'commands.command-ran'},defines.textcolor.info) end game.write_file('commands.log', game.tick ..' Player: "'..player_name..'"' diff --git a/ExpCore/ranking.lua b/ExpCore/ranking.lua index 8d0549d2..29750360 100644 --- a/ExpCore/ranking.lua +++ b/ExpCore/ranking.lua @@ -121,7 +121,7 @@ end -- @param[opt='server'] by_player the player who is giving the rank -- @param[opt=game.tick] tick the tick that the rank is being given on function Ranking.give_rank(player,rank,by_player,tick) - local print_colour = defines.text_color.info + local print_colour = defines.textcolor.info local tick = tick or game.tick local by_player_name = Game.get_player(by_player) and Game.get_player(by_player).name or game.player and game.player.name or is_type(by_player,'string') and by_player or 'server' local rank = Ranking.get_rank(rank) or Ranking.get_rank(Ranking._presets().meta.default) @@ -154,7 +154,7 @@ function Ranking.give_rank(player,rank,by_player,tick) if rank.group.name == 'Jail' and Ranking._presets().last_jail ~= player.name then Sync.emit_embeded{ title='Player Jail', - color=Color.to_hex(defines.text_color.med), + color=Color.to_hex(defines.textcolor.med), description='There was a player jailed.', ['Player:']=player.name, ['By:']='<>'..by_player_name, diff --git a/ExpCore/server.lua b/ExpCore/server.lua index c765c428..d4f77b07 100644 --- a/ExpCore/server.lua +++ b/ExpCore/server.lua @@ -122,7 +122,7 @@ function Server._thread_handler(event) table.each(Server._threads().print_to,function(print_to,player_index,event) if event.name == defines.events.on_tick then return true end if print_to[event.name] then - player_return(event,defines.text_color.bg,player_index) + player_return(event,defines.textcolor.bg,player_index) end end,event) local event_id = event.name diff --git a/ExpCore/sync.lua b/ExpCore/sync.lua index 4cfb4aa2..913ee247 100644 --- a/ExpCore/sync.lua +++ b/ExpCore/sync.lua @@ -93,7 +93,7 @@ end -- set up error handle verbose('Set New Error Handle') _G.error_handle = function(err) - local color = _G.Color and Color.to_hex(defines.text_color.bg) or '0x0' + local color = _G.Color and Color.to_hex(defines.textcolor.bg) or '0x0' Sync.emit_embeded{title='SCRIPT ERROR',color=color,description='There was an error in the script @Developers ',Error=err} end diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index 4daef9f1..cfaa326c 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -91,15 +91,25 @@ end -- @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( + --- Different verbose settings used for setVerbose + -- @table Manager.verboseSettings + -- @tfield boolean selfInit called while the manager is being set up + -- @tfield boolean moduleLoad when a module is required by the manager + -- @tfield boolean moduleInit when and within the initation of a module + -- @tfield boolean moduleEnv during module runtime, this is a global option set within each module(module_verbose=true ln:1) for fine control + -- @tfield boolean eventRegistered when a module registers its event handlers + -- @tfield boolean errorCaught when an error is caught during runtime + -- @tfield function output can be: print || log || or other function + -- @field _output a constant value that can used to store output data { - 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 + selfInit=true, + moduleLoad=false, + moduleInit=false, + moduleEnv=false, + eventRegistered=false, + errorCaught=true, + output=Manager._verbose, + _output={} }, { __metatable=false, @@ -442,7 +452,6 @@ Manager.event = setmetatable({ --- Sub set to Manger.event and acts as a coverter between event_name and event_id -- @table Manager.event.names -- @usage Manager.event[event_name] --- @see Manager.event rawset(Manager.event,'names',setmetatable({},{ __index=function(tbl,key) if type(key) == 'number' or tonumber(key) then diff --git a/doc/index.html b/doc/index.html index 3856ff87..0c5889c6 100644 --- a/doc/index.html +++ b/doc/index.html @@ -45,9 +45,9 @@
  • ExpGamingLib
  • Color
  • Game
  • -
  • string
  • -
  • table
  • -
  • defines.time
  • +
  • String
  • +
  • Table
  • +
  • Time
  • Scripts

      @@ -120,15 +120,15 @@ The game module. - string + String Extends Lua 5.2 string. - table + Table Extends Lua 5.2 table. - defines.time + Time A defines module for retrieving the number of ticks in 1 unit of time. @@ -148,7 +148,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
      diff --git a/doc/ldoc.css b/doc/ldoc.css index 809ab237..52c4ad2b 100644 --- a/doc/ldoc.css +++ b/doc/ldoc.css @@ -1,244 +1,303 @@ -/* universal */ +/* BEGIN RESET -body{background-color:#0F0F0F;color:#C8C8C8;font-family:'Lucida Grande',Arial,sans-serif} -a{text-decoration:none;border-style:none;outline:none!important} -a:link{color:#FF7200;text-decoration:none} -a:visited{color:#FF7200;text-decoration:none} -a:hover{color:#C8C8C8;text-decoration:none} -a:active{color:#C8C8C8;text-decoration:none} -h1{font-size:2.5rem} -h2{font-size:2.3rem} -h3{font-size:2rem} -h4{font-size:1.8rem} -h5{font-size:1.6rem} +Copyright (c) 2010, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.com/yui/license.html +version: 2.8.2r1 +*/ +html { + color: #000; + background: #FFF; +} +body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td { + margin: 0; + padding: 0; +} +table { + border-collapse: collapse; + border-spacing: 0; +} +fieldset,img { + border: 0; +} +address,caption,cite,code,dfn,em,strong,th,var,optgroup { + font-style: inherit; + font-weight: inherit; +} +del,ins { + text-decoration: none; +} +li { + margin-left: 20px; +} +caption,th { + text-align: left; +} +h1,h2,h3,h4,h5,h6 { + font-size: 100%; + font-weight: bold; +} +q:before,q:after { + content: ''; +} +abbr,acronym { + border: 0; + font-variant: normal; +} +sup { + vertical-align: baseline; +} +sub { + vertical-align: baseline; +} +legend { + color: #000; +} +input,button,textarea,select,optgroup,option { + font-family: inherit; + font-size: inherit; + font-style: inherit; + font-weight: inherit; +} +input,button,textarea,select {*font-size:100%; +} +/* END RESET */ - -/* table */ - -table,thead{text-align:left} -table,th,td{padding:2px} - - -/* sidebar */ - -.sidebar {height: 100%} - -.sidebar-custom { - border-right: 1px solid #2C2C2C; - padding-right: 1.4rem; - bottom: 0rem; +body { + margin-left: 1em; + margin-right: 1em; + font-family: arial, helvetica, geneva, sans-serif; + background-color: #ffffff; margin: 0px; } -@supports (-ms-ime-align:auto) { - .sidebar-custom { - height: 99%; +code, tt { font-family: monospace; font-size: 1.1em; } +span.parameter { font-family:monospace; } +span.parameter:after { content:":"; } +span.types:before { content:"("; } +span.types:after { content:")"; } +.type { font-weight: bold; font-style:italic } + +body, p, td, th { font-size: .95em; line-height: 1.2em;} + +p, ul { margin: 10px 0 0 0px;} + +strong { font-weight: bold;} + +em { font-style: italic;} + +h1 { + font-size: 1.5em; + margin: 20px 0 20px 0; +} +h2, h3, h4 { margin: 15px 0 10px 0; } +h2 { font-size: 1.25em; } +h3 { font-size: 1.15em; } +h4 { font-size: 1.06em; } + +a:link { font-weight: bold; color: #004080; text-decoration: none; } +a:visited { font-weight: bold; color: #006699; text-decoration: none; } +a:link:hover { text-decoration: underline; } + +hr { + color:#cccccc; + background: #00007f; + height: 1px; +} + +blockquote { margin-left: 3em; } + +ul { list-style-type: disc; } + +p.name { + font-family: "Andale Mono", monospace; + padding-top: 1em; +} + +pre { + background-color: rgb(245, 245, 245); + border: 1px solid #C0C0C0; /* silver */ + padding: 10px; + margin: 10px 0 10px 0; + overflow: auto; + font-family: "Andale Mono", monospace; +} + +pre.example { + font-size: .85em; +} + +table.index { border: 1px #00007f; } +table.index td { text-align: left; vertical-align: top; } + +#container { + margin-left: 1em; + margin-right: 1em; + background-color: #f0f0f0; +} + +#product { + text-align: center; + border-bottom: 1px solid #cccccc; + background-color: #ffffff; +} + +#product big { + font-size: 2em; +} + +#main { + background-color: #f0f0f0; + border-left: 2px solid #cccccc; +} + +#navigation { + float: left; + width: 14em; + vertical-align: top; + background-color: #f0f0f0; + overflow: visible; +} + +#navigation h2 { + background-color:#e7e7e7; + font-size:1.1em; + color:#000000; + text-align: left; + padding:0.2em; + border-top:1px solid #dddddd; + border-bottom:1px solid #dddddd; +} + +#navigation ul +{ + font-size:1em; + list-style-type: none; + margin: 1px 1px 10px 1px; +} + +#navigation li { + text-indent: -1em; + display: block; + margin: 3px 0px 0px 22px; +} + +#navigation li li a { + margin: 0px 3px 0px -1em; +} + +#content { + margin-left: 14em; + padding: 1em; + width: 700px; + border-left: 2px solid #cccccc; + border-right: 2px solid #cccccc; + background-color: #ffffff; +} + +#about { + clear: both; + padding: 5px; + border-top: 2px solid #cccccc; + background-color: #ffffff; +} + +@media print { + body { + font: 12pt "Times New Roman", "TimeNR", Times, serif; + } + a { font-weight: bold; color: #004080; text-decoration: underline; } + + #main { + background-color: #ffffff; + border-left: 0px; + } + + #container { + margin-left: 2%; + margin-right: 2%; + background-color: #ffffff; + } + + #content { + padding: 1em; + background-color: #ffffff; + } + + #navigation { + display: none; + } + pre.example { + font-family: "Andale Mono", monospace; + font-size: 10pt; + page-break-inside: avoid; } } -.up-to-top { - top: 1.5rem; - position: -webkit-sticky; - position: sticky; - text-align: right; - margin-right: 0.2rem; -} - -.up-to-top a{padding:20px} -.up-to-top a:link{color:#FF7200} -.up-to-top a:hover{color:#C8C8C8} -.icon-arrow-right-custom{margin-bottom:3px} -.project-infobox{text-align:right} -.project-infobox .project-desc{font-style:italic} -.nav-modules{text-align:right} -.nav-module-contents{text-align:right} - - -/* navigation */ - -.nav .nav a{color:#FF7200} -.nav .nav a:link{color:#FF7200} -.nav .nav a:visited{color:#FF7200} -.nav .nav a:hover{color:#C8C8C8;text-decoration:none} -.nav .nav-item.active>a:hover{color:#C8C8C8;text-decoration:none} -.nav .nav-item.active{margin-left:0} -.nav .nav a:active{color:#C8C8C8} - - -/* main page module list */ - -.body-module-name {font-weight: 500} - table.module_list { - border-spacing: 0; - display: table; + border-width: 1px; + border-style: solid; + border-color: #cccccc; border-collapse: collapse; - margin-bottom: 2.0rem; } - table.module_list td { - border-top: 1px solid #2C2C2C; - border-bottom: 1px solid #2C2C2C; - padding: 3px 7px 3px 7px; + border-width: 1px; + padding: 3px; + border-style: solid; + border-color: #cccccc; } +table.module_list td.name { background-color: #f0f0f0; min-width: 200px; } +table.module_list td.summary { width: 100%; } -table.module_list td.name { - vertical-align: top; - min-width: 125px; - background-color: #0D0D0D; -} -table.module_list td.summary {vertical-align: top} - -.module_list p {margin:0px} - -/* section */ - -.module-see-also li { - margin-top: 0.5rem; -} - -.section-title a:link{color:#C8C8C8} -.section-title a:visited{color:#C8C8C8} -.section-title a:hover{color:#FF7200} -.section-title a:active{color:#FF7200} - -.section-body-container dd { - margin: 1.0rem 0 1.5rem 0; -} - -table.section-content-list { - border-spacing: 0; - display: table; +table.function_list { + border-width: 1px; + border-style: solid; + border-color: #cccccc; border-collapse: collapse; - margin-bottom: 1.5rem; +} +table.function_list td { + border-width: 1px; + padding: 3px; + border-style: solid; + border-color: #cccccc; +} +table.function_list td.name { background-color: #f0f0f0; min-width: 200px; } +table.function_list td.summary { width: 100%; } + +ul.nowrap { + overflow:auto; + white-space:nowrap; } -table.section-content-list td { - border-top: 1px solid #2C2C2C; - border-bottom: 1px solid #2C2C2C; - padding: 3px 7px 3px 7px; -} +dl.table dt, dl.function dt {border-top: 1px solid #ccc; padding-top: 1em;} +dl.table dd, dl.function dd {padding-bottom: 1em; margin: 10px 0 0 20px;} +dl.table h3, dl.function h3 {font-size: .95em;} -table.section-content-list td.name { - background-color: #0D0D0D; - vertical-align: top; - white-space: nowrap; -} +/* stop sublists from having initial vertical space */ +ul ul { margin-top: 0px; } +ol ul { margin-top: 0px; } +ol ol { margin-top: 0px; } +ul ol { margin-top: 0px; } -table.section-content-list td.summary { - min-width: 200px; - vertical-align: top; -} - -.section-content-list p {margin: 0px} - -div.section-item-header .section-item-title { - font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; - font-size: 1.5rem; - margin-left: 3px; -} - -.section-title:target { - padding-left: 7px; - border-left: 5px solid #FF7200; - text-decoration: none; -} - -.section-item-title:target { - padding: 3px 5px 3px 5px; - background-color: #FF7200; - color: #000000; - text-decoration: none; -} - -.section-item-body {margin-left: 4rem} - -/*.section-subitem-li { - padding-left: 1.28571429em; - text-indent: -1.28571429em; -}*/ - -/*.section-subitem-module-field-li { - margin-left: -1.28571429em; - padding-left: 1.28571429em; - text-indent: -1.28571429em; -}*/ - -/* example pages */ - -pre.code.example{margin:0 0 1em} -pre.code.example code h2{display:none} -pre.code.example code pre{margin:0} - - -/* usage code */ - -code{background-color:#181818;color:#C8C8C8;font-size:1.3rem} -pre.code code{background-color:#282828;color:#C8C8C8;font-size:1.3rem} -pre.code .comment{color:#998d70} -pre.code .constant{color:#a8660d} -pre.code .escape{color:#844631} -pre.code .keyword{color:#c43724;font-weight:700} -pre.code .library{color:#0e7c6b} -pre.code .marker{color:#512b1e;background:#fedc56;font-weight:700} -pre.code .string{color:#99ca3c} -pre.code .number{color:#f8660d} -pre.code .operator{color:#2239a8;font-weight:700} -pre.code .preprocessor,pre .prepro{color:#a33243} -pre.code .global{color:#5798da} -pre.code .user-keyword{color:purple} -pre.code .prompt{color:#998d70} -pre.code .url{color:#272fc2;text-decoration:underline} - - -/* footer */ - -.footer{height:65px} -.sidebar-footer{text-align:left;padding-right:33px} -.content-footer{text-align:right} - - -/* misc */ - -.types {font-weight:bold;font-style:italic} - -.divider[data-content]::after,.divider-vert[data-content]::after{background:#262626;color:#C8C8C8} -.divider-custom{border-width:1px;border-color:#585959} - - -/* fragment hashtag */ - -.fragment-hashtag{color:#3C3C3C} -a.fragment-hashtag{color:#3C3C3C} -a.fragment-hashtag:hover{color:#FF7200} - - -/* mobile */ - -@media screen and (max-width: 540px) { - .up-to-top {display: none} - .sidebar-custom { - border-right: 1px solid #2C2C2C; - padding-right: 1.4rem; - bottom: 0rem; - margin-right: 0px; - } - .sidebar-footer { - text-align: right; - padding-right: 10px; - white-space: nowrap; - } - table.function_list td.name { - background-color: #0D0D0D; - vertical-align: top; - white-space: normal; - } - .function-item-spec-body-wrap {margin-left: 1.5rem} +/* make the target distinct; helps when we're navigating to a function */ +a:target + * { + background-color: #FF9; } -/* tablets */ +/* styles for prettification of source */ +pre .comment { color: #558817; } +pre .constant { color: #a8660d; } +pre .escape { color: #844631; } +pre .keyword { color: #aa5050; font-weight: bold; } +pre .library { color: #0e7c6b; } +pre .marker { color: #512b1e; background: #fedc56; font-weight: bold; } +pre .string { color: #8080ff; } +pre .number { color: #f8660d; } +pre .operator { color: #2239a8; font-weight: bold; } +pre .preprocessor, pre .prepro { color: #a33243; } +pre .global { color: #800080; } +pre .user-keyword { color: #800080; } +pre .prompt { color: #558817; } +pre .url { color: #272fc2; text-decoration: underline; } -@media screen and (min-width: 540px) and (max-width: 780px) { - .sidebar-footer {white-space: nowrap} -} diff --git a/doc/modules/Color.html b/doc/modules/Color.html index 94f0acff..c226c4c8 100644 --- a/doc/modules/Color.html +++ b/doc/modules/Color.html @@ -53,9 +53,9 @@
    • ExpGamingLib
    • Color
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • String
    • +
    • Table
    • +
    • Time

    Scripts

      @@ -111,6 +111,10 @@ defines.lightcolor Returns a lighter color of a named color. + + defines.textcolor + Returns a lighter color of a named color. +
      @@ -151,8 +155,8 @@

      Returns:

        - Concepts.Color - a color table that has the specified value for the alpha channel + a + color table that has the specified value for the alpha channel
      @@ -178,8 +182,8 @@

      Returns:

        - Concepts.Color - a converted color — { r = c\_arr[1], g = c\_arr[2], b = c\_arr[3], a = c\_arr[4] } + a + converted color — { r = c\_arr[1], g = c\_arr[2], b = c\_arr[3], a = c\_arr[4] }
      @@ -254,8 +258,8 @@

      Returns:

        - Concepts.Color - a color table with RGB converted from Hex and with alpha + a + color table with RGB converted from Hex and with alpha
      @@ -277,90 +281,67 @@

      Fields:

      • white - Concepts.Color - + {r=1.00,g=1.00,b=1.00}
      • black - Concepts.Color - + {r=0.00,g=0.00,b=0.00}
      • darkgrey - Concepts.Color - + {r=0.25,g=0.25,b=0.25}
      • grey - Concepts.Color - + {r=0.50,g=0.50,b=0.50}
      • lightgrey - Concepts.Color - + {r=0.75,g=0.75,b=0.75}
      • red - Concepts.Color - + {r=1.00,g=0.00,b=0.00}
      • darkred - Concepts.Color - + {r=0.50,g=0.00,b=0.00}
      • lightred - Concepts.Color - + {r=1.00,g=0.50,b=0.50}
      • green - Concepts.Color - + {r=0.00,g=1.00,b=0.00}
      • darkgreen - Concepts.Color - + {r=0.00,g=0.50,b=0.00}
      • lightgreen - Concepts.Color - + {r=0.50,g=1.00,b=0.50}
      • blue - Concepts.Color - + {r=0.00,g=0.00,b=1.00}
      • darkblue - Concepts.Color - + {r=0.00,g=0.00,b=0.50}
      • lightblue - Concepts.Color - + {r=0.50,g=0.50,b=1.00}
      • orange - Concepts.Color - + {r=1.00,g=0.55,b=0.10}
      • yellow - Concepts.Color - + {r=1.00,g=1.00,b=0.00}
      • pink - Concepts.Color - + {r=1.00,g=0.00,b=1.00}
      • purple - Concepts.Color - + {r=0.60,g=0.10,b=0.60}
      • brown - Concepts.Color - + {r=0.60,g=0.40,b=0.10}
      -

      Usage:

      -
        -
        color = defines.color.red
        -
      @@ -374,80 +355,61 @@

      Fields:

      • green - Concepts.Color - defines.color.black + defines.color.black
      • grey - Concepts.Color - defines.color.black + defines.color.black
      • lightblue - Concepts.Color - defines.color.black + defines.color.black
      • lightgreen - Concepts.Color - defines.color.black + defines.color.black
      • lightgrey - Concepts.Color - defines.color.black + defines.color.black
      • lightred - Concepts.Color - defines.color.black + defines.color.black
      • orange - Concepts.Color - defines.color.black + defines.color.black
      • white - Concepts.Color - defines.color.black + defines.color.black
      • yellow - Concepts.Color - defines.color.black + defines.color.black
      • black - Concepts.Color - defines.color.white + defines.color.white
      • blue - Concepts.Color - defines.color.white + defines.color.white
      • brown - Concepts.Color - defines.color.white + defines.color.white
      • darkblue - Concepts.Color - defines.color.white + defines.color.white
      • darkgreen - Concepts.Color - defines.color.white + defines.color.white
      • darkgrey - Concepts.Color - defines.color.white + defines.color.white
      • darkred - Concepts.Color - defines.color.white + defines.color.white
      • pink - Concepts.Color - defines.color.white + defines.color.white
      • purple - Concepts.Color - defines.color.white + defines.color.white
      • red - Concepts.Color - defines.color.white + defines.color.white
      @@ -467,36 +429,63 @@

      Fields:

      • white - Concepts.Color - defines.color.lightgrey + defines.color.lightgrey
      • grey - Concepts.Color - defines.color.darkgrey + defines.color.darkgrey
      • lightgrey - Concepts.Color - defines.color.grey + defines.color.grey
      • red - Concepts.Color - defines.color.lightred + defines.color.lightred
      • green - Concepts.Color - defines.color.lightgreen + defines.color.lightgreen
      • blue - Concepts.Color - defines.color.lightblue + defines.color.lightblue
      • yellow - Concepts.Color - defines.color.orange + defines.color.orange
      • pink - Concepts.Color - defines.color.purple + defines.color.purple +
      • +
      + + + + + + +
      + + defines.textcolor +
      +
      + Returns a lighter color of a named color. + + +

      Fields:

      +
        +
      • info + {r=0.21,g=0.95,b=1.00} +
      • +
      • bg + {r=0.00,g=0.00,b=0.00} +
      • +
      • low + {r=0.18,g=0.77,b=0.18} +
      • +
      • med + {r=1.00,g=0.89,b=0.26} +
      • +
      • high + {r=1.00,g=0.33,b=0.00} +
      • +
      • crit + {r=1.00,g=0.00,b=0.00}
      @@ -512,7 +501,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
      diff --git a/doc/modules/ExpGamingLib.html b/doc/modules/ExpGamingLib.html index f5ea6be6..022326d9 100644 --- a/doc/modules/ExpGamingLib.html +++ b/doc/modules/ExpGamingLib.html @@ -52,9 +52,9 @@
    • ExpGamingLib
    • Color
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • String
    • +
    • Table
    • +
    • Time

    Scripts

      @@ -371,7 +371,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
      diff --git a/doc/modules/FSM.html b/doc/modules/FSM.html index 4d8b6ca0..4d2b17e9 100644 --- a/doc/modules/FSM.html +++ b/doc/modules/FSM.html @@ -53,9 +53,9 @@
    • ExpGamingLib
    • Color
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • String
    • +
    • Table
    • +
    • Time

    Scripts

      @@ -114,6 +114,10 @@

      Tables

      + + + + @@ -335,6 +339,54 @@

      Tables

      +
      + + verboseSettings +
      +
      + Different verbose settings used for setVerbose + + +

      Fields:

      +
        +
      • selfInit + boolean + called while the manager is being set up +
      • +
      • moduleLoad + boolean + when a module is required by the manager +
      • +
      • moduleInit + boolean + when and within the initation of a module +
      • +
      • moduleEnv + boolean + during module runtime, this is a global option set within each module(module_verbose=true ln:1) for fine control +
      • +
      • eventRegistered + boolean + when a module registers its event handlers +
      • +
      • errorCaught + boolean + when an error is caught during runtime +
      • +
      • output + function + can be: print || log || or other function +
      • +
      • _output + a constant value that can used to store output data +
      • +
      + + + + + +
      Manager.event.names @@ -346,9 +398,6 @@ -

      See also:

      -
        -

      Usage:

        @@ -363,7 +412,7 @@
        generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
        diff --git a/doc/modules/Game.html b/doc/modules/Game.html index 480765da..4e981941 100644 --- a/doc/modules/Game.html +++ b/doc/modules/Game.html @@ -52,9 +52,9 @@
      • ExpGamingLib
      • Color
      • Game
      • -
      • string
      • -
      • table
      • -
      • defines.time
      • +
      • String
      • +
      • Table
      • +
      • Time

      Scripts

      verboseSettingsDifferent verbose settings used for setVerbose
      Manager.event.names Sub set to Manger.event and acts as a coverter between event_name and event_id
      + + + + + + + + +
      defines.timeReturns the number of ticks in a second, minute, hour, day, week, month, or year.
      TimeAllows index to deines.time though the Time module
      + +
      +
      + + +

      Tables

      + +
      +
      + + defines.time +
      +
      + Returns the number of ticks in a second, minute, hour, day, week, month, or year. + + +

      Fields:

      +
        +
      • second + the number of Factorio ticks in a second +
      • +
      • minute + the number of Factorio ticks in a second +
      • +
      • hour + the number of Factorio ticks in an hour +
      • +
      • day + the number of Factorio ticks in an day +
      • +
      • week + the number of Factorio ticks in a week +
      • +
      • month + the number of Factorio ticks in a month (30 days) +
      • +
      • year + the number of Factorio ticks in a year (365 days) +
      • +
      + + + + +

      Usage:

      +
        +
        local ten_seconds = defines.time.second * 10
        +
      + +
      +
      + + Time +
      +
      + Allows index to deines.time though the Time module + + + + + + + +
      +
      + + + + +
      +generated by LDoc 1.4.6 +Last updated 2018-05-29 22:53:53 +
      + + + diff --git a/doc/modules/expcore.commands.html b/doc/modules/expcore.commands.html index ab6186c5..c7194b1e 100644 --- a/doc/modules/expcore.commands.html +++ b/doc/modules/expcore.commands.html @@ -52,9 +52,9 @@
    • ExpGamingLib
    • Color
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • String
    • +
    • Table
    • +
    • Time

    Scripts

      @@ -129,7 +129,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
      diff --git a/doc/modules/expcore.gui.html b/doc/modules/expcore.gui.html index afff68dd..43fb1dca 100644 --- a/doc/modules/expcore.gui.html +++ b/doc/modules/expcore.gui.html @@ -52,9 +52,9 @@
    • ExpGamingLib
    • Color
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • String
    • +
    • Table
    • +
    • Time

    Scripts

      @@ -165,7 +165,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
      diff --git a/doc/modules/expcore.guiparts.center.html b/doc/modules/expcore.guiparts.center.html index f57a9762..83d9924e 100644 --- a/doc/modules/expcore.guiparts.center.html +++ b/doc/modules/expcore.guiparts.center.html @@ -52,9 +52,9 @@
    • ExpGamingLib
    • Color
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • String
    • +
    • Table
    • +
    • Time

    Scripts

      @@ -283,7 +283,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
      diff --git a/doc/modules/expcore.guiparts.inputs.html b/doc/modules/expcore.guiparts.inputs.html index de43e3f5..f9a46999 100644 --- a/doc/modules/expcore.guiparts.inputs.html +++ b/doc/modules/expcore.guiparts.inputs.html @@ -52,9 +52,9 @@
    • ExpGamingLib
    • Color
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • String
    • +
    • Table
    • +
    • Time

    Scripts

      @@ -439,7 +439,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
      diff --git a/doc/modules/expcore.guiparts.left.html b/doc/modules/expcore.guiparts.left.html index 5fceed56..fa801b76 100644 --- a/doc/modules/expcore.guiparts.left.html +++ b/doc/modules/expcore.guiparts.left.html @@ -52,9 +52,9 @@
    • ExpGamingLib
    • Color
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • String
    • +
    • Table
    • +
    • Time

    Scripts

      @@ -186,7 +186,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
      diff --git a/doc/modules/expcore.guiparts.popup.html b/doc/modules/expcore.guiparts.popup.html index 035361f7..aaf66311 100644 --- a/doc/modules/expcore.guiparts.popup.html +++ b/doc/modules/expcore.guiparts.popup.html @@ -52,9 +52,9 @@
    • ExpGamingLib
    • Color
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • String
    • +
    • Table
    • +
    • Time

    Scripts

      @@ -131,7 +131,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
      diff --git a/doc/modules/expcore.guiparts.toolbar.html b/doc/modules/expcore.guiparts.toolbar.html index a2ee5fd1..fdbdbe57 100644 --- a/doc/modules/expcore.guiparts.toolbar.html +++ b/doc/modules/expcore.guiparts.toolbar.html @@ -52,9 +52,9 @@
    • ExpGamingLib
    • Color
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • String
    • +
    • Table
    • +
    • Time

    Scripts

      @@ -122,7 +122,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
      diff --git a/doc/modules/expcore.ranking.html b/doc/modules/expcore.ranking.html index dba445c8..fd89f75f 100644 --- a/doc/modules/expcore.ranking.html +++ b/doc/modules/expcore.ranking.html @@ -52,9 +52,9 @@
    • ExpGamingLib
    • Color
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • String
    • +
    • Table
    • +
    • Time

    Scripts

      @@ -379,7 +379,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
      diff --git a/doc/modules/expcore.server.html b/doc/modules/expcore.server.html index d79511d4..7d7ddddc 100644 --- a/doc/modules/expcore.server.html +++ b/doc/modules/expcore.server.html @@ -52,9 +52,9 @@
    • ExpGamingLib
    • Color
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • String
    • +
    • Table
    • +
    • Time

    Scripts

      @@ -564,7 +564,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
      diff --git a/doc/modules/expcore.sync.html b/doc/modules/expcore.sync.html index dc46d448..627c68f4 100644 --- a/doc/modules/expcore.sync.html +++ b/doc/modules/expcore.sync.html @@ -52,9 +52,9 @@
    • ExpGamingLib
    • Color
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • String
    • +
    • Table
    • +
    • Time

    Scripts

      @@ -535,7 +535,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
      diff --git a/doc/modules/string.html b/doc/modules/string.html index 8119a1e6..588b54f2 100644 --- a/doc/modules/string.html +++ b/doc/modules/string.html @@ -52,9 +52,9 @@
    • ExpGamingLib
    • Color
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • String
    • +
    • Table
    • +
    • Time

    Scripts

      @@ -66,13 +66,9 @@
      -

      Module string

      +

      Module String

      Extends Lua 5.2 string.

      -

      See also:

      -

      Functions

      @@ -303,7 +299,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
      diff --git a/doc/modules/table.html b/doc/modules/table.html index 09446462..54fa86ca 100644 --- a/doc/modules/table.html +++ b/doc/modules/table.html @@ -52,9 +52,9 @@
    • ExpGamingLib
    • Color
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • String
    • +
    • Table
    • +
    • Time

    Scripts

      @@ -66,13 +66,9 @@
      -

      Module table

      +

      Module Table

      Extends Lua 5.2 table.

      -

      See also:

      -

      Functions

      @@ -172,7 +168,7 @@ Returns a value in a form able to be read as a key - to_string (tbl) + tostring (tbl) Returns a table in a form able to be read as a table @@ -366,17 +362,11 @@ -

      See also:

      -

      Usage:

        -
      • a= { 1, 2, 3, 4, 5}
        -table.any(a, function(v) return v % 2 == 0 end) --produces: true
      • -
      • a = {1, 2, 3, 4, 5}
        -table.any(a, function(v, k, x) return k % 2 == 1 end) --produces: true
      • +
      • a= { 1, 2, 3, 4, 5} table.any(a, function(v) return v % 2 == 0 end) --produces: true
      • +
      • a = {1, 2, 3, 4, 5} table.any(a, function(v, k, x) return k % 2 == 1 end) --produces: true
      @@ -978,8 +968,8 @@ some_func(1,2)
      - - to_string (tbl) + + tostring (tbl)
      Returns a table in a form able to be read as a table @@ -1138,7 +1128,7 @@ some_func(1,2)
      generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
      diff --git a/doc/scripts/control.lua.html b/doc/scripts/control.lua.html index d638ec17..e8827fb4 100644 --- a/doc/scripts/control.lua.html +++ b/doc/scripts/control.lua.html @@ -53,9 +53,9 @@
    • ExpGamingLib
    • Color
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • String
    • +
    • Table
    • +
    • Time
    @@ -78,7 +78,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
    diff --git a/doc/scripts/index.lua.html b/doc/scripts/index.lua.html index ac0f9c3b..aeb35e86 100644 --- a/doc/scripts/index.lua.html +++ b/doc/scripts/index.lua.html @@ -53,9 +53,9 @@
  • ExpGamingLib
  • Color
  • Game
  • -
  • string
  • -
  • table
  • -
  • defines.time
  • +
  • String
  • +
  • Table
  • +
  • Time
  • @@ -78,7 +78,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-29 22:53:53
    diff --git a/modules/ExpGamingLib/control.lua b/modules/ExpGamingLib/control.lua index efd40bd5..3cd59332 100644 --- a/modules/ExpGamingLib/control.lua +++ b/modules/ExpGamingLib/control.lua @@ -63,7 +63,7 @@ end -- @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.text_color[colour] ~= defines.color.white and defines.text_color[colour] or defines.color[colour] + local colour = ExpLib.is_type(colour) == 'table' and colour or defines.textcolor[colour] ~= defines.color.white and defines.textcolor[colour] or defines.color[colour] local player = player or game.player local function _return(callback,rtn) if ExpLib.is_type(rtn,'table') then diff --git a/modules/FactorioStdLib/color.lua b/modules/FactorioStdLib/color.lua index 2fe1e8e8..4a5e4c8d 100644 --- a/modules/FactorioStdLib/color.lua +++ b/modules/FactorioStdLib/color.lua @@ -12,125 +12,103 @@ defines = defines or {} --luacheck: ignore defines (This is used for testing locally) --- A table of colors allowing retrieval by color name. --- @usage color = defines.color.red --- @tfield Concepts.Color white --- @tfield Concepts.Color black --- @tfield Concepts.Color darkgrey --- @tfield Concepts.Color grey --- @tfield Concepts.Color lightgrey --- @tfield Concepts.Color red --- @tfield Concepts.Color darkred --- @tfield Concepts.Color lightred --- @tfield Concepts.Color green --- @tfield Concepts.Color darkgreen --- @tfield Concepts.Color lightgreen --- @tfield Concepts.Color blue --- @tfield Concepts.Color darkblue --- @tfield Concepts.Color lightblue --- @tfield Concepts.Color orange --- @tfield Concepts.Color yellow --- @tfield Concepts.Color pink --- @tfield Concepts.Color purple --- @tfield Concepts.Color brown +-- @table defines.color +-- @field white {r=1.00,g=1.00,b=1.00} +-- @field black {r=0.00,g=0.00,b=0.00} +-- @field darkgrey {r=0.25,g=0.25,b=0.25} +-- @field grey {r=0.50,g=0.50,b=0.50} +-- @field lightgrey {r=0.75,g=0.75,b=0.75} +-- @field red {r=1.00,g=0.00,b=0.00} +-- @field darkred {r=0.50,g=0.00,b=0.00} +-- @field lightred {r=1.00,g=0.50,b=0.50} +-- @field green {r=0.00,g=1.00,b=0.00} +-- @field darkgreen {r=0.00,g=0.50,b=0.00} +-- @field lightgreen {r=0.50,g=1.00,b=0.50} +-- @field blue {r=0.00,g=0.00,b=1.00} +-- @field darkblue {r=0.00,g=0.00,b=0.50} +-- @field lightblue {r=0.50,g=0.50,b=1.00} +-- @field orange {r=1.00,g=0.55,b=0.10} +-- @field yellow {r=1.00,g=1.00,b=0.00} +-- @field pink {r=1.00,g=0.00,b=1.00} +-- @field purple {r=0.60,g=0.10,b=0.60} +-- @field brown {r=0.60,g=0.40,b=0.10} defines.color = { - white = {r = 1.00, g = 1.00, b = 1.00}, - black = {r = 0.00, g = 0.00, b = 0.00}, - darkgrey = {r = 0.25, g = 0.25, b = 0.25}, - grey = {r = 0.50, g = 0.50, b = 0.50}, - lightgrey = {r = 0.75, g = 0.75, b = 0.75}, - red = {r = 1.00, g = 0.00, b = 0.00}, - darkred = {r = 0.50, g = 0.00, b = 0.00}, - lightred = {r = 1.00, g = 0.50, b = 0.50}, - green = {r = 0.00, g = 1.00, b = 0.00}, - darkgreen = {r = 0.00, g = 0.50, b = 0.00}, - lightgreen = {r = 0.50, g = 1.00, b = 0.50}, - blue = {r = 0.00, g = 0.00, b = 1.00}, - darkblue = {r = 0.00, g = 0.00, b = 0.50}, - lightblue = {r = 0.50, g = 0.50, b = 1.00}, - orange = {r = 1.00, g = 0.55, b = 0.10}, - yellow = {r = 1.00, g = 1.00, b = 0.00}, - pink = {r = 1.00, g = 0.00, b = 1.00}, - purple = {r = 0.60, g = 0.10, b = 0.60}, - brown = {r = 0.60, g = 0.40, b = 0.10} + white={r=1.00,g=1.00,b=1.00}, + black={r=0.00,g=0.00,b=0.00}, + darkgrey={r=0.25,g=0.25,b=0.25}, + grey={r=0.50,g=0.50,b=0.50}, + lightgrey={r=0.75,g=0.75,b=0.75}, + red={r=1.00,g=0.00,b=0.00}, + darkred={r=0.50,g=0.00,b=0.00}, + lightred={r=1.00,g=0.50,b=0.50}, + green={r=0.00,g=1.00,b=0.00}, + darkgreen={r=0.00,g=0.50,b=0.00}, + lightgreen={r=0.50,g=1.00,b=0.50}, + blue={r=0.00,g=0.00,b=1.00}, + darkblue={r=0.00,g=0.00,b=0.50}, + lightblue={r=0.50,g=0.50,b=1.00}, + orange={r=1.00,g=0.55,b=0.10}, + yellow={r=1.00,g=1.00,b=0.00}, + pink={r=1.00,g=0.00,b=1.00}, + purple={r=0.60,g=0.10,b=0.60}, + brown={r=0.60,g=0.40,b=0.10} } local colors = defines.color + --- Returns white for dark colors or black for lighter colors. --- @tfield Concepts.Color green defines.color.black --- @tfield Concepts.Color grey defines.color.black --- @tfield Concepts.Color lightblue defines.color.black --- @tfield Concepts.Color lightgreen defines.color.black --- @tfield Concepts.Color lightgrey defines.color.black --- @tfield Concepts.Color lightred defines.color.black --- @tfield Concepts.Color orange defines.color.black --- @tfield Concepts.Color white defines.color.black --- @tfield Concepts.Color yellow defines.color.black --- @tfield Concepts.Color black defines.color.white --- @tfield Concepts.Color blue defines.color.white --- @tfield Concepts.Color brown defines.color.white --- @tfield Concepts.Color darkblue defines.color.white --- @tfield Concepts.Color darkgreen defines.color.white --- @tfield Concepts.Color darkgrey defines.color.white --- @tfield Concepts.Color darkred defines.color.white --- @tfield Concepts.Color pink defines.color.white --- @tfield Concepts.Color purple defines.color.white --- @tfield Concepts.Color red defines.color.white +-- @table defines.anticolor defines.anticolor = { - green = colors.black, - grey = colors.black, - lightblue = colors.black, - lightgreen = colors.black, - lightgrey = colors.black, - lightred = colors.black, - orange = colors.black, - white = colors.black, - yellow = colors.black, - black = colors.white, - blue = colors.white, - brown = colors.white, - darkblue = colors.white, - darkgreen = colors.white, - darkgrey = colors.white, - darkred = colors.white, - pink = colors.white, - purple = colors.white, - red = colors.white + green = colors.black, -- defines.color.black + grey = colors.black, -- defines.color.black + lightblue = colors.black, -- defines.color.black + lightgreen = colors.black, -- defines.color.black + lightgrey = colors.black, -- defines.color.black + lightred = colors.black, -- defines.color.black + orange = colors.black, -- defines.color.black + white = colors.black, -- defines.color.black + yellow = colors.black, -- defines.color.black + black = colors.white, -- defines.color.white + blue = colors.white, -- defines.color.white + brown = colors.white, -- defines.color.white + darkblue = colors.white, -- defines.color.white + darkgreen = colors.white, -- defines.color.white + darkgrey = colors.white, -- defines.color.white + darkred = colors.white, -- defines.color.white + pink = colors.white, -- defines.color.white + purple = colors.white, -- defines.color.white + red = colors.white -- defines.color.white } --- Returns a lighter color of a named color. --- @tfield Concepts.Color white defines.color.lightgrey --- @tfield Concepts.Color grey defines.color.darkgrey --- @tfield Concepts.Color lightgrey defines.color.grey --- @tfield Concepts.Color red defines.color.lightred --- @tfield Concepts.Color green defines.color.lightgreen --- @tfield Concepts.Color blue defines.color.lightblue --- @tfield Concepts.Color yellow defines.color.orange --- @tfield Concepts.Color pink defines.color.purple +-- @table defines.lightcolor defines.lightcolor = { - white = colors.lightgrey, - grey = colors.darkgrey, - lightgrey = colors.grey, - red = colors.lightred, - green = colors.lightgreen, - blue = colors.lightblue, - yellow = colors.orange, - pink = colors.purple + white = colors.lightgrey, -- defines.color.lightgrey + grey = colors.darkgrey, -- defines.color.darkgrey + lightgrey = colors.grey, -- defines.color.grey + red = colors.lightred, -- defines.color.lightred + green = colors.lightgreen, -- defines.color.lightgreen + blue = colors.lightblue, -- defines.color.lightblue + yellow = colors.orange, -- defines.color.orange + pink = colors.purple -- defines.color.purple } --- added by cooldude2606 +-- added by cooldude260 + --- Returns a lighter color of a named color. --- @tfield Concepts.Color info --- @tfield Concepts.Color bg --- @tfield Concepts.Color low --- @tfield Concepts.Color med --- @tfield Concepts.Color high --- @tfield Concepts.Color crit -defines.text_color = { - info = {r = 0.21, g = 0.95, b = 1.00}, - bg = {r = 0.00, g = 0.00, b = 0.00}, - low = {r = 0.18, g = 0.77, b = 0.18}, - med = {r = 1.00, g = 0.89, b = 0.26}, - high = {r = 1.00, g = 0.33, b = 0.00}, - crit = {r = 1.00, g = 0.00, b = 0.00} +-- @table defines.textcolor +-- @field info {r=0.21,g=0.95,b=1.00} +-- @field bg {r=0.00,g=0.00,b=0.00} +-- @field low {r=0.18,g=0.77,b=0.18} +-- @field med {r=1.00,g=0.89,b=0.26} +-- @field high {r=1.00,g=0.33,b=0.00} +-- @field crit {r=1.00,g=0.00,b=0.00} +defines.textcolor = { + info={r=0.21,g=0.95,b=1.00}, + bg={r=0.00,g=0.00,b=0.00}, + low={r=0.18,g=0.77,b=0.18}, + med={r=1.00,g=0.89,b=0.26}, + high={r=1.00,g=0.33,b=0.00}, + crit={r=1.00,g=0.00,b=0.00} } -- metatable remade by cooldude @@ -152,7 +130,7 @@ local _mt = { setmetatable(defines.color, _mt) setmetatable(defines.anticolor, _mt) -setmetatable(defines.text_color, _mt) +setmetatable(defines.textcolor, _mt) setmetatable(defines.lightcolor, _mt) local Color = {} --luacheck: allow defined top @@ -166,7 +144,7 @@ local Color = {} --luacheck: allow defined top -- -- @tparam[opt=white] defines.color|Concepts.Color color the color to configure -- @tparam[opt=1] float alpha the alpha value (*[0 - 1]*) to set for the given color --- @treturn Concepts.Color a color table that has the specified value for the alpha channel +-- @treturn a color table that has the specified value for the alpha channel function Color.set(color, alpha) color = color or defines.color.white Color.to_table(color) @@ -176,7 +154,7 @@ end --- Converts a color in the array format to a color in the table format. -- @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] } +-- @treturn 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 return {r = c_arr[1], g = c_arr[2], b = c_arr[3], a = c_arr[4]} @@ -202,7 +180,7 @@ end -- Optionally provide the value for the alpha channel. -- @tparam string hex hexadecimal color string (#ffffff, not #fff) -- @tparam[opt=1] float alpha the alpha value to set; such that ***[ 0 ⋜ value ⋜ 1 ]*** --- @treturn Concepts.Color a color table with RGB converted from Hex and with alpha +-- @treturn a color table with RGB converted from Hex and with alpha function Color.from_hex(hex, alpha) if not _G.Game then error('StdLib/Game not loaded') end _G.Game.fail_if_missing(hex, "missing color hex value") diff --git a/modules/FactorioStdLib/table.lua b/modules/FactorioStdLib/table.lua index 1c8acd30..2afaf62b 100644 --- a/modules/FactorioStdLib/table.lua +++ b/modules/FactorioStdLib/table.lua @@ -69,11 +69,8 @@ end --- 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. --- @see table.find ---- @usage a= { 1, 2, 3, 4, 5} ----table.any(a, function(v) return v % 2 == 0 end) --produces: true ---- @usage a = {1, 2, 3, 4, 5} ----table.any(a, function(v, k, x) return k % 2 == 1 end) --produces: true +-- @usage a= { 1, 2, 3, 4, 5} table.any(a, function(v) return v % 2 == 0 end) --produces: true +-- @usage a = {1, 2, 3, 4, 5} table.any(a, function(v, k, x) return k % 2 == 1 end) --produces: true -- @tparam table tbl the table to be searched -- @tparam function func the function to use to search for any matching element -- @param[opt] ... additional arguments passed to the function diff --git a/modules/FactorioStdLib/time.lua b/modules/FactorioStdLib/time.lua index a7d9a128..f885f0e6 100644 --- a/modules/FactorioStdLib/time.lua +++ b/modules/FactorioStdLib/time.lua @@ -30,3 +30,7 @@ defines.time = { month = MONTH, -- the number of Factorio ticks in a month (30 days) year = YEAR, -- the number of Factorio ticks in a year (365 days) } + +--- Allows index to deines.time though the Time module +--@table Time +return setmetatable({},{__index=defines.time}) \ No newline at end of file From d8bb39d66138176a992ffbea087de27058893a3d Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Wed, 30 May 2018 00:08:59 +0100 Subject: [PATCH 009/231] Last Time Chaning Doc For StdLib --- doc/index.html | 22 +- doc/modules/Event.html | 210 -------------- doc/modules/ExpGamingLib.html | 12 +- doc/modules/FSM.html | 12 +- doc/modules/{Color.html => StdLib.Color.html} | 87 +++++- doc/modules/{Game.html => StdLib.Game.html} | 19 +- .../{string.html => StdLib.String.html} | 14 +- doc/modules/{table.html => StdLib.Table.html} | 14 +- .../{defines.time.html => StdLib.Time.html} | 19 +- doc/modules/{Time.html => StdLib.html} | 37 +-- doc/modules/expcore.commands.html | 12 +- doc/modules/expcore.gui.html | 12 +- doc/modules/expcore.guiparts.center.html | 12 +- doc/modules/expcore.guiparts.inputs.html | 12 +- doc/modules/expcore.guiparts.left.html | 12 +- doc/modules/expcore.guiparts.popup.html | 12 +- doc/modules/expcore.guiparts.toolbar.html | 12 +- doc/modules/expcore.ranking.html | 12 +- doc/modules/expcore.server.html | 12 +- doc/modules/expcore.sync.html | 12 +- ...html => modules.factoriostdlib.color.html} | 270 +++++++++++------- doc/scripts/control.lua.html | 12 +- doc/scripts/index.lua.html | 12 +- modules/FactorioStdLib/color.lua | 7 +- modules/FactorioStdLib/game.lua | 3 +- modules/FactorioStdLib/string.lua | 2 +- modules/FactorioStdLib/table.lua | 2 +- modules/FactorioStdLib/time.lua | 5 +- 28 files changed, 369 insertions(+), 510 deletions(-) delete mode 100644 doc/modules/Event.html rename doc/modules/{Color.html => StdLib.Color.html} (86%) rename doc/modules/{Game.html => StdLib.Game.html} (92%) rename doc/modules/{string.html => StdLib.String.html} (95%) rename doc/modules/{table.html => StdLib.Table.html} (98%) rename doc/modules/{defines.time.html => StdLib.Time.html} (88%) rename doc/modules/{Time.html => StdLib.html} (83%) rename doc/modules/{defines.color.html => modules.factoriostdlib.color.html} (66%) diff --git a/doc/index.html b/doc/index.html index 0c5889c6..d797fba0 100644 --- a/doc/index.html +++ b/doc/index.html @@ -43,11 +43,11 @@
  • expcore.sync
  • FSM
  • ExpGamingLib
  • -
  • Color
  • -
  • Game
  • -
  • String
  • -
  • Table
  • -
  • Time
  • +
  • StdLib.Color
  • +
  • StdLib.Game
  • +
  • StdLib.String
  • +
  • StdLib.Table
  • +
  • StdLib.Time
  • Scripts

      @@ -112,23 +112,23 @@ Adds some common functions used though out all ExpGaming modules - Color + StdLib.Color A defines module for retrieving colors by name. - Game + StdLib.Game The game module. - String + StdLib.String Extends Lua 5.2 string. - Table + StdLib.Table Extends Lua 5.2 table. - Time + StdLib.Time A defines module for retrieving the number of ticks in 1 unit of time. @@ -148,7 +148,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 22:53:53 +Last updated 2018-05-30 00:08:40
      diff --git a/doc/modules/Event.html b/doc/modules/Event.html deleted file mode 100644 index 85168be6..00000000 --- a/doc/modules/Event.html +++ /dev/null @@ -1,210 +0,0 @@ - - - - - Reference - - - - -
      - -
      - -
      -
      -
      - - -
      - - - - - - -
      - -

      Module Event

      -

      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(...)

      -

      Usage:

      -
        -
        require('stdlib/event/event')
        -
        -
      - - -

      Functions

      - - - - - - - - - - - - - -
      register (event, handler)Registers a function for a given event.
      dispatch (event)Calls the registerd handlers - Will stop dispatching remaning handlers if any handler passes invalid event userdata.
      remove (event, handler)Removes the handler from the event.
      - -
      -
      - - -

      Functions

      - -
      -
      - - register (event, handler) -
      -
      - 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 -
      -
      - - diff --git a/doc/modules/ExpGamingLib.html b/doc/modules/ExpGamingLib.html index 022326d9..dc02f790 100644 --- a/doc/modules/ExpGamingLib.html +++ b/doc/modules/ExpGamingLib.html @@ -50,11 +50,11 @@
    • expcore.sync
    • FSM
    • ExpGamingLib
    • -
    • Color
    • -
    • Game
    • -
    • String
    • -
    • Table
    • -
    • Time
    • +
    • StdLib.Color
    • +
    • StdLib.Game
    • +
    • StdLib.String
    • +
    • StdLib.Table
    • +
    • StdLib.Time

    Scripts

    Scripts

      @@ -412,7 +412,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 22:53:53 +Last updated 2018-05-30 00:08:40
      diff --git a/doc/modules/Color.html b/doc/modules/StdLib.Color.html similarity index 86% rename from doc/modules/Color.html rename to doc/modules/StdLib.Color.html index c226c4c8..8c8b4bf1 100644 --- a/doc/modules/Color.html +++ b/doc/modules/StdLib.Color.html @@ -51,11 +51,11 @@
    • expcore.sync
    • FSM
    • ExpGamingLib
    • -
    • Color
    • -
    • Game
    • -
    • String
    • -
    • Table
    • -
    • Time
    • +
    • StdLib.Color
    • +
    • StdLib.Game
    • +
    • StdLib.String
    • +
    • StdLib.Table
    • +
    • StdLib.Time

    Scripts

      @@ -67,15 +67,10 @@
      -

      Module Color

      +

      Module StdLib.Color

      A defines module for retrieving colors by name.

      Extends the Factorio defines table.

      -

      Usage:

      -
        -
        require('stdlib/defines/color')
        -
        -

      Functions

      @@ -96,6 +91,14 @@ from_hex (hex[, alpha=1]) Get a color table with a hexadecimal string. + + to_rgb (color) + Converts a color in the color table format to rgb + + + to_hex (color) + Converts a color in the color table format to hex +

      Tables

      @@ -109,7 +112,7 @@ - + @@ -141,7 +144,7 @@

      Parameters:

      • color - defines.color or Concepts.Color + defines.color or Concepts.Color the color to configure (default white)
      • @@ -265,6 +268,60 @@ + +
        + + to_rgb (color) +
        +
        + Converts a color in the color table format to rgb + + +

        Parameters:

        +
          +
        • color + table + the color to convert +
        • +
        + +

        Returns:

        +
          + + table + the color as rgb +
        + + + + +
        +
        + + to_hex (color) +
        +
        + Converts a color in the color table format to hex + + +

        Parameters:

        +
          +
        • color + table + the color to convert +
        • +
        + +

        Returns:

        +
          + + string + the color as hex +
        + + + +

        Tables

        @@ -423,7 +480,7 @@ defines.lightcolor
        - Returns a lighter color of a named color. + Returns a lighter color of a named color

        Fields:

        @@ -501,7 +558,7 @@
        generated by LDoc 1.4.6 -Last updated 2018-05-29 22:53:53 +Last updated 2018-05-30 00:08:40
        diff --git a/doc/modules/Game.html b/doc/modules/StdLib.Game.html similarity index 92% rename from doc/modules/Game.html rename to doc/modules/StdLib.Game.html index 4e981941..9e35cbfb 100644 --- a/doc/modules/Game.html +++ b/doc/modules/StdLib.Game.html @@ -50,11 +50,11 @@
      • expcore.sync
      • FSM
      • ExpGamingLib
      • -
      • Color
      • -
      • Game
      • -
      • String
      • -
      • Table
      • -
      • Time
      • +
      • StdLib.Color
      • +
      • StdLib.Game
      • +
      • StdLib.String
      • +
      • StdLib.Table
      • +
      • StdLib.Time

      Scripts

        @@ -66,14 +66,9 @@
        -

        Module Game

        +

        Module StdLib.Game

        The game module.

        -

        Usage:

        -
          -
          local Game = require('stdlib/game')
          -
          -

        Functions

        @@ -224,7 +219,7 @@
        generated by LDoc 1.4.6 -Last updated 2018-05-29 22:53:53 +Last updated 2018-05-30 00:08:40
        diff --git a/doc/modules/string.html b/doc/modules/StdLib.String.html similarity index 95% rename from doc/modules/string.html rename to doc/modules/StdLib.String.html index 588b54f2..d0253f49 100644 --- a/doc/modules/string.html +++ b/doc/modules/StdLib.String.html @@ -50,11 +50,11 @@
      • expcore.sync
      • FSM
      • ExpGamingLib
      • -
      • Color
      • -
      • Game
      • -
      • String
      • -
      • Table
      • -
      • Time
      • +
      • StdLib.Color
      • +
      • StdLib.Game
      • +
      • StdLib.String
      • +
      • StdLib.Table
      • +
      • StdLib.Time

      Scripts

        @@ -66,7 +66,7 @@
        -

        Module String

        +

        Module StdLib.String

        Extends Lua 5.2 string.

        @@ -299,7 +299,7 @@
        generated by LDoc 1.4.6 -Last updated 2018-05-29 22:53:53 +Last updated 2018-05-30 00:08:40
        diff --git a/doc/modules/table.html b/doc/modules/StdLib.Table.html similarity index 98% rename from doc/modules/table.html rename to doc/modules/StdLib.Table.html index 54fa86ca..9fb1220b 100644 --- a/doc/modules/table.html +++ b/doc/modules/StdLib.Table.html @@ -50,11 +50,11 @@
      • expcore.sync
      • FSM
      • ExpGamingLib
      • -
      • Color
      • -
      • Game
      • -
      • String
      • -
      • Table
      • -
      • Time
      • +
      • StdLib.Color
      • +
      • StdLib.Game
      • +
      • StdLib.String
      • +
      • StdLib.Table
      • +
      • StdLib.Time

      Scripts

        @@ -66,7 +66,7 @@
        -

        Module Table

        +

        Module StdLib.Table

        Extends Lua 5.2 table.

        @@ -1128,7 +1128,7 @@ some_func(1,2)
        generated by LDoc 1.4.6 -Last updated 2018-05-29 22:53:53 +Last updated 2018-05-30 00:08:40
        diff --git a/doc/modules/defines.time.html b/doc/modules/StdLib.Time.html similarity index 88% rename from doc/modules/defines.time.html rename to doc/modules/StdLib.Time.html index a3200293..f0352349 100644 --- a/doc/modules/defines.time.html +++ b/doc/modules/StdLib.Time.html @@ -50,11 +50,11 @@
      • expcore.sync
      • FSM
      • ExpGamingLib
      • -
      • Color
      • -
      • Game
      • -
      • string
      • -
      • table
      • -
      • defines.time
      • +
      • StdLib.Color
      • +
      • StdLib.Game
      • +
      • StdLib.String
      • +
      • StdLib.Table
      • +
      • StdLib.Time

      Scripts

        @@ -66,15 +66,10 @@
        -

        Module defines.time

        +

        Module StdLib.Time

        A defines module for retrieving the number of ticks in 1 unit of time.

        Extends the Factorio defines table.

        -

        Usage:

        -
          -
          require('stdlib/defines/time')
          -
          -

        Tables

        @@ -141,7 +136,7 @@
        generated by LDoc 1.4.6 -Last updated 2018-05-29 20:54:20 +Last updated 2018-05-30 00:08:40
        diff --git a/doc/modules/Time.html b/doc/modules/StdLib.html similarity index 83% rename from doc/modules/Time.html rename to doc/modules/StdLib.html index 2844d736..014bd5c6 100644 --- a/doc/modules/Time.html +++ b/doc/modules/StdLib.html @@ -50,11 +50,11 @@
      • expcore.sync
      • FSM
      • ExpGamingLib
      • -
      • Color
      • -
      • Game
      • -
      • String
      • -
      • Table
      • -
      • Time
      • +
      • StdLib.Color
      • +
      • StdLib.Game
      • +
      • StdLib.String
      • +
      • StdLib.Table
      • +
      • StdLib

      Scripts

        @@ -66,15 +66,10 @@
        -

        Module Time

        +

        Module StdLib

        A defines module for retrieving the number of ticks in 1 unit of time.

        Extends the Factorio defines table.

        -

        Usage:

        -
          -
          require('stdlib/defines/time')
          -
          -

        Tables

        @@ -83,10 +78,6 @@
      - - - -
      defines.lightcolorReturns a lighter color of a named color.Returns a lighter color of a named color
      defines.textcolor defines.time Returns the number of ticks in a second, minute, hour, day, week, month, or year.
      TimeAllows index to deines.time though the Time module

      @@ -137,20 +128,6 @@
      local ten_seconds = defines.time.second * 10
    - -
    - - Time -
    -
    - Allows index to deines.time though the Time module - - - - - - -
    @@ -159,7 +136,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 22:53:53 +Last updated 2018-05-30 00:08:33
    diff --git a/doc/modules/expcore.commands.html b/doc/modules/expcore.commands.html index c7194b1e..1d31df15 100644 --- a/doc/modules/expcore.commands.html +++ b/doc/modules/expcore.commands.html @@ -50,11 +50,11 @@
  • expcore.sync
  • FSM
  • ExpGamingLib
  • -
  • Color
  • -
  • Game
  • -
  • String
  • -
  • Table
  • -
  • Time
  • +
  • StdLib.Color
  • +
  • StdLib.Game
  • +
  • StdLib.String
  • +
  • StdLib.Table
  • +
  • StdLib.Time
  • Scripts

    Scripts

    Scripts

    Scripts

    Scripts

    Scripts

    Scripts

    Scripts

    Scripts

    Scripts

      @@ -535,7 +535,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 22:53:53 +Last updated 2018-05-30 00:08:40
      diff --git a/doc/modules/defines.color.html b/doc/modules/modules.factoriostdlib.color.html similarity index 66% rename from doc/modules/defines.color.html rename to doc/modules/modules.factoriostdlib.color.html index f30e1639..43b661cf 100644 --- a/doc/modules/defines.color.html +++ b/doc/modules/modules.factoriostdlib.color.html @@ -51,11 +51,8 @@
    • expcore.sync
    • FSM
    • ExpGamingLib
    • -
    • defines.color
    • -
    • Game
    • -
    • string
    • -
    • table
    • -
    • defines.time
    • +
    • StdLib
    • +
    • modules.factoriostdlib.color

    Scripts

      @@ -67,7 +64,7 @@
      -

      Module defines.color

      +

      Module modules.factoriostdlib.color

      A defines module for retrieving colors by name.

      Extends the Factorio defines table.

      @@ -96,6 +93,14 @@ Color.from_hex (hex[, alpha=1]) Get a color table with a hexadecimal string. + + Color.to_rgb (color) + Converts a color in the color table format to rgb + + + Color.to_hex (color) + Converts a color in the color table format to hex +

      Tables

      @@ -109,6 +114,10 @@ + + + +
      defines.lightcolorReturns a lighter color of a named color
      defines.textcolor Returns a lighter color of a named color.
      @@ -137,7 +146,7 @@

      Parameters:

      • color - defines.color or Concepts.Color + defines.color or Concepts.Color the color to configure (default white)
      • @@ -151,8 +160,8 @@

        Returns:

          - Concepts.Color - a color table that has the specified value for the alpha channel + a + color table that has the specified value for the alpha channel
        @@ -178,8 +187,8 @@

        Returns:

          - Concepts.Color - a converted color — { r = c\_arr[1], g = c\_arr[2], b = c\_arr[3], a = c\_arr[4] } + a + converted color — { r = c\_arr[1], g = c\_arr[2], b = c\_arr[3], a = c\_arr[4] }
        @@ -254,8 +263,62 @@

        Returns:

          - Concepts.Color - a color table with RGB converted from Hex and with alpha + a + color table with RGB converted from Hex and with alpha +
        + + + + + +
        + + Color.to_rgb (color) +
        +
        + Converts a color in the color table format to rgb + + +

        Parameters:

        +
          +
        • color + table + the color to convert +
        • +
        + +

        Returns:

        +
          + + table + the color as rgb +
        + + + + +
        +
        + + Color.to_hex (color) +
        +
        + Converts a color in the color table format to hex + + +

        Parameters:

        +
          +
        • color + table + the color to convert +
        • +
        + +

        Returns:

        +
          + + string + the color as hex
        @@ -277,90 +340,67 @@

        Fields:

        • white - Concepts.Color - + {r=1.00,g=1.00,b=1.00}
        • black - Concepts.Color - + {r=0.00,g=0.00,b=0.00}
        • darkgrey - Concepts.Color - + {r=0.25,g=0.25,b=0.25}
        • grey - Concepts.Color - + {r=0.50,g=0.50,b=0.50}
        • lightgrey - Concepts.Color - + {r=0.75,g=0.75,b=0.75}
        • red - Concepts.Color - + {r=1.00,g=0.00,b=0.00}
        • darkred - Concepts.Color - + {r=0.50,g=0.00,b=0.00}
        • lightred - Concepts.Color - + {r=1.00,g=0.50,b=0.50}
        • green - Concepts.Color - + {r=0.00,g=1.00,b=0.00}
        • darkgreen - Concepts.Color - + {r=0.00,g=0.50,b=0.00}
        • lightgreen - Concepts.Color - + {r=0.50,g=1.00,b=0.50}
        • blue - Concepts.Color - + {r=0.00,g=0.00,b=1.00}
        • darkblue - Concepts.Color - + {r=0.00,g=0.00,b=0.50}
        • lightblue - Concepts.Color - + {r=0.50,g=0.50,b=1.00}
        • orange - Concepts.Color - + {r=1.00,g=0.55,b=0.10}
        • yellow - Concepts.Color - + {r=1.00,g=1.00,b=0.00}
        • pink - Concepts.Color - + {r=1.00,g=0.00,b=1.00}
        • purple - Concepts.Color - + {r=0.60,g=0.10,b=0.60}
        • brown - Concepts.Color - + {r=0.60,g=0.40,b=0.10}
        -

        Usage:

        -
          -
          color = defines.color.red
          -
        @@ -374,80 +414,61 @@

        Fields:

        • green - Concepts.Color - defines.color.black + defines.color.black
        • grey - Concepts.Color - defines.color.black + defines.color.black
        • lightblue - Concepts.Color - defines.color.black + defines.color.black
        • lightgreen - Concepts.Color - defines.color.black + defines.color.black
        • lightgrey - Concepts.Color - defines.color.black + defines.color.black
        • lightred - Concepts.Color - defines.color.black + defines.color.black
        • orange - Concepts.Color - defines.color.black + defines.color.black
        • white - Concepts.Color - defines.color.black + defines.color.black
        • yellow - Concepts.Color - defines.color.black + defines.color.black
        • black - Concepts.Color - defines.color.white + defines.color.white
        • blue - Concepts.Color - defines.color.white + defines.color.white
        • brown - Concepts.Color - defines.color.white + defines.color.white
        • darkblue - Concepts.Color - defines.color.white + defines.color.white
        • darkgreen - Concepts.Color - defines.color.white + defines.color.white
        • darkgrey - Concepts.Color - defines.color.white + defines.color.white
        • darkred - Concepts.Color - defines.color.white + defines.color.white
        • pink - Concepts.Color - defines.color.white + defines.color.white
        • purple - Concepts.Color - defines.color.white + defines.color.white
        • red - Concepts.Color - defines.color.white + defines.color.white
        @@ -461,42 +482,69 @@ defines.lightcolor
        - Returns a lighter color of a named color. + Returns a lighter color of a named color

        Fields:

        • white - Concepts.Color - defines.color.lightgrey + defines.color.lightgrey
        • grey - Concepts.Color - defines.color.darkgrey + defines.color.darkgrey
        • lightgrey - Concepts.Color - defines.color.grey + defines.color.grey
        • red - Concepts.Color - defines.color.lightred + defines.color.lightred
        • green - Concepts.Color - defines.color.lightgreen + defines.color.lightgreen
        • blue - Concepts.Color - defines.color.lightblue + defines.color.lightblue
        • yellow - Concepts.Color - defines.color.orange + defines.color.orange
        • pink - Concepts.Color - defines.color.purple + defines.color.purple +
        • +
        + + + + + +
        +
        + + defines.textcolor +
        +
        + Returns a lighter color of a named color. + + +

        Fields:

        +
          +
        • info + {r=0.21,g=0.95,b=1.00} +
        • +
        • bg + {r=0.00,g=0.00,b=0.00} +
        • +
        • low + {r=0.18,g=0.77,b=0.18} +
        • +
        • med + {r=1.00,g=0.89,b=0.26} +
        • +
        • high + {r=1.00,g=0.33,b=0.00} +
        • +
        • crit + {r=1.00,g=0.00,b=0.00}
        @@ -512,7 +560,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-29 20:19:50 +Last updated 2018-05-29 23:30:03
      diff --git a/doc/scripts/control.lua.html b/doc/scripts/control.lua.html index e8827fb4..6e5604ce 100644 --- a/doc/scripts/control.lua.html +++ b/doc/scripts/control.lua.html @@ -51,11 +51,11 @@
    • expcore.sync
    • FSM
    • ExpGamingLib
    • -
    • Color
    • -
    • Game
    • -
    • String
    • -
    • Table
    • -
    • Time
    • +
    • StdLib.Color
    • +
    • StdLib.Game
    • +
    • StdLib.String
    • +
    • StdLib.Table
    • +
    • StdLib.Time
    @@ -78,7 +78,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 22:53:53 +Last updated 2018-05-30 00:08:40
    diff --git a/doc/scripts/index.lua.html b/doc/scripts/index.lua.html index aeb35e86..f912ae6d 100644 --- a/doc/scripts/index.lua.html +++ b/doc/scripts/index.lua.html @@ -51,11 +51,11 @@
  • expcore.sync
  • FSM
  • ExpGamingLib
  • -
  • Color
  • -
  • Game
  • -
  • String
  • -
  • Table
  • -
  • Time
  • +
  • StdLib.Color
  • +
  • StdLib.Game
  • +
  • StdLib.String
  • +
  • StdLib.Table
  • +
  • StdLib.Time
  • @@ -78,7 +78,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-29 22:53:53 +Last updated 2018-05-30 00:08:40
    diff --git a/modules/FactorioStdLib/color.lua b/modules/FactorioStdLib/color.lua index 4a5e4c8d..9ccedbc5 100644 --- a/modules/FactorioStdLib/color.lua +++ b/modules/FactorioStdLib/color.lua @@ -1,7 +1,6 @@ --- A defines module for retrieving colors by name. -- Extends the Factorio defines table. --- @usage require('stdlib/defines/color') --- @module Color +-- @module StdLib.Color -- @alias defines.color -- defines table is automatically required in all mod loading stages. @@ -79,7 +78,7 @@ defines.anticolor = { red = colors.white -- defines.color.white } ---- Returns a lighter color of a named color. +--- Returns a lighter color of a named color -- @table defines.lightcolor defines.lightcolor = { white = colors.lightgrey, -- defines.color.lightgrey @@ -196,6 +195,7 @@ function Color.from_hex(hex, alpha) end --added by cooldude2606 + --- Converts a color in the color table format to rgb -- @tparam table color the color to convert -- @treturn table the color as rgb @@ -208,6 +208,7 @@ function Color.to_rgb(color) end --added by cooldude2606 + --- Converts a color in the color table format to hex -- @tparam table color the color to convert -- @treturn string the color as hex diff --git a/modules/FactorioStdLib/game.lua b/modules/FactorioStdLib/game.lua index e108610e..219b88f7 100644 --- a/modules/FactorioStdLib/game.lua +++ b/modules/FactorioStdLib/game.lua @@ -1,6 +1,5 @@ --- The game module. --- @module Game --- @usage local Game = require('stdlib/game') +-- @module StdLib.Game local Game = { --luacheck: allow defined top VALID_FILTER = function(v) diff --git a/modules/FactorioStdLib/string.lua b/modules/FactorioStdLib/string.lua index 27a3aaed..24ff26ad 100644 --- a/modules/FactorioStdLib/string.lua +++ b/modules/FactorioStdLib/string.lua @@ -1,5 +1,5 @@ --- Extends Lua 5.2 string. --- @module String +-- @module StdLib.String -- @alias string -- luacheck: globals string (Allow mutating string) diff --git a/modules/FactorioStdLib/table.lua b/modules/FactorioStdLib/table.lua index 2afaf62b..f2c63683 100644 --- a/modules/FactorioStdLib/table.lua +++ b/modules/FactorioStdLib/table.lua @@ -1,5 +1,5 @@ --- Extends Lua 5.2 table. --- @module Table +-- @module StdLib.Table -- @alias table -- luacheck: globals table (Allow mutating global table) diff --git a/modules/FactorioStdLib/time.lua b/modules/FactorioStdLib/time.lua index f885f0e6..23554339 100644 --- a/modules/FactorioStdLib/time.lua +++ b/modules/FactorioStdLib/time.lua @@ -1,8 +1,7 @@ --- A defines module for retrieving the number of ticks in 1 unit of time. -- Extends the Factorio defines table. --- @module Time +-- @module StdLib.Time -- @alias defines.time --- @usage require('stdlib/defines/time') -- defines table is automatically required in all mod loading stages. -- luacheck: ignore 122/defines @@ -31,6 +30,4 @@ defines.time = { year = YEAR, -- the number of Factorio ticks in a year (365 days) } ---- Allows index to deines.time though the Time module ---@table Time return setmetatable({},{__index=defines.time}) \ No newline at end of file From eeb44c0c93a2452c4542188f8966fedd48d0a524 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Wed, 30 May 2018 00:25:14 +0100 Subject: [PATCH 010/231] Change To Readme --- README.md | 21 ++++++++++++++++++++- StandAlone/load.lua | 10 ---------- 2 files changed, 20 insertions(+), 11 deletions(-) delete mode 100644 StandAlone/load.lua diff --git a/README.md b/README.md index 668bf277..69123994 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,23 @@ -## ExpGaming Repository [![CodeFactor](https://www.codefactor.io/repository/github/badgamernl/explosivegaming-main/badge)](https://www.codefactor.io/repository/github/badgamernl/explosivegaming-main) [![dev chat](https://discordapp.com/api/guilds/260843215836545025/widget.png?style=shield)](https://discord.me/explosivegaming) +

    + logo +
    + + Tag + + + Star + + + Fork + + + CodeFactor + + + Discord + +

    +

    ExpGaming Scenario Repository

    #### Using The Core Files 1. Copy the core folder and the StdLib File diff --git a/StandAlone/load.lua b/StandAlone/load.lua deleted file mode 100644 index ce51227b..00000000 --- a/StandAlone/load.lua +++ /dev/null @@ -1,10 +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----------------------------------------------------------- --- this file will just contain all the diffrent requires \ No newline at end of file From 24598e594a28a9098592e9af2c03ac4e25065e54 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Wed, 30 May 2018 13:50:38 +0100 Subject: [PATCH 011/231] Added Module: ExpGamingCore --- Addons/load.lua | 10 --- ExpCore/load.lua | 43 ----------- FactorioSoftmodManager.lua | 55 +++++++------- control.lua | 2 +- doc/modules/StdLib.Table.html | 4 +- locale/en/ExpGamingCore.Commands.cfg | 9 +++ locale/en/ExpGamingCore.Gui.cfg | 4 + locale/en/ExpGamingCore.Ranking.cfg | 7 ++ locale/en/exp-core.cfg | 22 ------ .../ExpGamingCore/Commands/control.lua | 10 +-- .../ExpGamingCore/Gui}/GuiParts/center.lua | 0 .../ExpGamingCore/Gui}/GuiParts/inputs.lua | 0 .../ExpGamingCore/Gui}/GuiParts/left.lua | 0 .../ExpGamingCore/Gui}/GuiParts/popup.lua | 0 .../ExpGamingCore/Gui}/GuiParts/test.lua | 0 .../ExpGamingCore/Gui}/GuiParts/toolbar.lua | 0 .../ExpGamingCore/Gui/control.lua | 67 +++++++++-------- .../ExpGamingCore/Ranking/base_ranks.lua | 0 .../ExpGamingCore/Ranking/config_ranks.lua | 0 .../ExpGamingCore/Ranking/control.lua | 5 ++ .../ExpGamingCore/Server/control.lua | 29 +++---- .../ExpGamingCore/Sync/control.lua | 33 ++++---- modules/ExpGamingCore/softmod.json | 75 +++++++++++++++++++ modules/ExpGamingLib/softmod.json | 10 +-- modules/FactorioModGui/control.lua | 6 ++ modules/FactorioModGui/softmod.json | 12 +++ .../{color.lua => Color/control.lua} | 0 .../{game.lua => Game/control.lua} | 0 .../{string.lua => String/control.lua} | 0 .../{table.lua => Table/control.lua} | 4 +- .../{time.lua => Time/control.lua} | 0 modules/FactorioStdLib/softmod.json | 14 ++-- modules/index.lua | 18 +++-- 33 files changed, 250 insertions(+), 189 deletions(-) delete mode 100644 Addons/load.lua delete mode 100644 ExpCore/load.lua create mode 100644 locale/en/ExpGamingCore.Commands.cfg create mode 100644 locale/en/ExpGamingCore.Gui.cfg create mode 100644 locale/en/ExpGamingCore.Ranking.cfg delete mode 100644 locale/en/exp-core.cfg rename ExpCore/commands.lua => modules/ExpGamingCore/Commands/control.lua (94%) rename {ExpCore => modules/ExpGamingCore/Gui}/GuiParts/center.lua (100%) rename {ExpCore => modules/ExpGamingCore/Gui}/GuiParts/inputs.lua (100%) rename {ExpCore => modules/ExpGamingCore/Gui}/GuiParts/left.lua (100%) rename {ExpCore => modules/ExpGamingCore/Gui}/GuiParts/popup.lua (100%) rename {ExpCore => modules/ExpGamingCore/Gui}/GuiParts/test.lua (100%) rename {ExpCore => modules/ExpGamingCore/Gui}/GuiParts/toolbar.lua (100%) rename ExpCore/gui.lua => modules/ExpGamingCore/Gui/control.lua (78%) rename ExpCore/ranks.lua => modules/ExpGamingCore/Ranking/base_ranks.lua (100%) rename Addons/playerRanks.lua => modules/ExpGamingCore/Ranking/config_ranks.lua (100%) rename ExpCore/ranking.lua => modules/ExpGamingCore/Ranking/control.lua (99%) rename ExpCore/server.lua => modules/ExpGamingCore/Server/control.lua (93%) rename ExpCore/sync.lua => modules/ExpGamingCore/Sync/control.lua (94%) create mode 100644 modules/ExpGamingCore/softmod.json create mode 100644 modules/FactorioModGui/control.lua create mode 100644 modules/FactorioModGui/softmod.json rename modules/FactorioStdLib/{color.lua => Color/control.lua} (100%) rename modules/FactorioStdLib/{game.lua => Game/control.lua} (100%) rename modules/FactorioStdLib/{string.lua => String/control.lua} (100%) rename modules/FactorioStdLib/{table.lua => Table/control.lua} (99%) rename modules/FactorioStdLib/{time.lua => Time/control.lua} (100%) diff --git a/Addons/load.lua b/Addons/load.lua deleted file mode 100644 index ce51227b..00000000 --- a/Addons/load.lua +++ /dev/null @@ -1,10 +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----------------------------------------------------------- --- this file will just contain all the diffrent requires \ No newline at end of file diff --git a/ExpCore/load.lua b/ExpCore/load.lua deleted file mode 100644 index 2365a0c5..00000000 --- a/ExpCore/load.lua +++ /dev/null @@ -1,43 +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 -]] - ---[[ -ExpCore - -This file allow you to only require this one file to return the diffent libarys. -This file will return a function which can be used to access only the part you want. -Pass a table with the names of the objects you want and it will be return in that order -]] - -local StdExpCoreLib = {} - -require('commands') -StdExpCoreLib.Ranking = require('ranking') -StdExpCoreLib.Server = require('server') -StdExpCoreLib.Sync = require('sync') -StdExpCoreLib.Gui = require('gui') -verbose('Begain Gui Part Loading') -StdExpCoreLib.Gui:_load_parts{ - 'inputs', - 'toolbar', - 'center', - 'left', - 'popup' -} - -return function(rtn) - local _return = {} - for _,name in pairs(rtn) do - if StdExpCoreLib[name] then - verbose('Core File Extraction: '..name) - table.insert(_return,StdExpCoreLib[name]) - end - end - return unpack(_return) -end \ No newline at end of file diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index cfaa326c..7716deba 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -74,7 +74,7 @@ Manager.verbose = function(rtn,action) 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 + if module_verbose or action and (action == true or settings[action]) or (not action and 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) @@ -159,10 +159,12 @@ Manager.sandbox = setmetatable({ module_exports=false },{ __metatable=false, + __index=ReadOnlyManager, __call=function(tbl,callback,env,...) if type(callback) == 'function' then -- creates a new sandbox env local sandbox = tbl() + local env = type(env) == 'table' and env or type(env) ~= 'nil' and {env} or {} -- 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}) @@ -190,17 +192,17 @@ Manager.loadModules = setmetatable({}, -- 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) + for module_name,path in pairs(moduleIndex) do + Manager.verbose('Loading module: "'..module_name..'"; path: '..path) -- runs the module in a sandbox env - local sandbox, success, module = Manager.sandbox(require,{module_name=setupModuleName(module_name),module_location=location},location) + local sandbox, success, module = Manager.sandbox(require,{module_name=setupModuleName(module_name),module_path=path},path..'/control') -- 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) + Manager.verbose('Successfully loaded: "'..module_name..'"; path: '..path) -- 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 @@ -229,7 +231,7 @@ Manager.loadModules = setmetatable({}, -- 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) and type(tbl[module_name]) == 'table' then setmetatable(rawget(_G,module_name),{__index=tbl[module_name]}) end else - Manager.verbose('Failed load: "'..module_name..'"; Location: '..location..' ('..module..')','errorCaught') + Manager.verbose('Failed load: "'..module_name..'"; path: '..path..' ('..module..')','errorCaught') end end -- new state for the manager to allow control of verbose @@ -239,8 +241,8 @@ Manager.loadModules = setmetatable({}, -- 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) + Manager.verbose('Initiating module: "'..module_name..'"') + local sandbox, success, err = Manager.sandbox(data.on_init,{module_name=setupModuleName(module_name),module_path=moduleIndex[module_name]},data) if success then Manager.verbose('Successfully Initiated: "'..module_name..'"') else @@ -397,7 +399,7 @@ Manager.event = setmetatable({ 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,...) + local sandbox, success, err = Manager.sandbox(callback,{module_name=setupModuleName(module_name),module_path=moduleIndex[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 @@ -410,14 +412,19 @@ Manager.event = setmetatable({ -- 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') + Manager.verbose('Added Handler: "'..tbl.names[key]..'"','eventRegistered') -- 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 + if not rawget(rawget(tbl,'__events'),key) then + if key < 0 then rawget(tbl,tbl.names[key])(function(...) tbl(key,...) end) + else rawget(tbl,'__event')(key,function(...) tbl(key,...) end) 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) + -- few redirect key + local redirect={register=tbl,dispatch=tbl,remove=function(event_id) tbl[event_name]=nil end} + if rawget(redirect,key) then return rawget(redirect,key) end -- 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 @@ -458,12 +465,9 @@ rawset(Manager.event,'names',setmetatable({},{ -- 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) + if key == -1 then rawset(tbl,key,'__init') + elseif key == -2 then rawset(tbl,key,'__load') + elseif key == -3 then rawset(tbl,key,'__config') 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 @@ -473,19 +477,18 @@ rawset(Manager.event,'names',setmetatable({},{ -- 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 + else + if key == 'on_init' or key == 'init' or key == '__init' then return -1 + elseif key == 'on_load' or key == 'load' or key == '__load' then return -2 + elseif key == 'on_configuration_changed' or key == 'configuration_changed' or key == '__config' then return -3 + else return rawget(rawget(Manager.event,'events'),key) end + 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.mod_name = setmetatable({},{__index=_G.module_name}) script.on_event=Manager.event script.raise_event=Manager.event script.on_init=function(callback) Manager.event(-1,callback) end diff --git a/control.lua b/control.lua index 9aba66bc..741705fa 100644 --- a/control.lua +++ b/control.lua @@ -16,7 +16,7 @@ Manager.setVerbose{ 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 + eventRegistered=false, -- 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 } diff --git a/doc/modules/StdLib.Table.html b/doc/modules/StdLib.Table.html index 9fb1220b..84b9f1db 100644 --- a/doc/modules/StdLib.Table.html +++ b/doc/modules/StdLib.Table.html @@ -173,7 +173,7 @@ json (lua_table) - Simmilar to table.to_string but converts a lua table to a json one + Simmilar to table.tostring but converts a lua table to a json one autokey (tbl, str) @@ -1004,7 +1004,7 @@ some_func(1,2) json (lua_table)
    - Simmilar to table.to_string but converts a lua table to a json one + Simmilar to table.tostring but converts a lua table to a json one

    Parameters:

    diff --git a/locale/en/ExpGamingCore.Commands.cfg b/locale/en/ExpGamingCore.Commands.cfg new file mode 100644 index 00000000..a6323f71 --- /dev/null +++ b/locale/en/ExpGamingCore.Commands.cfg @@ -0,0 +1,9 @@ +[commands] +unauthorized=401 - Unauthorized: Access is denied due to invalid credentials +invalid-inputs=Invalid Input, /__1__ __2__ +invalid-range=Invalid Range, Min: __1__, Max: __2__ +invalid-length=Invalid Length, Max: __1__ +invalid-player=Invaild Player Name, __1__ ,try using tab key to auto-complete the name +offline-player=Player is offline: Command failed to run +dead-player=Player is dead: Command failed to run +command-ran=Command Complete \ No newline at end of file diff --git a/locale/en/ExpGamingCore.Gui.cfg b/locale/en/ExpGamingCore.Gui.cfg new file mode 100644 index 00000000..18fdb1a8 --- /dev/null +++ b/locale/en/ExpGamingCore.Gui.cfg @@ -0,0 +1,4 @@ +[gui] +unauthorized=401 - Unauthorized: Access is denied due to invalid credentials +cant-open=You can't open this panel right now, reason: __1__ +cant-open-no-reason=You can't open this panel right now \ No newline at end of file diff --git a/locale/en/ExpGamingCore.Ranking.cfg b/locale/en/ExpGamingCore.Ranking.cfg new file mode 100644 index 00000000..dc641783 --- /dev/null +++ b/locale/en/ExpGamingCore.Ranking.cfg @@ -0,0 +1,7 @@ +[ranking] +all-rank-print=[Everyone]: __1__ +rank-print=[__1__]: __2__ +rank-up=__1__ was promoted to __2__ by __3__ +rank-down=__1__ was demoted to __2__ by __3__ +rank-given=You have been given the __1__ Rank! +tag-reset=Your Tag was reset due to a Rank change \ No newline at end of file diff --git a/locale/en/exp-core.cfg b/locale/en/exp-core.cfg deleted file mode 100644 index c5453d60..00000000 --- a/locale/en/exp-core.cfg +++ /dev/null @@ -1,22 +0,0 @@ -[commands] -unauthorized=401 - Unauthorized: Access is denied due to invalid credentials -invalid-inputs=Invalid Input, /__1__ __2__ -invalid-range=Invalid Range, Min: __1__, Max: __2__ -invalid-length=Invalid Length, Max: __1__ -invalid-player=Invaild Player Name, __1__ ,try using tab key to auto-complete the name -offline-player=Player is offline: Command failed to run -dead-player=Player is dead: Command failed to run -command-ran=Command Complete - -[ranking] -all-rank-print=[Everyone]: __1__ -rank-print=[__1__]: __2__ -rank-up=__1__ was promoted to __2__ by __3__ -rank-down=__1__ was demoted to __2__ by __3__ -rank-given=You have been given the __1__ Rank! -tag-reset=Your Tag was reset due to a Rank change - -[gui] -unauthorized=401 - Unauthorized: Access is denied due to invalid credentials -cant-open=You can't open this panel right now, reason: __1__ -cant-open-no-reason=You can't open this panel right now diff --git a/ExpCore/commands.lua b/modules/ExpGamingCore/Commands/control.lua similarity index 94% rename from ExpCore/commands.lua rename to modules/ExpGamingCore/Commands/control.lua index 05986d75..911d50e1 100644 --- a/ExpCore/commands.lua +++ b/modules/ExpGamingCore/Commands/control.lua @@ -88,7 +88,7 @@ local function run_custom_command(command) game.tick ..' Player: "'..player_name..'"' ..' Failed to use command (Unauthorized): "'..command.name..'"' - ..' With args of: '..table.to_string(command_args(command,command_data)) + ..' With args of: '..table.tostring(command_args(command,command_data)) ..'\n' , true, 0) return @@ -102,7 +102,7 @@ local function run_custom_command(command) game.tick ..' Player: "'..player_name..'"' ..' Failed to use command (Invalid Args): "'..command.name..'"' - ..' With args of: '..table.to_string(args) + ..' With args of: '..table.tostring(args) ..'\n' , true, 0) return @@ -115,15 +115,15 @@ local function run_custom_command(command) game.tick ..' Player: "'..player_name..'"' ..' Used command: "'..command.name..'"' - ..' With args of: '..table.to_string(args) + ..' With args of: '..table.tostring(args) ..'\n' , true, 0) end -- this is a set of constants you can use commands._add_command = commands.add_command --if you dont want to use the custom commands interface -commands._expgaming = true --if you want to test if the custom commands are present -commands.error = 'COMMAND_ERROR' --if returned during a custom command, Command Complete message not printed +commands.expgaming = true --if you want to test if the custom commands are present +commands.error = {} --if returned during a custom command, Command Complete message not printed --- Used to define commands -- @usage inputs = {'player','reason',true} -- commands.add_command('ban','bans a player',inputs,function() return end) diff --git a/ExpCore/GuiParts/center.lua b/modules/ExpGamingCore/Gui/GuiParts/center.lua similarity index 100% rename from ExpCore/GuiParts/center.lua rename to modules/ExpGamingCore/Gui/GuiParts/center.lua diff --git a/ExpCore/GuiParts/inputs.lua b/modules/ExpGamingCore/Gui/GuiParts/inputs.lua similarity index 100% rename from ExpCore/GuiParts/inputs.lua rename to modules/ExpGamingCore/Gui/GuiParts/inputs.lua diff --git a/ExpCore/GuiParts/left.lua b/modules/ExpGamingCore/Gui/GuiParts/left.lua similarity index 100% rename from ExpCore/GuiParts/left.lua rename to modules/ExpGamingCore/Gui/GuiParts/left.lua diff --git a/ExpCore/GuiParts/popup.lua b/modules/ExpGamingCore/Gui/GuiParts/popup.lua similarity index 100% rename from ExpCore/GuiParts/popup.lua rename to modules/ExpGamingCore/Gui/GuiParts/popup.lua diff --git a/ExpCore/GuiParts/test.lua b/modules/ExpGamingCore/Gui/GuiParts/test.lua similarity index 100% rename from ExpCore/GuiParts/test.lua rename to modules/ExpGamingCore/Gui/GuiParts/test.lua diff --git a/ExpCore/GuiParts/toolbar.lua b/modules/ExpGamingCore/Gui/GuiParts/toolbar.lua similarity index 100% rename from ExpCore/GuiParts/toolbar.lua rename to modules/ExpGamingCore/Gui/GuiParts/toolbar.lua diff --git a/ExpCore/gui.lua b/modules/ExpGamingCore/Gui/control.lua similarity index 78% rename from ExpCore/gui.lua rename to modules/ExpGamingCore/Gui/control.lua index a3ee80da..a4def34d 100644 --- a/ExpCore/gui.lua +++ b/modules/ExpGamingCore/Gui/control.lua @@ -26,12 +26,11 @@ end function Gui._get_data(key) return Gui_data[key] end -function Gui:_load_parts(parts) - for _,part in pairs(parts) do - verbose('Gui Extraction: '..part) - self[part] = require('GuiParts/'..part) - end -end +Gui.center = require(module_path..'/GuiParts/center') +Gui.inputs = require(module_path..'/GuiParts/inputs') +Gui.left = require(module_path..'/GuiParts/left') +Gui.popup = require(module_path..'/GuiParts/popup') +Gui.toolbar = require(module_path..'/GuiParts/toolbar') --- Add a white bar to any gui frame -- @usage Gui.bar(frame,100) @@ -65,34 +64,38 @@ function Gui.set_dropdown_index(dropdown,_item) return dropdown end -Event.register(-1,function(event) - Server.new_thread{ - name='camera-follow', - data={cams={},cam_index=1,players={}} - }:on_event('tick',function(self) - local _cam = self.data.cams[self.data.cam_index] - if not _cam then self.data.cam_index = 1 _cam = self.data.cams[self.data.cam_index] end - if not _cam then return end - if not _cam.cam.valid then table.remove(self.data.cams,self.data.cam_index) - elseif not _cam.entity.valid then table.remove(self.data.cams,self.data.cam_index) - else _cam.cam.position = _cam.entity.position if not _cam.surface then _cam.cam.surface_index = _cam.entity.surface.index end self.data.cam_index = self.data.cam_index+1 - end - end):on_event('error',function(self,err) - -- posible error handling if needed - error(err) - end):on_event(defines.events.on_player_respawned,function(self,event) - if self.data.players[event.player_index] then - local remove = {} - for index,cam in pairs(self.data.players[event.player_index]) do - Gui.cam_link{cam=cam,entity=Game.get_player(event).character} - if not cam.valid then table.insert(remove,index) end +Gui.on_init=function(self) + Gui.test = require(module_path..'/GuiParts/test') + if not Server then return end + Event.register(-1,function(event) + Server.new_thread{ + name='camera-follow', + data={cams={},cam_index=1,players={}} + }:on_event('tick',function(self) + local _cam = self.data.cams[self.data.cam_index] + if not _cam then self.data.cam_index = 1 _cam = self.data.cams[self.data.cam_index] end + if not _cam then return end + if not _cam.cam.valid then table.remove(self.data.cams,self.data.cam_index) + elseif not _cam.entity.valid then table.remove(self.data.cams,self.data.cam_index) + else _cam.cam.position = _cam.entity.position if not _cam.surface then _cam.cam.surface_index = _cam.entity.surface.index end self.data.cam_index = self.data.cam_index+1 end - for _,index in pairs(remove) do - table.remove(self.data.players[event.player_index],index) + end):on_event('error',function(self,err) + -- posible error handling if needed + error(err) + end):on_event(defines.events.on_player_respawned,function(self,event) + if self.data.players[event.player_index] then + local remove = {} + for index,cam in pairs(self.data.players[event.player_index]) do + Gui.cam_link{cam=cam,entity=Game.get_player(event).character} + if not cam.valid then table.insert(remove,index) end + end + for _,index in pairs(remove) do + table.remove(self.data.players[event.player_index],index) + end end - end - end):open() -end) + end):open() + end) +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} diff --git a/ExpCore/ranks.lua b/modules/ExpGamingCore/Ranking/base_ranks.lua similarity index 100% rename from ExpCore/ranks.lua rename to modules/ExpGamingCore/Ranking/base_ranks.lua diff --git a/Addons/playerRanks.lua b/modules/ExpGamingCore/Ranking/config_ranks.lua similarity index 100% rename from Addons/playerRanks.lua rename to modules/ExpGamingCore/Ranking/config_ranks.lua diff --git a/ExpCore/ranking.lua b/modules/ExpGamingCore/Ranking/control.lua similarity index 99% rename from ExpCore/ranking.lua rename to modules/ExpGamingCore/Ranking/control.lua index 29750360..142ac0a3 100644 --- a/ExpCore/ranking.lua +++ b/modules/ExpGamingCore/Ranking/control.lua @@ -384,4 +384,9 @@ Event.register(defines.events.on_tick,function(event) end end) +Ranking.on_init=function(self) + require(module_path.."/base_ranks") + require(module_path.."/config_ranks") +end + return Ranking \ No newline at end of file diff --git a/ExpCore/server.lua b/modules/ExpGamingCore/Server/control.lua similarity index 93% rename from ExpCore/server.lua rename to modules/ExpGamingCore/Server/control.lua index d4f77b07..8cc08963 100644 --- a/ExpCore/server.lua +++ b/modules/ExpGamingCore/Server/control.lua @@ -139,8 +139,6 @@ function Server._thread_handler(event) end) end -for _,event in pairs(defines.events) do Event.register(event,Server._thread_handler) end - --[[ cant be used V --- Adds a event handler to tell threads about events -- @usage Server.add_thread_handler(defines.event) @@ -193,18 +191,6 @@ function Server.interface(callback,use_thread,...) end end -if commands._expgaming then - commands.add_command('interface', 'Runs the given input from the script', {'code',true}, function(event,args) - local callback = args.code - if not string.find(callback,'%s') and not string.find(callback,'return') then callback = 'return '..callback end - if game.player then callback = 'local player, surface, force, position, entity, tile = game.player, game.player.surface, game.player.force, game.player.position, game.player.selected, game.player.surface.get_tile(game.player.position);'..callback end - if Ranking and Ranking.get_rank and game.player then callback = 'local rank = Ranking.get_rank(game.player);'..callback end - local success, err = Server.interface(callback) - if not success and is_type(err,'string') then local _end = string.find(err,'stack traceback') if _end then err = string.sub(err,0,_end-2) end end - if err or err == false then player_return(err) end - end) -end - -- thread allows you to run fuinction async to the main game --- Returns a new thread object -- @usage new_thread = thread:create() @@ -393,6 +379,21 @@ Event.register(-2,function(event) end end) +Server.on_init=function(self) + Event.register(defines.event,Server._thread_handler) + if pcall(function() return commands._expgaming end) then + commands.add_command('interface', 'Runs the given input from the script', {'code',true}, function(event,args) + local callback = args.code + if not string.find(callback,'%s') and not string.find(callback,'return') then callback = 'return '..callback end + if game.player then callback = 'local player, surface, force, position, entity, tile = game.player, game.player.surface, game.player.force, game.player.position, game.player.selected, game.player.surface.get_tile(game.player.position);'..callback end + if Ranking and Ranking.get_rank and game.player then callback = 'local rank = Ranking.get_rank(game.player);'..callback end + local success, err = Server.interface(callback) + if not success and is_type(err,'string') then local _end = string.find(err,'stack traceback') if _end then err = string.sub(err,0,_end-2) end end + if err or err == false then player_return(err) end + end) + end +end + return Server --[[ Thread Example: diff --git a/ExpCore/sync.lua b/modules/ExpGamingCore/Sync/control.lua similarity index 94% rename from ExpCore/sync.lua rename to modules/ExpGamingCore/Sync/control.lua index 913ee247..862912bc 100644 --- a/ExpCore/sync.lua +++ b/modules/ExpGamingCore/Sync/control.lua @@ -15,7 +15,7 @@ local Sync_updates = {} --- Used as a faster way to get to the ranking function, overrides previous -- @usage Sync.set_ranks{name=rank_name} function Sync.set_ranks(...) - Ranking._base_preset(...) + if Ranking then Ranking._base_preset(...) else error('Ranking module not installed') end end --- Used to standidise the tick format for any sync info @@ -91,11 +91,10 @@ function Sync.emit_embeded(args) end -- set up error handle -verbose('Set New Error Handle') -_G.error_handle = function(err) +error.addHandler('Discord Emit',function(err) local color = _G.Color and Color.to_hex(defines.textcolor.bg) or '0x0' Sync.emit_embeded{title='SCRIPT ERROR',color=color,description='There was an error in the script @Developers ',Error=err} -end +end) --- used to get the number of admins currently online -- @usage Sync.count_admins() @@ -128,6 +127,7 @@ end -- @treturn table contains the ranks and the players in that rank function Sync.count_ranks() if not game then return {'Offline'} end + if not Ranking then return {'Ranking module not installed'} end local _ranks = {} for power,rank in pairs(Ranking._ranks()) do local players = rank:get_players() @@ -278,16 +278,21 @@ function Sync.add_to_gui(element,...) return true end --- Examples for Sync.add_to_gui --- adds a basic string to the table -Sync.add_to_gui('Welcome to the Explosive Gaming comunity! This is one of many servers which we host.') --- adds a string that can have depentant values -Sync.add_to_gui(function(player,frame) - return 'You have been assigned the rank \''..Ranking.get_rank(player).name..'\'' -end) -Sync.add_to_gui(function(player,frame) - return 'This server will reset at: '..Sync.info().reset_time -end) + +Sync.on_init=function(self) + -- Examples for Sync.add_to_gui + -- adds a basic string to the table + Sync.add_to_gui('Welcome to the Explosive Gaming comunity! This is one of many servers which we host.') + if Ranking then + -- adds a string that can have depentant values + Sync.add_to_gui(function(player,frame) + return 'You have been assigned the rank \''..Ranking.get_rank(player).name..'\'' + end) + end + Sync.add_to_gui(function(player,frame) + return 'This server will reset at: '..Sync.info().reset_time + end) +end -- if readme is included then see addons/guis/readme.lua for more examples -- used to load the gui infomation when _G.Gui is not yet loaded diff --git a/modules/ExpGamingCore/softmod.json b/modules/ExpGamingCore/softmod.json new file mode 100644 index 00000000..70f629b5 --- /dev/null +++ b/modules/ExpGamingCore/softmod.json @@ -0,0 +1,75 @@ +{ + "name": "ExpGamingCore", + "module": "Collection", + "description": "Explosive Gaming Core Files", + "keywords": ["Library","Lib","ExpGaming","Core"], + "version": "3.4.0", + "location": "url", + "submodules": { + "Commands": { + "name": "Commands", + "module": "commands", + "description": "A better command handler than the base game.", + "keywords": ["Library","Lib","ExpGaming","Core","Commands"], + "version": "3.4.0", + "location": "url", + "dependencies": { + "ExpGamingLib": ">=3.0.0", + "ExpGamingCore/Ranking": ">=3.0.0" + } + }, + "Gui": { + "name": "Gui", + "module": "Gui", + "description": "Adds a objective version to custom guis.", + "keywords": ["Library","Lib","ExpGaming","Core","Gui","ExpGui"], + "version": "3.4.0", + "location": "url", + "dependencies": { + "FactorioModGui": ">=1.0.0", + "ExpGamingLib": ">=3.0.0", + "ExpGamingCore/Ranking": ">=3.0.0", + "ExpGamingCore/Server": "?>=3.0.0" + } + }, + "Ranking": { + "name": "Ranking", + "module": "Ranking", + "description": "A full ranking system for factorio.", + "keywords": ["Library","Lib","ExpGaming","Core","Ranking","Ranks","Permissions","Roles"], + "version": "3.4.0", + "location": "url", + "dependencies": { + "ExpGamingLib": ">=3.0.0" + } + }, + "Server": { + "name": "Server", + "module": "Server", + "description": "Adds a thread system and event listening and a admin bypass (recommend to disable /c and use optional /interface)", + "keywords": ["Library","Lib","ExpGaming","Core","Server","Thread","Interface","Events"], + "version": "3.4.0", + "location": "url", + "dependencies": { + "ExpGamingLib": ">=3.0.0", + "ExpGamingCore/Ranking": "?>=3.0.0", + "ExpGamingCore/Commands": "?>=3.0.0" + } + }, + "Sync": { + "name": "Sync", + "module": "Sync", + "description": "Allows syncing with an outside server and info panle.", + "keywords": ["Library","Lib","ExpGaming","Core","Info","Sync","External","Discord"], + "version": "3.4.0", + "location": "url", + "dependencies": { + "ExpGamingLib": ">=3.0.0", + "Ranking": "?>=3.0.0" + } + } + }, + "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/ExpGamingLib/softmod.json b/modules/ExpGamingLib/softmod.json index 9b86aee9..0f433a9f 100644 --- a/modules/ExpGamingLib/softmod.json +++ b/modules/ExpGamingLib/softmod.json @@ -3,12 +3,12 @@ "module": "ExpLib", "description": "Adds some common functions used though out all ExpGaming modules", "keywords": ["ExpGaming","Lib"], - "version": "1.0.0", - "location": "nil", - "main": "control", + "version": "3.4.0", + "location": "url", "dependencies": { - "StdLib/Game": ">=1.0.0", - "StdLib/Color": ">=1.0.0" + "StdLib.Game": ">=0.8.0", + "StdLib.Color": ">=0.8.0", + "StdLib.Table": ">=0.8.0" }, "author": "Cooldude2606", "contact": "Discord: Cooldude2606#5241", diff --git a/modules/FactorioModGui/control.lua b/modules/FactorioModGui/control.lua new file mode 100644 index 00000000..40fa62b1 --- /dev/null +++ b/modules/FactorioModGui/control.lua @@ -0,0 +1,6 @@ +--- Redirect to factorio mod-gui +-- @module Factorio Mod Gui +-- @alias mod-gui +-- @author Factorio Dev Team + +return require("mod-gui") \ No newline at end of file diff --git a/modules/FactorioModGui/softmod.json b/modules/FactorioModGui/softmod.json new file mode 100644 index 00000000..b42b7844 --- /dev/null +++ b/modules/FactorioModGui/softmod.json @@ -0,0 +1,12 @@ +{ + "name": "FactorioModGui", + "module": "mod_gui", + "description": "A way to standadise the way mods hanndle their guis.", + "keywords": ["Factorio","Gui","Non-Download","Included"], + "version": "1.0.0", + "location": "url", + "dependencies": {}, + "author": "Factorio Dev Team", + "contact": "Any other questions please feel free to ask on the modding help forum.", + "license": "C:/Program Files (x86)/Steam/steamapps/common/Factorio/data/licenses.txt" +} \ No newline at end of file diff --git a/modules/FactorioStdLib/color.lua b/modules/FactorioStdLib/Color/control.lua similarity index 100% rename from modules/FactorioStdLib/color.lua rename to modules/FactorioStdLib/Color/control.lua diff --git a/modules/FactorioStdLib/game.lua b/modules/FactorioStdLib/Game/control.lua similarity index 100% rename from modules/FactorioStdLib/game.lua rename to modules/FactorioStdLib/Game/control.lua diff --git a/modules/FactorioStdLib/string.lua b/modules/FactorioStdLib/String/control.lua similarity index 100% rename from modules/FactorioStdLib/string.lua rename to modules/FactorioStdLib/String/control.lua diff --git a/modules/FactorioStdLib/table.lua b/modules/FactorioStdLib/Table/control.lua similarity index 99% rename from modules/FactorioStdLib/table.lua rename to modules/FactorioStdLib/Table/control.lua index f2c63683..bb3c57a8 100644 --- a/modules/FactorioStdLib/table.lua +++ b/modules/FactorioStdLib/Table/control.lua @@ -410,7 +410,7 @@ function table.val_to_str(v) end return '"'..string.gsub(v,'"', '\\"' )..'"' else - return "table" == type( v) and table.to_string(v) or + return "table" == type( v) and table.tostring(v) or "function" == type(v) and '"cant-display-function"' or "userdata" == type(v) and '"cant-display-userdata"' or tostring(v) @@ -450,7 +450,7 @@ function table.tostring(tbl) return "{"..table.concat(result,",") .."}" end ---- Simmilar to table.to_string but converts a lua table to a json one +--- Simmilar to table.tostring but converts a lua table to a json one -- @usage local a = {k1='foo',k2='bar'} -- talbe.json(a) -- return '{"k1":"foo","k2":"bar"}' -- @tparam table lua_table the table to convert diff --git a/modules/FactorioStdLib/time.lua b/modules/FactorioStdLib/Time/control.lua similarity index 100% rename from modules/FactorioStdLib/time.lua rename to modules/FactorioStdLib/Time/control.lua diff --git a/modules/FactorioStdLib/softmod.json b/modules/FactorioStdLib/softmod.json index 98acc3a7..89af4963 100644 --- a/modules/FactorioStdLib/softmod.json +++ b/modules/FactorioStdLib/softmod.json @@ -1,10 +1,10 @@ { "name": "FactorioStdLib", - "module": "StdLib", + "module": "Collection", "description": "Factorio Standard Library Projects", "keywords": ["Standard Library","Lib","StdLib"], "version": "0.8.0", - "location": "nil", + "location": "url", "submodules": { "Color": { "name": "Color", @@ -12,7 +12,7 @@ "description": "A defines module for retrieving colors by name.", "keywords": ["Standard Library","Lib","StdLib","Color","Extends"], "version": "0.8.0", - "location": "color", + "location": "url", "dependencies": {} }, "Game": { @@ -21,7 +21,7 @@ "description": "The game module.", "keywords": ["Standard Library","Lib","StdLib","Game","Extends"], "version": "0.8.0", - "location": "game", + "location": "url", "dependencies": {} }, "String": { @@ -30,7 +30,7 @@ "description": "Extends Lua 5.2 string.", "keywords": ["Standard Library","Lib","StdLib","String","Extends"], "version": "0.8.0", - "location": "string", + "location": "url", "dependencies": {} }, "Table": { @@ -39,7 +39,7 @@ "description": "Extends Lua 5.2 table.", "keywords": ["Standard Library","Lib","StdLib","Table","Extends"], "version": "0.8.0", - "location": "table", + "location": "url", "dependencies": {} }, "Time": { @@ -48,7 +48,7 @@ "description": "A defines module for retrieving the number of ticks in 1 unit of time.", "keywords": ["Standard Library","Lib","StdLib","Time","Extends"], "version": "0.8.0", - "location": "time", + "location": "url", "dependencies": {} } }, diff --git a/modules/index.lua b/modules/index.lua index 6fd4b693..643e99c5 100644 --- a/modules/index.lua +++ b/modules/index.lua @@ -1,10 +1,16 @@ --- Used to index the files to be loaded -- @script index.lua return { - ['ExpLib']='/modules/ExpGamingLib/control', - ['Game']='/modules/FactorioStdLib/game', - ['Time']='/modules/FactorioStdLib/time', - ['Color']='/modules/FactorioStdLib/color', - ['table']='/modules/FactorioStdLib/table', - ['string']='/modules/FactorioStdLib/string', + ['mod_gui']='/modules/FactorioModGui', + ['ExpLib']='/modules/ExpGamingLib', + ['Game']='/modules/FactorioStdLib/Game', + ['Time']='/modules/FactorioStdLib/Time', + ['Color']='/modules/FactorioStdLib/Color', + ['table']='/modules/FactorioStdLib/Table', + ['string']='/modules/FactorioStdLib/String', + ['Ranking']='/modules/ExpGamingCore/Ranking', + ['commands']='/modules/ExpGamingCore/Commands', + ['Gui']='/modules/ExpGamingCore/Gui', + ['Server']='/modules/ExpGamingCore/Server', + ['Sync']='/modules/ExpGamingCore/Sync', } \ No newline at end of file From 48e65ce78f73012616ba9c7fc9932366a9a811cd Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Wed, 30 May 2018 14:00:52 +0100 Subject: [PATCH 012/231] Fixed Server Threads --- FactorioSoftmodManager.lua | 4 ++-- control.lua | 2 +- modules/ExpGamingCore/Server/control.lua | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index 7716deba..28c9c3b0 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -74,7 +74,7 @@ Manager.verbose = function(rtn,action) 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 (not action and settings[state]) then + if module_verbose or (action and (action == true or settings[action])) or (not action and 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) @@ -487,7 +487,7 @@ rawset(Manager.event,'names',setmetatable({},{ })) --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}) +Event=setmetatable({},{__call=Manager.event,__index=function(tbl,key) return Manager.event[key] or script[key] or error('Invalid Index To Table Event') end}) script.mod_name = setmetatable({},{__index=_G.module_name}) script.on_event=Manager.event script.raise_event=Manager.event diff --git a/control.lua b/control.lua index 741705fa..9aba66bc 100644 --- a/control.lua +++ b/control.lua @@ -16,7 +16,7 @@ Manager.setVerbose{ 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=false, -- when a module registers its event handlers + 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 } diff --git a/modules/ExpGamingCore/Server/control.lua b/modules/ExpGamingCore/Server/control.lua index 8cc08963..d8c6347f 100644 --- a/modules/ExpGamingCore/Server/control.lua +++ b/modules/ExpGamingCore/Server/control.lua @@ -380,7 +380,7 @@ Event.register(-2,function(event) end) Server.on_init=function(self) - Event.register(defines.event,Server._thread_handler) + Event.register(defines.events,Server._thread_handler) if pcall(function() return commands._expgaming end) then commands.add_command('interface', 'Runs the given input from the script', {'code',true}, function(event,args) local callback = args.code From 2dd50c8d9c08a7ba635886183aa37ef74e2f7e86 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Wed, 30 May 2018 20:05:12 +0100 Subject: [PATCH 013/231] Added Module: ExpGamingCore.Sync --- FactorioSoftmodManager.lua | 1 + modules/ExpGamingCore/Sync/control.lua | 298 ++++++++------------- modules/ExpGamingCore/Sync/lib/gui.lua | 93 +++++++ modules/ExpGamingCore/Sync/lib/ranking.lua | 39 +++ modules/ExpGamingCore/softmod.json | 7 +- modules/ExpGamingLib/control.lua | 17 ++ modules/ExpGamingLib/softmod.json | 2 +- 7 files changed, 261 insertions(+), 196 deletions(-) create mode 100644 modules/ExpGamingCore/Sync/lib/gui.lua create mode 100644 modules/ExpGamingCore/Sync/lib/ranking.lua diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index 28c9c3b0..4d549d64 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -155,6 +155,7 @@ Manager.verbose('Current state is now: "selfInit"; The verbose state is: '..tost Manager.sandbox = setmetatable({ -- can not use existing keys of _G verbose=Manager.verbose, + loaded_modules=ReadOnlyManager, module_verbose=false, module_exports=false },{ diff --git a/modules/ExpGamingCore/Sync/control.lua b/modules/ExpGamingCore/Sync/control.lua index 862912bc..17a312ed 100644 --- a/modules/ExpGamingCore/Sync/control.lua +++ b/modules/ExpGamingCore/Sync/control.lua @@ -9,44 +9,38 @@ Discord: https://discord.gg/r6dC2uK --Please Only Edit Below This Line----------------------------------------------------------- -- this file is used to allow easy syncing with out side programes local Sync = {} -local Sync_gui_functions = {} local Sync_updates = {} ---- Used as a faster way to get to the ranking function, overrides previous --- @usage Sync.set_ranks{name=rank_name} -function Sync.set_ranks(...) - if Ranking then Ranking._base_preset(...) else error('Ranking module not installed') end -end - --- Used to standidise the tick format for any sync info -- @usage Sync.tick_format(60) -- return {60,'1.00M'} +-- @treturn {number,string} table containg both the raw number and clean version of a time function Sync.tick_format(tick) + if not is_type(tick,'number') then error('Tick was not given to Sync.tick_format',2) end return {tick,tick_to_display_format(tick)} end --- Prints to chat as if it were a player -- @usage Sync.print('Test','Cooldude2606') --- @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] player_colour the colour of the message --- @param[opt] prefix add a prefix before the chat eg [IRC] +-- @tparam string player_message the message to be printed in chat +-- @tparam string player_name the name of the player sending the message +-- @tparam[opt] string player_tag the tag apllied to the player's name +-- @tparam[opt] string player_colour the colour of the message, either hex or named colour +-- @tparam[opt] string 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 + if not player_message then error('No message given to Sync.print',2) end local player = game.player or game.players[player_name] local tag = player_tag and player_tag ~= '' and ' '..player_tag or '' - local colour = player_colour and player_colour ~= '' and player_colour or '#FFFFFF' + local colour = type(player_colour) == 'string' and player_colour or '#FFFFFF' local prefix = prefix and prefix..' ' or '' + -- if it is an ingame player it will over ride the given params if player then tag = ' '..player.tag colour = player.chat_color player_name = player.name else - if colour:find('#') then - colour = Color.from_hex(colour) - else - colour = defines.color[player_colour] - end + -- converts colour into the accepted factorio version + if colour:find('#') then colour = Color.from_hex(colour) + else colour = defines.color[player_colour] end end game.print(prefix..player_name..tag..': '..player_message,colour) end @@ -54,6 +48,7 @@ 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 args a table which contains everything that the embeded will use +-- @table args -- @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 @@ -61,26 +56,30 @@ end -- @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 + if not is_type(args,'table') then error('Args table not given to Sync.emit_embeded',2) end local title = is_type(args.title,'string') and args.title or '' local color = is_type(args.color,'string') and args.color:find("0x") and args.color or '0x0' local description = is_type(args.description,'string') and args.description or '' local server_detail = is_type(args.server_detail,'string') and args.server_detail or '' - local mods_online = 'Mods Online: '..Sync.info().players.admins_online + local mods_online = 'Mods Online: '..Sync.info.players.admins_online + -- creates the first field given for every emit local done, fields = {title=true,color=true,description=true,server_detail=true}, {{ - name='Server Details', + name='Server Details', value='Server Name: {{ serverName }} Online Players: '..#game.connected_players..' '..mods_online..' Server Time: '..tick_to_display_format(game.tick)..' '..server_detail }} + -- for each value given in args it will create a new field for the embed for key, value in pairs(args) do if not done[key] then done[key] = true local f = {name=key,value='',inline=false} + -- if <> is present then it will cause the field to be inline if the previous local value, inline = value:gsub("<>",'',1) - f.value = value if inline > 0 then f.inline = true end + f.value = value table.insert(fields,f) end end + -- forms the data that will be emited to the file local log_data = { title=title, description=description, @@ -90,16 +89,19 @@ function Sync.emit_embeded(args) game.write_file('embeded.json',table.json(log_data)..'\n',true,0) end --- set up error handle +--- The error handle setup by sync to emit a discord embed for any errors +-- @function errorHandler +-- @tparam string err the error passed by the err control error.addHandler('Discord Emit',function(err) - local color = _G.Color and Color.to_hex(defines.textcolor.bg) or '0x0' + local color = Color and Color.to_hex(defines.textcolor.bg) or '0x0' Sync.emit_embeded{title='SCRIPT ERROR',color=color,description='There was an error in the script @Developers ',Error=err} end) ---- used to get the number of admins currently online --- @usage Sync.count_admins() --- @treturn int the number of admins online +--- Used to get the number of admins currently online +-- @usage Sync.count_admins() -- returns number +-- @treturn number the number of admins online function Sync.count_admins() + -- game check if not game then return 0 end local _count = 0 for _,player in pairs(game.connected_players) do @@ -108,10 +110,10 @@ function Sync.count_admins() return _count end ---- used to get the number of afk players defined by 2 min by default +--- Used to get the number of afk players defined by 2 min by default -- @usage Sync.count_afk() -- @tparam[opt=7200] int time in ticks that a player is called afk --- @treturn int the number of afk players +-- @treturn number the number of afk players function Sync.count_afk(time) if not game then return 0 end local time = time or 7200 @@ -122,27 +124,30 @@ function Sync.count_afk(time) return _count end ---- used to get the number of players in each rank and currently online +--- Used to get the number of players in each rank and currently online; if ExpGamingCore/Ranking is present then it will give more than admin and user -- @usage Sync.count_ranks() -- @treturn table contains the ranks and the players in that rank function Sync.count_ranks() if not game then return {'Offline'} end - if not Ranking then return {'Ranking module not installed'} end - local _ranks = {} - for power,rank in pairs(Ranking._ranks()) do - local players = rank:get_players() - for k,player in pairs(players) do players[k] = player.name end - local online = rank:get_players(true) - for k,player in pairs(online) do online[k] = player.name end - _ranks[rank.name] = {players=players,online=online,n_players=#players,n_online=#online} + local _ranks = {admin={online={},players={}},user={online={},players={}}} + for power,rank in pairs(game.players) do + if player.admin then + table.insert(_ranks.admin.players,player.name) + if player.connected then table.insert(_ranks.admin.online,player.name) end + else + table.insert(_ranks.user.players,player.name) + if player.connected then table.insert(_ranks.user.online,player.name) end + end end + _ranks.admin.n_players,_ranks.admin.n_online=#_ranks.admin.players,#_ranks.admin.online + _ranks.user.n_players,_ranks.user.n_online=#_ranks.user.players,#_ranks.user.online return _ranks end ---- used to get the number of players either online or all +--- Used to get a list of every player name with the option to limit to only online players -- @usage Sync.count_players() --- @tparam bolean online if true only get online players --- @treturn table contains player names +-- @tparam boolean online true will get only the online players +-- @treturn table table of player names function Sync.count_players(online) if not game then return {'Offline'} end local _players = {} @@ -152,9 +157,9 @@ function Sync.count_players(online) return players end ---- used to get the number of players resulting in there play times +--- Used to get a list of every player name with the amount of time they have played for -- @usage Sync.count_player_times() --- @treturn table contains players and each player is given a tick amount and a formated string +-- @treturn table table indexed by player name, each value contains the raw tick and then the clean string function Sync.count_player_times() if not game then return {'Offline'} end local _players = {} @@ -164,64 +169,50 @@ function Sync.count_player_times() return _players end ---- used to return the global list and set values in it --- @usage Sync.info{server_name='Factorio Server 2'} +--- used to get the global list that has been defined, also used to set that list +-- @usage Sync.info{server_name='Factorio Server 2'} -- returns true +-- @usage Sync.info -- table of 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 - if not global.exp_core.sync then global.exp_core.sync = { - server_name='Factorio Server', - server_description='A factorio server for everyone', - reset_time='On Demand', - time='Day Mth 00 00:00:00 UTC Year', - time_set=Sync.tick_format(0), - last_update=Sync.tick_format(0), - time_period=Sync.tick_format(18000), - players={ - online=Sync.count_players(true), - n_online=#game.connected_players, - all=Sync.count_players(), - n_all=#game.players, - admins_online=Sync.count_admins(), - afk_players=Sync.count_afk(), - times=Sync.count_player_times() - }, - ranks=Sync.count_ranks(), - rockets=game.forces['player'].get_item_launched('satellite'), - mods={'base'} - } end - if not set then return global.exp_core.sync - else +-- @treturn boolean success was the data set +Sync.info = setmetatable({},{ + __index=function(tbl,key) + if not global.exp_core then global.exp_core = {} end + if not global.exp_core.sync then global.exp_core.sync = { + server_name='Factorio Server', + server_description='A factorio server for everyone', + reset_time='On Demand', + time='Day Mth 00 00:00:00 UTC Year', + time_set=Sync.tick_format(0), + last_update=Sync.tick_format(0), + time_period=Sync.tick_format(18000), + players={ + online=Sync.count_players(true), + n_online=#game.connected_players, + all=Sync.count_players(), + n_all=#game.players, + admins_online=Sync.count_admins(), + afk_players=Sync.count_afk(), + times=Sync.count_player_times() + }, + ranks=Sync.count_ranks(), + rockets=game.forces['player'].get_item_launched('satellite'), + mods={'base'} + } end + return global.exp_core.sync[key] + end, + __call=function(tbl,set) + local _ = tbl.time -- used to create the global if not made if not is_type(set,'table') then return false end - for key,value in pairs(set) do - global.exp_core.sync[key] = value - end + for key,value in pairs(set) do global.exp_core.sync[key] = value end return true end -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 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() - if not set then return info.time..' (+'..(game.tick-info.time_set[1])..' Ticks)' - else - if not is_type(set,'string') then return false end - info.time = set - info.time_set[1] = game.tick - info.time_set[2] = tick_to_display_format(game.tick) - return true - end -end - ---- called to update values inside of the info +--- Called to update values inside of the info -- @usage Sync.update() -- @return all of the new info function Sync.update() - local info = Sync.info() + local info = Sync.info info.time_period[2] = tick_to_display_format(info.time_period[1]) info.last_update[1] = game.tick info.last_update[2] = tick_to_display_format(game.tick) @@ -253,112 +244,33 @@ end --- outputs the curent server info into a file -- @usage Sync.emit_data() function Sync.emit_data() - local info = Sync.info() + local info = Sync.info game.write_file('server-info.json',table.json(info),false,0) end -- will auto replace the file every 5 min by default -Event.register(defines.events.on_tick,function(event) - local time = Sync.info().time_period[1] +script.on_event('on_tick',function(event) + local time = Sync.info.time_period[1] if (event.tick%time)==0 then Sync.update() Sync.emit_data() end end) ---- Adds a emeltent to the sever info gui --- @usage Sync.add_to_gui('string') -- return trues --- @param element see examples before for what can be used, it can also be a return from Gui.inputs.add --- @treturn bolean based on weather it was successful or not -function Sync.add_to_gui(element,...) - if game then return false end - if is_type(element,'function') then - table.insert(Sync_gui_functions,{'function',element,...}) - elseif is_type(element,'table') then - if element.draw then table.insert(Sync_gui_functions,{'gui',element}) - else table.insert(Sync_gui_functions,{'table',element}) end - else table.insert(Sync_gui_functions,{'string',element}) end - return true +function Sync:on_init() + --- Used to return and set the current IRL time; not very good need a better way to do this + -- @usage Sync.time('Sun Apr 1 18:44:30 UTC 2018') + -- @usage Sync.time -- string + -- @tparam[opt=nil] string set the date time to be set + -- @treturn boolean if the datetime set was successful + Sync.time=add_metatable({},function(set) + local info = Sync.info + if not is_type(set,'string') then return false end + info.time = set + info.time_set[1] = game.tick + info.time_set[2] = tick_to_display_format(game.tick) + return true + end,function() local info = Sync.info return info.time..' (+'..(game.tick-info.time_set[1])..' Ticks)' end) + -- optinal dependies + if loaded_modules.Gui then verbose('ExpGamingCore.Gui is installed; Loading gui lib') require(module_path..'/lib/gui') end + if loaded_modules.Ranking then verbose('ExpGamingCore.Ranking is installed; Loading ranking lib') require(module_path..'/lib/ranking') end end - -Sync.on_init=function(self) - -- Examples for Sync.add_to_gui - -- adds a basic string to the table - Sync.add_to_gui('Welcome to the Explosive Gaming comunity! This is one of many servers which we host.') - if Ranking then - -- adds a string that can have depentant values - Sync.add_to_gui(function(player,frame) - return 'You have been assigned the rank \''..Ranking.get_rank(player).name..'\'' - end) - end - Sync.add_to_gui(function(player,frame) - return 'This server will reset at: '..Sync.info().reset_time - end) -end --- if readme is included then see addons/guis/readme.lua for more examples - --- used to load the gui infomation when _G.Gui is not yet loaded --- internal use not recomend to be used -function Sync._load() - local function label_format(label,width) - label.style.width = width - label.style.align = 'center' - label.style.single_line = false - end - Gui.center.add{ - name='server-info', - caption='Server Info', - tooltip='Basic info about the current server', - draw=function(self,frame) - frame.caption = '' - local info = Sync.info() - local frame = frame.add{type='flow',direction='vertical'} - local _flow = frame.add{type='flow'} - Gui.bar(_flow,200) - label_format(_flow.add{ - type='label', - caption='Welcome To '..info.server_name, - style='caption_label' - },180) - Gui.bar(_flow,200) - label_format(frame.add{ - type='label', - caption=info.server_description,style='description_label' - },600) - Gui.bar(frame,600) - local _frame = frame - local frame = frame.add{ - type='frame', - direction='vertical', - style='image_frame' - } - frame.style.width = 600 - local text_flow = frame.add{type='flow',direction='vertical'} - local button_flow = frame.add{type='table',column_count=3} - for _,element in pairs(table.deepcopy(Sync_gui_functions)) do - local _type = table.remove(element,1) - if _type == 'function' then - local success, err = pcall(table.remove(element,1),frame.player_index,frame,unpack(element)) - if not success then error(err) else - if is_type(err,'table') then - if element.draw then element:draw(button_flow).style.width = 195 - else label_format(text_flow.add{type='label',caption=err},585) end - else label_format(text_flow.add{type='label',caption=tostring(err)},585) end - end - elseif _type == 'gui' then element[1]:draw(button_flow).style.width = 195 - elseif _type == 'string' then label_format(text_flow.add{type='label',caption=tostring(element[1])},585) - elseif _type == 'table' then label_format(text_flow.add{type='label',caption=element[1]},585) end - end - _frame.add{ - type='label', - caption='Press Ecs or E to close; this is only visible once!', - style='fake_disabled_label' - }.style.font='default-small' - end} -end - --- opens the server info gui for all new joins except admins -Event.register(defines.events.on_player_joined_game,function(event) - local player = Game.get_player(event) - Gui.center.open(player,'server-info') -end) - return Sync \ No newline at end of file diff --git a/modules/ExpGamingCore/Sync/lib/gui.lua b/modules/ExpGamingCore/Sync/lib/gui.lua new file mode 100644 index 00000000..8a1c5771 --- /dev/null +++ b/modules/ExpGamingCore/Sync/lib/gui.lua @@ -0,0 +1,93 @@ +--- Description - A small description that will be displayed on the doc +-- @submodule ExpGamingCore.Sync +-- @alias Sync +-- @author Cooldude2606 +-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE + +-- this file will be loaded when ExpGamingCore/Gui is present + +local Sync_gui_functions = {} + +--- Adds a emeltent to the sever info gui +-- @usage Sync.add_to_gui('string') -- return true +-- @param element see examples before for what can be used, it can also be a return from Gui.inputs.add +-- @treturn bolean based on weather it was successful or not +function Sync.add_to_gui(element,...) + if game then return false end + if is_type(element,'function') then + table.insert(Sync_gui_functions,{'function',element,...}) + elseif is_type(element,'table') then + if element.draw then table.insert(Sync_gui_functions,{'gui',element}) + else table.insert(Sync_gui_functions,{'table',element}) end + else table.insert(Sync_gui_functions,{'string',element}) end + return true +end + +Sync.add_to_gui('Welcome to the Explosive Gaming comunity! This is one of many servers which we host.') +Sync.add_to_gui(function(player,frame) return 'This server will reset at: '..Sync.info.reset_time end) + +--- Formats a lable to be a certain format +-- @local label_format +local function label_format(label,width) + label.style.width = width + label.style.align = 'center' + label.style.single_line = false +end + +--- Creates a center gui that will appear on join +-- @local call to Gui.Center +Gui.center.add{ + name='server-info', + caption='Server Info', + tooltip='Basic info about the current server', + draw=function(self,frame) + frame.caption = '' + local info = Sync.info + local frame = frame.add{type='flow',direction='vertical'} + local _flow = frame.add{type='flow'} + Gui.bar(_flow,200) + label_format(_flow.add{ + type='label', + caption='Welcome To '..info.server_name, + style='caption_label' + },180) + Gui.bar(_flow,200) + label_format(frame.add{ + type='label', + caption=info.server_description,style='description_label' + },600) + Gui.bar(frame,600) + local _frame = frame + local frame = frame.add{ + type='frame', + direction='vertical', + style='image_frame' + } + frame.style.width = 600 + local text_flow = frame.add{type='flow',direction='vertical'} + local button_flow = frame.add{type='table',column_count=3} + for _,element in pairs(table.deepcopy(Sync_gui_functions)) do + local _type = table.remove(element,1) + if _type == 'function' then + local success, err = pcall(table.remove(element,1),frame.player_index,frame,unpack(element)) + if not success then error(err) else + if is_type(err,'table') then + if element.draw then element:draw(button_flow).style.width = 195 + else label_format(text_flow.add{type='label',caption=err},585) end + else label_format(text_flow.add{type='label',caption=tostring(err)},585) end + end + elseif _type == 'gui' then element[1]:draw(button_flow).style.width = 195 + elseif _type == 'string' then label_format(text_flow.add{type='label',caption=tostring(element[1])},585) + elseif _type == 'table' then label_format(text_flow.add{type='label',caption=element[1]},585) end + end + _frame.add{ + type='label', + caption='Press Ecs or E to close; this is only visible once!', + style='fake_disabled_label' + }.style.font='default-small' +end} + +script.on_event(defines.events.on_player_joined_game,function(event) + local player = Game.get_player(event) + Gui.center.open(player,'server-info') +end) \ No newline at end of file diff --git a/modules/ExpGamingCore/Sync/lib/ranking.lua b/modules/ExpGamingCore/Sync/lib/ranking.lua new file mode 100644 index 00000000..81e671da --- /dev/null +++ b/modules/ExpGamingCore/Sync/lib/ranking.lua @@ -0,0 +1,39 @@ +--- Description - A small description that will be displayed on the doc +-- @submodule ExpGamingCore.Sync +-- @alias Sync +-- @author Cooldude2606 +-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE + +-- this file will be loaded when ExpGamingCore/Ranking is present + +--- Used as a redirect to Ranking._base_preset that will set the rank given to a player apon joining +-- @usage Sync.set_ranks{player_name=rank_name,...} +-- @see Ranking._base_preset +function Sync.set_ranks(...) + Ranking._base_preset(...) +end + +--- Used to get the number of players in each rank and currently online +-- @usage Sync.count_ranks() +-- @treturn table contains the ranks and the players in that rank +function Sync.count_ranks() + if not game then return {'Offline'} end + if not Ranking then return {'Ranking module not installed'} end + local _ranks = {} + for power,rank in pairs(Ranking._ranks()) do + local players = rank:get_players() + for k,player in pairs(players) do players[k] = player.name end + local online = rank:get_players(true) + for k,player in pairs(online) do online[k] = player.name end + _ranks[rank.name] = {players=players,online=online,n_players=#players,n_online=#online} + end + return _ranks +end + +--- Adds a caption to the info gui that shows the rank given to the player +-- @local callback for Sync.add_to_gui +if Sync.add_to_gui then + Sync.add_to_gui(function(player,frame) + return 'You have been assigned the rank \''..Ranking.get_rank(player).name..'\'' + end) +end \ No newline at end of file diff --git a/modules/ExpGamingCore/softmod.json b/modules/ExpGamingCore/softmod.json index 70f629b5..2515b2d7 100644 --- a/modules/ExpGamingCore/softmod.json +++ b/modules/ExpGamingCore/softmod.json @@ -65,11 +65,14 @@ "location": "url", "dependencies": { "ExpGamingLib": ">=3.0.0", - "Ranking": "?>=3.0.0" + "FactorioStdLib.Color": ">=0.8.0", + "FactorioStdLib.Table": ">=0.8.0", + "ExpGamingCore.Ranking": "?>=3.0.0", + "ExpGamingCore.Gui": "?>=3.0.0" } } }, "author": "Cooldude2606", "contact": "Discord: Cooldude2606#5241", - "license": "https://github.com/badgamernl/explosivegaming-main/blob/master/LICENSE" + "license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE" } \ No newline at end of file diff --git a/modules/ExpGamingLib/control.lua b/modules/ExpGamingLib/control.lua index 3cd59332..103d49b5 100644 --- a/modules/ExpGamingLib/control.lua +++ b/modules/ExpGamingLib/control.lua @@ -45,6 +45,23 @@ function ExpLib.get_env() return env end +--- Creats a table that will act like a string and a function +-- @usage add_metatable({},function) -- returns table +-- @tparam table tbl the table that will have its metatable set +-- @tparam[opt=tostring] function callback the function that will be used for the call +-- @tparam[opt=table.tostring] ?function|string string a function that resolves to a string or a string +-- @treturn table the new table with its metatable set +function ExpLib.add_metatable(tbl,callback,string) + if not ExpLib.is_type(tbl,'table') then error('No table given to add_metatable',2) end + local callback = ExpLib.is_type(callback,'function') and callback or tostring + local string = ExpLib.is_type(string,'function') and string or ExpLib.is_type(string,'string') and function() return string end or table.tostring + return setmetatable(tbl,{ + __tostring=string, + __concat=function(val1,val2) return type(val1) == 'string' and val1..string() or string()..val2 end, + __call=callback + }) +end + --- Compear types faster for faster valadation of prams -- @usage is_type('foo','string') -- return true -- @usage is_type('foo') -- return false diff --git a/modules/ExpGamingLib/softmod.json b/modules/ExpGamingLib/softmod.json index 0f433a9f..d247df06 100644 --- a/modules/ExpGamingLib/softmod.json +++ b/modules/ExpGamingLib/softmod.json @@ -12,6 +12,6 @@ }, "author": "Cooldude2606", "contact": "Discord: Cooldude2606#5241", - "license": "https://github.com/badgamernl/explosivegaming-main/blob/master/LICENSE" + "license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE" } \ No newline at end of file From 153c6af18fbe4756ee2b40320c5063d5264182c1 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Thu, 31 May 2018 00:45:42 +0100 Subject: [PATCH 014/231] Change to sync docs --- control.lua | 3 +- doc/index.html | 94 +-- doc/modules/ExpGamingCore.Sync.html | 705 ++++++++++++++++++ doc/modules/ExpGamingLib.html | 72 +- doc/modules/FSM.html | 27 +- doc/modules/StdLib.Color.html | 27 +- doc/modules/StdLib.Game.html | 27 +- doc/modules/StdLib.String.html | 27 +- doc/modules/StdLib.Table.html | 27 +- doc/modules/StdLib.Time.html | 27 +- doc/modules/StdLib.html | 143 ---- doc/modules/expcore.sync.html | 542 -------------- ...dules.expgamingcore.commands.control.html} | 35 +- ...=> modules.expgamingcore.gui.control.html} | 29 +- ...es.expgamingcore.gui.guiparts.center.html} | 29 +- ...es.expgamingcore.gui.guiparts.inputs.html} | 29 +- ...ules.expgamingcore.gui.guiparts.left.html} | 29 +- ...les.expgamingcore.gui.guiparts.popup.html} | 29 +- ...s.expgamingcore.gui.guiparts.toolbar.html} | 29 +- ...odules.expgamingcore.ranking.control.html} | 29 +- ...modules.expgamingcore.server.control.html} | 29 +- doc/modules/modules.factoriostdlib.color.html | 567 -------------- doc/scripts/control.lua.html | 85 --- doc/scripts/index.lua.html | 85 --- modules/ExpGamingCore/Sync/control.lua | 32 +- modules/ExpGamingCore/Sync/lib/gui.lua | 5 +- modules/ExpGamingCore/Sync/lib/ranking.lua | 9 +- modules/FactorioModGui/control.lua | 4 +- modules/index.lua | 1 + 29 files changed, 1007 insertions(+), 1769 deletions(-) create mode 100644 doc/modules/ExpGamingCore.Sync.html delete mode 100644 doc/modules/StdLib.html delete mode 100644 doc/modules/expcore.sync.html rename doc/modules/{expcore.commands.html => modules.expgamingcore.commands.control.html} (65%) rename doc/modules/{expcore.gui.html => modules.expgamingcore.gui.control.html} (76%) rename doc/modules/{expcore.guiparts.center.html => modules.expgamingcore.gui.guiparts.center.html} (85%) rename doc/modules/{expcore.guiparts.inputs.html => modules.expgamingcore.gui.guiparts.inputs.html} (91%) rename doc/modules/{expcore.guiparts.left.html => modules.expgamingcore.gui.guiparts.left.html} (78%) rename doc/modules/{expcore.guiparts.popup.html => modules.expgamingcore.gui.guiparts.popup.html} (71%) rename doc/modules/{expcore.guiparts.toolbar.html => modules.expgamingcore.gui.guiparts.toolbar.html} (67%) rename doc/modules/{expcore.ranking.html => modules.expgamingcore.ranking.control.html} (88%) rename doc/modules/{expcore.server.html => modules.expgamingcore.server.control.html} (92%) delete mode 100644 doc/modules/modules.factoriostdlib.color.html delete mode 100644 doc/scripts/control.lua.html delete mode 100644 doc/scripts/index.lua.html diff --git a/control.lua b/control.lua index 9aba66bc..ba0f4c33 100644 --- a/control.lua +++ b/control.lua @@ -1,3 +1,4 @@ +-- not_luadoc=true --- Root Script File -- @script control.lua function _log(...) log(...) end @@ -16,7 +17,7 @@ Manager.setVerbose{ 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 + eventRegistered=false, -- 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 } diff --git a/doc/index.html b/doc/index.html index d797fba0..7dbc8d4a 100644 --- a/doc/index.html +++ b/doc/index.html @@ -31,17 +31,17 @@

    Modules

    -

    Scripts

    - @@ -64,48 +59,48 @@

    Modules

    - - + + - - - - - - - - - - - - - - - - - + - + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - + + @@ -132,23 +127,12 @@
    expcore.guiparts.centerAdds a new obj to the center guiFSMFactorio Softmod Manager
    expcore.guiparts.inputsSets the input to trigger on an certain event
    expcore.guiparts.leftUsed to add a left gui frame
    expcore.guiparts.popupUsed to add a popup gui style
    expcore.guiparts.toolbarAdd a button to the toolbar, ranks need to be allowed to use these buttons if ranks is preset
    expcore.commandsmodules.expgamingcore.commands.control Uses a commands data to return the inputs as a string
    expcore.guimodules.expgamingcore.gui.guiparts.centerAdds a new obj to the center gui
    modules.expgamingcore.gui.guiparts.inputsSets the input to trigger on an certain event
    modules.expgamingcore.gui.guiparts.leftUsed to add a left gui frame
    modules.expgamingcore.gui.guiparts.popupUsed to add a popup gui style
    modules.expgamingcore.gui.guiparts.toolbarAdd a button to the toolbar, ranks need to be allowed to use these buttons if ranks is preset
    modules.expgamingcore.gui.control Add a white bar to any gui frame
    expcore.rankingmodules.expgamingcore.ranking.control Returns a rank object given a player or rank name
    expcore.servermodules.expgamingcore.server.control Returns a un-used uuid (better system needed)
    expcore.syncUsed as a faster way to get to the ranking function, overrides previous
    FSMFactorio Softmod ManagerExpGamingCore.SyncDescription - A small description that will be displayed on the doc
    ExpGamingLibA defines module for retrieving the number of ticks in 1 unit of time.
    -

    Scripts

    - - - - - - - - - -
    control.luaRoot Script File
    index.luaUsed to index the files to be loaded
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/ExpGamingCore.Sync.html b/doc/modules/ExpGamingCore.Sync.html new file mode 100644 index 00000000..7f2b0843 --- /dev/null +++ b/doc/modules/ExpGamingCore.Sync.html @@ -0,0 +1,705 @@ + + + + + Reference + + + + +
    + +
    + +
    +
    +
    + + +
    + + + + + + +
    + +

    Module ExpGamingCore.Sync

    +

    Description - A small description that will be displayed on the doc

    +

    +

    Info:

    +
      +
    • License: https://github.com/explosivegaming/scenario/blob/master/LICENSE
    • +
    • Author: Cooldude2606
    • +
    + + +

    Functions

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    tick_format (tick)Used to standidise the tick format for any sync info
    print (player_message, player_name[, player_tag[, player_colour[, prefix]]])Prints to chat as if it were a player
    emit_embeded (args)Logs an embed to the json.data we use a js script to add things we cant here
    count_admins ()Used to get the number of admins currently online
    count_afk ([time=7200])Used to get the number of afk players defined by 2 min by default
    count_ranks ()Used to get the number of players in each rank and currently online; if ExpGamingCore/Ranking is present then it will give more than admin and user
    count_players (online)Used to get a list of every player name with the option to limit to only online players
    count_player_times ()Used to get a list of every player name with the amount of time they have played for
    update ()Called to update values inside of the info
    add_update (key, callback)Adds a callback to be called when the info is updated
    emit_data ()Outputs the curent server info into a file
    +

    Tables

    + + + + + +
    EmitEmbededParamatersOutline of the paramaters accepted by Sync.emit_embeded
    +

    Fields

    + + + + + + + + + +
    infoused to get the global list that has been defined, also used to set that list
    timeUsed to return and set the current IRL time; not very good need a better way to do this
    +

    modules.expgamingcore.sync.lib.gui Functions

    + + + + + + + + + +
    _comment ()This file will be loaded when ExpGamingCore/Gui is present
    add_to_gui (element)Adds a emeltent to the sever info gui
    +

    modules.expgamingcore.sync.lib.ranking Functions

    + + + + + + + + + + + + + +
    _comment ()This file will be loaded when ExpGamingCore/Ranking is present
    set_ranks (...)Used as a redirect to Ranking._base_preset that will set the rank given to a player apon joining
    count_ranks ()Used to get the number of players in each rank and currently online
    + +
    +
    + + +

    Functions

    + +
    +
    + + tick_format (tick) +
    +
    + Used to standidise the tick format for any sync info + + +

    Parameters:

    +
      +
    • tick + +
    • +
    + +

    Returns:

    +
      + + {number,string} + table containg both the raw number and clean version of a time +
    + + + +

    Usage:

    +
      +
      Sync.tick_format(60) -- return {60,'1.00M'}
      +
    + +
    +
    + + print (player_message, player_name[, player_tag[, player_colour[, prefix]]]) +
    +
    + Prints to chat as if it were a player + + +

    Parameters:

    +
      +
    • player_message + string + the message to be printed in chat +
    • +
    • player_name + string + the name of the player sending the message +
    • +
    • player_tag + string + the tag apllied to the player's name + (optional) +
    • +
    • player_colour + string + the colour of the message, either hex or named colour + (optional) +
    • +
    • prefix + string + add a prefix before the chat eg [IRC] + (optional) +
    • +
    + + + + +

    Usage:

    +
      +
      Sync.print('Test','Cooldude2606')
      +
    + +
    +
    + + emit_embeded (args) +
    +
    + Logs an embed to the json.data we use a js script to add things we cant here + + +

    Parameters:

    +
      +
    • args + table + a table which contains everything that the embeded will use +
    • +
    + + + +

    See also:

    + + +

    Usage:

    +
      +
      Sync.emit_embeded{title='BAN',color='0x0',description='A player was banned' ... }
      +
    + +
    +
    + + count_admins () +
    +
    + Used to get the number of admins currently online + + + +

    Returns:

    +
      + + number + the number of admins online +
    + + + +

    Usage:

    +
      +
      Sync.count_admins() -- returns number
      +
    + +
    +
    + + count_afk ([time=7200]) +
    +
    + Used to get the number of afk players defined by 2 min by default + + +

    Parameters:

    +
      +
    • time + int + in ticks that a player is called afk + (default 7200) +
    • +
    + +

    Returns:

    +
      + + number + the number of afk players +
    + + + +

    Usage:

    +
      +
      Sync.count_afk()
      +
    + +
    +
    + + count_ranks () +
    +
    + Used to get the number of players in each rank and currently online; if ExpGamingCore/Ranking is present then it will give more than admin and user + + + +

    Returns:

    +
      + + table + contains the ranks and the players in that rank +
    + + + +

    Usage:

    +
      +
      Sync.count_ranks()
      +
    + +
    +
    + + count_players (online) +
    +
    + Used to get a list of every player name with the option to limit to only online players + + +

    Parameters:

    +
      +
    • online + boolean + true will get only the online players +
    • +
    + +

    Returns:

    +
      + + table + table of player names +
    + + + +

    Usage:

    +
      +
      Sync.count_players()
      +
    + +
    +
    + + count_player_times () +
    +
    + Used to get a list of every player name with the amount of time they have played for + + + +

    Returns:

    +
      + + table + table indexed by player name, each value contains the raw tick and then the clean string +
    + + + +

    Usage:

    +
      +
      Sync.count_player_times()
      +
    + +
    +
    + + update () +
    +
    + Called to update values inside of the info + + + +

    Returns:

    +
      + + all of the new info +
    + + + +

    Usage:

    +
      +
      Sync.update()
      +
    + +
    +
    + + add_update (key, callback) +
    +
    + Adds a callback to be called when the info is updated + + +

    Parameters:

    +
      +
    • key + string + the key that the value will be stored in +
    • +
    • callback + function + the function which will return this value +
    • +
    + + + + +

    Usage:

    +
      +
      Sync.add_update('players',function() return #game.players end)
      +
    + +
    +
    + + emit_data () +
    +
    + Outputs the curent server info into a file + + + + + + +

    Usage:

    +
      +
      Sync.emit_data()
      +
    + +
    +
    +

    Tables

    + +
    +
    + + EmitEmbededParamaters +
    +
    + Outline of the paramaters accepted by Sync.emit_embeded + + +

    Fields:

    +
      +
    • title + the tile of the embed +
    • +
    • color + the color given in hex you can use Color.to_hex{r=0,g=0,b=0} +
    • +
    • description + the description of the embed +
    • +
    • server_detail + sting to add onto the pre-set server detail +
    • +
    • fieldone + the filed to add to the embed (key is name) (value is text) (start value with <<inline>> to make inline) +
    • +
    • fieldtwo + the filed to add to the embed (key is name) (value is text) (start value with <<inline>> to make inline) +
    • +
    + + + + + +
    +
    +

    Fields

    + +
    +
    + + info +
    +
    + used to get the global list that has been defined, also used to set that list + + +
      +
    • set + table + keys to be replaced in the server info + (default nil) +
    • +
    + + + + +

    Usage:

    +
      +
    • Sync.info{server_name='Factorio Server 2'} -- returns true
    • +
    • Sync.info -- table of info
    • +
    + +
    +
    + + time +
    +
    + Used to return and set the current IRL time; not very good need a better way to do this + + +
      +
    • set + string + the date time to be set + (default nil) +
    • +
    + + + + +

    Usage:

    +
      +
    • Sync.time('Sun Apr  1 18:44:30 UTC 2018')
    • +
    • Sync.time -- string
    • +
    + +
    +
    +

    modules.expgamingcore.sync.lib.gui Functions

    + +
    +
    + + _comment () +
    +
    + This file will be loaded when ExpGamingCore/Gui is present + + + + + + + +
    +
    + + add_to_gui (element) +
    +
    + Adds a emeltent to the sever info gui + + +

    Parameters:

    +
      +
    • element + see examples before for what can be used, it can also be a return from Gui.inputs.add +
    • +
    + +

    Returns:

    +
      + + bolean + based on weather it was successful or not +
    + + + +

    Usage:

    +
      +
      Sync.add_to_gui('string') -- return true
      +
    + +
    +
    +

    modules.expgamingcore.sync.lib.ranking Functions

    + +
    +
    + + _comment () +
    +
    + This file will be loaded when ExpGamingCore/Ranking is present + + + + + + + +
    +
    + + set_ranks (...) +
    +
    + Used as a redirect to Ranking._base_preset that will set the rank given to a player apon joining + + +

    Parameters:

    +
      +
    • ... + +
    • +
    + + + + +

    Usage:

    +
      +
      Sync.set_ranks{player_name=rank_name,...}
      +
    + +
    +
    + + count_ranks () +
    +
    + Used to get the number of players in each rank and currently online + + + +

    Returns:

    +
      + + table + contains the ranks and the players in that rank +
    + + + +

    Usage:

    +
      +
      Sync.count_ranks()
      +
    + +
    +
    + + +
    +
    +
    +generated by LDoc 1.4.6 +Last updated 2018-05-31 00:41:31 +
    +
    + + diff --git a/doc/modules/ExpGamingLib.html b/doc/modules/ExpGamingLib.html index dc02f790..7a44bc2e 100644 --- a/doc/modules/ExpGamingLib.html +++ b/doc/modules/ExpGamingLib.html @@ -38,17 +38,17 @@

    Modules

    -

    Scripts

    - @@ -86,6 +81,10 @@ Used to get the current ENV with all _G keys removed; useful when saving function to global + add_metatable (tbl[, callback=tostring[, string=table.tostring]]) + Creats a table that will act like a string and a function + + is_type (v[, test_type=nil]) Compear types faster for faster valadation of prams @@ -166,6 +165,47 @@
    get_env() returns current ENV with _G keys removed
    +
    +
    + + add_metatable (tbl[, callback=tostring[, string=table.tostring]]) +
    +
    + Creats a table that will act like a string and a function + + +

    Parameters:

    +
      +
    • tbl + table + the table that will have its metatable set +
    • +
    • callback + function + the function that will be used for the call + (default tostring) +
    • +
    • string + function or string + a function that resolves to a string or a string + (default table.tostring) +
    • +
    + +

    Returns:

    +
      + + table + the new table with its metatable set +
    + + + +

    Usage:

    +
      +
      add_metatable({},function) -- returns table
      +
    +
    @@ -371,7 +411,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/FSM.html b/doc/modules/FSM.html index 99d6ba47..6db19fc5 100644 --- a/doc/modules/FSM.html +++ b/doc/modules/FSM.html @@ -39,17 +39,17 @@

    Modules

    -

    Scripts

    - @@ -412,7 +407,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/StdLib.Color.html b/doc/modules/StdLib.Color.html index 8c8b4bf1..7cc11d31 100644 --- a/doc/modules/StdLib.Color.html +++ b/doc/modules/StdLib.Color.html @@ -39,17 +39,17 @@

    Modules

    -

    Scripts

    - @@ -558,7 +553,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/StdLib.Game.html b/doc/modules/StdLib.Game.html index 9e35cbfb..5b4f4488 100644 --- a/doc/modules/StdLib.Game.html +++ b/doc/modules/StdLib.Game.html @@ -38,17 +38,17 @@

    Modules

    -

    Scripts

    - @@ -219,7 +214,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/StdLib.String.html b/doc/modules/StdLib.String.html index d0253f49..4d2128bc 100644 --- a/doc/modules/StdLib.String.html +++ b/doc/modules/StdLib.String.html @@ -38,17 +38,17 @@

    Modules

    -

    Scripts

    - @@ -299,7 +294,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/StdLib.Table.html b/doc/modules/StdLib.Table.html index 84b9f1db..d2a41200 100644 --- a/doc/modules/StdLib.Table.html +++ b/doc/modules/StdLib.Table.html @@ -38,17 +38,17 @@

    Modules

    -

    Scripts

    - @@ -1128,7 +1123,7 @@ some_func(1,2)
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/StdLib.Time.html b/doc/modules/StdLib.Time.html index f0352349..b42b0935 100644 --- a/doc/modules/StdLib.Time.html +++ b/doc/modules/StdLib.Time.html @@ -38,17 +38,17 @@

    Modules

    -

    Scripts

    - @@ -136,7 +131,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/StdLib.html b/doc/modules/StdLib.html deleted file mode 100644 index 014bd5c6..00000000 --- a/doc/modules/StdLib.html +++ /dev/null @@ -1,143 +0,0 @@ - - - - - Reference - - - - -
    - -
    - -
    -
    -
    - - -
    - - - - - - -
    - -

    Module StdLib

    -

    A defines module for retrieving the number of ticks in 1 unit of time.

    -

    - Extends the Factorio defines table.

    - - -

    Tables

    - - - - - -
    defines.timeReturns the number of ticks in a second, minute, hour, day, week, month, or year.
    - -
    -
    - - -

    Tables

    - -
    -
    - - defines.time -
    -
    - Returns the number of ticks in a second, minute, hour, day, week, month, or year. - - -

    Fields:

    -
      -
    • second - the number of Factorio ticks in a second -
    • -
    • minute - the number of Factorio ticks in a second -
    • -
    • hour - the number of Factorio ticks in an hour -
    • -
    • day - the number of Factorio ticks in an day -
    • -
    • week - the number of Factorio ticks in a week -
    • -
    • month - the number of Factorio ticks in a month (30 days) -
    • -
    • year - the number of Factorio ticks in a year (365 days) -
    • -
    - - - - -

    Usage:

    -
      -
      local ten_seconds = defines.time.second * 10
      -
    - -
    -
    - - -
    -
    -
    -generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:33 -
    -
    - - diff --git a/doc/modules/expcore.sync.html b/doc/modules/expcore.sync.html deleted file mode 100644 index f931601a..00000000 --- a/doc/modules/expcore.sync.html +++ /dev/null @@ -1,542 +0,0 @@ - - - - - Reference - - - - -
    - -
    - -
    -
    -
    - - -
    - - - - - - -
    - -

    Module expcore.sync

    -

    Used as a faster way to get to the ranking function, overrides previous

    -

    -

    Usage:

    -
      -
      Sync.set_ranks{name=rank_name}
      -
      -
    - - -

    Functions

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Sync.tick_format (tick)Used to standidise the tick format for any sync info
    Sync.print (player_message, player_name[, player_tag[, player_colour[, prefix]]])Prints to chat as if it were a player
    Sync.emit_embeded (args)Logs an embed to the json.data we use a js script to add things we cant here
    Sync.count_admins ()used to get the number of admins currently online
    Sync.count_afk ([time=7200])used to get the number of afk players defined by 2 min by default
    Sync.count_ranks ()used to get the number of players in each rank and currently online
    Sync.count_players (online)used to get the number of players either online or all
    Sync.count_player_times ()used to get the number of players resulting in there play times
    Sync.info ([set=nil])used to return the global list and set values in it
    Sync.time ([set=nil])used to return the global time and set its value
    Sync.update ()called to update values inside of the info
    Sync.add_update (key, callback)Adds a callback to be called when the info is updated
    Sync.emit_data ()outputs the curent server info into a file
    Sync.add_to_gui (element)Adds a emeltent to the sever info gui
    - -
    -
    - - -

    Functions

    - -
    -
    - - Sync.tick_format (tick) -
    -
    - Used to standidise the tick format for any sync info - - -

    Parameters:

    -
      -
    • tick - -
    • -
    - - - - -

    Usage:

    -
      -
      Sync.tick_format(60) -- return {60,'1.00M'}
      -
    - -
    -
    - - Sync.print (player_message, player_name[, player_tag[, player_colour[, prefix]]]) -
    -
    - Prints to chat as if it were a player - - -

    Parameters:

    -
      -
    • player_message - the message to be printed in chat -
    • -
    • player_name - the name of the player sending the message -
    • -
    • player_tag - the tag apllied to the player's name - (optional) -
    • -
    • player_colour - the colour of the message - (optional) -
    • -
    • prefix - add a prefix before the chat eg [IRC] - (optional) -
    • -
    - - - - -

    Usage:

    -
      -
      Sync.print('Test','Cooldude2606')
      -
    - -
    -
    - - Sync.emit_embeded (args) -
    -
    - Logs an embed to the json.data we use a js script to add things we cant here - - -

    Parameters:

    -
      -
    • args - table - a table which contains everything that the embeded will use -
    • -
    - - - - -

    Usage:

    -
      -
      Sync.emit_embeded{title='BAN',color='0x0',description='A player was banned' ... }
      -
    - -
    -
    - - Sync.count_admins () -
    -
    - used to get the number of admins currently online - - - -

    Returns:

    -
      - - int - the number of admins online -
    - - - -

    Usage:

    -
      -
      Sync.count_admins()
      -
    - -
    -
    - - Sync.count_afk ([time=7200]) -
    -
    - used to get the number of afk players defined by 2 min by default - - -

    Parameters:

    -
      -
    • time - int - in ticks that a player is called afk - (default 7200) -
    • -
    - -

    Returns:

    -
      - - int - the number of afk players -
    - - - -

    Usage:

    -
      -
      Sync.count_afk()
      -
    - -
    -
    - - Sync.count_ranks () -
    -
    - used to get the number of players in each rank and currently online - - - -

    Returns:

    -
      - - table - contains the ranks and the players in that rank -
    - - - -

    Usage:

    -
      -
      Sync.count_ranks()
      -
    - -
    -
    - - Sync.count_players (online) -
    -
    - used to get the number of players either online or all - - -

    Parameters:

    -
      -
    • online - bolean - if true only get online players -
    • -
    - -

    Returns:

    -
      - - table - contains player names -
    - - - -

    Usage:

    -
      -
      Sync.count_players()
      -
    - -
    -
    - - Sync.count_player_times () -
    -
    - used to get the number of players resulting in there play times - - - -

    Returns:

    -
      - - table - contains players and each player is given a tick amount and a formated string -
    - - - -

    Usage:

    -
      -
      Sync.count_player_times()
      -
    - -
    -
    - - Sync.info ([set=nil]) -
    -
    - used to return the global list and set values in it - - -

    Parameters:

    -
      -
    • set - table - keys to be replaced in the server info - (default nil) -
    • -
    - -

    Returns:

    -
      - - either returns success when setting or the info when not setting -
    - - - -

    Usage:

    -
      -
      Sync.info{server_name='Factorio Server 2'}
      -
    - -
    -
    - - Sync.time ([set=nil]) -
    -
    - used to return the global time and set its value - - -

    Parameters:

    -
      -
    • set - string - the date time to be set - (default nil) -
    • -
    - -

    Returns:

    -
      - - either true false if setting or the date time and tick off set -
    - - - -

    Usage:

    -
      -
      Sync.time('Sun Apr  1 18:44:30 UTC 2018')
      -
    - -
    -
    - - Sync.update () -
    -
    - called to update values inside of the info - - - -

    Returns:

    -
      - - all of the new info -
    - - - -

    Usage:

    -
      -
      Sync.update()
      -
    - -
    -
    - - Sync.add_update (key, callback) -
    -
    - Adds a callback to be called when the info is updated - - -

    Parameters:

    -
      -
    • key - string - the key that the value will be stored in -
    • -
    • callback - function - the function which will return this value -
    • -
    - - - - -

    Usage:

    -
      -
      Sync.add_update('players',function() return #game.players end)
      -
    - -
    -
    - - Sync.emit_data () -
    -
    - outputs the curent server info into a file - - - - - - -

    Usage:

    -
      -
      Sync.emit_data()
      -
    - -
    -
    - - Sync.add_to_gui (element) -
    -
    - Adds a emeltent to the sever info gui - - -

    Parameters:

    -
      -
    • element - see examples before for what can be used, it can also be a return from Gui.inputs.add -
    • -
    - -

    Returns:

    -
      - - bolean - based on weather it was successful or not -
    - - - -

    Usage:

    -
      -
      Sync.add_to_gui('string') -- return trues
      -
    - -
    -
    - - -
    -
    -
    -generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 -
    -
    - - diff --git a/doc/modules/expcore.commands.html b/doc/modules/modules.expgamingcore.commands.control.html similarity index 65% rename from doc/modules/expcore.commands.html rename to doc/modules/modules.expgamingcore.commands.control.html index 1d31df15..f3323613 100644 --- a/doc/modules/expcore.commands.html +++ b/doc/modules/modules.expgamingcore.commands.control.html @@ -38,17 +38,17 @@

    Modules

    -

    Scripts

    -
    -

    Module expcore.commands

    +

    Module modules.expgamingcore.commands.control

    Uses a commands data to return the inputs as a string

    Usage:

    @@ -80,7 +75,7 @@

    Functions

    - +
    get_commands (player)commands.get_commands (player) Used to return all the commands a player can use
    @@ -93,8 +88,8 @@
    - - get_commands (player) + + commands.get_commands (player)
    Used to return all the commands a player can use @@ -129,7 +124,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/expcore.gui.html b/doc/modules/modules.expgamingcore.gui.control.html similarity index 76% rename from doc/modules/expcore.gui.html rename to doc/modules/modules.expgamingcore.gui.control.html index 79e8f946..4f951cc4 100644 --- a/doc/modules/expcore.gui.html +++ b/doc/modules/modules.expgamingcore.gui.control.html @@ -38,17 +38,17 @@

    Modules

    -

    Scripts

    -
    -

    Module expcore.gui

    +

    Module modules.expgamingcore.gui.control

    Add a white bar to any gui frame

    Usage:

    @@ -165,7 +160,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/expcore.guiparts.center.html b/doc/modules/modules.expgamingcore.gui.guiparts.center.html similarity index 85% rename from doc/modules/expcore.guiparts.center.html rename to doc/modules/modules.expgamingcore.gui.guiparts.center.html index d9f8dd00..7dd28f1a 100644 --- a/doc/modules/expcore.guiparts.center.html +++ b/doc/modules/modules.expgamingcore.gui.guiparts.center.html @@ -38,17 +38,17 @@

    Modules

    -

    Scripts

    -
    -

    Module expcore.guiparts.center

    +

    Module modules.expgamingcore.gui.guiparts.center

    Adds a new obj to the center gui

    Usage:

    @@ -283,7 +278,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/expcore.guiparts.inputs.html b/doc/modules/modules.expgamingcore.gui.guiparts.inputs.html similarity index 91% rename from doc/modules/expcore.guiparts.inputs.html rename to doc/modules/modules.expgamingcore.gui.guiparts.inputs.html index 40cfab8b..82977f9e 100644 --- a/doc/modules/expcore.guiparts.inputs.html +++ b/doc/modules/modules.expgamingcore.gui.guiparts.inputs.html @@ -38,17 +38,17 @@

    Modules

    -

    Scripts

    -
    -

    Module expcore.guiparts.inputs

    +

    Module modules.expgamingcore.gui.guiparts.inputs

    Sets the input to trigger on an certain event

    Usage:

    @@ -439,7 +434,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/expcore.guiparts.left.html b/doc/modules/modules.expgamingcore.gui.guiparts.left.html similarity index 78% rename from doc/modules/expcore.guiparts.left.html rename to doc/modules/modules.expgamingcore.gui.guiparts.left.html index f631247f..2d78fe94 100644 --- a/doc/modules/expcore.guiparts.left.html +++ b/doc/modules/modules.expgamingcore.gui.guiparts.left.html @@ -38,17 +38,17 @@

    Modules

    -

    Scripts

    -
    -

    Module expcore.guiparts.left

    +

    Module modules.expgamingcore.gui.guiparts.left

    Used to add a left gui frame

    Usage:

    @@ -186,7 +181,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/expcore.guiparts.popup.html b/doc/modules/modules.expgamingcore.gui.guiparts.popup.html similarity index 71% rename from doc/modules/expcore.guiparts.popup.html rename to doc/modules/modules.expgamingcore.gui.guiparts.popup.html index 5cd26f05..6309f7b2 100644 --- a/doc/modules/expcore.guiparts.popup.html +++ b/doc/modules/modules.expgamingcore.gui.guiparts.popup.html @@ -38,17 +38,17 @@

    Modules

    -

    Scripts

    -
    -

    Module expcore.guiparts.popup

    +

    Module modules.expgamingcore.gui.guiparts.popup

    Used to add a popup gui style

    Usage:

    @@ -131,7 +126,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/expcore.guiparts.toolbar.html b/doc/modules/modules.expgamingcore.gui.guiparts.toolbar.html similarity index 67% rename from doc/modules/expcore.guiparts.toolbar.html rename to doc/modules/modules.expgamingcore.gui.guiparts.toolbar.html index 58bb65e6..483c4c9f 100644 --- a/doc/modules/expcore.guiparts.toolbar.html +++ b/doc/modules/modules.expgamingcore.gui.guiparts.toolbar.html @@ -38,17 +38,17 @@

    Modules

    -

    Scripts

    -
    -

    Module expcore.guiparts.toolbar

    +

    Module modules.expgamingcore.gui.guiparts.toolbar

    Add a button to the toolbar, ranks need to be allowed to use these buttons if ranks is preset

    Usage:

    @@ -122,7 +117,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/expcore.ranking.html b/doc/modules/modules.expgamingcore.ranking.control.html similarity index 88% rename from doc/modules/expcore.ranking.html rename to doc/modules/modules.expgamingcore.ranking.control.html index b5a57000..690fa714 100644 --- a/doc/modules/expcore.ranking.html +++ b/doc/modules/modules.expgamingcore.ranking.control.html @@ -38,17 +38,17 @@

    Modules

    -

    Scripts

    -
    -

    Module expcore.ranking

    +

    Module modules.expgamingcore.ranking.control

    Returns a rank object given a player or rank name

    Usage:

    @@ -379,7 +374,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/expcore.server.html b/doc/modules/modules.expgamingcore.server.control.html similarity index 92% rename from doc/modules/expcore.server.html rename to doc/modules/modules.expgamingcore.server.control.html index 688c54bd..603165ee 100644 --- a/doc/modules/expcore.server.html +++ b/doc/modules/modules.expgamingcore.server.control.html @@ -38,17 +38,17 @@

    Modules

    -

    Scripts

    -
    -

    Module expcore.server

    +

    Module modules.expgamingcore.server.control

    Returns a un-used uuid (better system needed)

    Usage:

    @@ -564,7 +559,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 +Last updated 2018-05-31 00:41:31
    diff --git a/doc/modules/modules.factoriostdlib.color.html b/doc/modules/modules.factoriostdlib.color.html deleted file mode 100644 index 43b661cf..00000000 --- a/doc/modules/modules.factoriostdlib.color.html +++ /dev/null @@ -1,567 +0,0 @@ - - - - - Reference - - - - -
    - -
    - -
    -
    -
    - - -
    - - - - - - -
    - -

    Module modules.factoriostdlib.color

    -

    A defines module for retrieving colors by name.

    -

    - Extends the Factorio defines table.

    -

    Usage:

    -
      -
      require('stdlib/defines/color')
      -
      -
    - - -

    Functions

    - - - - - - - - - - - - - - - - - - - - - - - - - -
    Color.set ([color=white[, alpha=1]])Set a value for the alpha channel in the given color table.
    Color.to_table (c_arr)Converts a color in the array format to a color in the table format.
    Color.from_rgb ([r=0[, g=0[, b=0[, a=255]]]])Converts a color in the rgb format to a color table
    Color.from_hex (hex[, alpha=1])Get a color table with a hexadecimal string.
    Color.to_rgb (color)Converts a color in the color table format to rgb
    Color.to_hex (color)Converts a color in the color table format to hex
    -

    Tables

    - - - - - - - - - - - - - - - - - -
    defines.colorA table of colors allowing retrieval by color name.
    defines.anticolorReturns white for dark colors or black for lighter colors.
    defines.lightcolorReturns a lighter color of a named color
    defines.textcolorReturns a lighter color of a named color.
    - -
    -
    - - -

    Functions

    - -
    -
    - - Color.set ([color=white[, alpha=1]]) -
    -
    - Set a value for the alpha channel in the given color table. - `color.a` represents the alpha channel in the given color table. -
      -
    • If ***alpha*** is given, set `color.a` to it. -
    • If ***alpha*** is not given, and if the given color table does not have a value for `color.a`, set `color.a` to 1. -
    • If ***alpha*** is not given, and if the given color table already has a value for `color.a`, then leave `color.a` alone. -
    - - -

    Parameters:

    -
      -
    • color - defines.color or Concepts.Color - the color to configure - (default white) -
    • -
    • alpha - float - the alpha value (*[0 - 1]*) to set for the given color - (default 1) -
    • -
    - -

    Returns:

    -
      - - a - color table that has the specified value for the alpha channel -
    - - - - -
    -
    - - Color.to_table (c_arr) -
    -
    - Converts a color in the array format to a color in the table format. - - -

    Parameters:

    -
      -
    • c_arr - table - the color to convert -
    • -
    - -

    Returns:

    -
      - - a - converted color — { r = c\_arr[1], g = c\_arr[2], b = c\_arr[3], a = c\_arr[4] } -
    - - - - -
    -
    - - Color.from_rgb ([r=0[, g=0[, b=0[, a=255]]]]) -
    -
    - Converts a color in the rgb format to a color table - - -

    Parameters:

    -
      -
    • r - int - 0-255 red - (default 0) -
    • -
    • g - int - 0-255 green - (default 0) -
    • -
    • b - int - 0-255 blue - (default 0) -
    • -
    • a - int - 0-255 alpha - (default 255) -
    • -
    - -

    Returns:

    -
      - - Concepts.Color - -
    - - - - -
    -
    - - Color.from_hex (hex[, alpha=1]) -
    -
    - Get a color table with a hexadecimal string. - Optionally provide the value for the alpha channel. - - -

    Parameters:

    -
      -
    • hex - string - hexadecimal color string (#ffffff, not #fff) -
    • -
    • alpha - float - the alpha value to set; such that ***[ 0 ⋜ value ⋜ 1 ]*** - (default 1) -
    • -
    - -

    Returns:

    -
      - - a - color table with RGB converted from Hex and with alpha -
    - - - - -
    -
    - - Color.to_rgb (color) -
    -
    - Converts a color in the color table format to rgb - - -

    Parameters:

    -
      -
    • color - table - the color to convert -
    • -
    - -

    Returns:

    -
      - - table - the color as rgb -
    - - - - -
    -
    - - Color.to_hex (color) -
    -
    - Converts a color in the color table format to hex - - -

    Parameters:

    -
      -
    • color - table - the color to convert -
    • -
    - -

    Returns:

    -
      - - string - the color as hex -
    - - - - -
    -
    -

    Tables

    - -
    -
    - - defines.color -
    -
    - A table of colors allowing retrieval by color name. - - -

    Fields:

    -
      -
    • white - {r=1.00,g=1.00,b=1.00} -
    • -
    • black - {r=0.00,g=0.00,b=0.00} -
    • -
    • darkgrey - {r=0.25,g=0.25,b=0.25} -
    • -
    • grey - {r=0.50,g=0.50,b=0.50} -
    • -
    • lightgrey - {r=0.75,g=0.75,b=0.75} -
    • -
    • red - {r=1.00,g=0.00,b=0.00} -
    • -
    • darkred - {r=0.50,g=0.00,b=0.00} -
    • -
    • lightred - {r=1.00,g=0.50,b=0.50} -
    • -
    • green - {r=0.00,g=1.00,b=0.00} -
    • -
    • darkgreen - {r=0.00,g=0.50,b=0.00} -
    • -
    • lightgreen - {r=0.50,g=1.00,b=0.50} -
    • -
    • blue - {r=0.00,g=0.00,b=1.00} -
    • -
    • darkblue - {r=0.00,g=0.00,b=0.50} -
    • -
    • lightblue - {r=0.50,g=0.50,b=1.00} -
    • -
    • orange - {r=1.00,g=0.55,b=0.10} -
    • -
    • yellow - {r=1.00,g=1.00,b=0.00} -
    • -
    • pink - {r=1.00,g=0.00,b=1.00} -
    • -
    • purple - {r=0.60,g=0.10,b=0.60} -
    • -
    • brown - {r=0.60,g=0.40,b=0.10} -
    • -
    - - - - - -
    -
    - - defines.anticolor -
    -
    - Returns white for dark colors or black for lighter colors. - - -

    Fields:

    -
      -
    • green - defines.color.black -
    • -
    • grey - defines.color.black -
    • -
    • lightblue - defines.color.black -
    • -
    • lightgreen - defines.color.black -
    • -
    • lightgrey - defines.color.black -
    • -
    • lightred - defines.color.black -
    • -
    • orange - defines.color.black -
    • -
    • white - defines.color.black -
    • -
    • yellow - defines.color.black -
    • -
    • black - defines.color.white -
    • -
    • blue - defines.color.white -
    • -
    • brown - defines.color.white -
    • -
    • darkblue - defines.color.white -
    • -
    • darkgreen - defines.color.white -
    • -
    • darkgrey - defines.color.white -
    • -
    • darkred - defines.color.white -
    • -
    • pink - defines.color.white -
    • -
    • purple - defines.color.white -
    • -
    • red - defines.color.white -
    • -
    - - - - - -
    -
    - - defines.lightcolor -
    -
    - Returns a lighter color of a named color - - -

    Fields:

    -
      -
    • white - defines.color.lightgrey -
    • -
    • grey - defines.color.darkgrey -
    • -
    • lightgrey - defines.color.grey -
    • -
    • red - defines.color.lightred -
    • -
    • green - defines.color.lightgreen -
    • -
    • blue - defines.color.lightblue -
    • -
    • yellow - defines.color.orange -
    • -
    • pink - defines.color.purple -
    • -
    - - - - - -
    -
    - - defines.textcolor -
    -
    - Returns a lighter color of a named color. - - -

    Fields:

    -
      -
    • info - {r=0.21,g=0.95,b=1.00} -
    • -
    • bg - {r=0.00,g=0.00,b=0.00} -
    • -
    • low - {r=0.18,g=0.77,b=0.18} -
    • -
    • med - {r=1.00,g=0.89,b=0.26} -
    • -
    • high - {r=1.00,g=0.33,b=0.00} -
    • -
    • crit - {r=1.00,g=0.00,b=0.00} -
    • -
    - - - - - -
    -
    - - -
    -
    -
    -generated by LDoc 1.4.6 -Last updated 2018-05-29 23:30:03 -
    -
    - - diff --git a/doc/scripts/control.lua.html b/doc/scripts/control.lua.html deleted file mode 100644 index 6e5604ce..00000000 --- a/doc/scripts/control.lua.html +++ /dev/null @@ -1,85 +0,0 @@ - - - - - Reference - - - - -
    - -
    - -
    -
    -
    - - -
    - - - - - - -
    - -

    Script control.lua

    -

    Root Script File

    -

    - - - -
    -
    - - - - -
    -
    -
    -generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 -
    -
    - - diff --git a/doc/scripts/index.lua.html b/doc/scripts/index.lua.html deleted file mode 100644 index f912ae6d..00000000 --- a/doc/scripts/index.lua.html +++ /dev/null @@ -1,85 +0,0 @@ - - - - - Reference - - - - -
    - -
    - -
    -
    -
    - - -
    - - - - - - -
    - -

    Script index.lua

    -

    Used to index the files to be loaded

    -

    - - - -
    -
    - - - - -
    -
    -
    -generated by LDoc 1.4.6 -Last updated 2018-05-30 00:08:40 -
    -
    - - diff --git a/modules/ExpGamingCore/Sync/control.lua b/modules/ExpGamingCore/Sync/control.lua index 17a312ed..0d97f529 100644 --- a/modules/ExpGamingCore/Sync/control.lua +++ b/modules/ExpGamingCore/Sync/control.lua @@ -1,13 +1,9 @@ ---[[ -Explosive Gaming +--- Description - A small description that will be displayed on the doc +-- @module ExpGamingCore.Sync +-- @alias Sync +-- @author Cooldude2606 +-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -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----------------------------------------------------------- --- this file is used to allow easy syncing with out side programes local Sync = {} local Sync_updates = {} @@ -45,16 +41,19 @@ function Sync.print(player_message,player_name,player_tag,player_colour,prefix) game.print(prefix..player_name..tag..': '..player_message,colour) 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 args a table which contains everything that the embeded will use --- @table args +--- Outline of the paramaters accepted by Sync.emit_embeded +-- @table EmitEmbededParamaters -- @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) +-- @field fieldone the filed to add to the embed (key is name) (value is text) (start value with <<inline>> to make inline) +-- @field fieldtwo the filed to add to the embed (key is name) (value is text) (start value with <<inline>> to make inline) + +--- 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 args a table which contains everything that the embeded will use +-- @see EmitEmbededParamaters function Sync.emit_embeded(args) if not is_type(args,'table') then error('Args table not given to Sync.emit_embeded',2) end local title = is_type(args.title,'string') and args.title or '' @@ -90,6 +89,7 @@ function Sync.emit_embeded(args) end --- The error handle setup by sync to emit a discord embed for any errors +-- @local here -- @function errorHandler -- @tparam string err the error passed by the err control error.addHandler('Discord Emit',function(err) @@ -241,7 +241,7 @@ function Sync.add_update(key,callback) Sync_updates[key] = callback end ---- outputs the curent server info into a file +--- Outputs the curent server info into a file -- @usage Sync.emit_data() function Sync.emit_data() local info = Sync.info diff --git a/modules/ExpGamingCore/Sync/lib/gui.lua b/modules/ExpGamingCore/Sync/lib/gui.lua index 8a1c5771..a1ddd980 100644 --- a/modules/ExpGamingCore/Sync/lib/gui.lua +++ b/modules/ExpGamingCore/Sync/lib/gui.lua @@ -4,7 +4,9 @@ -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- this file will be loaded when ExpGamingCore/Gui is present +--- This file will be loaded when ExpGamingCore/Gui is present +-- @function _comment + local Sync_gui_functions = {} @@ -35,6 +37,7 @@ local function label_format(label,width) end --- Creates a center gui that will appear on join +-- @table server-info -- @local call to Gui.Center Gui.center.add{ name='server-info', diff --git a/modules/ExpGamingCore/Sync/lib/ranking.lua b/modules/ExpGamingCore/Sync/lib/ranking.lua index 81e671da..4925290b 100644 --- a/modules/ExpGamingCore/Sync/lib/ranking.lua +++ b/modules/ExpGamingCore/Sync/lib/ranking.lua @@ -4,11 +4,11 @@ -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- this file will be loaded when ExpGamingCore/Ranking is present - +--- This file will be loaded when ExpGamingCore/Ranking is present +-- @function _comment + --- Used as a redirect to Ranking._base_preset that will set the rank given to a player apon joining -- @usage Sync.set_ranks{player_name=rank_name,...} --- @see Ranking._base_preset function Sync.set_ranks(...) Ranking._base_preset(...) end @@ -30,8 +30,7 @@ function Sync.count_ranks() return _ranks end ---- Adds a caption to the info gui that shows the rank given to the player --- @local callback for Sync.add_to_gui +-- Adds a caption to the info gui that shows the rank given to the player if Sync.add_to_gui then Sync.add_to_gui(function(player,frame) return 'You have been assigned the rank \''..Ranking.get_rank(player).name..'\'' diff --git a/modules/FactorioModGui/control.lua b/modules/FactorioModGui/control.lua index 40fa62b1..1f3bbf83 100644 --- a/modules/FactorioModGui/control.lua +++ b/modules/FactorioModGui/control.lua @@ -1,6 +1,8 @@ +-- not_luadoc=true --- Redirect to factorio mod-gui -- @module Factorio Mod Gui --- @alias mod-gui +-- @alias mod_gui -- @author Factorio Dev Team +-- redirect to normal require of mod gui return require("mod-gui") \ No newline at end of file diff --git a/modules/index.lua b/modules/index.lua index 643e99c5..8488de38 100644 --- a/modules/index.lua +++ b/modules/index.lua @@ -1,3 +1,4 @@ +-- not_luadoc=true --- Used to index the files to be loaded -- @script index.lua return { From 9430843820dcd90801f02ef4e91c11571bdf1e0f Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Thu, 31 May 2018 15:29:32 +0100 Subject: [PATCH 015/231] Rename lib to scr --- modules/ExpGamingCore/Sync/{lib => src}/gui.lua | 0 modules/ExpGamingCore/Sync/{lib => src}/ranking.lua | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename modules/ExpGamingCore/Sync/{lib => src}/gui.lua (100%) rename modules/ExpGamingCore/Sync/{lib => src}/ranking.lua (100%) diff --git a/modules/ExpGamingCore/Sync/lib/gui.lua b/modules/ExpGamingCore/Sync/src/gui.lua similarity index 100% rename from modules/ExpGamingCore/Sync/lib/gui.lua rename to modules/ExpGamingCore/Sync/src/gui.lua diff --git a/modules/ExpGamingCore/Sync/lib/ranking.lua b/modules/ExpGamingCore/Sync/src/ranking.lua similarity index 100% rename from modules/ExpGamingCore/Sync/lib/ranking.lua rename to modules/ExpGamingCore/Sync/src/ranking.lua From eaf47f2d6e6b6d58f83b8f94cda54f781922b0dc Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Thu, 31 May 2018 17:58:32 +0100 Subject: [PATCH 016/231] Added Manager.global --- FactorioSoftmodManager.lua | 47 +++++++++++++++++---- modules/ExpGamingCore/Sync/control.lua | 56 +++++++++++++------------- modules/ExpGamingCore/Sync/src/gui.lua | 1 - modules/ExpGamingLib/control.lua | 3 ++ 4 files changed, 70 insertions(+), 37 deletions(-) diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index 4d549d64..3dfb0ae0 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -145,6 +145,38 @@ Manager.setVerbose = setmetatable( -- 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) +--- An optinal feature that can be used if you dont want to worry about conflicting global paths +-- @usage local global = global_manager() -- sets up the global struture +-- @usage global{'foo','bar'} -- sets the default value +-- @tparam[opt={}] table default the default value of global +-- @treturn table the new global table for that module +function Manager.global(default) + local default = default or {} + return setmetatable(default,{ + __call=function(tbl,default) + if default then rawset(tbl,'default',default) end + local global = _G.global + if not module_path then return global end + local path = 'global' + local new_dir = false -- this is to test if the default should be used + for dir in module_path:gmatch('%a+') do + path = path..'.'..dir + if not rawget(global,dir) then new_dir=true Manager.verbose('Added Global Dir: '..path) rawset(global,dir,{}) end + global = rawget(global,dir) + end + if new_dir then + Manager.verbose('Set Global Dir: '..path..' to its default') + for key,value in pairs(rawget(tbl,'default')) do rawset(global,key,value) end + end + return global + end, + __index=function(tbl,key) return rawget(tbl(),key) or rawget(_G.global,key) end, + __newindex=function(tbl,key,value) rawset(tbl(),key,value) end, + __pairs=function(tbl) return pairs(tbl()) end, + __ipairs=function(tbl) return ipairs(tbl()) end + }) +end + --- 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 @@ -233,6 +265,7 @@ Manager.loadModules = setmetatable({}, if rawget(_G,module_name) and type(tbl[module_name]) == 'table' then setmetatable(rawget(_G,module_name),{__index=tbl[module_name]}) end else Manager.verbose('Failed load: "'..module_name..'"; path: '..path..' ('..module..')','errorCaught') + for event_name,callbacks in pairs(Manager.event) do Manager.verbose('Removed Event Handler: "'..module_name..'/'..tbl.names[event_name],'eventRegistered') callbacks[module_name] = nil end end end -- new state for the manager to allow control of verbose @@ -243,7 +276,7 @@ Manager.loadModules = setmetatable({}, 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),module_path=moduleIndex[module_name]},data) + local sandbox, success, err = Manager.sandbox(data.on_init,{module_name=setupModuleName(module_name),module_path=moduleIndex[tostring(module_name)]},data) if success then Manager.verbose('Successfully Initiated: "'..module_name..'"') else @@ -400,8 +433,8 @@ Manager.event = setmetatable({ 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),module_path=moduleIndex[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 + local sandbox, success, err = Manager.sandbox(callback,{module_name=setupModuleName(module_name),module_path=moduleIndex[tostring(module_name)]},new_callback,...) + if not success then Manager.verbose('Event Failed: "'..module_name..'/'..tbl.names[event_name]..'" ('..err..')','errorCaught') error('Event Failed: "'..module_name..'/'..tbl.names[event_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 @@ -415,12 +448,12 @@ Manager.event = setmetatable({ -- converts the key to a number index for the event Manager.verbose('Added Handler: "'..tbl.names[key]..'"','eventRegistered') -- 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 + if not rawget(rawget(tbl,'__events'),key) then if key < 0 then rawget(tbl,tbl.names[key])(function(...) tbl(key,...) end) else rawget(tbl,'__event')(key,function(...) tbl(key,...) end) 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) + rawset(rawget(rawget(tbl,'__events'),key),tostring(module_name),value) end, __index=function(tbl,key) -- few redirect key @@ -429,8 +462,8 @@ Manager.event = setmetatable({ -- 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) + return rawget(rawget(tbl,'__events'),key) and rawget(rawget(rawget(tbl,'__events'),key),tostring(module_name)) + or rawget(rawget(tbl,'__events'),rawget(tbl,'names')[key]) and rawget(rawget(rawget(tbl,'__events'),rawget(tbl,'names')[key]),tostring(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 diff --git a/modules/ExpGamingCore/Sync/control.lua b/modules/ExpGamingCore/Sync/control.lua index 0d97f529..e7a14d52 100644 --- a/modules/ExpGamingCore/Sync/control.lua +++ b/modules/ExpGamingCore/Sync/control.lua @@ -6,6 +6,7 @@ local Sync = {} local Sync_updates = {} +local global = Manager.global() --- Used to standidise the tick format for any sync info -- @usage Sync.tick_format(60) -- return {60,'1.00M'} @@ -175,35 +176,10 @@ end -- @tparam[opt=nil] table set keys to be replaced in the server info -- @treturn boolean success was the data set Sync.info = setmetatable({},{ - __index=function(tbl,key) - if not global.exp_core then global.exp_core = {} end - if not global.exp_core.sync then global.exp_core.sync = { - server_name='Factorio Server', - server_description='A factorio server for everyone', - reset_time='On Demand', - time='Day Mth 00 00:00:00 UTC Year', - time_set=Sync.tick_format(0), - last_update=Sync.tick_format(0), - time_period=Sync.tick_format(18000), - players={ - online=Sync.count_players(true), - n_online=#game.connected_players, - all=Sync.count_players(), - n_all=#game.players, - admins_online=Sync.count_admins(), - afk_players=Sync.count_afk(), - times=Sync.count_player_times() - }, - ranks=Sync.count_ranks(), - rockets=game.forces['player'].get_item_launched('satellite'), - mods={'base'} - } end - return global.exp_core.sync[key] - end, + __index=global, __call=function(tbl,set) - local _ = tbl.time -- used to create the global if not made if not is_type(set,'table') then return false end - for key,value in pairs(set) do global.exp_core.sync[key] = value end + for key,value in pairs(set) do global[key] = value end return true end }) @@ -268,9 +244,31 @@ function Sync:on_init() info.time_set[2] = tick_to_display_format(game.tick) return true end,function() local info = Sync.info return info.time..' (+'..(game.tick-info.time_set[1])..' Ticks)' end) + -- sets up the global for this module + global{ + server_name='Factorio Server', + server_description='A factorio server for everyone', + reset_time='On Demand', + time='Day Mth 00 00:00:00 UTC Year', + time_set=Sync.tick_format(0), + last_update=Sync.tick_format(0), + time_period=Sync.tick_format(18000), + players={ + online=Sync.count_players(true), + n_online=game and #game.connected_players or 0, + all=Sync.count_players(), + n_all=game and #game.players or 0, + admins_online=Sync.count_admins(), + afk_players=Sync.count_afk(), + times=Sync.count_player_times() + }, + ranks=Sync.count_ranks(), + rockets=game and game.forces['player'].get_item_launched('satellite') or 0, + mods=table.keys(loaded_modules) + } -- optinal dependies - if loaded_modules.Gui then verbose('ExpGamingCore.Gui is installed; Loading gui lib') require(module_path..'/lib/gui') end - if loaded_modules.Ranking then verbose('ExpGamingCore.Ranking is installed; Loading ranking lib') require(module_path..'/lib/ranking') end + if loaded_modules.Gui then verbose('ExpGamingCore.Gui is installed; Loading gui lib') require(module_path..'/src/gui') end + if loaded_modules.Ranking then verbose('ExpGamingCore.Ranking is installed; Loading ranking lib') require(module_path..'/src/ranking') end end return Sync \ No newline at end of file diff --git a/modules/ExpGamingCore/Sync/src/gui.lua b/modules/ExpGamingCore/Sync/src/gui.lua index a1ddd980..9b120853 100644 --- a/modules/ExpGamingCore/Sync/src/gui.lua +++ b/modules/ExpGamingCore/Sync/src/gui.lua @@ -7,7 +7,6 @@ --- This file will be loaded when ExpGamingCore/Gui is present -- @function _comment - local Sync_gui_functions = {} --- Adds a emeltent to the sever info gui diff --git a/modules/ExpGamingLib/control.lua b/modules/ExpGamingLib/control.lua index 103d49b5..8c0f3773 100644 --- a/modules/ExpGamingLib/control.lua +++ b/modules/ExpGamingLib/control.lua @@ -110,6 +110,7 @@ end -- @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 + if not game then return math.floor(tick/216000) end return math.floor(tick/(216000*game.speed)) end @@ -119,6 +120,7 @@ end -- @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 + if not game then return math.floor(tick/3600) end return math.floor(tick/(3600*game.speed)) end @@ -130,6 +132,7 @@ end 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 + if not game then return math.floor(tick/3600) end return string.format('%.2f M',tick/(3600*game.speed)) else return string.format('%d H %d M', From c834aadca1a4d650d04bb288c269b6cf32c15676 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Thu, 31 May 2018 17:59:39 +0100 Subject: [PATCH 017/231] Changed Doc --- FactorioSoftmodManager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index 3dfb0ae0..b477646f 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -146,7 +146,7 @@ Manager.setVerbose = setmetatable( Manager.verbose('Current state is now: "selfInit"; The verbose state is: '..tostring(Manager.setVerbose.selfInit),true) --- An optinal feature that can be used if you dont want to worry about conflicting global paths --- @usage local global = global_manager() -- sets up the global struture +-- @usage local global = Manager.global() -- sets up the global struture -- @usage global{'foo','bar'} -- sets the default value -- @tparam[opt={}] table default the default value of global -- @treturn table the new global table for that module From 2ddbd964769e57c56a61d9e39bfd515cef213a40 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Thu, 31 May 2018 20:24:18 +0100 Subject: [PATCH 018/231] Sync Now Ready --- FactorioSoftmodManager.lua | 33 ++++++++++++--------- modules/ExpGamingCore/Sync/control.lua | 41 +++++++++++--------------- modules/index.lua | 8 ++--- 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index b477646f..d0184387 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -145,20 +145,18 @@ Manager.setVerbose = setmetatable( -- 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) ---- An optinal feature that can be used if you dont want to worry about conflicting global paths --- @usage local global = Manager.global() -- sets up the global struture +--- Used to avoid conflicts in the global table +-- @usage global[key] -- used like the normal global table -- @usage global{'foo','bar'} -- sets the default value -- @tparam[opt={}] table default the default value of global -- @treturn table the new global table for that module -function Manager.global(default) - local default = default or {} - return setmetatable(default,{ +Manager.global=setmetatable({__global=global,__defaults={}},{ __call=function(tbl,default) - if default then rawset(tbl,'default',default) end - local global = _G.global - if not module_path then return global end + local global = rawget(tbl,'__global') + if not module_path or not module_name then return global end + if default then rawset(rawget(tbl,'__defaults'),tostring(module_name),default) end local path = 'global' - local new_dir = false -- this is to test if the default should be used + local new_dir = false for dir in module_path:gmatch('%a+') do path = path..'.'..dir if not rawget(global,dir) then new_dir=true Manager.verbose('Added Global Dir: '..path) rawset(global,dir,{}) end @@ -166,7 +164,7 @@ function Manager.global(default) end if new_dir then Manager.verbose('Set Global Dir: '..path..' to its default') - for key,value in pairs(rawget(tbl,'default')) do rawset(global,key,value) end + for key,value in pairs(rawget(rawget(tbl,'__defaults'),tostring(module_name))) do rawset(global,key,value) end end return global end, @@ -174,8 +172,8 @@ function Manager.global(default) __newindex=function(tbl,key,value) rawset(tbl(),key,value) end, __pairs=function(tbl) return pairs(tbl()) end, __ipairs=function(tbl) return ipairs(tbl()) end - }) -end +}) +global=Manager.global --- Creates a sand box envorment and runs a callback in that sand box; provents global pollution -- @function Manager.sandbox @@ -188,6 +186,7 @@ Manager.sandbox = setmetatable({ -- can not use existing keys of _G verbose=Manager.verbose, loaded_modules=ReadOnlyManager, + global=Manager.global, module_verbose=false, module_exports=false },{ @@ -265,7 +264,7 @@ Manager.loadModules = setmetatable({}, if rawget(_G,module_name) and type(tbl[module_name]) == 'table' then setmetatable(rawget(_G,module_name),{__index=tbl[module_name]}) end else Manager.verbose('Failed load: "'..module_name..'"; path: '..path..' ('..module..')','errorCaught') - for event_name,callbacks in pairs(Manager.event) do Manager.verbose('Removed Event Handler: "'..module_name..'/'..tbl.names[event_name],'eventRegistered') callbacks[module_name] = nil end + for event_name,callbacks in pairs(Manager.event) do Manager.verbose('Removed Event Handler: "'..module_name..'/'..Manager.event.names[event_name],'eventRegistered') callbacks[module_name] = nil end end end -- new state for the manager to allow control of verbose @@ -449,7 +448,8 @@ Manager.event = setmetatable({ Manager.verbose('Added Handler: "'..tbl.names[key]..'"','eventRegistered') -- 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 - if key < 0 then rawget(tbl,tbl.names[key])(function(...) tbl(key,...) end) + if key == -1 then -- this already has a handler + elseif key < 0 then rawget(tbl,tbl.names[key])(function(...) tbl(key,...) end) else rawget(tbl,'__event')(key,function(...) tbl(key,...) end) end rawset(rawget(tbl,'__events'),key,{}) end -- adds callback to Manager.event.__events[event_id][module_name] @@ -520,6 +520,11 @@ rawset(Manager.event,'names',setmetatable({},{ end })) +script.on_init(function(...) + --rawset(Manager.global,'_global',global) + --global = Manager.global + Manager.event(key,...) +end) --over rides for the base values; can be called though Event Event=setmetatable({},{__call=Manager.event,__index=function(tbl,key) return Manager.event[key] or script[key] or error('Invalid Index To Table Event') end}) script.mod_name = setmetatable({},{__index=_G.module_name}) diff --git a/modules/ExpGamingCore/Sync/control.lua b/modules/ExpGamingCore/Sync/control.lua index e7a14d52..50180328 100644 --- a/modules/ExpGamingCore/Sync/control.lua +++ b/modules/ExpGamingCore/Sync/control.lua @@ -6,7 +6,20 @@ local Sync = {} local Sync_updates = {} -local global = Manager.global() +-- sets up the global for this module +global{ + server_name='Factorio Server', + server_description='A factorio server for everyone', + reset_time='On Demand', + time='Day Mth 00 00:00:00 UTC Year', + time_set={0,'0.00M'}, + last_update={0,'0.00M'}, + time_period={18000,'5.00M'}, + players={online={'Offline'},n_online=0,all={'Offline'},n_all=0,admins_online=0,afk_players=0,times={'Offline'}}, + ranks={'Offline'}, + rockets=0, + mods={'Offline'} +} --- Used to standidise the tick format for any sync info -- @usage Sync.tick_format(60) -- return {60,'1.00M'} @@ -131,7 +144,7 @@ end function Sync.count_ranks() if not game then return {'Offline'} end local _ranks = {admin={online={},players={}},user={online={},players={}}} - for power,rank in pairs(game.players) do + for index,player in pairs(game.players) do if player.admin then table.insert(_ranks.admin.players,player.name) if player.connected then table.insert(_ranks.admin.online,player.name) end @@ -244,28 +257,8 @@ function Sync:on_init() info.time_set[2] = tick_to_display_format(game.tick) return true end,function() local info = Sync.info return info.time..' (+'..(game.tick-info.time_set[1])..' Ticks)' end) - -- sets up the global for this module - global{ - server_name='Factorio Server', - server_description='A factorio server for everyone', - reset_time='On Demand', - time='Day Mth 00 00:00:00 UTC Year', - time_set=Sync.tick_format(0), - last_update=Sync.tick_format(0), - time_period=Sync.tick_format(18000), - players={ - online=Sync.count_players(true), - n_online=game and #game.connected_players or 0, - all=Sync.count_players(), - n_all=game and #game.players or 0, - admins_online=Sync.count_admins(), - afk_players=Sync.count_afk(), - times=Sync.count_player_times() - }, - ranks=Sync.count_ranks(), - rockets=game and game.forces['player'].get_item_launched('satellite') or 0, - mods=table.keys(loaded_modules) - } + -- updates installed mods + Sync.info{mods=table.keys(loaded_modules)} -- optinal dependies if loaded_modules.Gui then verbose('ExpGamingCore.Gui is installed; Loading gui lib') require(module_path..'/src/gui') end if loaded_modules.Ranking then verbose('ExpGamingCore.Ranking is installed; Loading ranking lib') require(module_path..'/src/ranking') end diff --git a/modules/index.lua b/modules/index.lua index 8488de38..873f1090 100644 --- a/modules/index.lua +++ b/modules/index.lua @@ -9,9 +9,9 @@ return { ['Color']='/modules/FactorioStdLib/Color', ['table']='/modules/FactorioStdLib/Table', ['string']='/modules/FactorioStdLib/String', - ['Ranking']='/modules/ExpGamingCore/Ranking', - ['commands']='/modules/ExpGamingCore/Commands', - ['Gui']='/modules/ExpGamingCore/Gui', - ['Server']='/modules/ExpGamingCore/Server', + --['Ranking']='/modules/ExpGamingCore/Ranking', + --['commands']='/modules/ExpGamingCore/Commands', + --['Gui']='/modules/ExpGamingCore/Gui', + --['Server']='/modules/ExpGamingCore/Server', ['Sync']='/modules/ExpGamingCore/Sync', } \ No newline at end of file From 121dcbe70e2bb9979278fd23d4ed6193d4868c0b Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 1 Jun 2018 00:30:00 +0100 Subject: [PATCH 019/231] Global Now Works No Bugs --- FactorioSoftmodManager.lua | 86 +++++++++++++++--------- modules/ExpGamingCore/Sync/control.lua | 3 +- modules/FactorioStdLib/Table/control.lua | 8 +-- 3 files changed, 62 insertions(+), 35 deletions(-) diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index d0184387..9db5bfe6 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -70,8 +70,9 @@ 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..'] '..tostring(rtn) - else rtn='[FSM] '..tostring(rtn) end + local rtn = type(rtn) == table and serpent.line(rtn) or tostring(rtn) + 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 (not action and settings[state]) then @@ -150,30 +151,52 @@ Manager.verbose('Current state is now: "selfInit"; The verbose state is: '..tost -- @usage global{'foo','bar'} -- sets the default value -- @tparam[opt={}] table default the default value of global -- @treturn table the new global table for that module -Manager.global=setmetatable({__global=global,__defaults={}},{ - __call=function(tbl,default) - local global = rawget(tbl,'__global') - if not module_path or not module_name then return global end - if default then rawset(rawget(tbl,'__defaults'),tostring(module_name),default) end - local path = 'global' - local new_dir = false - for dir in module_path:gmatch('%a+') do - path = path..'.'..dir - if not rawget(global,dir) then new_dir=true Manager.verbose('Added Global Dir: '..path) rawset(global,dir,{}) end - global = rawget(global,dir) - end - if new_dir then - Manager.verbose('Set Global Dir: '..path..' to its default') - for key,value in pairs(rawget(rawget(tbl,'__defaults'),tostring(module_name))) do rawset(global,key,value) end - end - return global - end, - __index=function(tbl,key) return rawget(tbl(),key) or rawget(_G.global,key) end, - __newindex=function(tbl,key,value) rawset(tbl(),key,value) end, - __pairs=function(tbl) return pairs(tbl()) end, - __ipairs=function(tbl) return ipairs(tbl()) end +Manager.global=setmetatable({__defaults={},__global={ + __call=function(tbl,default) Manager.global(default) end, + __index=function(tbl,key) return Manager.global() == tbl and nil or rawget(Manager.global(),key) end, + __newindex=function(tbl,key,value) rawset(Manager.global(),key,value) end, + __pairs=function(tbl) + Manager.verbose('Global Pair 1') + local tbl = Manager.global() + Manager.verbose('Global Pair 2') + local function next_pair(tbl,k) + k, v = next(tbl, k) + if type(v) ~= nil then return k,v end + end + return next_pair, tbl, nil + end +}},{ + __call=function(tbl,default) + local global = _G.global + if not module_path or not module_name then return _G.global end + if default then rawset(rawget(tbl,'__defaults'),tostring(module_name),default) end + local path = 'global' + local new_dir = false + for dir in module_path:gmatch('%a+') do + path = path..'.'..dir + if not rawget(global,dir) then new_dir=true Manager.verbose('Added Global Dir: '..path) rawset(global,dir,{}) end + global = rawget(global,dir) + end + if new_dir and rawget(rawget(tbl,'__defaults'),tostring(module_name)) then + Manager.verbose('Set Global Dir: '..path..' to its default') + for key,value in pairs(rawget(rawget(tbl,'__defaults'),tostring(module_name))) do rawset(global,key,value) end + end + return global + end, + __index=function(tbl,key) Manager.verbose('Manager Index') return rawget(tbl(),key) or rawget(_G.global,key) end, + __newindex=function(tbl,key,value) rawset(tbl(),key,value) end, + __pairs=function(tbl) + Manager.verbose('Manager Pair 1') + local tbl = Manager.global() + Manager.verbose('Manager Pair 2') + local function next_pair(tbl,k) + k, v = next(tbl, k) + if type(v) ~= nil then return k,v end + end + return next_pair, tbl, nil + end }) -global=Manager.global +setmetatable(global,Manager.global.__global) --- Creates a sand box envorment and runs a callback in that sand box; provents global pollution -- @function Manager.sandbox @@ -186,7 +209,6 @@ Manager.sandbox = setmetatable({ -- can not use existing keys of _G verbose=Manager.verbose, loaded_modules=ReadOnlyManager, - global=Manager.global, module_verbose=false, module_exports=false },{ @@ -448,7 +470,7 @@ Manager.event = setmetatable({ Manager.verbose('Added Handler: "'..tbl.names[key]..'"','eventRegistered') -- 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 - if key == -1 then -- this already has a handler + if key == -1 or key == -2 then -- this already has a handler elseif key < 0 then rawget(tbl,tbl.names[key])(function(...) tbl(key,...) end) else rawget(tbl,'__event')(key,function(...) tbl(key,...) end) end rawset(rawget(tbl,'__events'),key,{}) end @@ -521,9 +543,13 @@ rawset(Manager.event,'names',setmetatable({},{ })) script.on_init(function(...) - --rawset(Manager.global,'_global',global) - --global = Manager.global - Manager.event(key,...) + setmetatable(global,Manager.global.__global) + Manager.event(-1,...) +end) + +script.on_load(function(...) + setmetatable(global,Manager.global.__global) + Manager.event(-2,...) end) --over rides for the base values; can be called though Event Event=setmetatable({},{__call=Manager.event,__index=function(tbl,key) return Manager.event[key] or script[key] or error('Invalid Index To Table Event') end}) diff --git a/modules/ExpGamingCore/Sync/control.lua b/modules/ExpGamingCore/Sync/control.lua index 50180328..247e5696 100644 --- a/modules/ExpGamingCore/Sync/control.lua +++ b/modules/ExpGamingCore/Sync/control.lua @@ -190,6 +190,7 @@ end -- @treturn boolean success was the data set Sync.info = setmetatable({},{ __index=global, + __newindex=global, __call=function(tbl,set) if not is_type(set,'table') then return false end for key,value in pairs(set) do global[key] = value end @@ -258,7 +259,7 @@ function Sync:on_init() return true end,function() local info = Sync.info return info.time..' (+'..(game.tick-info.time_set[1])..' Ticks)' end) -- updates installed mods - Sync.info{mods=table.keys(loaded_modules)} + --Sync.info{mods=table.keys(loaded_modules)} -- optinal dependies if loaded_modules.Gui then verbose('ExpGamingCore.Gui is installed; Loading gui lib') require(module_path..'/src/gui') end if loaded_modules.Ranking then verbose('ExpGamingCore.Ranking is installed; Loading ranking lib') require(module_path..'/src/ranking') end diff --git a/modules/FactorioStdLib/Table/control.lua b/modules/FactorioStdLib/Table/control.lua index bb3c57a8..08afc6fd 100644 --- a/modules/FactorioStdLib/Table/control.lua +++ b/modules/FactorioStdLib/Table/control.lua @@ -442,10 +442,10 @@ function table.tostring(tbl) done[k] = true end for k, v in pairs(tbl) do - if not done[k] then - table.insert(result, - table.key_to_str(k).."="..table.val_to_str(v)) - end + if not done[k] then + table.insert(result, + table.key_to_str(k).."="..table.val_to_str(v)) + end end return "{"..table.concat(result,",") .."}" end From 22d3efc4a13c7e3de2f4b15f7d04a6d3cf79f03e Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 1 Jun 2018 00:58:02 +0100 Subject: [PATCH 020/231] ExpLib always in global now --- modules/ExpGamingCore/Sync/control.lua | 29 +++++++++++++------------- modules/ExpGamingLib/control.lua | 7 ++----- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/modules/ExpGamingCore/Sync/control.lua b/modules/ExpGamingCore/Sync/control.lua index 247e5696..00a0bdc0 100644 --- a/modules/ExpGamingCore/Sync/control.lua +++ b/modules/ExpGamingCore/Sync/control.lua @@ -238,6 +238,20 @@ function Sync.emit_data() game.write_file('server-info.json',table.json(info),false,0) end +--- Used to return and set the current IRL time; not very good need a better way to do this +-- @usage Sync.time('Sun Apr 1 18:44:30 UTC 2018') +-- @usage Sync.time -- string +-- @tparam[opt=nil] string set the date time to be set +-- @treturn boolean if the datetime set was successful +Sync.time=add_metatable({},function(set) + local info = Sync.info + if not is_type(set,'string') then return false end + info.time = set + info.time_set[1] = game.tick + info.time_set[2] = tick_to_display_format(game.tick) + return true +end,function() local info = Sync.info return info.time..' (+'..(game.tick-info.time_set[1])..' Ticks)' end) + -- will auto replace the file every 5 min by default script.on_event('on_tick',function(event) local time = Sync.info.time_period[1] @@ -245,21 +259,8 @@ script.on_event('on_tick',function(event) end) function Sync:on_init() - --- Used to return and set the current IRL time; not very good need a better way to do this - -- @usage Sync.time('Sun Apr 1 18:44:30 UTC 2018') - -- @usage Sync.time -- string - -- @tparam[opt=nil] string set the date time to be set - -- @treturn boolean if the datetime set was successful - Sync.time=add_metatable({},function(set) - local info = Sync.info - if not is_type(set,'string') then return false end - info.time = set - info.time_set[1] = game.tick - info.time_set[2] = tick_to_display_format(game.tick) - return true - end,function() local info = Sync.info return info.time..' (+'..(game.tick-info.time_set[1])..' Ticks)' end) -- updates installed mods - --Sync.info{mods=table.keys(loaded_modules)} + Sync.info{mods=table.keys(loaded_modules)} -- optinal dependies if loaded_modules.Gui then verbose('ExpGamingCore.Gui is installed; Loading gui lib') require(module_path..'/src/gui') end if loaded_modules.Ranking then verbose('ExpGamingCore.Ranking is installed; Loading ranking lib') require(module_path..'/src/ranking') end diff --git a/modules/ExpGamingLib/control.lua b/modules/ExpGamingLib/control.lua index 8c0f3773..07d852d9 100644 --- a/modules/ExpGamingLib/control.lua +++ b/modules/ExpGamingLib/control.lua @@ -161,9 +161,6 @@ function ExpLib.gui_tree(root) return tree end --- unpacks lib to _G on module init -function ExpLib.on_init(self) - self:unpack_to_G() -end - +-- bypasses the module sandbox and places functions into _G +ExpLib:unpack_to_G() return ExpLib \ No newline at end of file From 5eb8600411d833923f6954b3765c195ff564b747 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 1 Jun 2018 16:12:39 +0100 Subject: [PATCH 021/231] Added moduole: ExpGamingCore.Server --- FactorioSoftmodManager.lua | 9 +- modules/ExpGamingCore/Server/control.lua | 410 ++++++++++-------- modules/ExpGamingCore/Server/src/commands.lua | 31 ++ modules/ExpGamingCore/Sync/control.lua | 37 +- modules/ExpGamingCore/Sync/src/gui.lua | 2 +- modules/ExpGamingCore/Sync/src/ranking.lua | 2 +- modules/ExpGamingCore/softmod.json | 1 + modules/ExpGamingLib/control.lua | 12 +- modules/index.lua | 2 +- 9 files changed, 302 insertions(+), 204 deletions(-) create mode 100644 modules/ExpGamingCore/Server/src/commands.lua diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index 9db5bfe6..93382980 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -149,16 +149,15 @@ Manager.verbose('Current state is now: "selfInit"; The verbose state is: '..tost --- Used to avoid conflicts in the global table -- @usage global[key] -- used like the normal global table -- @usage global{'foo','bar'} -- sets the default value --- @tparam[opt={}] table default the default value of global +-- @usage global(true) -- restores global to default +-- @tparam[opt={}] ?table|true default the default value of global, if true then default is restored -- @treturn table the new global table for that module Manager.global=setmetatable({__defaults={},__global={ - __call=function(tbl,default) Manager.global(default) end, + __call=function(tbl,default) return Manager.global(default) end, __index=function(tbl,key) return Manager.global() == tbl and nil or rawget(Manager.global(),key) end, __newindex=function(tbl,key,value) rawset(Manager.global(),key,value) end, __pairs=function(tbl) - Manager.verbose('Global Pair 1') local tbl = Manager.global() - Manager.verbose('Global Pair 2') local function next_pair(tbl,k) k, v = next(tbl, k) if type(v) ~= nil then return k,v end @@ -177,7 +176,7 @@ Manager.global=setmetatable({__defaults={},__global={ if not rawget(global,dir) then new_dir=true Manager.verbose('Added Global Dir: '..path) rawset(global,dir,{}) end global = rawget(global,dir) end - if new_dir and rawget(rawget(tbl,'__defaults'),tostring(module_name)) then + if (new_dir or default == true) and rawget(rawget(tbl,'__defaults'),tostring(module_name)) then Manager.verbose('Set Global Dir: '..path..' to its default') for key,value in pairs(rawget(rawget(tbl,'__defaults'),tostring(module_name))) do rawset(global,key,value) end end diff --git a/modules/ExpGamingCore/Server/control.lua b/modules/ExpGamingCore/Server/control.lua index d8c6347f..5e9b9522 100644 --- a/modules/ExpGamingCore/Server/control.lua +++ b/modules/ExpGamingCore/Server/control.lua @@ -1,60 +1,67 @@ ---[[ -Explosive Gaming +--- Adds a thread system and event listening and a admin bypass (recommend to disable /c and use optional /interface) +-- @module ExpGamingCore.Server +-- @alias Server +-- @author Cooldude2606 +-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -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----------------------------------------------------------- --- server allows control over threads and other features the devs missed out local Server = {} -Server._thread = {} ---- Returns a un-used uuid (better system needed) --- @usage obj.uuid = Server.new_uuid() +--- Global Table +-- @table global +local global = global{ + all={_n=0}, -- a list of every thread (indexed by uuid) + queue={}, -- an index for threads which will be resolved (contains uuids) + tick={}, -- an index for threads which will run every tick (contains uuids) + timeout={}, -- an index for threads which will timeout (contains uuids) + events={}, -- an index of threads based on event ids (contains uuids) + paused={}, -- an index of pasued threads (contains uuids) + named={}, -- a name index for thread uuids + print_to={}, -- contains players that event details will be printed to + uuid=nil -- contains the random number generator for the uuid system +} + +--- Used to generate a new uuid for the thread system +-- @usage local uuid = tostring(Server.uuid) -- calling tostring locks the value -- @treturn string the new uuid -function Server.new_uuid() - local uuid = tostring(Server._uuid()()) - uuid = string.to_hex('uuid'..uuid) - return uuid -end +Server.uuid = add_metatable({},function() + if not global.uuid then global.uuid = game.create_random_generator() end + return global.uuid() +end,function() + return string.to_hex(tostring(Server.uuid())) +end) --- use this to change the location of the server uuids -function Server._uuid(reset) - global.exp_core = not reset and global.exp_core or {} - global.exp_core.uuids = not reset and global.exp_core.uuids or game.create_random_generator() - return global.exp_core.uuids -end +--- Redirect to the thread index +-- @usage Server.threads -- return #global.all +-- @usage Server.threads -- return global.all +-- @treturn[1] number the number of threads +-- @treturn[2] table table of all threads +Server.threads = setmetatable({},{ + __call=function(tbl) return global.all._n end, + __index=function(tbl,key) return rawget(global.all,key) end, + __newindex=function(tbl,key,value) rawset(global.all,key,value) end, + __pairs=function(tbl) + local tbl = global.all + local function next_pair(tbl,k) + k, v = next(tbl, k) + if type(v) ~= nil and k ~= '_n' then return k,v end + end + return next_pair, tbl, nil + end +}) ---- Returns either the number of threads or a able of threads --- @usage Server.threads() -- return {...} --- Server.threads(true) -- return int --- @tparam[opt=nil] bolean count true to return the number of threads --- @return either a list of threads or a number -function Server.threads(count) - return count and Server._threads().all._n or Server._threads().all -end +--- Generates a new thread object +-- @usage Server.new_thread{name='foo',data={}} +-- @tparam table obj the atributes to give to the thread +-- @treturn Server._thread the new thread created +function Server.new_thread(obj) return Server._thread:create(obj) end --- use this to change the location of the server threads --- all stores the threads indexed uuid, the other three only store the uuid's to index in the all table -function Server._threads(reset) - global.exp_core = not reset and global.exp_core or {} - global.exp_core.threads = not reset and global.exp_core.threads or {print_to={},queue={},tick={},timeout={},events={},all={_n=0},paused={},named={}} - return global.exp_core.threads -end - --- see thread:create (this was done so thread can remain local) -function Server.new_thread(obj) - return Server._thread:create(obj) -end - ---- Used to get a thread via it's uuid or by name if one is given +--- Used to get a thread via uuid or name (if one is assied) -- @usage Server.get_thread('decon') -- return thread -- @param mixed either a uuid or the name given to a thread --- @treturn table the thread by that name or uuid +-- @treturn[1] Server._thread the thread by that name or uuid +-- @treturn[2] boolean if false is returned then no thread existes function Server.get_thread(mixed) - local threads = Server._threads() + local threads = global if threads.named[mixed] then return threads.all[threads.named[mixed]] elseif threads.paused[mixed] then return threads.all[threads.paused[mixed]] elseif threads.all[mixed] then return threads.all[mixed] @@ -63,33 +70,29 @@ end --- Adds a thread into the resolve queue, can be used to lower lag -- @usage Server.queue_thread(thread) -- return true/false --- @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 +-- @tparam Server._thread thread_to_queue the thread to be added to the queue, must be open and have a on_resolve function +-- @treturn boolean was it added successfuly 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 - table.insert(Server._threads().queue,thread_to_queue.uuid) + table.insert(global.queue,thread_to_queue.uuid) return true end --- Closes all active threads, can use force if it causes errors --- @usage Server.close_all_threads() --- Server.close_all_threads(true) -- use if no force makes errors +-- @usage Server.close_all_threads() -- asks all threads to close +-- @usage Server.close_all_threads(true) -- forcefuly close all threads -- @tparam bolean with_force use force when closing function Server.close_all_threads(with_force) if not with_force then - for uuid,next_thread in pairs(Server.threads()) do - if uuid ~= '_n' then next_thread:close() end - end - else - Server._threads(true) - end + for uuid,thread in pairs(Server.threads) do thread:close() end + else global(true) end end --- Runs all the theads which have opened with an on_tick event -- @usage Server.run_tick_threads() function Server.run_tick_threads() - table.each(Server._threads().tick,function(uuid) + table.each(global.tick,function(uuid) local next_thread = Server.get_thread(uuid) if next_thread and next_thread:valid() and next_thread._tick then local success, err = pcall(next_thread._tick,next_thread) @@ -101,7 +104,7 @@ end --- Checks the timeout on all active timeout threads -- @usage Server.check_timeouts() function Server.check_timeouts() - table.each(Server._threads().timeout,function(uuid) + table.each(global.timeout,function(uuid) local next_thread = Server.get_thread(uuid) if next_thread and next_thread:valid() then next_thread:check_timeout() @@ -109,35 +112,51 @@ function Server.check_timeouts() end) end --- for use in debuging -function Server._thread_handler_debuger(player,event,state) +--- Used to print event info to a player +-- @usage Server._thread_debuger('Cooldude2606','on_player_died',true) -- will output event info to 'Cooldude2606' for 'on_player_died' +-- @tparam ?name|index|LuaPlayer player the player that the info will be returned to +-- @tparam ?name|index event the event that info will be returned fo +-- @tparam[opt=toggle] boolean state will info be returned, nil to toggle current state +function Server._thread_debuger(player,event,state) local player = Game.get_player(player) - local print_to = Server._threads().print_to + local event = tonumber(event) or Manager.event.names[event] + local print_to = global.print_to print_to[player.index] = print_to[player.index] or {} - print_to[player.index][event] = state + if state then print_to[player.index][event] = state + elseif print_to[player.index][event] then print_to[player.index][event] = false + else print_to[player.index][event] = true end end + --- Calles all threads on a certain game event (used with script.on_event) +-- @local Server._thread_handler +-- @usage script.on_event(defines.events,Server._thread_handler) -- adds this handler -- @tparam table event the event that is called function Server._thread_handler(event) - table.each(Server._threads().print_to,function(print_to,player_index,event) + -- returns to players who have set _thread_debuger to trye + table.each(global.print_to,function(print_to,player_index,event) if event.name == defines.events.on_tick then return true end if print_to[event.name] then player_return(event,defines.textcolor.bg,player_index) end end,event) + -- gets the thread uuids local event_id = event.name - local threads = Server._threads().events[event_id] + local threads = global.events[event_id] if not threads then return end + -- loops over the uuids table.each(threads,function(uuid) - local next_thread = Server.get_thread(uuid) - if next_thread and next_thread:valid() then - if is_type(next_thread._events[event_id],'function') then - local success, err = pcall(next_thread._events[event_id],next_thread,event) - if not success then next_thread:error(err) end + local thread = Server.get_thread(uuid) + if thread and thread:valid() then + if is_type(thread._events[event_id],'function') then + -- runs the function in the same env it was created (avoids desyncs) + local sandbox, success, err = Manager.sandbox(thread._events[event_id],thread._env,thread,event) + -- if there is an error it asks the thread to deal with it + if not success then thread:error(err) end end end end) end +script.on_event(defines.events,Server._thread_handler) --[[ cant be used V --- Adds a event handler to tell threads about events @@ -146,78 +165,96 @@ end -- @treturn bolean if the handler was added function Server.add_thread_handler(event) if not is_type(event,'number') then return false end - local threads = Server._threads() + local threads = global if not threads.events[event] then threads.events[event] = {} - Event.register(event,Server._thread_handler) + script.on_event(event,Server._thread_handler) return true end return false end ]] ---- Given a string or function it will run that function and return any values +--- Acts as a bypass for running functions, can accept a string -- @usage Server.interface('local x = 1+1 print(x) return x') -- return 2 --- Server.interface('local x = 1+1 print(x)',thread) -- no return --- @param callback either a function or string which will be ran via pcall --- @param[opt] use_thread give a thread for the interface to run on (does not need to be open, but cant use on_resolve) +-- @usage Server.interface('local x = 1+1 print(x)',true) -- will creat a thread to run as root (this is the bypass) +-- @tparam ?string|function callback function to be ran +-- @tparam[opt] ?Server._thread|true use_thread run the command on a premade thread or let it make its own +-- @tparam[opt] table env run the env to run the command in must have _env key as true to be -- @param[opt] ... any args you want to pass to the function -function Server.interface(callback,use_thread,...) +-- @return if no thread then it will return the value(s) returned by the callback +function Server.interface(callback,use_thread,env,...) if use_thread then - if use_thread == true then use_thread = Server.new_thread{data={callback,...}} end + -- if use_thread is true then it makes a new thread + if use_thread == true then use_thread = Server.new_thread{data={callback,env,...}} end + -- creates the resolve function for the thread use_thread:on_event('resolve',function(thread) - if is_type(thread.data[1],'function') then - local success, err = pcall(unpack(thread.data)) + local callback = table.remove(thread.data,1) + callback = is_type(callback,'function') and callback or loadstring(callback) + local env = table.remove(thread.data,1) + if is_type(env,'table') and env._env == true then + local sandbox, success, err = Manager.sandbox(callback,env,unpack(thread.data)) if not success then error(err) end return err else - local callback = table.remove(thread.data,1) - local success, err = pcall(loadstring(callback),unpack(thread.data)) + local sandbox, success, err = Manager.sandbox(callback,{},env,unpack(thread.data)) if not success then error(err) end return err end end) + -- opens the thread and then queues it use_thread:open() Server.queue_thread(use_thread) else - if is_type(callback,'function') then - local success, err = pcall(callback,...) - return success, err + local callback = is_type(callback,'function') and callback or loadstring(callback) + if is_type(env,'table') and env._env == true then + local sandbox, success, err = Manager.sandbox(callback,env,unpack(thread.data)) + if not success then error(err) end + return err else - local success, err = pcall(loadstring(callback),...) - return success, err + local sandbox, success, err = Manager.sandbox(callback,{},env,unpack(thread.data)) + if not success then error(err) end + return err end - return false end end --- thread allows you to run fuinction async to the main game +--- The class for the server threads, allows abbilty to run async function +-- @class Thread +-- @alias Server._thread +Server._thread = {} + --- Returns a new thread object -- @usage new_thread = thread:create() --- @tparam[opt={}] table obj all are opt {timeout=int,name=str,data=any} advanced users can prefix with _function to avoid the on_function functions --- @treturn table the new thread object +-- @tparam[opt={}] table obj all values are opt {timeout=int,name=str,data=any} +-- @treturn Server._thread the new thread object function Server._thread:create(obj) local obj = obj or {} setmetatable(obj,{__index=Server._thread}) - obj.uuid = Server.new_uuid() + obj.uuid = tostring(Server.uuid) + obj._env = get_env() + obj._env.obj = nil -- provents infinte recusion return obj end --- see Server.queue_thread - this just opens it first +--- Opens and queses a thread +-- @usage Server._thread:queue() -- returns true/false +-- @treturn boolean was the thread queued successfuly +-- @see Server.queue_thread function Server._thread:queue() self:open() return Server.queue_thread(self) end --- Test if the thread has all requied parts --- @usage if thread:valid() then end --- @tparam bolean skip_location_check true to skip the location check --- @treturn bolean is the thread valid +-- @usage if thread:valid() then end -- basic test for valid +-- @tparam[opt=false] bolean skip_location_check true to skip the location checking +-- @treturn boolean is the thread valid function Server._thread:valid(skip_location_check) local skip_location_check = skip_location_check or false if is_type(self.uuid,'string') and skip_location_check or is_type(self.opened,'number') and - skip_location_check or is_type(Server._threads().all[self.uuid],'table') and + skip_location_check or is_type(global.all[self.uuid],'table') and is_type(self.timeout) or is_type(self.timeout,'number') and is_type(self.name) or is_type(self.name,'string') and is_type(self._close) or is_type(self._close,'function') and @@ -226,64 +263,78 @@ function Server._thread:valid(skip_location_check) is_type(self._resolve) or is_type(self._resolve,'function') and is_type(self._success) or is_type(self._success,'function') and is_type(self._error) or is_type(self._error,'function') then + -- all above must be true to be vaild, must accept nil and function return true end return false end ---- Opens the thread by storing it in a place the server object can find it +--- Opens the thread; indexs this thread in the global index -- @usage thread:open() -- return true --- @treturn bolean if the thread was opened +-- @treturn bolean if the thread was opened successfuly function Server._thread:open() + -- if the thread is valid and not already opended if not self:valid(true) or self.opened then return false end - local threads = Server._threads() local uuid = self.uuid + -- sets the thread to open, this is the tick it was opened self.opened = game.tick - threads.all[uuid] = threads.all[uuid] or self - threads.all._n = threads.all._n+1 - if threads.paused[self.name] then threads.paused[self.name] = nil end - if is_type(self.timeout,'number') then table.insert(threads.timeout,uuid) end - if is_type(self._tick,'function') then table.insert(threads.tick,uuid) end - if is_type(self.name,'string') then threads.named[self.name] = threads.named[self.name] or self.uuid end + -- creats the global index + global.all[uuid] = global.all[uuid] or self + global.all._n = global.all._n+1 + -- indexs the thread in other places if it has more function + -- if it was paused before (ie did not run any events) then the index is removed from the paused index + if global.paused[self.name] then global.paused[self.name] = nil end + -- if it has a timeout or on_tick handler then it is indexed in those indexs + if is_type(self.timeout,'number') then table.insert(global.timeout,uuid) end + if is_type(self._tick,'function') then table.insert(global.tick,uuid) end + -- if the thread is given a name then a index from the name to uuid is made + if is_type(self.name,'string') then global.named[self.name] = global.named[self.name] or self.uuid end + -- if there are event handlers then it will loop over them and add them to the event index if is_type(self._events,'table') then - table.each(self._events,function(callback,event,threads,uuid) + table.each(self._events,function(callback,event,global,uuid) -- cant be used V --Server.add_thread_handler(event) - if not threads.events[event] then threads.events[event] = {} end - table.insert(threads.events[event],uuid) - end,threads,self.uuid) + if not global.events[event] then global.events[event] = {} end + table.insert(global.events[event],uuid) + end,global,self.uuid) end return true end ---- Inverse of thread:open() - it removes the thread and calles on_close +--- Inverse of thread:open() - Removes all indexs to this thread, most cases this will cause it to become inassible -- @usage thread:close() -- return true --- @treturn bolean if the thread had a on_close function +-- @treturn boolean if the thread had a on_close function function Server._thread:close() - local threads = Server._threads() local uuid = self.uuid local _return = false + -- if there is a call to the threads on close event, will later return true if is_type(self._close,'function') then pcall(self._close,self) _return = true end - local value,key = table.find(threads.queue,function(v,k,uuid) return v == uuid end,uuid) - if key then table.remove(threads.queue,key) end - local value,key = table.find(threads.timeout,function(v,k,uuid) return v == uuid end,uuid) - if key then table.remove(threads.timeout,key) end - local value,key = table.find(threads.tick,function(v,k,uuid) return v == uuid end,uuid) - if key then table.remove(threads.tick,key) end + -- will search every possible location for this thread and remove it + local value,key = table.find(global.queue,function(v,k,uuid) return v == uuid end,uuid) + if key then table.remove(global.queue,key) end -- queue + local value,key = table.find(global.timeout,function(v,k,uuid) return v == uuid end,uuid) + if key then table.remove(global.timeout,key) end -- timeouts + local value,key = table.find(global.tick,function(v,k,uuid) return v == uuid end,uuid) + if key then table.remove(global.tick,key) end -- on_tick + -- then will look for it in the event handlers and remove it if found if is_type(self._events,'table') then table.each(self._events,function(callback,event) - if threads.events[event] then - local value,key = table.find(threads.events[event],function(v,k,uuid) return v == uuid end,uuid) - if key then table.remove(threads.events[event],key) end + if global.events[event] then + local value,key = table.find(global.events[event],function(v,k,uuid) return v == uuid end,uuid) + if key then table.remove(global.events[event],key) end -- cant be used V - --if #threads.events[event] == 0 then Event.remove(event,Server.game_event) threads.events[event] = nil end + --if #global.events[event] == 0 then Event.remove(event,Server.game_event) global.events[event] = nil end end end) end + -- sets the thread to closed self.opened=nil + -- unless the thread has a name or is assied to be reopened if self.reopen == true then self:open() else - if is_type(self.name,'string') then threads.paused[self.name]=self.uuid - else threads.all[uuid] = nil threads.all._n = threads.all._n-1 end + -- if it has a name but not assied to reopen then it will become 'pasued' + if is_type(self.name,'string') then global.paused[self.name]=self.uuid + -- else it will just be wiped from the global index + else global.all[uuid] = nil global.all._n = global.all._n-1 end end return _return end @@ -294,107 +345,105 @@ end -- @treturn bolean true if the thread called on_success or on_error function Server._thread:resolve(...) local _return = false + -- checks if the resolve haddler is still present if is_type(self._resolve,'function') then - local success, err = pcall(self._resolve,self,...) + local sandbox, success, err = Manager.sandbox(self._resolve,thread._env,self,...) if success then + -- if it was successful then it will attemp to call the success handler if is_type(self._success,'function') then - Server.interface(function(thread,err) - local success,err = pcall(thread._success,thread,err) + -- interface is used as a way to delay the success call till the next tick + Server.interface(function(thread,err) + local sandbox, success, err = Manager.sandbox(thread._success,thread._env,thread,err) if not success then thread:error(err) end end,true,self,err) + -- later returns true if there was a call to the success handler _return = true end - else - _return = self:error(err) - end + -- if there is an error the thread is asked to deal with it, returns true/false based on result of handler + else _return = self:error(err) end end + -- closes the thread as it is no longer needed as its command has be ran self:close() return _return end ---- Checks the timeout on a thread - if timedout then it calles on_timeout and closes +--- Checks the timeout on a thread - if timed out then it calles on_timeout and closes -- @usage thread:check_timeout() -- return true --- @treturn bolean if the thread timedout +-- @treturn bolean if the thread timed out function Server._thread:check_timeout() local _return = false + -- makes sure the thread is still valid if not self:valid() then return false end + -- checks if the thread has been opened longer than its time out period if is_type(self.timeout,'number') and game.tick >= (self.opened+self.timeout) then if is_type(self._timeout,'function') then - pcall(self._timeout,self) + -- we do not care if the time out has caused an error as it is in most cases an error in its own right + Manager.sandbox(self._timeout,thread._env,self) end _return = true + -- closes the thread to provent any further event calls self:close() end return _return end ---- Rasies an error on this thread +--- Used to check and raise the error handler of the thread, if not present it raises an error -- @usage thread:error(err) -- return true --- @param err the err to be rasied --- @treturn bolean did the thread handdle the error +-- @tparam string err the err to be rasied +-- @treturn boolean did the thread have an error handler function Server._thread:error(err) local _return = false if is_type(self._error,'function') then pcall(self._error,self,err) _return = true - else - error(err) - end + else error(err) end return _return end ---- 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 --- @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 --- @tparam string event the name of the event that it is called on --- @tparam function callback the function which is called on the event --- @treturn table returns self so that there can be chained + +--- Set function to run then an event is triggered, none of them are 'needed' but you are advised to have atleast one +-- @usage thread:on_event('close',function) -- if event is not one below then a game event is used +-- @usage thread_only_events = ['close','timeout','tick','resolve','success','error'] +-- @tparam ?string|index event the name of the event that the function should be called on +-- @tparam function callback the function which is called by the event trigger +-- @treturn table returns self so that they can be chained together function Server._thread:on_event(event,callback) local events = {'close','timeout','tick','resolve','success','error'} + -- seaches the above list for the event local value = table.find(events,function(v,k,find) return v == string.lower(find) end,event) if value and is_type(callback,'function') then + -- if it is a thread_only_event then it will add it to its core values self['_'..value] = callback elseif is_type(event,'number') and is_type(callback,'function') then + -- other wise it is appended to the event index of the thread if not self._events then self._events = {} end self._events[event] = callback end + -- returns self to allowing chaining of on_event():on_event():on_event() etc.. return self end -Event.register(defines.events.on_tick,function(event) +script.on_event(defines.events.on_tick,function(event) + -- uses its own on_tick event so that other actions can be tested for if event.tick < 10 then return end - local threads = Server._threads() - if #threads.tick > 0 then Server.run_tick_threads() end - if #threads.timeout > 0 then Server.check_timeouts() end - if #threads.queue > 0 then - local current_thread = threads.all[threads.queue[1]] + if #global.tick > 0 then Server.run_tick_threads() end -- on tick events + if #global.timeout > 0 then Server.check_timeouts() end -- timeout checks + if #global.queue > 0 then -- resolve one thread + local current_thread = global.all[global.queue[1]] if current_thread and current_thread:valid() then current_thread:resolve() end end end) -Event.register(-2,function(event) - local threads = Server.threads() - for uuid,thread in pairs(threads) do - if uuid ~= '_n' then setmetatable(thread,{__index=Server._thread}) end - end +script.on_event(-2,function(event) + -- sets up metatable again so that threads contiune to work + for uuid,thread in pairs(Server.threads) do setmetatable(thread,{__index=Server._thread}) end end) Server.on_init=function(self) - Event.register(defines.events,Server._thread_handler) - if pcall(function() return commands._expgaming end) then - commands.add_command('interface', 'Runs the given input from the script', {'code',true}, function(event,args) - local callback = args.code - if not string.find(callback,'%s') and not string.find(callback,'return') then callback = 'return '..callback end - if game.player then callback = 'local player, surface, force, position, entity, tile = game.player, game.player.surface, game.player.force, game.player.position, game.player.selected, game.player.surface.get_tile(game.player.position);'..callback end - if Ranking and Ranking.get_rank and game.player then callback = 'local rank = Ranking.get_rank(game.player);'..callback end - local success, err = Server.interface(callback) - if not success and is_type(err,'string') then local _end = string.find(err,'stack traceback') if _end then err = string.sub(err,0,_end-2) end end - if err or err == false then player_return(err) end - end) - end + if loaded_modules.commands then require(module_path..'/src/commands') end end return Server + --[[ Thread Example: @@ -424,5 +473,22 @@ return Server end) thread:open() - all on_event functions can be chained from the thread creation rather than use varibles + all on_event functions can be chained from the thread creation rather than use varibles eg: + Server.new_thread{ + name='tree-decon', + data={} + }:on_event('tick',function(self) + local trees = self.data + if #trees == 0 then return end + local tree = table.remove(trees,1) + if tree.valid then tree.destroy() end + end):on_event('error',function(self,err) + -- cant see how this can cause an error + -- but this is where error handling goes + -- any event including on_resolve and on_tick can raise this + end):on_event(defines.events.on_marked_for_deconstruction,function(self,event) + if event.entity.type == 'tree' then + table.insert(self.data,event.entity) + end + end):open() ]] \ No newline at end of file diff --git a/modules/ExpGamingCore/Server/src/commands.lua b/modules/ExpGamingCore/Server/src/commands.lua new file mode 100644 index 00000000..ce8ccd35 --- /dev/null +++ b/modules/ExpGamingCore/Server/src/commands.lua @@ -0,0 +1,31 @@ +--- Description - A small description that will be displayed on the doc +-- @submodule ExpGamingCore.Server +-- @alias Server +-- @author Cooldude2606 +-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE + +--- This file will be loaded when ExpGamingCore.Commands is present +-- @function _comment + +commands.add_command('interface', 'Runs the given input from the script', {'code',true}, function(event,args) + local callback = args.code + -- looks for spaces, if non the it will prefix the command with return + if not string.find(callback,'%s') and not string.find(callback,'return') then callback = 'return '..callback end + -- sets up an env for the command to run in + local env = {_env=true,} + if game.player then + env.player = game.player + env.surface = game.player.surface + env.force = game.player.force + env.position = game.player.position + env.entity = game.player.selected + env.tile = game.player.surface.get_tile(game.player.position) + if Ranking and Ranking.get_rank then env.rank = Ranking.get_rank(game.player) end + end + -- runs the function + local success, err = Server.interface(callback,false,env) + -- if there is an error then it will remove the stacktrace and return the error + if not success and is_type(err,'string') then local _end = string.find(err,'stack traceback') if _end then err = string.sub(err,0,_end-2) end end + -- if there is a value returned that is not nill then it will return that value + if err or err == false then player_return(err) end +end) \ No newline at end of file diff --git a/modules/ExpGamingCore/Sync/control.lua b/modules/ExpGamingCore/Sync/control.lua index 00a0bdc0..d1ee6a31 100644 --- a/modules/ExpGamingCore/Sync/control.lua +++ b/modules/ExpGamingCore/Sync/control.lua @@ -1,4 +1,4 @@ ---- Description - A small description that will be displayed on the doc +--- Allows syncing with an outside server and info panle. -- @module ExpGamingCore.Sync -- @alias Sync -- @author Cooldude2606 @@ -6,19 +6,28 @@ local Sync = {} local Sync_updates = {} --- sets up the global for this module -global{ - server_name='Factorio Server', - server_description='A factorio server for everyone', - reset_time='On Demand', - time='Day Mth 00 00:00:00 UTC Year', - time_set={0,'0.00M'}, - last_update={0,'0.00M'}, - time_period={18000,'5.00M'}, - players={online={'Offline'},n_online=0,all={'Offline'},n_all=0,admins_online=0,afk_players=0,times={'Offline'}}, - ranks={'Offline'}, - rockets=0, - mods={'Offline'} +--- Global Table +-- @table global +local global = global{ + server_name='Factorio Server', -- the server name + server_description='A factorio server for everyone', -- a short description of the server + reset_time='On Demand', -- the reset time of the server + time='Day Mth 00 00:00:00 UTC Year', -- the last knowen irl time + time_set={0,'0.00M'}, -- the last in game time that the time was set + last_update={0,'0.00M'}, -- the last time that this info was updated + time_period={18000,'5.00M'}, -- how often this infomation is updated + players={ + online={'Offline'}, -- list of all players online + n_online=0, -- the number of players online + all={'Offline'}, -- list of all player on or offline + n_all=0, -- the number of players who have joined the server + admins_online=0, -- the number of admins online + afk_players=0, -- the number of afk players + times={'Offline'} -- the play times of every player + }, -- a sub list of players in the game + ranks={'Offline'}, -- a list of player ranks + rockets=0, -- the number of rockets launched + mods={'Offline'} -- the mods which are loaded } --- Used to standidise the tick format for any sync info diff --git a/modules/ExpGamingCore/Sync/src/gui.lua b/modules/ExpGamingCore/Sync/src/gui.lua index 9b120853..dc3b4b23 100644 --- a/modules/ExpGamingCore/Sync/src/gui.lua +++ b/modules/ExpGamingCore/Sync/src/gui.lua @@ -4,7 +4,7 @@ -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE ---- This file will be loaded when ExpGamingCore/Gui is present +--- This file will be loaded when ExpGamingCore.Gui is present -- @function _comment local Sync_gui_functions = {} diff --git a/modules/ExpGamingCore/Sync/src/ranking.lua b/modules/ExpGamingCore/Sync/src/ranking.lua index 4925290b..fa719f2e 100644 --- a/modules/ExpGamingCore/Sync/src/ranking.lua +++ b/modules/ExpGamingCore/Sync/src/ranking.lua @@ -4,7 +4,7 @@ -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE ---- This file will be loaded when ExpGamingCore/Ranking is present +--- This file will be loaded when ExpGamingCore.Ranking is present -- @function _comment --- Used as a redirect to Ranking._base_preset that will set the rank given to a player apon joining diff --git a/modules/ExpGamingCore/softmod.json b/modules/ExpGamingCore/softmod.json index 2515b2d7..752d42c8 100644 --- a/modules/ExpGamingCore/softmod.json +++ b/modules/ExpGamingCore/softmod.json @@ -52,6 +52,7 @@ "location": "url", "dependencies": { "ExpGamingLib": ">=3.0.0", + "FactorioStdLib.Table": ">=0.8.0", "ExpGamingCore/Ranking": "?>=3.0.0", "ExpGamingCore/Commands": "?>=3.0.0" } diff --git a/modules/ExpGamingLib/control.lua b/modules/ExpGamingLib/control.lua index 07d852d9..b44bf297 100644 --- a/modules/ExpGamingLib/control.lua +++ b/modules/ExpGamingLib/control.lua @@ -1,17 +1,9 @@ ---[[ -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----------------------------------------------------------- - --- Adds some common functions used though out all ExpGaming modules -- @module ExpGamingLib -- @alias ExpLib -- @author Cooldude2606 +-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE + local module_verbose = false -- there is no verbose in this file so true will do nothing local ExpLib = {} diff --git a/modules/index.lua b/modules/index.lua index 873f1090..08e83cdb 100644 --- a/modules/index.lua +++ b/modules/index.lua @@ -12,6 +12,6 @@ return { --['Ranking']='/modules/ExpGamingCore/Ranking', --['commands']='/modules/ExpGamingCore/Commands', --['Gui']='/modules/ExpGamingCore/Gui', - --['Server']='/modules/ExpGamingCore/Server', + ['Server']='/modules/ExpGamingCore/Server', ['Sync']='/modules/ExpGamingCore/Sync', } \ No newline at end of file From 4d05f13cb39245404ba2eb9e26f98157e8c2968d Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 1 Jun 2018 16:30:32 +0100 Subject: [PATCH 022/231] Updated Doc --- config.ld | 1 + doc/index.html | 10 +- doc/modules/ExpGamingCore.Server.html | 835 ++++++++++++++++++ doc/modules/ExpGamingCore.Sync.html | 122 ++- doc/modules/ExpGamingLib.html | 5 +- doc/modules/FSM.html | 43 +- doc/modules/StdLib.Color.html | 4 +- doc/modules/StdLib.Game.html | 4 +- doc/modules/StdLib.String.html | 4 +- doc/modules/StdLib.Table.html | 4 +- doc/modules/StdLib.Time.html | 4 +- ...odules.expgamingcore.commands.control.html | 4 +- .../modules.expgamingcore.gui.control.html | 4 +- ...les.expgamingcore.gui.guiparts.center.html | 4 +- ...les.expgamingcore.gui.guiparts.inputs.html | 4 +- ...dules.expgamingcore.gui.guiparts.left.html | 4 +- ...ules.expgamingcore.gui.guiparts.popup.html | 4 +- ...es.expgamingcore.gui.guiparts.toolbar.html | 4 +- ...modules.expgamingcore.ranking.control.html | 4 +- .../modules.expgamingcore.server.control.html | 566 ------------ modules/ExpGamingCore/Server/control.lua | 29 +- modules/ExpGamingCore/Server/src/commands.lua | 3 + modules/ExpGamingCore/Sync/control.lua | 58 +- 23 files changed, 1082 insertions(+), 642 deletions(-) create mode 100644 config.ld create mode 100644 doc/modules/ExpGamingCore.Server.html delete mode 100644 doc/modules/modules.expgamingcore.server.control.html diff --git a/config.ld b/config.ld new file mode 100644 index 00000000..9efa37a4 --- /dev/null +++ b/config.ld @@ -0,0 +1 @@ +new_type('command','Commands',false,'param') \ No newline at end of file diff --git a/doc/index.html b/doc/index.html index 7dbc8d4a..9feb5b9d 100644 --- a/doc/index.html +++ b/doc/index.html @@ -40,7 +40,7 @@
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • modules.expgamingcore.ranking.control
  • -
  • modules.expgamingcore.server.control
  • +
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • StdLib.Color
  • @@ -95,12 +95,12 @@ Returns a rank object given a player or rank name - modules.expgamingcore.server.control - Returns a un-used uuid (better system needed) + ExpGamingCore.Server + Adds a thread system and event listening and a admin bypass (recommend to disable /c and use optional /interface) ExpGamingCore.Sync - Description - A small description that will be displayed on the doc + Allows syncing with an outside server and info panle. ExpGamingLib @@ -132,7 +132,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
    diff --git a/doc/modules/ExpGamingCore.Server.html b/doc/modules/ExpGamingCore.Server.html new file mode 100644 index 00000000..e6a302f3 --- /dev/null +++ b/doc/modules/ExpGamingCore.Server.html @@ -0,0 +1,835 @@ + + + + + Reference + + + + +
    + +
    + +
    +
    +
    + + +
    + + + + + + +
    + +

    Module ExpGamingCore.Server

    +

    Adds a thread system and event listening and a admin bypass (recommend to disable /c and use optional /interface)

    +

    +

    Info:

    +
      +
    • License: https://github.com/explosivegaming/scenario/blob/master/LICENSE
    • +
    • Author: Cooldude2606
    • +
    + + +

    Functions

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    new_thread (obj)Generates a new thread object
    get_thread (mixed)Used to get a thread via uuid or name (if one is assied)
    queue_thread (thread_to_queue)Adds a thread into the resolve queue, can be used to lower lag
    close_all_threads (with_force)Closes all active threads, can use force if it causes errors
    run_tick_threads ()Runs all the theads which have opened with an on_tick event
    check_timeouts ()Checks the timeout on all active timeout threads
    _thread_debuger (player, event[, state=toggle])Used to print event info to a player
    interface (callback[, use_thread[, env[, ...]]])Acts as a bypass for running functions, can accept a string
    +

    Tables

    + + + + + +
    globalGlobal Table
    +

    Fields

    + + + + + + + + + +
    uuidUsed to generate a new uuid for the thread system
    threadsRedirect to the thread index
    +

    Class Thread

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Server._thread:create ([obj={}])Returns a new thread object
    Server._thread:queue ()Opens and queses a thread
    Server._thread:valid ([skip_location_check=false])Test if the thread has all requied parts
    Server._thread:open ()Opens the thread; indexs this thread in the global index
    Server._thread:close ()Inverse of thread:open() - Removes all indexs to this thread, most cases this will cause it to become inassible
    Server._thread:resolve ([...])Trigger the on_resolve function and closes the thread - error and success called based on result of pcall (useful for async)
    Server._thread:check_timeout ()Checks the timeout on a thread - if timed out then it calles on_timeout and closes
    Server._thread:error (err)Used to check and raise the error handler of the thread, if not present it raises an error
    Server._thread:on_event (event, callback)Set function to run then an event is triggered, none of them are 'needed' but you are advised to have atleast one
    +

    modules.expgamingcore.server.src.commands Functions

    + + + + + + + + + +
    _comment ()This file will be loaded when ExpGamingCore.Commands is present
    interfaceRuns the given input from the script
    + +
    +
    + + +

    Functions

    + +
    +
    + + new_thread (obj) +
    +
    + Generates a new thread object + + +

    Parameters:

    +
      +
    • obj + table + the atributes to give to the thread +
    • +
    + +

    Returns:

    +
      + + Server._thread + the new thread created +
    + + + +

    Usage:

    +
      +
      Server.new_thread{name='foo',data={}}
      +
    + +
    +
    + + get_thread (mixed) +
    +
    + Used to get a thread via uuid or name (if one is assied) + + +

    Parameters:

    +
      +
    • mixed + either a uuid or the name given to a thread +
    • +
    + +

    Returns:

    +
      + + Server._thread + the thread by that name or uuid +
    +

    Or

    +
      + + boolean + if false is returned then no thread existes +
    + + + +

    Usage:

    +
      +
      Server.get_thread('decon') -- return thread
      +
    + +
    +
    + + queue_thread (thread_to_queue) +
    +
    + Adds a thread into the resolve queue, can be used to lower lag + + +

    Parameters:

    +
      +
    • thread_to_queue + Server._thread + the thread to be added to the queue, must be open and have a on_resolve function +
    • +
    + +

    Returns:

    +
      + + boolean + was it added successfuly +
    + + + +

    Usage:

    +
      +
      Server.queue_thread(thread) -- return true/false
      +
    + +
    +
    + + close_all_threads (with_force) +
    +
    + Closes all active threads, can use force if it causes errors + + +

    Parameters:

    +
      +
    • with_force + bolean + use force when closing +
    • +
    + + + + +

    Usage:

    +
      +
    • Server.close_all_threads() -- asks all threads to close
    • +
    • Server.close_all_threads(true) -- forcefuly close all threads
    • +
    + +
    +
    + + run_tick_threads () +
    +
    + Runs all the theads which have opened with an on_tick event + + + + + + +

    Usage:

    +
      +
      Server.run_tick_threads()
      +
    + +
    +
    + + check_timeouts () +
    +
    + Checks the timeout on all active timeout threads + + + + + + +

    Usage:

    +
      +
      Server.check_timeouts()
      +
    + +
    +
    + + _thread_debuger (player, event[, state=toggle]) +
    +
    + Used to print event info to a player + + +

    Parameters:

    +
      +
    • player + name, index or LuaPlayer + the player that the info will be returned to +
    • +
    • event + name or index + the event that info will be returned fo +
    • +
    • state + boolean + will info be returned, nil to toggle current state + (default toggle) +
    • +
    + + + + +

    Usage:

    +
      +
      Server._thread_debuger('Cooldude2606','on_player_died',true) -- will output event info to 'Cooldude2606' for 'on_player_died'
      +
    + +
    +
    + + interface (callback[, use_thread[, env[, ...]]]) +
    +
    + Acts as a bypass for running functions, can accept a string + + +

    Parameters:

    +
      +
    • callback + string or function + function to be ran +
    • +
    • use_thread + Server._thread or true + run the command on a premade thread or let it make its own + (optional) +
    • +
    • env + table + run the env to run the command in must have _env key as true to be + (optional) +
    • +
    • ... + any args you want to pass to the function + (optional) +
    • +
    + +

    Returns:

    +
      + + if no thread then it will return the value(s) returned by the callback +
    + + + +

    Usage:

    +
      +
    • Server.interface('local x = 1+1 print(x) return x') -- return 2
    • +
    • Server.interface('local x = 1+1 print(x)',true) -- will creat a thread to run as root (this is the bypass)
    • +
    + +
    +
    +

    Tables

    + +
    +
    + + global +
    +
    + Global Table + + +

    Fields:

    +
      +
    • all + a list of every thread (indexed by uuid) +
    • +
    • queue + an index for threads which will be resolved (contains uuids) +
    • +
    • tick + an index for threads which will run every tick (contains uuids) +
    • +
    • timeout + an index for threads which will timeout (contains uuids) +
    • +
    • events + an index of threads based on event ids (contains uuids) +
    • +
    • paused + an index of pasued threads (contains uuids) +
    • +
    • named + a name index for thread uuids +
    • +
    • print_to + contains players that event details will be printed to +
    • +
    • uuid + contains the random number generator for the uuid system +
    • +
    + + + + + +
    +
    +

    Fields

    + +
    +
    + + uuid +
    +
    + Used to generate a new uuid for the thread system + + + + + + +

    Usage:

    +
      +
      local uuid = tostring(Server.uuid) -- calling tostring locks the value
      +
    + +
    +
    + + threads +
    +
    + Redirect to the thread index + + + + + + +

    Usage:

    +
      +
    • Server.threads -- return #global.all
    • +
    • Server.threads -- return global.all
    • +
    + +
    +
    +

    Class Thread

    + +
    + The class for the server threads, allows abbilty to run async function +
    +
    +
    + + Server._thread:create ([obj={}]) +
    +
    + Returns a new thread object + + +

    Parameters:

    +
      +
    • obj + table + all values are opt {timeout=int,name=str,data=any} + (default {}) +
    • +
    + +

    Returns:

    +
      + + Server._thread + the new thread object +
    + + + +

    Usage:

    +
      +
      new_thread = thread:create()
      +
    + +
    +
    + + Server._thread:queue () +
    +
    + Opens and queses a thread + + + +

    Returns:

    +
      + + boolean + was the thread queued successfuly +
    + + +

    See also:

    + + +

    Usage:

    +
      +
      Server._thread:queue() -- returns true/false
      +
    + +
    +
    + + Server._thread:valid ([skip_location_check=false]) +
    +
    + Test if the thread has all requied parts + + +

    Parameters:

    +
      +
    • skip_location_check + bolean + true to skip the location checking + (default false) +
    • +
    + +

    Returns:

    +
      + + boolean + is the thread valid +
    + + + +

    Usage:

    +
      +
      if thread:valid() then end -- basic test for valid
      +
    + +
    +
    + + Server._thread:open () +
    +
    + Opens the thread; indexs this thread in the global index + + + +

    Returns:

    +
      + + bolean + if the thread was opened successfuly +
    + + + +

    Usage:

    +
      +
      thread:open() -- return true
      +
    + +
    +
    + + Server._thread:close () +
    +
    + Inverse of thread:open() - Removes all indexs to this thread, most cases this will cause it to become inassible + + + +

    Returns:

    +
      + + boolean + 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 timed out then it calles on_timeout and closes + + + +

    Returns:

    +
      + + bolean + if the thread timed out +
    + + + +

    Usage:

    +
      +
      thread:check_timeout() -- return true
      +
    + +
    +
    + + Server._thread:error (err) +
    +
    + Used to check and raise the error handler of the thread, if not present it raises an error + + +

    Parameters:

    +
      +
    • err + string + the err to be rasied +
    • +
    + +

    Returns:

    +
      + + boolean + did the thread have an error handler +
    + + + +

    Usage:

    +
      +
      thread:error(err) -- return true
      +
    + +
    +
    + + Server._thread:on_event (event, callback) +
    +
    + Set function to run then an event is triggered, none of them are 'needed' but you are advised to have atleast one + + +

    Parameters:

    +
      +
    • event + string or index + the name of the event that the function should be called on +
    • +
    • callback + function + the function which is called by the event trigger +
    • +
    + +

    Returns:

    +
      + + table + returns self so that they can be chained together +
    + + + +

    Usage:

    +
      +
    • thread:on_event('close',function) -- if event is not one below then a game event is used
    • +
    • thread_only_events = ['close','timeout','tick','resolve','success','error']
    • +
    + +
    +
    +

    modules.expgamingcore.server.src.commands Functions

    + +
    +
    + + _comment () +
    +
    + This file will be loaded when ExpGamingCore.Commands is present + + + + + + + +
    +
    + + interface +
    +
    + Runs the given input from the script + + +

    param:

    +
      +
    • code + The code that will be ran +
    • +
    + + + + + +
    +
    + + +
    +
    +
    +generated by LDoc 1.4.6 +Last updated 2018-06-01 16:29:39 +
    +
    + + diff --git a/doc/modules/ExpGamingCore.Sync.html b/doc/modules/ExpGamingCore.Sync.html index 7f2b0843..20c91a7f 100644 --- a/doc/modules/ExpGamingCore.Sync.html +++ b/doc/modules/ExpGamingCore.Sync.html @@ -35,8 +35,8 @@
  • Functions
  • Tables
  • Fields
  • -
  • modules.expgamingcore.sync.lib.gui Functions
  • -
  • modules.expgamingcore.sync.lib.ranking Functions
  • +
  • modules.expgamingcore.sync.src.gui Functions
  • +
  • modules.expgamingcore.sync.src.ranking Functions
  • @@ -51,7 +51,7 @@
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • modules.expgamingcore.ranking.control
  • -
  • modules.expgamingcore.server.control
  • +
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • StdLib.Color
  • @@ -66,7 +66,7 @@

    Module ExpGamingCore.Sync

    -

    Description - A small description that will be displayed on the doc

    +

    Allows syncing with an outside server and info panle.

    Info:

      @@ -124,6 +124,14 @@

      Tables

      + + + + + + + + @@ -140,22 +148,22 @@
      globalGlobal Table
      global.playersPlayer sub-table
      EmitEmbededParamaters Outline of the paramaters accepted by Sync.emit_embededUsed to return and set the current IRL time; not very good need a better way to do this
      -

      modules.expgamingcore.sync.lib.gui Functions

      +

      modules.expgamingcore.sync.src.gui Functions

      - +
      _comment ()This file will be loaded when ExpGamingCore/Gui is presentThis file will be loaded when ExpGamingCore.Gui is present
      add_to_gui (element) Adds a emeltent to the sever info gui
      -

      modules.expgamingcore.sync.lib.ranking Functions

      +

      modules.expgamingcore.sync.src.ranking Functions

      - + @@ -486,6 +494,94 @@

      Tables

      +
      + + global +
      +
      + Global Table + + +

      Fields:

      +
        +
      • server_name + the server name +
      • +
      • server_description + a short description of the server +
      • +
      • reset_time + the reset time of the server +
      • +
      • time + the last knowen irl time +
      • +
      • time_set + the last in game time that the time was set +
      • +
      • last_update + the last time that this info was updated +
      • +
      • time_period + how often this infomation is updated +
      • +
      • players + a list of different player related states +
      • +
      • ranks + a list of player ranks +
      • +
      • rockets + the number of rockets launched +
      • +
      • mods + the mods which are loaded +
      • +
      + + + + + +
      +
      + + global.players +
      +
      + Player sub-table + + +

      Fields:

      +
        +
      • online + list of all players online +
      • +
      • n_online + the number of players online +
      • +
      • all + list of all player on or offline +
      • +
      • n_all + the number of players who have joined the server +
      • +
      • admins_online + the number of admins online +
      • +
      • afk_players + the number of afk players +
      • +
      • times + the play times of every player +
      • +
      + + + + + +
      EmitEmbededParamaters @@ -578,7 +674,7 @@
      -

      modules.expgamingcore.sync.lib.gui Functions

      +

      modules.expgamingcore.sync.src.gui Functions

      @@ -586,7 +682,7 @@ _comment ()
      - This file will be loaded when ExpGamingCore/Gui is present + This file will be loaded when ExpGamingCore.Gui is present @@ -626,7 +722,7 @@
      -

      modules.expgamingcore.sync.lib.ranking Functions

      +

      modules.expgamingcore.sync.src.ranking Functions

      @@ -634,7 +730,7 @@ _comment ()
      - This file will be loaded when ExpGamingCore/Ranking is present + This file will be loaded when ExpGamingCore.Ranking is present @@ -698,7 +794,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
      diff --git a/doc/modules/ExpGamingLib.html b/doc/modules/ExpGamingLib.html index 7a44bc2e..7b623237 100644 --- a/doc/modules/ExpGamingLib.html +++ b/doc/modules/ExpGamingLib.html @@ -47,7 +47,7 @@
    • modules.expgamingcore.gui.guiparts.toolbar
    • modules.expgamingcore.gui.control
    • modules.expgamingcore.ranking.control
    • -
    • modules.expgamingcore.server.control
    • +
    • ExpGamingCore.Server
    • ExpGamingCore.Sync
    • ExpGamingLib
    • StdLib.Color
    • @@ -66,6 +66,7 @@

      Info:

        +
      • License: https://github.com/explosivegaming/scenario/blob/master/LICENSE
      • Author: Cooldude2606
      @@ -411,7 +412,7 @@
      generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
      diff --git a/doc/modules/FSM.html b/doc/modules/FSM.html index 6db19fc5..acd010c5 100644 --- a/doc/modules/FSM.html +++ b/doc/modules/FSM.html @@ -34,6 +34,7 @@ @@ -48,7 +49,7 @@
    • modules.expgamingcore.gui.guiparts.toolbar
    • modules.expgamingcore.gui.control
    • modules.expgamingcore.ranking.control
    • -
    • modules.expgamingcore.server.control
    • +
    • ExpGamingCore.Server
    • ExpGamingCore.Sync
    • ExpGamingLib
    • StdLib.Color
    • @@ -118,6 +119,13 @@
      _comment ()This file will be loaded when ExpGamingCore/Ranking is presentThis file will be loaded when ExpGamingCore.Ranking is present
      set_ranks (...) Sub set to Manger.event and acts as a coverter between event_name and event_id
      +

      Fields

      + + + + + +
      globalUsed to avoid conflicts in the global table


      @@ -399,6 +407,37 @@
      Manager.event[event_name]
    + + +

    Fields

    + +
    +
    + + global +
    +
    + Used to avoid conflicts in the global table + + +
      +
    • default + table or true + the default value of global, if true then default is restored + (default {}) +
    • +
    + + + + +

    Usage:

    +
      +
    • global[key] -- used like the normal global table
    • +
    • global{'foo','bar'} -- sets the default value
    • +
    • global(true) -- restores global to default
    • +
    +
    @@ -407,7 +446,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
    diff --git a/doc/modules/StdLib.Color.html b/doc/modules/StdLib.Color.html index 7cc11d31..e2efad66 100644 --- a/doc/modules/StdLib.Color.html +++ b/doc/modules/StdLib.Color.html @@ -48,7 +48,7 @@
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • modules.expgamingcore.ranking.control
  • -
  • modules.expgamingcore.server.control
  • +
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • StdLib.Color
  • @@ -553,7 +553,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
    diff --git a/doc/modules/StdLib.Game.html b/doc/modules/StdLib.Game.html index 5b4f4488..a3d7da7a 100644 --- a/doc/modules/StdLib.Game.html +++ b/doc/modules/StdLib.Game.html @@ -47,7 +47,7 @@
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • modules.expgamingcore.ranking.control
  • -
  • modules.expgamingcore.server.control
  • +
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • StdLib.Color
  • @@ -214,7 +214,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
    diff --git a/doc/modules/StdLib.String.html b/doc/modules/StdLib.String.html index 4d2128bc..b2924c8a 100644 --- a/doc/modules/StdLib.String.html +++ b/doc/modules/StdLib.String.html @@ -47,7 +47,7 @@
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • modules.expgamingcore.ranking.control
  • -
  • modules.expgamingcore.server.control
  • +
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • StdLib.Color
  • @@ -294,7 +294,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
    diff --git a/doc/modules/StdLib.Table.html b/doc/modules/StdLib.Table.html index d2a41200..5a85e0e7 100644 --- a/doc/modules/StdLib.Table.html +++ b/doc/modules/StdLib.Table.html @@ -47,7 +47,7 @@
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • modules.expgamingcore.ranking.control
  • -
  • modules.expgamingcore.server.control
  • +
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • StdLib.Color
  • @@ -1123,7 +1123,7 @@ some_func(1,2)
    generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
    diff --git a/doc/modules/StdLib.Time.html b/doc/modules/StdLib.Time.html index b42b0935..9b5dd816 100644 --- a/doc/modules/StdLib.Time.html +++ b/doc/modules/StdLib.Time.html @@ -47,7 +47,7 @@
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • modules.expgamingcore.ranking.control
  • -
  • modules.expgamingcore.server.control
  • +
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • StdLib.Color
  • @@ -131,7 +131,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
    diff --git a/doc/modules/modules.expgamingcore.commands.control.html b/doc/modules/modules.expgamingcore.commands.control.html index f3323613..bd16c3b0 100644 --- a/doc/modules/modules.expgamingcore.commands.control.html +++ b/doc/modules/modules.expgamingcore.commands.control.html @@ -47,7 +47,7 @@
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • modules.expgamingcore.ranking.control
  • -
  • modules.expgamingcore.server.control
  • +
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • StdLib.Color
  • @@ -124,7 +124,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
    diff --git a/doc/modules/modules.expgamingcore.gui.control.html b/doc/modules/modules.expgamingcore.gui.control.html index 4f951cc4..ab3125b7 100644 --- a/doc/modules/modules.expgamingcore.gui.control.html +++ b/doc/modules/modules.expgamingcore.gui.control.html @@ -47,7 +47,7 @@
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • modules.expgamingcore.ranking.control
  • -
  • modules.expgamingcore.server.control
  • +
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • StdLib.Color
  • @@ -160,7 +160,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
    diff --git a/doc/modules/modules.expgamingcore.gui.guiparts.center.html b/doc/modules/modules.expgamingcore.gui.guiparts.center.html index 7dd28f1a..124667d9 100644 --- a/doc/modules/modules.expgamingcore.gui.guiparts.center.html +++ b/doc/modules/modules.expgamingcore.gui.guiparts.center.html @@ -47,7 +47,7 @@
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • modules.expgamingcore.ranking.control
  • -
  • modules.expgamingcore.server.control
  • +
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • StdLib.Color
  • @@ -278,7 +278,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
    diff --git a/doc/modules/modules.expgamingcore.gui.guiparts.inputs.html b/doc/modules/modules.expgamingcore.gui.guiparts.inputs.html index 82977f9e..7e375716 100644 --- a/doc/modules/modules.expgamingcore.gui.guiparts.inputs.html +++ b/doc/modules/modules.expgamingcore.gui.guiparts.inputs.html @@ -47,7 +47,7 @@
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • modules.expgamingcore.ranking.control
  • -
  • modules.expgamingcore.server.control
  • +
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • StdLib.Color
  • @@ -434,7 +434,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
    diff --git a/doc/modules/modules.expgamingcore.gui.guiparts.left.html b/doc/modules/modules.expgamingcore.gui.guiparts.left.html index 2d78fe94..c08d35f9 100644 --- a/doc/modules/modules.expgamingcore.gui.guiparts.left.html +++ b/doc/modules/modules.expgamingcore.gui.guiparts.left.html @@ -47,7 +47,7 @@
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • modules.expgamingcore.ranking.control
  • -
  • modules.expgamingcore.server.control
  • +
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • StdLib.Color
  • @@ -181,7 +181,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
    diff --git a/doc/modules/modules.expgamingcore.gui.guiparts.popup.html b/doc/modules/modules.expgamingcore.gui.guiparts.popup.html index 6309f7b2..e73fe754 100644 --- a/doc/modules/modules.expgamingcore.gui.guiparts.popup.html +++ b/doc/modules/modules.expgamingcore.gui.guiparts.popup.html @@ -47,7 +47,7 @@
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • modules.expgamingcore.ranking.control
  • -
  • modules.expgamingcore.server.control
  • +
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • StdLib.Color
  • @@ -126,7 +126,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
    diff --git a/doc/modules/modules.expgamingcore.gui.guiparts.toolbar.html b/doc/modules/modules.expgamingcore.gui.guiparts.toolbar.html index 483c4c9f..e27ca143 100644 --- a/doc/modules/modules.expgamingcore.gui.guiparts.toolbar.html +++ b/doc/modules/modules.expgamingcore.gui.guiparts.toolbar.html @@ -47,7 +47,7 @@
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • modules.expgamingcore.ranking.control
  • -
  • modules.expgamingcore.server.control
  • +
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • StdLib.Color
  • @@ -117,7 +117,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
    diff --git a/doc/modules/modules.expgamingcore.ranking.control.html b/doc/modules/modules.expgamingcore.ranking.control.html index 690fa714..8e203aae 100644 --- a/doc/modules/modules.expgamingcore.ranking.control.html +++ b/doc/modules/modules.expgamingcore.ranking.control.html @@ -47,7 +47,7 @@
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • modules.expgamingcore.ranking.control
  • -
  • modules.expgamingcore.server.control
  • +
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • StdLib.Color
  • @@ -374,7 +374,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-05-31 00:41:31 +Last updated 2018-06-01 16:29:39
    diff --git a/doc/modules/modules.expgamingcore.server.control.html b/doc/modules/modules.expgamingcore.server.control.html deleted file mode 100644 index 603165ee..00000000 --- a/doc/modules/modules.expgamingcore.server.control.html +++ /dev/null @@ -1,566 +0,0 @@ - - - - - Reference - - - - -
    - -
    - -
    -
    -
    - - -
    - - - - - - -
    - -

    Module modules.expgamingcore.server.control

    -

    Returns a un-used uuid (better system needed)

    -

    -

    Usage:

    -
      -
      obj.uuid = Server.new_uuid()
      -
      -
    - - -

    Functions

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Server.threads ([count=nil])Returns either the number of threads or a able of threads
    Server.get_thread (mixed)Used to get a thread via it's uuid or by name if one is given
    Server.queue_thread (thread_to_queue)Adds a thread into the resolve queue, can be used to lower lag
    Server.close_all_threads (with_force)Closes all active threads, can use force if it causes errors
    Server.run_tick_threads ()Runs all the theads which have opened with an on_tick event
    Server.check_timeouts ()Checks the timeout on all active timeout threads
    Server._thread_handler (event)Calles all threads on a certain game event (used with script.on_event)
    Server.interface (callback[, use_thread[, ...]])Given a string or function it will run that function and return any values
    Server._thread:valid (skip_location_check)Test if the thread has all requied parts
    Server._thread:open ()Opens the thread by storing it in a place the server object can find it
    Server._thread:close ()Inverse of thread:open() - it removes the thread and calles on_close
    Server._thread:resolve ([...])Trigger the on_resolve function and closes the thread - error and success called based on result of pcall (useful for async)
    Server._thread:check_timeout ()Checks the timeout on a thread - if timedout then it calles on_timeout and closes
    Server._thread:error (err)Rasies an error on this thread
    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
    - -
    -
    - - -

    Functions

    - -
    -
    - - Server.threads ([count=nil]) -
    -
    - Returns either the number of threads or a able of threads - - -

    Parameters:

    -
      -
    • count - bolean - true to return the number of threads - (default nil) -
    • -
    - -

    Returns:

    -
      - - either a list of threads or a number -
    - - - -

    Usage:

    -
      -
      Server.threads() -- return {...}
      - Server.threads(true) -- return int
      -
    - -
    -
    - - Server.get_thread (mixed) -
    -
    - Used to get a thread via it's uuid or by name if one is given - - -

    Parameters:

    -
      -
    • mixed - either a uuid or the name given to a thread -
    • -
    - -

    Returns:

    -
      - - table - the thread by that name or uuid -
    - - - -

    Usage:

    -
      -
      Server.get_thread('decon') -- return thread
      -
    - -
    -
    - - Server.queue_thread (thread_to_queue) -
    -
    - Adds a thread into the resolve queue, can be used to lower lag - - -

    Parameters:

    -
      -
    • thread_to_queue - table - the thread to add to the queue must have a resolve function (must be open) -
    • -
    - -

    Returns:

    -
      - - boolean - was the thread added -
    - - - -

    Usage:

    -
      -
      Server.queue_thread(thread) -- return true/false
      -
    - -
    -
    - - Server.close_all_threads (with_force) -
    -
    - Closes all active threads, can use force if it causes errors - - -

    Parameters:

    -
      -
    • with_force - bolean - use force when closing -
    • -
    - - - - -

    Usage:

    -
      -
      Server.close_all_threads()
      - Server.close_all_threads(true) -- use if no force makes errors
      -
    - -
    -
    - - Server.run_tick_threads () -
    -
    - Runs all the theads which have opened with an on_tick event - - - - - - -

    Usage:

    -
      -
      Server.run_tick_threads()
      -
    - -
    -
    - - Server.check_timeouts () -
    -
    - Checks the timeout on all active timeout threads - - - - - - -

    Usage:

    -
      -
      Server.check_timeouts()
      -
    - -
    -
    - - Server._thread_handler (event) -
    -
    - Calles all threads on a certain game event (used with script.on_event) - - -

    Parameters:

    -
      -
    • event - table - the event that is called -
    • -
    - - - - - -
    -
    - - Server.interface (callback[, use_thread[, ...]]) -
    -
    - 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() then end
      -
    - -
    -
    - - 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-31 00:41:31 -
    -
    - - diff --git a/modules/ExpGamingCore/Server/control.lua b/modules/ExpGamingCore/Server/control.lua index 5e9b9522..15a9114a 100644 --- a/modules/ExpGamingCore/Server/control.lua +++ b/modules/ExpGamingCore/Server/control.lua @@ -8,16 +8,25 @@ local Server = {} --- Global Table -- @table global +-- @field all a list of every thread (indexed by uuid) +-- @field queue an index for threads which will be resolved (contains uuids) +-- @field tick an index for threads which will run every tick (contains uuids) +-- @field timeout an index for threads which will timeout (contains uuids) +-- @field events an index of threads based on event ids (contains uuids) +-- @field paused an index of pasued threads (contains uuids) +-- @field named a name index for thread uuids +-- @field print_to contains players that event details will be printed to +-- @field uuid contains the random number generator for the uuid system local global = global{ - all={_n=0}, -- a list of every thread (indexed by uuid) - queue={}, -- an index for threads which will be resolved (contains uuids) - tick={}, -- an index for threads which will run every tick (contains uuids) - timeout={}, -- an index for threads which will timeout (contains uuids) - events={}, -- an index of threads based on event ids (contains uuids) - paused={}, -- an index of pasued threads (contains uuids) - named={}, -- a name index for thread uuids - print_to={}, -- contains players that event details will be printed to - uuid=nil -- contains the random number generator for the uuid system + all={_n=0}, + queue={}, + tick={}, + timeout={}, + events={}, + paused={}, + named={}, + print_to={}, + uuid=nil } --- Used to generate a new uuid for the thread system @@ -220,7 +229,7 @@ function Server.interface(callback,use_thread,env,...) end --- The class for the server threads, allows abbilty to run async function --- @class Thread +-- @type Thread -- @alias Server._thread Server._thread = {} diff --git a/modules/ExpGamingCore/Server/src/commands.lua b/modules/ExpGamingCore/Server/src/commands.lua index ce8ccd35..7f83ebd5 100644 --- a/modules/ExpGamingCore/Server/src/commands.lua +++ b/modules/ExpGamingCore/Server/src/commands.lua @@ -7,6 +7,9 @@ --- This file will be loaded when ExpGamingCore.Commands is present -- @function _comment +--- Runs the given input from the script +-- @command interface +-- @param code The code that will be ran commands.add_command('interface', 'Runs the given input from the script', {'code',true}, function(event,args) local callback = args.code -- looks for spaces, if non the it will prefix the command with return diff --git a/modules/ExpGamingCore/Sync/control.lua b/modules/ExpGamingCore/Sync/control.lua index d1ee6a31..5158bff9 100644 --- a/modules/ExpGamingCore/Sync/control.lua +++ b/modules/ExpGamingCore/Sync/control.lua @@ -6,30 +6,52 @@ local Sync = {} local Sync_updates = {} + --- Global Table -- @table global +-- @field server_name the server name +-- @field server_description a short description of the server +-- @field reset_time the reset time of the server +-- @field time the last knowen irl time +-- @field time_set the last in game time that the time was set +-- @field last_update the last time that this info was updated +-- @field time_period how often this infomation is updated +-- @field players a list of different player related states +-- @field ranks a list of player ranks +-- @field rockets the number of rockets launched +-- @field mods the mods which are loaded local global = global{ - server_name='Factorio Server', -- the server name - server_description='A factorio server for everyone', -- a short description of the server - reset_time='On Demand', -- the reset time of the server - time='Day Mth 00 00:00:00 UTC Year', -- the last knowen irl time - time_set={0,'0.00M'}, -- the last in game time that the time was set - last_update={0,'0.00M'}, -- the last time that this info was updated - time_period={18000,'5.00M'}, -- how often this infomation is updated + server_name='Factorio Server', + server_description='A factorio server for everyone', + reset_time='On Demand', + time='Day Mth 00 00:00:00 UTC Year', + time_set={0,'0.00M'}, + last_update={0,'0.00M'}, + time_period={18000,'5.00M'}, players={ - online={'Offline'}, -- list of all players online - n_online=0, -- the number of players online - all={'Offline'}, -- list of all player on or offline - n_all=0, -- the number of players who have joined the server - admins_online=0, -- the number of admins online - afk_players=0, -- the number of afk players - times={'Offline'} -- the play times of every player - }, -- a sub list of players in the game - ranks={'Offline'}, -- a list of player ranks - rockets=0, -- the number of rockets launched - mods={'Offline'} -- the mods which are loaded + online={'Offline'}, + n_online=0, + all={'Offline'}, + n_all=0, + admins_online=0, + afk_players=0, + times={'Offline'} + }, + ranks={'Offline'}, + rockets=0, + mods={'Offline'} } +--- Player sub-table +-- @table global.players +-- @field online list of all players online +-- @field n_online the number of players online +-- @field all list of all player on or offline +-- @field n_all the number of players who have joined the server +-- @field admins_online the number of admins online +-- @field afk_players the number of afk players +-- @field times the play times of every player + --- Used to standidise the tick format for any sync info -- @usage Sync.tick_format(60) -- return {60,'1.00M'} -- @treturn {number,string} table containg both the raw number and clean version of a time From b8b514b1334d67071bb582cd2bfd155af4368a6a Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 2 Jun 2018 21:08:33 +0100 Subject: [PATCH 023/231] Added module: ExpGamingCore.Ranking --- FactorioSoftmodManager.lua | 7 +- config.ld | 4 +- modules/ExpGamingCore/Ranking/control.lua | 535 ++++++++++-------- .../{config_ranks.lua => src/config.lua} | 40 +- .../Ranking/{base_ranks.lua => src/core.lua} | 113 +--- modules/ExpGamingCore/Ranking/src/server.lua | 43 ++ modules/ExpGamingCore/Server/control.lua | 6 + modules/ExpGamingCore/Sync/control.lua | 1 + modules/ExpGamingCore/Sync/src/ranking.lua | 23 +- modules/ExpGamingCore/softmod.json | 9 +- modules/ExpGamingLib/control.lua | 2 +- modules/index.lua | 2 +- 12 files changed, 432 insertions(+), 353 deletions(-) rename modules/ExpGamingCore/Ranking/{config_ranks.lua => src/config.lua} (80%) rename modules/ExpGamingCore/Ranking/{base_ranks.lua => src/core.lua} (53%) create mode 100644 modules/ExpGamingCore/Ranking/src/server.lua diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index 93382980..863f2a5c 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -150,7 +150,8 @@ Manager.verbose('Current state is now: "selfInit"; The verbose state is: '..tost -- @usage global[key] -- used like the normal global table -- @usage global{'foo','bar'} -- sets the default value -- @usage global(true) -- restores global to default --- @tparam[opt={}] ?table|true default the default value of global, if true then default is restored +-- @usage global(mopdule_name) -- returns that module's global +-- @tparam[opt={}] ?table|string|true if table then the default for the global, if a string then the module to get the global of, if true then reset the global to default -- @treturn table the new global table for that module Manager.global=setmetatable({__defaults={},__global={ __call=function(tbl,default) return Manager.global(default) end, @@ -167,8 +168,10 @@ Manager.global=setmetatable({__defaults={},__global={ }},{ __call=function(tbl,default) local global = _G.global + local module_name = type(default) == 'string' and default or module_name + local module_path = type(default) == 'string' and moduleIndex[default] or module_path if not module_path or not module_name then return _G.global end - if default then rawset(rawget(tbl,'__defaults'),tostring(module_name),default) end + if type(default) == 'table' then rawset(rawget(tbl,'__defaults'),tostring(module_name),default) end local path = 'global' local new_dir = false for dir in module_path:gmatch('%a+') do diff --git a/config.ld b/config.ld index 9efa37a4..e8a714be 100644 --- a/config.ld +++ b/config.ld @@ -1 +1,3 @@ -new_type('command','Commands',false,'param') \ No newline at end of file +new_type('command','Commands',false,'param') +new_type('event','Commands',false,'field') +new_type('gui','Commands') \ No newline at end of file diff --git a/modules/ExpGamingCore/Ranking/control.lua b/modules/ExpGamingCore/Ranking/control.lua index 142ac0a3..4e578f53 100644 --- a/modules/ExpGamingCore/Ranking/control.lua +++ b/modules/ExpGamingCore/Ranking/control.lua @@ -1,104 +1,168 @@ ---[[ -Explosive Gaming +--- A full ranking system for factorio. +-- @module ExpGamingCore.Ranking +-- @alias Ranking +-- @author Cooldude2606 +-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -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 Ranking = {} -defines.events.rank_change = script.generate_event_name() -Ranking._rank = {} -Ranking._group = {} --- this is just for debuging when setting you rank powers +local module_verbose = false --true|false + +--- Global Table +-- @table global +-- @field old contains the previous rank a use had before a rank change +-- @field preset contains the preset ranks that users will recive apon joining +-- @filed last_change contains the name of the player who last had there rank chagned +local global = global{old={},preset={},last_change=nil} + +--- Called when there is a rank change for a user +-- @event rank_change +-- @field name the rank id +-- @field tick the tick which the event was raised on +-- @field player_index the player whos rank was changed +-- @field by_player_index the player who changed the rank, 0 means server +-- @field new_rank the name of the rank that was given +-- @field old_rank the name of the rank the player had +script.generate_event_name('rank_change') + +--- Outputs as a string all the ranks and the loaded order +-- @usage Ranking.output_ranks(player) -- prints to player +-- @tparam[opt=server] ?player_name|player_index|LuaPlayer player the player that the info will be printed to, nil will print to server +-- @todo show inheritance of ranks function Ranking.output_ranks(player) local player = Game.get_player(player) or game.player or nil - if not player then return end - for power,rank in pairs(Ranking._ranks()) do - local output = power..') '..rank.name - output=output..' '..rank.tag + local function output(rank) local admin = 'No'; if rank.is_root then admin = 'Root' elseif rank.is_admin then admin = 'Yes' end - output=output..' Admin: '..admin - output=output..' Group: '..rank.group.name - output=output..' AFK: '..tostring(rank.base_afk_time) - player_return(output,rank.colour,player) + local rtn = string.format('%s) %q %s > Admin: %s Group: %q AFK: %s Time: %s', + rank.power,rank.name,rank.tag,admin,rank.group,tostring(rank.base_afk_time),tostring(rank.time)) + player_return(rtn,rank.colour,player) end + local function recur(_rank) + for name,rank in pairs(_rank.children) do output(Ranking.ranks[rank]) end + for name,rank in pairs(_rank.children) do recur(Ranking.ranks[rank]) end + end + local root = Ranking.get_rank(Ranking.meta.root) + output(root) + recur(root) end --- this function is to avoid errors - see /ranks.lua -function Ranking._ranks(names) - return {} -end +--- Contains the location of all the ranks, readonly during runtime +-- @table Ranking.ranks +Ranking.ranks = setmetatable({},{ + __metatable=false, + __index=table.autokey, + __newindex=function(tbl,key,value) if game then error('Can not create new ranks during runtime',2) else rawset(tbl,key,value) end end, + __len=function(tbl) + local rtn = 0 + for name,rank in pairs(tbl) do + rtn=rtn+1 + end + return rtn + end +}) --- this function is to avoid errors - see /ranks.lua -function Ranking._groups(names) - return {} -end +--- Contains the location of all the rank groups, readonly during runtime +-- @table Ranking.ranks +Ranking.groups = setmetatable({},{ + __metatable=false, + __index=table.autokey, + __newindex=function(tbl,key,value) if game then error('Can not create new rank groups during runtime',2) else rawset(tbl,key,value) end end, + __len=function(tbl) + local rtn = 0 + for name,rank in pairs(tbl) do + rtn=rtn+1 + end + return rtn + end +}) --- this function is to avoid errors - see /ranks.lua -function Ranking._meta() - return {} -end +--- Contains some meta data about the ranks +-- @table Ranking.meta +-- @field default this is the name of the default rank +-- @filed root this is the name of the root rank +-- @field time_ranks a list of all ranks which have a time requirement +-- @field time_highest the power of the highest rank that has a time requirement +-- @field time_lowest the lowest amount of time required for a time rank +Ranking.meta = setmetatable({},{ + __metatable=false, + __call=function(tbl) + rawset(tbl,'time_ranks',{}) + for name,rank in pairs(Ranking.ranks) do + if not rawget(tbl,'default') and rank.is_default then rawset(tbl,'default',rank.name) end + if not rawget(tbl,'root') and rank.is_root then rawset(tbl,'root',rank.name) end + if rank.time then + table.insert(tbl.time_ranks,rank.name) + if not rawget(tbl,'time_highest') or rank.power < tbl.time_highest then if rank.power then rawset(tbl,'time_highest',rank.power) end end + if not rawget(tbl,'time_lowest') or rank.time < tbl.time_lowest then rawset(tbl,'time_lowest',rank.time) end + end + end + if not rawget(tbl,'default') then error('No default rank') end + if not rawget(tbl,'root') then error('No root rank') end + end, + __index=function(tbl,key) + tbl() + return rawget(tbl,key) + end, + __newindex=function() error('Ranking metadata is read only',2) end +}) --- this function is to avoid errors - see addons/playerRanks.lua -function Ranking._base_preset(table) - Ranking._presets().current = table -end - --- this returns a global list -function Ranking._presets() - if not global.exp_core then global.exp_core = {} end - if not global.exp_core.ranking then global.exp_core.ranking = {meta=Ranking._meta(),old={},current={},last_jail=nil} end - return global.exp_core.ranking +--- Used to set the prset ranks that will be given to players +-- @usage Ranking._base_preset{name=rank_name,nameTwo=rank_name_two} -- sets player name to have rank rank_name on join +-- @tparam table ranks table of player names with the player name as the key and rank name as the value +function Ranking._base_preset(ranks) + if not is_type(ranks,'table') then error('Ranking._base_preset was not given a table',2) end + global.preset = ranks end --- Returns a rank object given a player or rank name --- @usage Ranking.get_rank(game.player) --- Ranking.get_rank('admin') --- @param mixed player|player index|player name|rank name|rank|'server'|'root' what rank to get --- @treturn table the rank that is linked to mixed +-- @usage Ranking.get_rank(game.player) -- returns player's rank +-- @usage Ranking.get_rank('admin') -- returns rank by the name of admin +-- @tparam ?player|player_index|player_name|rank_name|Ranking._rank|'server'|'root' mixed what rank to get +-- @treturn[1] table the rank that is linked to mixed +-- @trrturn[2] nil there was no rank found function Ranking.get_rank(mixed) - if not mixed then return false end - local ranks = Ranking._ranks(true) + if not mixed then return error('Ranking.get_rank recived no paramerters') end + local ranks = Ranking.ranks local _return = false if is_type(mixed,'table') then - if mixed.index then - _return = game.players[mixed.index] and ranks[mixed.permission_group.name] or nil - else - _return = mixed.group and mixed or nil - end + -- is it a player, then get player rank; if it is a rank then return the rank + if mixed.index then _return = game.players[mixed.index] and ranks[mixed.permission_group.name] or error('Invalid player name to Ranking.get_rank',2) + else _return = mixed.group and mixed or nil end else - _return = game.players[mixed] and ranks[game.players[mixed].permission_group.name] + -- if it is a player name/index, then get player rank; if it is a rank name, get that rank; if it is server or root; return root rank; else nil + _return = game and game.players[mixed] and ranks[game.players[mixed].permission_group.name] or table.autokey(ranks,mixed) and table.autokey(ranks,mixed) - or string.contains(mixed,'server') and Ranking.get_rank(Ranking._presets().meta.root) - or string.contains(mixed,'root') and Ranking.get_rank(Ranking._presets().meta.root) + or string.contains(mixed,'server') and Ranking.get_rank(Ranking.meta.root) + or string.contains(mixed,'root') and Ranking.get_rank(Ranking.meta.root) or nil end return _return end ---- Returns the group object used to sort ranks given group name or see Ranking.get_rank --- @usage Ranking.get_group(game.player) --- Ranking.get_group('root') --- @param mixed player|player index|player name|rank name|rank|'server'|'root'|group name|group what group to get --- @treturn table the group that is linked to mixed +--- Returns the group object used to sort ranks given group name or rank +-- @usage Ranking.get_group(game.player) -- returns player's rank group +-- @usage Ranking.get_group('root') -- returns group by name of root +-- @tparam ?player|player_index|player_name|rank_name|rank|'server'|'root'|group name|group mixed what group to get +-- @see Ranking.get_rank +-- @treturn[1] table the group that is linked to mixed +-- @trrturn[2] nil there was no rank group found function Ranking.get_group(mixed) - if not mixed then return false end - local groups = Ranking._groups(true) + if not mixed then return error('Ranking.get_group recived no paramerters') end + local groups = Ranking.groups local rank = Ranking.get_rank(mixed) - return rank and rank.group - or is_type(mixed,'table') and mixed.ranks and mixed - or is_type(mixed,'string') and table.autokey(groups,mixed) and table.autokey(groups,mixed) - or false + -- if it is a table see if it is a group, return the group; if it is a string, return group by that name; if there is a rank found, return the ranks group + return is_type(mixed,'table') and not mixed.__self and mixed.ranks and mixed + or is_type(mixed,'string') and table.autokey(groups,mixed) + or rank and rank.group + or nil end --- Prints to all rank of greater/lower power of the rank given -- @usage Ranking.print('admin','We got a grifer') --- @param rank_base the rank that acts as the cut off point (rank is always included) +-- @todo change to use parent and child ranks rather than power +-- @tparam ?Ranking._rank|pointerToRank 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 +-- @tparam[opt=defines.color.white] defines.color colour the colour that will be used to print +-- @tparam[opt=false] boolean below if true print to children rather than parents function Ranking.print(rank_base,rtn,colour,below) local colour = colour or defines.color.white local rank_base = Ranking.get_rank(rank_base) @@ -116,89 +180,83 @@ end --- Gives a user a rank -- @usage Ranking.give_rank(1,'admin') --- @param player the player to give the rank to --- @param rank the rank to give to the player --- @param[opt='server'] by_player the player who is giving the rank --- @param[opt=game.tick] tick the tick that the rank is being given on +-- @tparam ?LuaPlayer|pointerToPlayer player the player to give the rank to +-- @tparam[opt=default] ?Ranking._rank|pointerToRank rank the rank to give to the player +-- @tparam[opt='server'] ?LuaPlayer|pointerToPlayer by_player the player who is giving the rank +-- @tparam[opt=game.tick] number tick the tick that the rank is being given on, used as pass though function Ranking.give_rank(player,rank,by_player,tick) local print_colour = defines.textcolor.info local tick = tick or game.tick local by_player_name = Game.get_player(by_player) and Game.get_player(by_player).name or game.player and game.player.name or is_type(by_player,'string') and by_player or 'server' - local rank = Ranking.get_rank(rank) or Ranking.get_rank(Ranking._presets().meta.default) - local player = Game.get_player(player) or error('No Player To Give Rank') - local old_rank = Ranking.get_rank(player) or Ranking.get_rank(Ranking._presets().meta.default) + local rank = Ranking.get_rank(rank) or Ranking.get_rank(Ranking.meta.default) + local player = Game.get_player(player) or error('No player given to Ranking.give_rank',2) + local old_rank = Ranking.get_rank(player) or Ranking.get_rank(Ranking.meta.default) local message = 'ranking.rank-down' -- messaging if old_rank.name == rank.name then return end if rank.power < old_rank.power then message = 'ranking.rank-up' player.play_sound{path='utility/achievement_unlocked'} else player.play_sound{path='utility/game_lost'} end if player.online_time > 60 or by_player_name ~= 'server' then game.print({message,player.name,rank.name,by_player_name},print_colour) end - if rank.group.name ~= 'User' then player_return({'ranking.rank-given',rank.name},print_colour,player) end + if rank.group ~= 'User' then player_return({'ranking.rank-given',rank.name},print_colour,player) end if player.tag ~= old_rank.tag then player_return({'ranking.tag-reset'},print_colour,player) end -- rank change player.permission_group = game.permissions.get_group(rank.name) player.tag = rank.tag - if old_rank.group.name ~= 'Jail' then Ranking._presets().old[player.index] = old_rank.name end + if old_rank.group ~= 'Jail' then global.old[player.index] = old_rank.name end player.admin = rank.is_admin or false player.spectator = rank.is_spectator or false - if defines.events.rank_change then - script.raise_event(defines.events.rank_change,{ - name=defines.events.rank_change, - tick=tick, - player_index=player.index, - by_player_name=by_player_name, - new_rank=rank, - old_rank=old_rank - }) + local by_player_index = by_player_name == 'server' and 0 or Game.get_player(by_player_name).index + script.raise_event(defines.events.rank_change,{ + name=defines.events.rank_change, + tick=tick, + player_index=player.index, + by_player_index=by_player_index, + new_rank=rank.name, + old_rank=old_rank.name + }) + -- logs to file if rank is chagned after first join + if player.online_time > 60 then + game.write_file('ranking-change.json', + table.json({ + tick=tick, + play_time=player.online_time, + player_name=player.name, + by_player_name=by_player_name, + new_rank=rank.name, + old_rank=old_rank.name + })..'\n' + , true, 0) end - if rank.group.name == 'Jail' and Ranking._presets().last_jail ~= player.name then - Sync.emit_embeded{ - title='Player Jail', - color=Color.to_hex(defines.textcolor.med), - description='There was a player jailed.', - ['Player:']=player.name, - ['By:']='<>'..by_player_name, - ['Reason:']='No Reason' - } - end - game.write_file('ranking-change.json', - table.json({ - tick=tick, - play_time=player.online_time, - player_name=player.name, - by_player_name=by_player_name, - new_rank=rank.name, - old_rank=old_rank.name, - power_increase=(old_rank.power-rank.power) - })..'\n' - , true, 0) end --- Revert the last change to a players rank --- @usage Ranking.revert(1) --- @param player the player to revert the rank of +-- @usage Ranking.revert(1) -- reverts the rank of player with index 1 +-- @tparam ?LuaPlayer|pointerToPlayer player the player to revert the rank of -- @param[opt=nil] by_player the player who is doing the revert function Ranking.revert(player,by_player) local player = Game.get_player(player) - Ranking.give_rank(player,Ranking._presets().old[player.index],by_player) + Ranking.give_rank(player,global.old[player.index],by_player) 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 +--- Given that the player has a rank in the preset table it is given; also will attempt to promote players if a time requirement is met +-- @usage Ranking.find_preset(1) -- attemps to find the preset for player with index 1 +-- @tparam ?LuaPlayer|pointerToPlayer player the player to test for an auto rank -- @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 + local presets = global.preset + local meta_data = Ranking.meta local default = Ranking.get_rank(meta_data.default) local player = Game.get_player(player) - local current_rank = Ranking.get_rank(player) or {power=-1,group={name='not jail'}} + local current_rank = Ranking.get_rank(player) or {power=-1,group='not jail'} local ranks = {default} - if current_rank.group.name == 'Jail' then return end + -- users in rank group jail are ingroned + if current_rank.group == 'Jail' then return end + -- looks in preset table for player name if presets[string.lower(player.name)] then local rank = Ranking.get_rank(presets[string.lower(player.name)]) table.insert(ranks,rank) end + -- if the player mets check requirements then play time is checked if current_rank.power > meta_data.time_highest and tick_to_min(player.online_time) > meta_data.time_lowest then for _,rank_name in pairs(meta_data.time_ranks) do local rank = Ranking.get_rank(rank_name) @@ -207,186 +265,213 @@ function Ranking.find_preset(player,tick) end end end + -- if the new rank is closer to root then it is the new rank local _rank = current_rank for _,rank in pairs(ranks) do if rank.power < _rank.power or _rank.power == -1 then _rank = rank end end - if _rank then - if _rank.name == default.name then - player.tag = _rank.tag - player.permission_group = game.permissions.get_group(_rank.name) - else - Ranking.give_rank(player,_rank,nil,tick) - end + -- this new rank is given to the player + if _rank.name == current_rank.name then return end + if _rank.name == default.name then + player.tag = _rank.tag + player.permission_group = game.permissions.get_group(_rank.name) + else + Ranking.give_rank(player,_rank,nil,tick) end end --- this is the base rank object, do not store in global - +--- The class for the ranks +-- @type Rank +-- @alias Ranking._rank +-- @field name the name that is given to the rank, must be unique +-- @field short_hand the shorter way of displaying this rank, can be used by other modules +-- @field tag the tag that player in this rank will be given +-- @field colour the colour that modules should display this rank as in guis +-- @field parent the name of the rank that permissions are inherited from, allow comes from children, disallow given to children +-- @field base_afk_time a relative number that the rank should be given that other modules can use for relitive importance +-- @field time the time that is requied for this rank to be given, can be nil for manal only +-- @field allow a list of permissions that this rank is allowed +-- @field disallow a list of acctions that is blocked by the ingame permission system +-- @field is_default will be given to all players if no other rank is set for them +-- @field is_admin will promote player to ingame admin if flag set (will auto demote if not set) +-- @field is_spectator will auto set the spectator option for the player (will cleat option if not set) +-- @field is_root rank is always allowed all action, when present in root group will become the root child that all ranks are indexed from +Ranking._rank = {} + --- Is this rank allowed to open this gui or use this command etc. --- @usage rank:allowed('server-interface') +-- @usage rank:allowed('interface') -- does the rank have permision for 'interface' -- @tparam teh action to test for --- @treturn bolean is it allowed +-- @treturn boolean is it allowed function Ranking._rank:allowed(action) return self.allow[action] or self.is_root or false end --- Get all the players in this rank -- @usage rank:get_players() --- @tparam bolean online get only online players +-- @tparam[opt=false] boolean online get only online players -- @treturn table a table of all players in this rank function Ranking._rank:get_players(online) local players = game.permissions.get_group(self.name).players local _return = {} if online then - for _,player in pairs(players) do - if player.connected then table.insert(_return,player) end - end - else - _return = players - end + for _,player in pairs(players) do if player.connected then table.insert(_return,player) end end + else _return = players end return _return end --- Print a message to all players of this rank --- @usage rank:print('foo') +-- @usage rank:print('foo') -- prints to all members of this rank -- @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 +-- @tparam[opt=defines.color.white] define.color colour the colour that will be used to print +-- @tparam[opt=false] boolean show_default weather to use the default rank name for the print, used as a pass though function Ranking._rank:print(rtn,colour,show_default) local colour = colour or defines.color.white - local meta_data = Ranking._presets().meta - local default = Ranking.get_rank(meta_data.default) - if not Server or not Server._thread then - for _,player in pairs(self:get_players(true)) do - if self.name == default.name or show_default then - player_return({'ranking.all-rank-print',rtn},colour,player) - else - player_return({'ranking.rank-print',self.name,rtn},colour,player) - end - end - else - -- using threads to make less lag - Server.new_thread{ - data={rank=self,rtn=rtn,default=default.name,all=show_default} - }:on_event('resolve',function(thread) - return thread.data.rank:get_players(true) - end):on_event('success',function(thread,players) - for _,player in pairs(players) do - if thread.data.rank.name == thread.data.default or thread.data.all then - player_return({'ranking.all-rank-print',thread.data.rtn},colour,player) - else - player_return({'ranking.rank-print',thread.data.rank.name,thread.data.rtn},colour,player) - end - end - end):queue() + local default = Ranking.get_rank(Ranking.meta.default) + for _,player in pairs(self:get_players(true)) do + if self.name == default.name or show_default then player_return({'ranking.all-rank-print',rtn},colour,player) + else player_return({'ranking.rank-print',self.name,rtn},colour,player) end end end --- this is used to edit a group once made key is what is being edited and set_value makes it over ride the current value --- see Addons/playerRanks for examples -function Ranking._rank:edit(key,set_value,value) +--- Allows for a clean way to edit rank objects +-- @usage rank:edit('allow',{'interface'}) -- allows this rank to use 'interface' +-- @tparam string key the key to edit, often allow or disallow +-- @param value the new value to be set +function Ranking._rank:edit(key,value) if game then return end - verbose('Edited Rank: '..self.name..'/'..key) - if set_value then self[key] = value return end - if key == 'disallow' then - self.disallow = table.merge(self.disallow,value,true) - elseif key == 'allow' then - self.allow = table.merge(self.allow,value) - end - Ranking._update_rank(self) + verbose('Edited Rank: '..self.group..'/'..self.name..'/'..key) + if key == 'disallow' then self.disallow = table.merge(self.disallow,value,true) + elseif key == 'allow' then self.allow = table.merge(self.allow,value) + else self[key] = value end end --- this is the base group object, do not store in global, these cant be used in game +--- The class for the rank groups, the way to allow modules to idex a group that is always present, ranks will always look to there group as a parent +-- @type Group +-- @alias Ranking._group +-- @field name the name that is given to the rank group, must be unique +-- @field parent the name of the group that permissions are inherited from +-- @field allow a list of permissions that this rank is allowed +-- @field disallow a list of acctions that is blocked by the ingame permission system +Ranking._group = {} --- this makes a new group --- {name='root',allow={},disallow={}} +--- Creates a new group +-- @usage Ranking._group:create{name='root'} -- returns group with name root +-- @tparam table obj the fields for this object +-- @treturn Ranking._group returns the object to allow chaining function Ranking._group:create(obj) if game then return end - if not is_type(obj.name,'string') then return end + if not is_type(obj.name,'string') then error('Group creationg is invalid',2) end verbose('Created Group: '..obj.name) setmetatable(obj,{__index=Ranking._group}) - self.index = #Ranking._groups(names)+1 obj.ranks = {} obj.allow = obj.allow or {} obj.disallow = obj.disallow or {} - Ranking._add_group(obj) + Ranking.groups[obj.name] = obj return obj end --- this makes a new rank in side this group --- {name='Root',short_hand='Root',tag='[Root]',time=nil,colour=defines.colors.white,allow={},disallow={}} --- if the rank is given power then it is given that place realative to the highest rank in that group,if no power then it is added to the end +--- Creats a new rank with this group as its group +-- @usage group:add_rank{name='root'} -- returns self +-- @tparam table obj the fields for this object +-- @treturn Ranking._group returns the object to allow chaining function Ranking._group:add_rank(obj) if game then return end if not is_type(obj.name,'string') or not is_type(obj.short_hand,'string') or not is_type(obj.tag,'string') or - not is_type(obj.colour,'table') then return end + not is_type(obj.colour,'table') then error('Rank creation is invalid',2) end verbose('Created Rank: '..obj.name) setmetatable(obj,{__index=Ranking._rank}) - obj.group = self + obj.group = self.name + obj.children = {} obj.allow = obj.allow or {} obj.disallow = obj.disallow or {} - obj.power = obj.power and self.highest and self.highest.power+obj.power or obj.power or self.lowest and self.lowest.power+1 or nil - setmetatable(obj.allow,{__index=self.allow}) - setmetatable(obj.disallow,{__index=self.disallow}) - Ranking._add_rank(obj,obj.power) - Ranking._set_rank_power() - table.insert(self.ranks,obj) - if not self.highest or obj.power < self.highest.power then self.highest = obj end - if not self.lowest or obj.power > self.lowest.power then self.lowest = obj end + table.insert(self.ranks,obj.name) + Ranking.ranks[obj.name] = obj + return self end --- this is used to edit a group once made key is what is being edited and set_value makes it over ride the current value --- see Addons/playerRanks for examples -function Ranking._group:edit(key,set_value,value) +--- Allows for a clean way to edit rank group objects +-- @usage group:edit('allow',{'interface'}) -- allows this rank to use 'interface' +-- @tparam string key the key to edit, often allow or disallow +-- @param value the new value to be set +function Ranking._group:edit(key,value) if game then return end verbose('Edited Group: '..self.name..'/'..key) - if set_value then self[key] = value return end - if key == 'disallow' then - self.disallow = table.merge(self.disallow,value,true) - elseif key == 'allow' then - self.allow = table.merge(self.allow,value) - end - Ranking._update_group(self) + if key == 'disallow' then self.disallow = table.merge(self.disallow,value,true) + elseif key == 'allow' then self.allow = table.merge(self.allow,value) + else self[key] = value end end -Event.register(defines.events.on_player_joined_game,function(event) +script.on_event('on_player_joined_game',function(event) Ranking.find_preset(event.player_index) end) -Event.register(-1,function(event) - for power,rank in pairs(Ranking._ranks()) do - local perm = game.permissions.create_group(rank.name) +script.on_event('on_init',function(event) + for name,rank in pairs(Ranking.ranks) do + local perm = game.permissions.create_group(name) for _,toRemove in pairs(rank.disallow) do perm.set_allows_action(defines.input_action[toRemove],false) end end end) -Event.register(defines.events.on_tick,function(event) +script.on_event('on_tick',function(event) if (((event.tick+10)/(3600*game.speed))+(15/2))% 15 == 0 then -- this is the system to auto rank players - if not Server or not Server._thread then - for _,player in pairs(game.connected_players) do - Ranking.find_preset(player,tick) - end - else - Server.new_thread{ - data={players=game.connected_players} - }:on_event('tick',function(thread) - if #thread.data.players == 0 then thread:close() return end - local player = table.remove(thread.data.players,1) - Ranking.find_preset(player,tick) - end):open() + for _,player in pairs(game.connected_players) do + Ranking.find_preset(player,tick) end - end + end end) Ranking.on_init=function(self) - require(module_path.."/base_ranks") - require(module_path.."/config_ranks") + if loaded_modules.Server then require(module_path..'/src/server') end + require(module_path..'/src/core') + require(module_path..'/src/config') + -- sets up the power system, the lower the power the closer to root, root is 0 + -- there must be a rank with is_root flag set and one rank with is_default flag set, if multiple found then first found is used + local root = Ranking.get_rank(Ranking.meta.root) + root:edit('power',0) + -- asigning of children + verbose('Creating Rank Tree') + for name,rank in pairs(Ranking.ranks) do + if rank ~= root then + if not rank.parent then error('Rank has no parent: "'..name..'"') end + if not Ranking.ranks[rank.parent] then error('Invalid parent rank: "'..rank.parent..'"') end + table.insert(Ranking.ranks[rank.parent].children,name) + Ranking.ranks[rank.parent]:edit('allow',rank.allow) + rank:edit('disallow',Ranking.ranks[rank.parent].disallow) + end + end + -- asigning of powers + verbose('Assigning Rank Powers') + local power = 1 + local function set_powers(rank) + for _,name in pairs(rank.children) do + Ranking.ranks[name]:edit('power',power) + power=power+1 + end + for _,name in pairs(rank.children) do set_powers(Ranking.ranks[name]) end + end + set_powers(root) + -- asigning group meta data + verbose('Creating Rank-Group Relationship') + for name,group in pairs(Ranking.groups) do + if name ~= 'Root' then + if not group.parent then error('Group has no parent: "'..name..'"') end + if not Ranking.groups[group.parent] then error('Invalid parent rank: "'..group.parent..'"') end + Ranking.groups[group.parent]:edit('allow',group.allow) + group:edit('disallow',Ranking.groups[group.parent].disallow) + end + for _,name in pairs(group.ranks) do + local rank = Ranking.ranks[name] + rank:edit('disallow',group.disallow) + rank:edit('allow',group.allow) + if not group.highest or Ranking.ranks[group.highest].power > rank.power then group.highest = rank.name end + if not group.lowest or Ranking.ranks[group.highest].power < rank.power then group.lowest = rank.name end + end + end end return Ranking \ No newline at end of file diff --git a/modules/ExpGamingCore/Ranking/config_ranks.lua b/modules/ExpGamingCore/Ranking/src/config.lua similarity index 80% rename from modules/ExpGamingCore/Ranking/config_ranks.lua rename to modules/ExpGamingCore/Ranking/src/config.lua index b475c0e3..2a50707d 100644 --- a/modules/ExpGamingCore/Ranking/config_ranks.lua +++ b/modules/ExpGamingCore/Ranking/src/config.lua @@ -1,12 +1,8 @@ ---[[ -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----------------------------------------------------------- +--- Description - A small description that will be displayed on the doc +-- @submodule ExpGamingCore.Ranking +-- @alias Ranking +-- @author Cooldude2606 +-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --[[ How to use groups: @@ -34,18 +30,14 @@ Example: defines.input_action.drop_item -> 'drop_item' http://lua-api.factorio.com/latest/defines.html#defines.input_action --]] --- See ExpCore/ranks.lua for examples - you add your own and edit pre-made ones here. - -local groups = Ranking._groups(true) - -groups['Root']:edit('allow',false,{ - ['testing']=true -}) +local groups = Ranking.groups +local ranks = Ranking.ranks groups['Root']:add_rank{ name='Owner', short_hand='Owner', tag='[Owner]', + parent='Root', time=nil, colour={r=170,g=0,b=0}, is_admin = true, @@ -56,6 +48,7 @@ groups['Root']:add_rank{ name='Community Manager', short_hand='Com Mngr', tag='[Com Mngr]', + parent='Root', colour={r=150,g=68,b=161}, is_admin = true, is_spectator=true, @@ -65,16 +58,19 @@ groups['Root']:add_rank{ name='Developer', short_hand='Dev', tag='[Dev]', + parent='Root', colour={r=179,g=125,b=46}, is_admin = true, is_spectator=true, base_afk_time=false } +ranks['Admin']:edit('parent','Developer') groups['Admin']:add_rank{ name='Mod', short_hand='Mod', tag='[Mod]', + parent='Admin', colour={r=0,g=170,b=0}, disallow={ 'server_command' @@ -88,8 +84,8 @@ groups['User']:add_rank{ name='Donator', short_hand='P2W', tag='[P2W]', + parent='Mod', colour={r=233,g=63,b=233}, - power=0, is_spectator=true, base_afk_time=120 } @@ -97,24 +93,22 @@ groups['User']:add_rank{ name='Veteran', short_hand='Vet', tag='[Veteran]', + parent='Donator', time=600, colour={r=140,g=120,b=200}, - power=1, base_afk_time=60 } +ranks['Member']:edit('parent','Veteran') groups['User']:add_rank{ name='Regular', short_hand='Reg', tag='[Regular]', + parent='Member', time=180, colour={r=24,g=172,b=188}, - power=3, base_afk_time=30 } - -local ranks = Ranking._ranks(true) - -ranks['Root']:edit('test',true,'testing') +ranks['Guest']:edit('parent','Regular') Ranking._base_preset{ ['badgamernl']='Owner', diff --git a/modules/ExpGamingCore/Ranking/base_ranks.lua b/modules/ExpGamingCore/Ranking/src/core.lua similarity index 53% rename from modules/ExpGamingCore/Ranking/base_ranks.lua rename to modules/ExpGamingCore/Ranking/src/core.lua index b1ba5252..d8ad5c81 100644 --- a/modules/ExpGamingCore/Ranking/base_ranks.lua +++ b/modules/ExpGamingCore/Ranking/src/core.lua @@ -1,20 +1,8 @@ ---[[ -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 groups = {} -local ranks = {} - -function Ranking._add_group(group) if game then return end table.insert(groups,group) end -function Ranking._add_rank(rank,pos) if game then return end if pos then table.insert(ranks,pos,rank) else table.insert(ranks,rank) end end -function Ranking._set_rank_power() if game then return end for power,rank in pairs(ranks) do rank.power = power end end -function Ranking._update_rank(rank) if game then return end ranks[rank.power] = rank end -function Ranking._update_group(group) if game then return end groups[group.index] = group end +--- Description - A small description that will be displayed on the doc +-- @submodule ExpGamingCore.Ranking +-- @alias Ranking +-- @author Cooldude2606 +-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --[[ How to use groups: @@ -42,11 +30,10 @@ Example: defines.input_action.drop_item -> 'drop_item' http://lua-api.factorio.com/latest/defines.html#defines.input_action --]] --- If you wish to add more groups please use addons/playerRanks.lua --- If you wish to add to these rank groups use addons/playerRanks.lua --- Ranks will inherite from each other ie higher ranks can do everything lower ranks can +-- If you wish to add more groups please use src/config or add during your own module +-- If you wish to add to these rank groups use src/config or add during your own module -- But groups do not inherite from each other --- DO NOT REMOVE ANY OF THESE GROUPS +-- DO NOT REMOVE ANY OF THESE GROUPS!!! local root = Ranking._group:create{ name='Root', @@ -57,9 +44,9 @@ local root = Ranking._group:create{ } local admin = Ranking._group:create{ name='Admin', + parent='Root', allow={}, disallow={ - 'set_allow_commands', 'edit_permission_group', 'delete_permission_group', 'add_permission_group' @@ -67,22 +54,15 @@ local admin = Ranking._group:create{ } local user = Ranking._group:create{ name='User', + parent='Admin', allow={}, - disallow={ - 'set_allow_commands', - 'edit_permission_group', - 'delete_permission_group', - 'add_permission_group' - } + disallow={} } local jail = Ranking._group:create{ name='Jail', + parent='User', allow={}, disallow={ - 'set_allow_commands', - 'edit_permission_group', - 'delete_permission_group', - 'add_permission_group', 'open_character_gui', 'begin_mining', 'start_walking', @@ -110,8 +90,8 @@ local jail = Ranking._group:create{ } } --- If you wish to add more ranks please use addons/playerRanks.lua --- If you wish to add to these rank use addons/playerRanks.lua +-- If you wish to add more ranks please use src/config or add during your own module +-- If you wish to add to these rank use src/config or add during your own module root:add_rank{ name='Root', short_hand='Root', @@ -127,6 +107,7 @@ admin:add_rank{ name='Admin', short_hand='Admin', tag='[Admin]', + parent='Root', colour={r=233,g=63,b=233}, is_admin=true, is_spectator=true, @@ -137,6 +118,7 @@ user:add_rank{ name='Member', short_hand='Mem', tag='[Member]', + parent='Admin', colour={r=24,g=172,b=188}, disallow={ 'set_auto_launch_rocket', @@ -149,6 +131,7 @@ user:add_rank{ name='Guest', short_hand='', tag='', + parent='Member', colour={r=255,g=159,b=27}, is_default=true, disallow={ @@ -165,66 +148,8 @@ jail:add_rank{ name='Jail', short_hand='Jail', tag='[Jail]', + parent='Guest', colour={r=50,g=50,b=50}, disallow={}, base_afk_time=false -} - -function Ranking._auto_edit_ranks() - for power,rank in pairs(ranks) do - if ranks[power-1] then - rank:edit('disallow',false,ranks[power-1].disallow) - end - end - for power = #ranks, 1, -1 do - local rank = ranks[power] - rank:edit('disallow',false,rank.group.disallow) - if ranks[power+1] then - rank:edit('allow',false,ranks[power+1].allow) - end - end -end --- used to force rank to be read-only -function Ranking._groups(name) - if name then - if name then - local _return = {} - for power,group in pairs(groups) do - _return[group.name] = group - end - return _return - end - end - return groups -end - -function Ranking._ranks(name) - if name then - local _return = {} - for power,rank in pairs(ranks) do - _return[rank.name] = rank - end - return _return - end - return ranks -end - --- used to save lag by doing some calculation at the start -function Ranking._meta() - local meta = {time_ranks={}} - for power,rank in pairs(ranks) do - meta.rank_count = power - if rank.is_default then - meta.default = rank.name - end - if rank.is_root then - meta.root = rank.name - end - if rank.time then - table.insert(meta.time_ranks,rank.name) - if not meta.time_highest or power < meta.time_highest then meta.time_highest = power end - if not meta.time_lowest or rank.time < meta.time_lowest then meta.time_lowest = rank.time end - end - end - return meta -end \ No newline at end of file +} \ No newline at end of file diff --git a/modules/ExpGamingCore/Ranking/src/server.lua b/modules/ExpGamingCore/Ranking/src/server.lua new file mode 100644 index 00000000..22b66ef7 --- /dev/null +++ b/modules/ExpGamingCore/Ranking/src/server.lua @@ -0,0 +1,43 @@ +--- Description - A small description that will be displayed on the doc +-- @submodule ExpGamingCore.Ranking +-- @alias Ranking +-- @author Cooldude2606 +-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE + +--- This file will be loaded when ExpGamingCore.Server is present +-- @function _comment + +--- Print a message to all players of this rank +-- @usage rank:print('foo') -- prints to all members of this rank +-- @param rtn any value you want to return +-- @tparam[opt=defines.color.white] define.color colour the colour that will be used to print +-- @tparam[opt=false] boolean show_default weather to use the default rank name for the print, used as a pass though +function Ranking._rank:print(rtn,colour,show_default) + local colour = colour or defines.color.white + local default = Ranking.get_rank(Ranking.meta.default) + Server.new_thread{ + data={rank=self,rtn=rtn,default=default.name,all=show_default} + }:on_event('resolve',function(thread) + return thread.data.rank:get_players(true) + end):on_event('success',function(thread,players) + for _,player in pairs(players) do + if thread.data.rank.name == thread.data.default or thread.data.all then + player_return({'ranking.all-rank-print',thread.data.rtn},colour,player) + else + player_return({'ranking.rank-print',thread.data.rank.name,thread.data.rtn},colour,player) + end + end + end):queue() +end + +script.on_event('on_tick',function(event) + if (((event.tick+10)/(3600*game.speed))+(15/2))% 15 == 0 then + Server.new_thread{ + data={players=game.connected_players} + }:on_event('tick',function(thread) + if #thread.data.players == 0 then thread:close() return end + local player = table.remove(thread.data.players,1) + Ranking.find_preset(player,tick) + end):open() + end +end) \ No newline at end of file diff --git a/modules/ExpGamingCore/Server/control.lua b/modules/ExpGamingCore/Server/control.lua index 15a9114a..9b5716d0 100644 --- a/modules/ExpGamingCore/Server/control.lua +++ b/modules/ExpGamingCore/Server/control.lua @@ -5,6 +5,7 @@ -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE local Server = {} +local module_verbose = false --true|false --- Global Table -- @table global @@ -45,6 +46,7 @@ end) -- @treturn[1] number the number of threads -- @treturn[2] table table of all threads Server.threads = setmetatable({},{ + __metatable=false, __call=function(tbl) return global.all._n end, __index=function(tbl,key) return rawget(global.all,key) end, __newindex=function(tbl,key,value) rawset(global.all,key,value) end, @@ -231,6 +233,10 @@ end --- The class for the server threads, allows abbilty to run async function -- @type Thread -- @alias Server._thread +-- @field name the name that is given to the thread, use for easy later indexing +-- @field timeout the time in ticks that the thread will have before it times out +-- @field reopen when true the thread will reopen itself untill set to false, combine with timeout to create a long on_nth_tick wait +-- @field data any data that the thread will beable to access Server._thread = {} --- Returns a new thread object diff --git a/modules/ExpGamingCore/Sync/control.lua b/modules/ExpGamingCore/Sync/control.lua index 5158bff9..b36ff928 100644 --- a/modules/ExpGamingCore/Sync/control.lua +++ b/modules/ExpGamingCore/Sync/control.lua @@ -6,6 +6,7 @@ local Sync = {} local Sync_updates = {} +local module_verbose = false --true|false --- Global Table -- @table global diff --git a/modules/ExpGamingCore/Sync/src/ranking.lua b/modules/ExpGamingCore/Sync/src/ranking.lua index fa719f2e..a15944db 100644 --- a/modules/ExpGamingCore/Sync/src/ranking.lua +++ b/modules/ExpGamingCore/Sync/src/ranking.lua @@ -18,9 +18,8 @@ end -- @treturn table contains the ranks and the players in that rank function Sync.count_ranks() if not game then return {'Offline'} end - if not Ranking then return {'Ranking module not installed'} end local _ranks = {} - for power,rank in pairs(Ranking._ranks()) do + for name,rank in pairs(Ranking.ranks) do local players = rank:get_players() for k,player in pairs(players) do players[k] = player.name end local online = rank:get_players(true) @@ -35,4 +34,22 @@ if Sync.add_to_gui then Sync.add_to_gui(function(player,frame) return 'You have been assigned the rank \''..Ranking.get_rank(player).name..'\'' end) -end \ No newline at end of file +end + +-- adds a discord emit for rank chaning +script.on_event('rank_change',function(event) + local rank = Ranking.get_rank(event.new_rank) + local player = Game.get_player(event) + local by_player_name = Game.get_player(event.by_player_index) or '' + local global = global('Ranking') + if rank.group.name == 'Jail' and global.last_change ~= player.name then + Sync.emit_embeded{ + title='Player Jail', + color=Color.to_hex(defines.textcolor.med), + description='There was a player jailed.', + ['Player:']='<>'..player.name, + ['By:']='<>'..by_player_name, + ['Reason:']='No Reason' + } + end +end) \ No newline at end of file diff --git a/modules/ExpGamingCore/softmod.json b/modules/ExpGamingCore/softmod.json index 752d42c8..98e4a8ec 100644 --- a/modules/ExpGamingCore/softmod.json +++ b/modules/ExpGamingCore/softmod.json @@ -40,7 +40,10 @@ "version": "3.4.0", "location": "url", "dependencies": { - "ExpGamingLib": ">=3.0.0" + "ExpGamingLib": ">=3.0.0", + "FactorioStdLib.Color": ">=0.8.0", + "FactorioStdLib.Table": ">=0.8.0", + "ExpGamingCore.Server": "?>=3.0.0" } }, "Server": { @@ -53,8 +56,8 @@ "dependencies": { "ExpGamingLib": ">=3.0.0", "FactorioStdLib.Table": ">=0.8.0", - "ExpGamingCore/Ranking": "?>=3.0.0", - "ExpGamingCore/Commands": "?>=3.0.0" + "ExpGamingCore.Ranking": "?>=3.0.0", + "ExpGamingCore.Commands": "?>=3.0.0" } }, "Sync": { diff --git a/modules/ExpGamingLib/control.lua b/modules/ExpGamingLib/control.lua index b44bf297..2c0e5721 100644 --- a/modules/ExpGamingLib/control.lua +++ b/modules/ExpGamingLib/control.lua @@ -72,7 +72,7 @@ end -- @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.textcolor[colour] ~= defines.color.white and defines.textcolor[colour] or defines.color[colour] + local colour = ExpLib.is_type(colour,'table') and colour or defines.textcolor[colour] ~= defines.color.white and defines.textcolor[colour] or defines.color[colour] local player = player or game.player local function _return(callback,rtn) if ExpLib.is_type(rtn,'table') then diff --git a/modules/index.lua b/modules/index.lua index 08e83cdb..8ecaf4c6 100644 --- a/modules/index.lua +++ b/modules/index.lua @@ -9,7 +9,7 @@ return { ['Color']='/modules/FactorioStdLib/Color', ['table']='/modules/FactorioStdLib/Table', ['string']='/modules/FactorioStdLib/String', - --['Ranking']='/modules/ExpGamingCore/Ranking', + ['Ranking']='/modules/ExpGamingCore/Ranking', --['commands']='/modules/ExpGamingCore/Commands', --['Gui']='/modules/ExpGamingCore/Gui', ['Server']='/modules/ExpGamingCore/Server', From e1330b024215191779738e4f026a095c629bf415 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 2 Jun 2018 21:12:17 +0100 Subject: [PATCH 024/231] Fixed Error --- modules/ExpGamingCore/Ranking/control.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ExpGamingCore/Ranking/control.lua b/modules/ExpGamingCore/Ranking/control.lua index 4e578f53..7a56de38 100644 --- a/modules/ExpGamingCore/Ranking/control.lua +++ b/modules/ExpGamingCore/Ranking/control.lua @@ -125,7 +125,7 @@ function Ranking.get_rank(mixed) local _return = false if is_type(mixed,'table') then -- is it a player, then get player rank; if it is a rank then return the rank - if mixed.index then _return = game.players[mixed.index] and ranks[mixed.permission_group.name] or error('Invalid player name to Ranking.get_rank',2) + if mixed.index then _return = game.players[mixed.index] and ranks[mixed.permission_group.name] or nil else _return = mixed.group and mixed or nil end else -- if it is a player name/index, then get player rank; if it is a rank name, get that rank; if it is server or root; return root rank; else nil From df7b3fb291e4df5ecbe30884e3c6464457df655a Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 2 Jun 2018 21:41:17 +0100 Subject: [PATCH 025/231] Updated Doc --- FactorioSoftmodManager.lua | 6 +- config.ld | 4 +- doc/index.html | 8 +- doc/modules/ExpGamingCore.Ranking.html | 882 ++++++++++++++++++ doc/modules/ExpGamingCore.Server.html | 4 +- doc/modules/ExpGamingCore.Sync.html | 22 +- doc/modules/ExpGamingLib.html | 4 +- doc/modules/FSM.html | 11 +- doc/modules/StdLib.Color.html | 4 +- doc/modules/StdLib.Game.html | 4 +- doc/modules/StdLib.String.html | 4 +- doc/modules/StdLib.Table.html | 4 +- doc/modules/StdLib.Time.html | 4 +- ...odules.expgamingcore.commands.control.html | 4 +- .../modules.expgamingcore.gui.control.html | 4 +- ...les.expgamingcore.gui.guiparts.center.html | 4 +- ...les.expgamingcore.gui.guiparts.inputs.html | 4 +- ...dules.expgamingcore.gui.guiparts.left.html | 4 +- ...ules.expgamingcore.gui.guiparts.popup.html | 4 +- ...es.expgamingcore.gui.guiparts.toolbar.html | 4 +- ...modules.expgamingcore.ranking.control.html | 381 -------- modules/ExpGamingCore/Ranking/control.lua | 11 +- modules/ExpGamingCore/Ranking/src/config.lua | 6 - modules/ExpGamingCore/Ranking/src/core.lua | 6 - modules/ExpGamingCore/Ranking/src/server.lua | 2 +- modules/ExpGamingCore/Sync/src/gui.lua | 5 +- modules/ExpGamingCore/Sync/src/ranking.lua | 2 +- 27 files changed, 953 insertions(+), 449 deletions(-) create mode 100644 doc/modules/ExpGamingCore.Ranking.html delete mode 100644 doc/modules/modules.expgamingcore.ranking.control.html diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index 863f2a5c..e1916ba0 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -155,7 +155,7 @@ Manager.verbose('Current state is now: "selfInit"; The verbose state is: '..tost -- @treturn table the new global table for that module Manager.global=setmetatable({__defaults={},__global={ __call=function(tbl,default) return Manager.global(default) end, - __index=function(tbl,key) return Manager.global() == tbl and nil or rawget(Manager.global(),key) end, + __index=function(tbl,key) return Manager.global() == tbl and nil or rawget(Manager.global(),key) or tbl(key) end, __newindex=function(tbl,key,value) rawset(Manager.global(),key,value) end, __pairs=function(tbl) local tbl = Manager.global() @@ -185,12 +185,10 @@ Manager.global=setmetatable({__defaults={},__global={ end return global end, - __index=function(tbl,key) Manager.verbose('Manager Index') return rawget(tbl(),key) or rawget(_G.global,key) end, + __index=function(tbl,key) return rawget(tbl(),key) or rawget(_G.global,key) or tbl(key) end, __newindex=function(tbl,key,value) rawset(tbl(),key,value) end, __pairs=function(tbl) - Manager.verbose('Manager Pair 1') local tbl = Manager.global() - Manager.verbose('Manager Pair 2') local function next_pair(tbl,k) k, v = next(tbl, k) if type(v) ~= nil then return k,v end diff --git a/config.ld b/config.ld index e8a714be..c79db209 100644 --- a/config.ld +++ b/config.ld @@ -1,3 +1,3 @@ new_type('command','Commands',false,'param') -new_type('event','Commands',false,'field') -new_type('gui','Commands') \ No newline at end of file +new_type('event','Events',false,'field') +new_type('gui','Guis') \ No newline at end of file diff --git a/doc/index.html b/doc/index.html index 9feb5b9d..27be2284 100644 --- a/doc/index.html +++ b/doc/index.html @@ -39,7 +39,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -91,8 +91,8 @@ Add a white bar to any gui frame - modules.expgamingcore.ranking.control - Returns a rank object given a player or rank name + ExpGamingCore.Ranking + A full ranking system for factorio. ExpGamingCore.Server @@ -132,7 +132,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/ExpGamingCore.Ranking.html b/doc/modules/ExpGamingCore.Ranking.html new file mode 100644 index 00000000..b221ebdc --- /dev/null +++ b/doc/modules/ExpGamingCore.Ranking.html @@ -0,0 +1,882 @@ + + + + + Reference + + + + +
    + +
    + +
    +
    +
    + + +
    + + + + + + +
    + +

    Module ExpGamingCore.Ranking

    +

    A full ranking system for factorio.

    +

    +

    Info:

    +
      +
    • License: https://github.com/explosivegaming/scenario/blob/master/LICENSE
    • +
    • Author: Cooldude2606
    • +
    + + +

    Functions

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    output_ranks ([player=server])Outputs as a string all the ranks and the loaded order
    _base_preset (ranks)Used to set the prset ranks that will be given to players
    get_rank (mixed)Returns a rank object given a player or rank name
    get_group (mixed)Returns the group object used to sort ranks given group name or rank
    print (rank_base, rtn[, colour=defines.color.white[, below=false]])Prints to all rank of greater/lower power of the rank given
    give_rank (player[, rank=default[, by_player='server'[, tick=game.tick]]])Gives a user a rank
    revert (player[, by_player=nil])Revert the last change to a players rank
    find_preset (player[, tick=nil])Given that the player has a rank in the preset table it is given; also will attempt to promote players if a time requirement is met
    +

    Tables

    + + + + + + + + + + + + + + + + + +
    globalGlobal Table
    ranksContains the location of all the ranks, readonly during runtime
    ranksContains the location of all the rank groups, readonly during runtime
    metaContains some meta data about the ranks
    +

    Events

    + + + + + +
    rank_changeCalled when there is a rank change for a user
    +

    Class Rank

    + + + + + + + + + + + + + + + + + +
    Ranking._rank:allowed (action)Is this rank allowed to open this gui or use this command etc.
    Ranking._rank:get_players ([online=false])Get all the players in this rank
    Ranking._rank:print (rtn[, colour=defines.color.white[, show_default=false]])Print a message to all players of this rank
    Ranking._rank:edit (key, value)Allows for a clean way to edit rank objects
    +

    Class Group

    + + + + + + + + + + + + + +
    Ranking._group:create (obj)Creates a new group
    Ranking._group:add_rank (obj)Creats a new rank with this group as its group
    Ranking._group:edit (key, value)Allows for a clean way to edit rank group objects
    +

    modules.expgamingcore.ranking.src.server Functions

    + + + + + + + + + +
    _comment ()This file will be loaded when ExpGamingCore.Server is present
    Ranking._rank:print (rtn[, colour=defines.color.white[, show_default=false]])Print a message to all players of this rank
    + +
    +
    + + +

    Functions

    + +
    +
    + + output_ranks ([player=server]) +
    +
    + Outputs as a string all the ranks and the loaded order + + +

    Parameters:

    +
      +
    • player + player_name, player_index or LuaPlayer + the player that the info will be printed to, nil will print to server + (default server) +
    • +
    + + + + +

    Usage:

    +
      +
      Ranking.output_ranks(player) -- prints to player
      +
    + +
    +
    + + _base_preset (ranks) +
    +
    + Used to set the prset ranks that will be given to players + + +

    Parameters:

    +
      +
    • ranks + table + table of player names with the player name as the key and rank name as the value +
    • +
    + + + + +

    Usage:

    +
      +
      Ranking._base_preset{name=rank_name,nameTwo=rank_name_two} -- sets player name to have rank rank_name on join
      +
    + +
    +
    + + get_rank (mixed) +
    +
    + Returns a rank object given a player or rank name + + +

    Parameters:

    +
      +
    • mixed + player, player_index, player_name, rank_name, Ranking._rank, 'server' or 'root' + what rank to get +
    • +
    + +

    Returns:

    +
      + + table + the rank that is linked to mixed +
    +

    Or

    +
      + + nil + there was no rank found +
    + + + +

    Usage:

    +
      +
    • Ranking.get_rank(game.player) -- returns player's rank
    • +
    • Ranking.get_rank('admin') -- returns rank by the name of admin
    • +
    + +
    +
    + + get_group (mixed) +
    +
    + Returns the group object used to sort ranks given group name or rank + + +

    Parameters:

    +
      +
    • mixed + player, player_index, player_name, rank_name, rank, 'server', 'root', group_name or group + what group to get +
    • +
    + +

    Returns:

    +
      + + table + the group that is linked to mixed +
    +

    Or

    +
      + + nil + there was no rank group found +
    + + +

    See also:

    + + +

    Usage:

    +
      +
    • Ranking.get_group(game.player) -- returns player's rank group
    • +
    • Ranking.get_group('root') -- returns group by name of root
    • +
    + +
    +
    + + print (rank_base, rtn[, colour=defines.color.white[, below=false]]) +
    +
    + Prints to all rank of greater/lower power of the rank given + + +

    Parameters:

    +
      +
    • rank_base + Ranking._rank or pointerToRank + the rank that acts as the cut off point (rank is always included) +
    • +
    • rtn + what do you want to return to the players +
    • +
    • colour + defines.color + the colour that will be used to print + (default defines.color.white) +
    • +
    • below + boolean + if true print to children rather than parents + (default false) +
    • +
    + + + + +

    Usage:

    +
      +
      Ranking.print('admin','We got a grifer')
      +
    + +
    +
    + + give_rank (player[, rank=default[, by_player='server'[, tick=game.tick]]]) +
    +
    + Gives a user a rank + + +

    Parameters:

    +
      +
    • player + LuaPlayer or pointerToPlayer + the player to give the rank to +
    • +
    • rank + Ranking._rank or pointerToRank + the rank to give to the player + (default default) +
    • +
    • by_player + LuaPlayer or pointerToPlayer + the player who is giving the rank + (default 'server') +
    • +
    • tick + number + the tick that the rank is being given on, used as pass though + (default game.tick) +
    • +
    + + + + +

    Usage:

    +
      +
      Ranking.give_rank(1,'admin')
      +
    + +
    +
    + + revert (player[, by_player=nil]) +
    +
    + Revert the last change to a players rank + + +

    Parameters:

    +
      +
    • player + LuaPlayer or pointerToPlayer + the player to revert the rank of +
    • +
    • by_player + the player who is doing the revert + (default nil) +
    • +
    + + + + +

    Usage:

    +
      +
      Ranking.revert(1) -- reverts the rank of player with index 1
      +
    + +
    +
    + + find_preset (player[, tick=nil]) +
    +
    + Given that the player has a rank in the preset table it is given; also will attempt to promote players if a time requirement is met + + +

    Parameters:

    +
      +
    • player + LuaPlayer or pointerToPlayer + the player to test for an auto rank +
    • +
    • tick + number + the tick it happens on + (default nil) +
    • +
    + + + + +

    Usage:

    +
      +
      Ranking.find_preset(1) -- attemps to find the preset for player with index 1
      +
    + +
    +
    +

    Tables

    + +
    +
    + + global +
    +
    + Global Table + + +

    Fields:

    +
      +
    • old + contains the previous rank a use had before a rank change +
    • +
    • preset + contains the preset ranks that users will recive apon joining +
    • +
    • last_change + contains the name of the player who last had there rank chagned +
    • +
    + + + + + +
    +
    + + ranks +
    +
    + Contains the location of all the ranks, readonly during runtime + + + + + + + +
    +
    + + ranks +
    +
    + Contains the location of all the rank groups, readonly during runtime + + + + + + + +
    +
    + + meta +
    +
    + Contains some meta data about the ranks + + +

    Fields:

    +
      +
    • default + this is the name of the default rank +
    • +
    • root + this is the name of the root rank +
    • +
    • time_ranks + a list of all ranks which have a time requirement +
    • +
    • time_highest + the power of the highest rank that has a time requirement +
    • +
    • time_lowest + the lowest amount of time required for a time rank +
    • +
    + + + + + +
    +
    +

    Events

    + +
    +
    + + rank_change +
    +
    + Called when there is a rank change for a user + + +

    field:

    +
      +
    • name + the rank id +
    • +
    • tick + the tick which the event was raised on +
    • +
    • player_index + the player whos rank was changed +
    • +
    • by_player_index + the player who changed the rank, 0 means server +
    • +
    • new_rank + the name of the rank that was given +
    • +
    • old_rank + the name of the rank the player had +
    • +
    + + + + + +
    +
    +

    Class Rank

    + +
    + The class for the ranks +
    +
    +
    + + Ranking._rank:allowed (action) +
    +
    + Is this rank allowed to open this gui or use this command etc. + + +

    Parameters:

    +
      +
    • action + teh + to test for +
    • +
    + +

    Returns:

    +
      + + boolean + is it allowed +
    + + + +

    Usage:

    +
      +
      rank:allowed('interface') -- does the rank have permision for 'interface'
      +
    + +
    +
    + + Ranking._rank:get_players ([online=false]) +
    +
    + Get all the players in this rank + + +

    Parameters:

    +
      +
    • online + boolean + get only online players + (default false) +
    • +
    + +

    Returns:

    +
      + + table + a table of all players in this rank +
    + + + +

    Usage:

    +
      +
      rank:get_players()
      +
    + +
    +
    + + Ranking._rank:print (rtn[, colour=defines.color.white[, show_default=false]]) +
    +
    + Print a message to all players of this rank + + +

    Parameters:

    +
      +
    • rtn + any value you want to return +
    • +
    • colour + define.color + the colour that will be used to print + (default defines.color.white) +
    • +
    • show_default + boolean + weather to use the default rank name for the print, used as a pass though + (default false) +
    • +
    + + + + +

    Usage:

    +
      +
      rank:print('foo') -- prints to all members of this rank
      +
    + +
    +
    + + Ranking._rank:edit (key, value) +
    +
    + Allows for a clean way to edit rank objects + + +

    Parameters:

    +
      +
    • key + string + the key to edit, often allow or disallow +
    • +
    • value + the new value to be set +
    • +
    + + + + +

    Usage:

    +
      +
      rank:edit('allow',{'interface'}) -- allows this rank to use 'interface'
      +
    + +
    +
    +

    Class Group

    + +
    + The class for the rank groups, the way to allow modules to idex a group that is always present, ranks will always look to there group as a parent +
    +
    +
    + + Ranking._group:create (obj) +
    +
    + Creates a new group + + +

    Parameters:

    +
      +
    • obj + table + the fields for this object +
    • +
    + +

    Returns:

    +
      + + Ranking._group + returns the object to allow chaining +
    + + + +

    Usage:

    +
      +
      Ranking._group:create{name='root'} -- returns group with name root
      +
    + +
    +
    + + Ranking._group:add_rank (obj) +
    +
    + Creats a new rank with this group as its group + + +

    Parameters:

    +
      +
    • obj + table + the fields for this object +
    • +
    + +

    Returns:

    +
      + + Ranking._group + returns the object to allow chaining +
    + + + +

    Usage:

    +
      +
      group:add_rank{name='root'} -- returns self
      +
    + +
    +
    + + Ranking._group:edit (key, value) +
    +
    + Allows for a clean way to edit rank group objects + + +

    Parameters:

    +
      +
    • key + string + the key to edit, often allow or disallow +
    • +
    • value + the new value to be set +
    • +
    + + + + +

    Usage:

    +
      +
      group:edit('allow',{'interface'}) -- allows this rank to use 'interface'
      +
    + +
    +
    +

    modules.expgamingcore.ranking.src.server Functions

    + +
    +
    + + _comment () +
    +
    + This file will be loaded when ExpGamingCore.Server is present + + + + + + + +
    +
    + + Ranking._rank:print (rtn[, colour=defines.color.white[, show_default=false]]) +
    +
    + Print a message to all players of this rank + + +

    Parameters:

    +
      +
    • rtn + any value you want to return +
    • +
    • colour + define.color + the colour that will be used to print + (default defines.color.white) +
    • +
    • show_default + boolean + weather to use the default rank name for the print, used as a pass though + (default false) +
    • +
    + + + + +

    Usage:

    +
      +
      rank:print('foo') -- prints to all members of this rank
      +
    + +
    +
    + + +
    +
    +
    +generated by LDoc 1.4.6 +Last updated 2018-06-02 21:40:51 +
    +
    + + diff --git a/doc/modules/ExpGamingCore.Server.html b/doc/modules/ExpGamingCore.Server.html index e6a302f3..af7f3d4e 100644 --- a/doc/modules/ExpGamingCore.Server.html +++ b/doc/modules/ExpGamingCore.Server.html @@ -50,7 +50,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -828,7 +828,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/ExpGamingCore.Sync.html b/doc/modules/ExpGamingCore.Sync.html index 20c91a7f..45206ac7 100644 --- a/doc/modules/ExpGamingCore.Sync.html +++ b/doc/modules/ExpGamingCore.Sync.html @@ -50,7 +50,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -158,6 +158,10 @@ add_to_gui (element) Adds a emeltent to the sever info gui + + server-info + Creates a center gui that will appear on join +

    modules.expgamingcore.sync.src.ranking Functions

    @@ -720,6 +724,20 @@
    Sync.add_to_gui('string') -- return true
    + +
    + + server-info +
    +
    + Creates a center gui that will appear on join + + + + + + +

    modules.expgamingcore.sync.src.ranking Functions

    @@ -794,7 +812,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/ExpGamingLib.html b/doc/modules/ExpGamingLib.html index 7b623237..b044c6e7 100644 --- a/doc/modules/ExpGamingLib.html +++ b/doc/modules/ExpGamingLib.html @@ -46,7 +46,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -412,7 +412,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/FSM.html b/doc/modules/FSM.html index acd010c5..a4595c28 100644 --- a/doc/modules/FSM.html +++ b/doc/modules/FSM.html @@ -48,7 +48,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -421,9 +421,9 @@
      -
    • default - table or true - the default value of global, if true then default is restored +
    • if + table, string or true + table then the default for the global, if a string then the module to get the global of, if true then reset the global to default (default {})
    @@ -436,6 +436,7 @@
  • global[key] -- used like the normal global table
  • global{'foo','bar'} -- sets the default value
  • global(true) -- restores global to default
  • +
  • global(mopdule_name) -- returns that module's global
  • @@ -446,7 +447,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/StdLib.Color.html b/doc/modules/StdLib.Color.html index e2efad66..935a6c09 100644 --- a/doc/modules/StdLib.Color.html +++ b/doc/modules/StdLib.Color.html @@ -47,7 +47,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -553,7 +553,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/StdLib.Game.html b/doc/modules/StdLib.Game.html index a3d7da7a..441381ef 100644 --- a/doc/modules/StdLib.Game.html +++ b/doc/modules/StdLib.Game.html @@ -46,7 +46,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -214,7 +214,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/StdLib.String.html b/doc/modules/StdLib.String.html index b2924c8a..b3e89aab 100644 --- a/doc/modules/StdLib.String.html +++ b/doc/modules/StdLib.String.html @@ -46,7 +46,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -294,7 +294,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/StdLib.Table.html b/doc/modules/StdLib.Table.html index 5a85e0e7..3864f2ce 100644 --- a/doc/modules/StdLib.Table.html +++ b/doc/modules/StdLib.Table.html @@ -46,7 +46,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -1123,7 +1123,7 @@ some_func(1,2)
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/StdLib.Time.html b/doc/modules/StdLib.Time.html index 9b5dd816..26c9fd4b 100644 --- a/doc/modules/StdLib.Time.html +++ b/doc/modules/StdLib.Time.html @@ -46,7 +46,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -131,7 +131,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/modules.expgamingcore.commands.control.html b/doc/modules/modules.expgamingcore.commands.control.html index bd16c3b0..ea606cc1 100644 --- a/doc/modules/modules.expgamingcore.commands.control.html +++ b/doc/modules/modules.expgamingcore.commands.control.html @@ -46,7 +46,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -124,7 +124,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/modules.expgamingcore.gui.control.html b/doc/modules/modules.expgamingcore.gui.control.html index ab3125b7..8614ed29 100644 --- a/doc/modules/modules.expgamingcore.gui.control.html +++ b/doc/modules/modules.expgamingcore.gui.control.html @@ -46,7 +46,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -160,7 +160,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/modules.expgamingcore.gui.guiparts.center.html b/doc/modules/modules.expgamingcore.gui.guiparts.center.html index 124667d9..65c35f8b 100644 --- a/doc/modules/modules.expgamingcore.gui.guiparts.center.html +++ b/doc/modules/modules.expgamingcore.gui.guiparts.center.html @@ -46,7 +46,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -278,7 +278,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/modules.expgamingcore.gui.guiparts.inputs.html b/doc/modules/modules.expgamingcore.gui.guiparts.inputs.html index 7e375716..70e4eb4b 100644 --- a/doc/modules/modules.expgamingcore.gui.guiparts.inputs.html +++ b/doc/modules/modules.expgamingcore.gui.guiparts.inputs.html @@ -46,7 +46,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -434,7 +434,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/modules.expgamingcore.gui.guiparts.left.html b/doc/modules/modules.expgamingcore.gui.guiparts.left.html index c08d35f9..0196fe8f 100644 --- a/doc/modules/modules.expgamingcore.gui.guiparts.left.html +++ b/doc/modules/modules.expgamingcore.gui.guiparts.left.html @@ -46,7 +46,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -181,7 +181,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/modules.expgamingcore.gui.guiparts.popup.html b/doc/modules/modules.expgamingcore.gui.guiparts.popup.html index e73fe754..5de07ceb 100644 --- a/doc/modules/modules.expgamingcore.gui.guiparts.popup.html +++ b/doc/modules/modules.expgamingcore.gui.guiparts.popup.html @@ -46,7 +46,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -126,7 +126,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/modules.expgamingcore.gui.guiparts.toolbar.html b/doc/modules/modules.expgamingcore.gui.guiparts.toolbar.html index e27ca143..8898c1b5 100644 --- a/doc/modules/modules.expgamingcore.gui.guiparts.toolbar.html +++ b/doc/modules/modules.expgamingcore.gui.guiparts.toolbar.html @@ -46,7 +46,7 @@
  • modules.expgamingcore.gui.guiparts.popup
  • modules.expgamingcore.gui.guiparts.toolbar
  • modules.expgamingcore.gui.control
  • -
  • modules.expgamingcore.ranking.control
  • +
  • ExpGamingCore.Ranking
  • ExpGamingCore.Server
  • ExpGamingCore.Sync
  • ExpGamingLib
  • @@ -117,7 +117,7 @@
    generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 +Last updated 2018-06-02 21:40:51
    diff --git a/doc/modules/modules.expgamingcore.ranking.control.html b/doc/modules/modules.expgamingcore.ranking.control.html deleted file mode 100644 index 8e203aae..00000000 --- a/doc/modules/modules.expgamingcore.ranking.control.html +++ /dev/null @@ -1,381 +0,0 @@ - - - - - Reference - - - - -
    - -
    - -
    -
    -
    - - -
    - - - - - - -
    - -

    Module modules.expgamingcore.ranking.control

    -

    Returns a rank object given a player or rank name

    -

    -

    Usage:

    -
      -
      Ranking.get_rank(game.player)
      - Ranking.get_rank('admin')
      -
      -
    - - -

    Functions

    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Ranking.get_group (mixed)Returns the group object used to sort ranks given group name or see Ranking.get_rank
    Ranking.print (rank_base, rtn, colour, below)Prints to all rank of greater/lower power of the rank given
    Ranking.give_rank (player, rank[, by_player='server'[, tick=game.tick]])Gives a user a rank
    Ranking.revert (player[, by_player=nil])Revert the last change to a players rank
    Ranking.find_preset (player[, tick=nil])Given the player has a rank in the preset table it is given
    Ranking._rank:allowed (action)Is this rank allowed to open this gui or use this command etc.
    Ranking._rank:get_players (online)Get all the players in this rank
    Ranking._rank:print (rtn, colour, show_default)Print a message to all players of this rank
    - -
    -
    - - -

    Functions

    - -
    -
    - - Ranking.get_group (mixed) -
    -
    - Returns the group object used to sort ranks given group name or see Ranking.get_rank - - -

    Parameters:

    -
      -
    • mixed - player|player index|player name|rank name|rank|'server'|'root'|group name|group what group to get -
    • -
    - -

    Returns:

    -
      - - table - the group that is linked to mixed -
    - - - -

    Usage:

    -
      -
      Ranking.get_group(game.player)
      - Ranking.get_group('root')
      -
    - -
    -
    - - Ranking.print (rank_base, rtn, colour, below) -
    -
    - Prints to all rank of greater/lower power of the rank given - - -

    Parameters:

    -
      -
    • rank_base - the rank that acts as the cut off point (rank is always included) -
    • -
    • rtn - what do you want to return to the players -
    • -
    • colour - defines.color - the colour that will be used to print -
    • -
    • below - bolean - if true rank below base are printed to -
    • -
    - - - - -

    Usage:

    -
      -
      Ranking.print('admin','We got a grifer')
      -
    - -
    -
    - - Ranking.give_rank (player, rank[, by_player='server'[, tick=game.tick]]) -
    -
    - Gives a user a rank - - -

    Parameters:

    -
      -
    • player - the player to give the rank to -
    • -
    • rank - the rank to give to the player -
    • -
    • by_player - the player who is giving the rank - (default 'server') -
    • -
    • tick - the tick that the rank is being given on - (default game.tick) -
    • -
    - - - - -

    Usage:

    -
      -
      Ranking.give_rank(1,'admin')
      -
    - -
    -
    - - Ranking.revert (player[, by_player=nil]) -
    -
    - Revert the last change to a players rank - - -

    Parameters:

    -
      -
    • player - the player to revert the rank of -
    • -
    • by_player - the player who is doing the revert - (default nil) -
    • -
    - - - - -

    Usage:

    -
      -
      Ranking.revert(1)
      -
    - -
    -
    - - Ranking.find_preset (player[, tick=nil]) -
    -
    - Given the player has a rank in the preset table it is given - - -

    Parameters:

    -
      -
    • player - the player to test for an auto rank -
    • -
    • tick - number - the tick it happens on - (default nil) -
    • -
    - - - - -

    Usage:

    -
      -
      Ranking.find_preset(1)
      -
    - -
    -
    - - Ranking._rank:allowed (action) -
    -
    - Is this rank allowed to open this gui or use this command etc. - - -

    Parameters:

    -
      -
    • action - teh - to test for -
    • -
    - -

    Returns:

    -
      - - bolean - is it allowed -
    - - - -

    Usage:

    -
      -
      rank:allowed('server-interface')
      -
    - -
    -
    - - Ranking._rank:get_players (online) -
    -
    - Get all the players in this rank - - -

    Parameters:

    -
      -
    • online - bolean - get only online players -
    • -
    - -

    Returns:

    -
      - - table - a table of all players in this rank -
    - - - -

    Usage:

    -
      -
      rank:get_players()
      -
    - -
    -
    - - Ranking._rank:print (rtn, colour, show_default) -
    -
    - Print a message to all players of this rank - - -

    Parameters:

    -
      -
    • rtn - any value you want to return -
    • -
    • colour - define.color - the colour that will be used to print -
    • -
    • show_default - boolean - weather to use the default rank name for the print -
    • -
    - - - - -

    Usage:

    -
      -
      rank:print('foo')
      -
    - -
    -
    - - - - -
    -generated by LDoc 1.4.6 -Last updated 2018-06-01 16:29:39 -
    - - - diff --git a/modules/ExpGamingCore/Ranking/control.lua b/modules/ExpGamingCore/Ranking/control.lua index 7a56de38..644684c9 100644 --- a/modules/ExpGamingCore/Ranking/control.lua +++ b/modules/ExpGamingCore/Ranking/control.lua @@ -3,7 +3,6 @@ -- @alias Ranking -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE - local Ranking = {} local module_verbose = false --true|false @@ -11,7 +10,7 @@ local module_verbose = false --true|false -- @table global -- @field old contains the previous rank a use had before a rank change -- @field preset contains the preset ranks that users will recive apon joining --- @filed last_change contains the name of the player who last had there rank chagned +-- @field last_change contains the name of the player who last had there rank chagned local global = global{old={},preset={},last_change=nil} --- Called when there is a rank change for a user @@ -78,7 +77,7 @@ Ranking.groups = setmetatable({},{ --- Contains some meta data about the ranks -- @table Ranking.meta -- @field default this is the name of the default rank --- @filed root this is the name of the root rank +-- @field root this is the name of the root rank -- @field time_ranks a list of all ranks which have a time requirement -- @field time_highest the power of the highest rank that has a time requirement -- @field time_lowest the lowest amount of time required for a time rank @@ -118,7 +117,7 @@ end -- @usage Ranking.get_rank('admin') -- returns rank by the name of admin -- @tparam ?player|player_index|player_name|rank_name|Ranking._rank|'server'|'root' mixed what rank to get -- @treturn[1] table the rank that is linked to mixed --- @trrturn[2] nil there was no rank found +-- @treturn[2] nil there was no rank found function Ranking.get_rank(mixed) if not mixed then return error('Ranking.get_rank recived no paramerters') end local ranks = Ranking.ranks @@ -141,10 +140,10 @@ end --- Returns the group object used to sort ranks given group name or rank -- @usage Ranking.get_group(game.player) -- returns player's rank group -- @usage Ranking.get_group('root') -- returns group by name of root --- @tparam ?player|player_index|player_name|rank_name|rank|'server'|'root'|group name|group mixed what group to get +-- @tparam ?player|player_index|player_name|rank_name|rank|'server'|'root'|group_name|group mixed what group to get -- @see Ranking.get_rank -- @treturn[1] table the group that is linked to mixed --- @trrturn[2] nil there was no rank group found +-- @treturn[2] nil there was no rank group found function Ranking.get_group(mixed) if not mixed then return error('Ranking.get_group recived no paramerters') end local groups = Ranking.groups diff --git a/modules/ExpGamingCore/Ranking/src/config.lua b/modules/ExpGamingCore/Ranking/src/config.lua index 2a50707d..fde68174 100644 --- a/modules/ExpGamingCore/Ranking/src/config.lua +++ b/modules/ExpGamingCore/Ranking/src/config.lua @@ -1,9 +1,3 @@ ---- Description - A small description that will be displayed on the doc --- @submodule ExpGamingCore.Ranking --- @alias Ranking --- @author Cooldude2606 --- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE - --[[ How to use groups: name The name that you can use to reference it. diff --git a/modules/ExpGamingCore/Ranking/src/core.lua b/modules/ExpGamingCore/Ranking/src/core.lua index d8ad5c81..b8707489 100644 --- a/modules/ExpGamingCore/Ranking/src/core.lua +++ b/modules/ExpGamingCore/Ranking/src/core.lua @@ -1,9 +1,3 @@ ---- Description - A small description that will be displayed on the doc --- @submodule ExpGamingCore.Ranking --- @alias Ranking --- @author Cooldude2606 --- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE - --[[ How to use groups: name the name that you can use to refence it. diff --git a/modules/ExpGamingCore/Ranking/src/server.lua b/modules/ExpGamingCore/Ranking/src/server.lua index 22b66ef7..bef291b1 100644 --- a/modules/ExpGamingCore/Ranking/src/server.lua +++ b/modules/ExpGamingCore/Ranking/src/server.lua @@ -1,4 +1,4 @@ ---- Description - A small description that will be displayed on the doc +--- A full ranking system for factorio. -- @submodule ExpGamingCore.Ranking -- @alias Ranking -- @author Cooldude2606 diff --git a/modules/ExpGamingCore/Sync/src/gui.lua b/modules/ExpGamingCore/Sync/src/gui.lua index dc3b4b23..914cb883 100644 --- a/modules/ExpGamingCore/Sync/src/gui.lua +++ b/modules/ExpGamingCore/Sync/src/gui.lua @@ -1,4 +1,4 @@ ---- Description - A small description that will be displayed on the doc +--- Allows syncing with an outside server and info panle. -- @submodule ExpGamingCore.Sync -- @alias Sync -- @author Cooldude2606 @@ -36,8 +36,7 @@ local function label_format(label,width) end --- Creates a center gui that will appear on join --- @table server-info --- @local call to Gui.Center +-- @gui server-info Gui.center.add{ name='server-info', caption='Server Info', diff --git a/modules/ExpGamingCore/Sync/src/ranking.lua b/modules/ExpGamingCore/Sync/src/ranking.lua index a15944db..c0bb7bef 100644 --- a/modules/ExpGamingCore/Sync/src/ranking.lua +++ b/modules/ExpGamingCore/Sync/src/ranking.lua @@ -1,4 +1,4 @@ ---- Description - A small description that will be displayed on the doc +--- Allows syncing with an outside server and info panle. -- @submodule ExpGamingCore.Sync -- @alias Sync -- @author Cooldude2606 From 6272e29606a5a8d2f8c565ce4c06a58db864191a Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 2 Jun 2018 21:42:17 +0100 Subject: [PATCH 026/231] Changed Version To 4.0.0 --- modules/ExpGamingCore/softmod.json | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/ExpGamingCore/softmod.json b/modules/ExpGamingCore/softmod.json index 98e4a8ec..00e74eca 100644 --- a/modules/ExpGamingCore/softmod.json +++ b/modules/ExpGamingCore/softmod.json @@ -14,8 +14,8 @@ "version": "3.4.0", "location": "url", "dependencies": { - "ExpGamingLib": ">=3.0.0", - "ExpGamingCore/Ranking": ">=3.0.0" + "ExpGamingLib": ">=4.0.0", + "ExpGamingCore/Ranking": ">=4.0.0" } }, "Gui": { @@ -27,9 +27,9 @@ "location": "url", "dependencies": { "FactorioModGui": ">=1.0.0", - "ExpGamingLib": ">=3.0.0", - "ExpGamingCore/Ranking": ">=3.0.0", - "ExpGamingCore/Server": "?>=3.0.0" + "ExpGamingLib": ">=4.0.0", + "ExpGamingCore/Ranking": ">=4.0.0", + "ExpGamingCore/Server": "?>=4.0.0" } }, "Ranking": { @@ -40,10 +40,10 @@ "version": "3.4.0", "location": "url", "dependencies": { - "ExpGamingLib": ">=3.0.0", + "ExpGamingLib": ">=4.0.0", "FactorioStdLib.Color": ">=0.8.0", "FactorioStdLib.Table": ">=0.8.0", - "ExpGamingCore.Server": "?>=3.0.0" + "ExpGamingCore.Server": "?>=4.0.0" } }, "Server": { @@ -54,10 +54,10 @@ "version": "3.4.0", "location": "url", "dependencies": { - "ExpGamingLib": ">=3.0.0", + "ExpGamingLib": ">=4.0.0", "FactorioStdLib.Table": ">=0.8.0", - "ExpGamingCore.Ranking": "?>=3.0.0", - "ExpGamingCore.Commands": "?>=3.0.0" + "ExpGamingCore.Ranking": "?>=4.0.0", + "ExpGamingCore.Commands": "?>=4.0.0" } }, "Sync": { @@ -68,11 +68,11 @@ "version": "3.4.0", "location": "url", "dependencies": { - "ExpGamingLib": ">=3.0.0", + "ExpGamingLib": ">=4.0.0", "FactorioStdLib.Color": ">=0.8.0", "FactorioStdLib.Table": ">=0.8.0", - "ExpGamingCore.Ranking": "?>=3.0.0", - "ExpGamingCore.Gui": "?>=3.0.0" + "ExpGamingCore.Ranking": "?>=4.0.0", + "ExpGamingCore.Gui": "?>=4.0.0" } } }, From 9be85f04a61720dad2f0729bf2b135db9d4090bb Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 5 Jun 2018 19:32:29 +0100 Subject: [PATCH 027/231] Added module: ExpGamingCore.Commands --- FactorioSoftmodManager.lua | 5 +- doc/index.html | 8 +- doc/modules/ExpGamingCore.Commands.html | 400 ++++++++++++++++++ doc/modules/ExpGamingCore.Ranking.html | 4 +- doc/modules/ExpGamingCore.Server.html | 20 +- doc/modules/ExpGamingCore.Sync.html | 4 +- doc/modules/ExpGamingLib.html | 4 +- doc/modules/FSM.html | 4 +- doc/modules/StdLib.Color.html | 4 +- doc/modules/StdLib.Game.html | 4 +- doc/modules/StdLib.String.html | 4 +- doc/modules/StdLib.Table.html | 4 +- doc/modules/StdLib.Time.html | 4 +- ...odules.expgamingcore.commands.control.html | 131 ------ .../modules.expgamingcore.gui.control.html | 4 +- ...les.expgamingcore.gui.guiparts.center.html | 4 +- ...les.expgamingcore.gui.guiparts.inputs.html | 4 +- ...dules.expgamingcore.gui.guiparts.left.html | 4 +- ...ules.expgamingcore.gui.guiparts.popup.html | 4 +- ...es.expgamingcore.gui.guiparts.toolbar.html | 4 +- locale/en/ExpGamingCore.Commands.cfg | 13 +- locale/en/ExpGamingCore.Server.cfg | 2 + modules/ExpGamingCore/Commands/control.lua | 249 +++++++---- modules/ExpGamingCore/Ranking/control.lua | 4 + modules/ExpGamingCore/Server/control.lua | 24 +- modules/ExpGamingCore/Server/src/commands.lua | 6 +- modules/ExpGamingCore/Sync/control.lua | 1 + modules/ExpGamingCore/softmod.json | 43 +- modules/ExpGamingLib/control.lua | 1 + modules/ExpGamingLib/softmod.json | 6 +- modules/index.lua | 2 +- 31 files changed, 686 insertions(+), 289 deletions(-) create mode 100644 doc/modules/ExpGamingCore.Commands.html delete mode 100644 doc/modules/modules.expgamingcore.commands.control.html create mode 100644 locale/en/ExpGamingCore.Server.cfg diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index e1916ba0..e501e76a 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -69,6 +69,7 @@ end Manager.verbose = function(rtn,action) local settings = Manager.setVerbose local state = Manager.currentState + if Manager.error and state == Manager.error.__crash then return end -- if ran in a module the the global module_name is present local rtn = type(rtn) == table and serpent.line(rtn) or tostring(rtn) if module_name then rtn='['..module_name..'] '..rtn @@ -341,6 +342,7 @@ Manager.loadModules = setmetatable({}, -- @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({ + __crash=false, __error_call=error, __error_const={}, __error_handler=function(handler_name,callback) @@ -400,7 +402,7 @@ Manager.error = setmetatable({ 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 k == '__error_call' or k == '__error_const' or k == '__error_handler' or k == '__crash' then return next_pair(tbl,k) end if type(v) == 'function' then return k,v end end return next_pair, tbl, nil @@ -437,6 +439,7 @@ Manager.event = setmetatable({ },{ __metatable=false, __call=function(tbl,event_name,new_callback,...) + if Manager.error.__crash then Manager.error.__error_call('No error handlers loaded; Game not loaded; Forced crash: '..tostring(Manager.error.__crash)) end -- 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 diff --git a/doc/index.html b/doc/index.html index 27be2284..221fde79 100644 --- a/doc/index.html +++ b/doc/index.html @@ -32,7 +32,7 @@

    Modules

    - Outline of the paramaters accepted by Sync.emit_embeded + Outline of the paramaters accepted by Sync.emit_embedded

    Fields:

    diff --git a/modules/AdvancedStartingItems/control.lua b/modules/AdvancedStartingItems/control.lua index 5b55ee9e..31c1e718 100644 --- a/modules/AdvancedStartingItems/control.lua +++ b/modules/AdvancedStartingItems/control.lua @@ -2,9 +2,9 @@ -- @module AdvancedStartingItems@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule --- Local Varibles +-- Local Variables local items = { ['iron-plate']=function(player,made) if tick_to_min(game.tick) < 5 then return 8 else return (made*10)/math.pow(tick_to_min(game.tick),2) end end, ['copper-plate']=function(player,made) if tick_to_min(game.tick) < 5 then return 0 else return (made*8)/math.pow(tick_to_min(game.tick),2) end end, @@ -12,9 +12,9 @@ local items = { ['iron-gear-wheel']=function(player,made) if tick_to_min(game.tick) < 5 then return 0 else return (made*6)/math.pow(tick_to_min(game.tick),2) end end, ['steel-plate']=function(player,made) if tick_to_min(game.tick) < 5 then return 0 else return(made*4)/math.pow(tick_to_min(game.tick),2) end end, ['pistol']=function(player,made) if player.force.item_production_statistics.get_input_count('submachine-gun') > 5 then return 0 else return 1 end end, - ['submachine-gun']=function(player,made) if made > 5 then return 1 else return 0 end end, + ['submachine-gun']=function(player,made) if made > 5 then return 1 else return 0 end end, ['firearm-magazine']=function(player,made) if player.force.item_production_statistics.get_input_count('piercing-rounds-magazine') > 100 then return 0 else return 10 end end, - ['piercing-rounds-magazine']=function(player,made) if made > 100 then return 10 else return 0 end end, + ['piercing-rounds-magazine']=function(player,made) if made > 100 then return 10 else return 0 end end, ['light-armor']=function(player,made) if made > 5 and player.force.item_production_statistics.get_input_count('heavy-armor') <= 5 then return 1 else return 0 end end, ['heavy-armor']=function(player,made) if made > 5 then return 1 else return 0 end end, ['burner-mining-drill']=function(player,made) if tick_to_min(game.tick) < 5 then return 4 else return 0 end end, @@ -28,7 +28,7 @@ local module_verbose = false local ThisModule = {} -- Event Handlers Define -Event.register(defines.events.on_player_created, function(event) +script.on_event(defines.events.on_player_created, function(event) local player = game.players[event.player_index] if event.player_index == 1 then player.force.friendly_fire = false @@ -42,4 +42,4 @@ Event.register(defines.events.on_player_created, function(event) end) -- Module Return -return ThisModule \ No newline at end of file +return ThisModule \ No newline at end of file diff --git a/modules/ChatPopup/control.lua b/modules/ChatPopup/control.lua index 1ddd025e..c22c1564 100644 --- a/modules/ChatPopup/control.lua +++ b/modules/ChatPopup/control.lua @@ -2,7 +2,7 @@ -- @module ChatPopup@4.0.0 -- @author badgamernl -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ChatPopup +-- @alias ChatPopup -- Module Require local Game = require('FactorioStdLib.Game') @@ -19,7 +19,7 @@ function ChatPopup.sendFlyingText(player, text) for i=1, #text, chunkSize do chunks[#chunks+1] = text:sub(i,i+chunkSize - 1) end - -- Itterate over text chunks and create them as floating text centered above the player + -- Iterate over text chunks and create them as floating text centered above the player -- Disabled false centering because of not being able to disable scaling: (1 / 7.9 * #value) for i,value in ipairs(chunks) do _player.surface.create_entity{ @@ -31,11 +31,11 @@ function ChatPopup.sendFlyingText(player, text) end end -Event.register(defines.events.on_console_chat, function(event) +script.on_event(defines.events.on_console_chat, function(event) local player = game.players[event.player_index] if not player then return end if not event.message then return end - + -- Send message player send to player itself local message = player.name .. ': ' .. event.message ChatPopup.sendFlyingText(player, message) @@ -50,7 +50,7 @@ Event.register(defines.events.on_console_chat, function(event) end end end - + end) return ChatPopup \ No newline at end of file diff --git a/modules/DamagePopup/control.lua b/modules/DamagePopup/control.lua index adbd7b0b..b75b2003 100644 --- a/modules/DamagePopup/control.lua +++ b/modules/DamagePopup/control.lua @@ -1,20 +1,20 @@ ---- When a entibty is damaged y a player it will show how much damage you've dealth, When a player gets attacked by a entity it will popup the player's health in color. +--- When a entity is damaged y a player it will show how much damage you've death, When a player gets attacked by a entity it will popup the player's health in color. -- @module DamagePopup@4.0.0 -- @author badgamernl -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais DamagePopup +-- @alias DamagePopup -- Module Require local Color = require('FactorioStdLib.Color') local DamagePopup = {} -Event.register(defines.events.on_entity_damaged, function(event) +script.on_event(defines.events.on_entity_damaged, function(event) local entity = event.entity local cause = event.cause local damage = event.original_damage_amount local health = entity.health - -- local pre_attack_health = health + damage -- Didn't use it after all, maybe usefull later + -- local pre_attack_health = health + damage -- Didn't use it after all, maybe useful later local color = defines.textcolor.crit @@ -36,7 +36,7 @@ Event.register(defines.events.on_entity_damaged, function(event) entity.surface.create_entity{ name="flying-text", color=defines.textcolor.med, - text='-'..math.floor(damage), -- cooldude2606 added floor for damage ammount + text='-'..math.floor(damage), -- cooldude2606 added floor for damage amount position=entity.position } end diff --git a/modules/DeathMarkers/control.lua b/modules/DeathMarkers/control.lua index 3b47970a..051e5eb3 100644 --- a/modules/DeathMarkers/control.lua +++ b/modules/DeathMarkers/control.lua @@ -2,7 +2,7 @@ -- @module DeathMarkers@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Define local module_verbose = false @@ -14,7 +14,7 @@ local global = global{ } -- Event Handlers Define -Event.register(defines.events.on_player_died, function(event) +script.on_event(defines.events.on_player_died, function(event) local player = game.players[event.player_index] local tag = player.force.add_chart_tag(player.surface,{ position=player.position, @@ -24,7 +24,7 @@ Event.register(defines.events.on_player_died, function(event) table.insert(global.corpses,tag) end) -Event.register(defines.events.on_tick, function(event) +script.on_event(defines.events.on_tick, function(event) if (game.tick%3600) ~= 0 then return end if not global.corpses then global.corpses = {} end local key = 1 @@ -42,4 +42,4 @@ Event.register(defines.events.on_tick, function(event) end) -- Module Return -return ThisModule \ No newline at end of file +return ThisModule \ No newline at end of file diff --git a/modules/DeconControl/control.lua b/modules/DeconControl/control.lua index 6b658fa3..2976cb33 100644 --- a/modules/DeconControl/control.lua +++ b/modules/DeconControl/control.lua @@ -2,7 +2,7 @@ -- @module DeconControl@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Game = require('FactorioStdLib.Game') @@ -23,40 +23,40 @@ local ThisModule = { Event.register(-1,function(event) Server.new_thread{ name='tree-decon', - data={trees={},chache={},clear=0} + data={trees={},cache={},clear=0} }:on_event('tick',function(self) local trees = self.data.trees - if self.data.clear ~= 0 and self.data.clear < game.tick then self.data.chache = {} self.data.clear = 0 end + if self.data.clear ~= 0 and self.data.clear < game.tick then self.data.cache = {} self.data.clear = 0 end if #trees == 0 then return end for i = 0,math.ceil(#trees/10) do local tree = table.remove(trees,1) if tree and tree.valid then tree.destroy() end end end):on_event(defines.events.on_marked_for_deconstruction,function(self,event) - local chache = self.data.chache[event.player_index] - if not chache then + local cache = self.data.cache[event.player_index] + if not cache then local player = Game.get_player(event) if not player then return end if not Role then - if player.admin then self.data.chache[event.player_index] = {'tree-decon',false} - else self.data.chache[event.player_index] = {'decon',false} end + if player.admin then self.data.cache[event.player_index] = {'tree-decon',false} + else self.data.cache[event.player_index] = {'decon',false} end else - if Role.allowed(player,'tree-decon') then self.data.chache[event.player_index] = {'tree-decon',false} - elseif not Role.allowed(player,'decon') then self.data.chache[event.player_index] = {'no-decon',false} - else self.data.chache[event.player_index] = {'decon',false} end + if Role.allowed(player,'tree-decon') then self.data.cache[event.player_index] = {'tree-decon',false} + elseif not Role.allowed(player,'decon') then self.data.cache[event.player_index] = {'no-decon',false} + else self.data.cache[event.player_index] = {'decon',false} end end - chache = self.data.chache[event.player_index] + cache = self.data.cache[event.player_index] end if not event.entity.last_user or event.entity.name == 'entity-ghost' then - if chache[1] == 'tree-decon' then + if cache[1] == 'tree-decon' then table.insert(self.data.trees,event.entity) self.data.clear = game.tick + 10 end else - if chache[1] == 'no-decon' then + if cache[1] == 'no-decon' then event.entity.cancel_deconstruction('player') - if not chache[2] then - chache[2] = true + if not cache[2] then + cache[2] = true local player = Game.get_player(event) player_return({'DeconControl.player-print'},defines.textcolor.crit,player) Role.print(Role.meta.groups.Admin.lowest,{'DeconControl.rank-print',player.name},defines.textcolor.info) @@ -69,4 +69,4 @@ Event.register(-1,function(event) end) -- Module Return -return ThisModule \ No newline at end of file +return ThisModule \ No newline at end of file diff --git a/modules/ExpGamingAdmin/Ban/control.lua b/modules/ExpGamingAdmin/Ban/control.lua index 32bb1085..0a5f1935 100644 --- a/modules/ExpGamingAdmin/Ban/control.lua +++ b/modules/ExpGamingAdmin/Ban/control.lua @@ -2,7 +2,7 @@ -- @module ExpGamingAdmin.Ban@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Admin = require('ExpGamingAdmin') @@ -27,11 +27,11 @@ AdminGui.add_button('Ban','utility/danger_icon',{'ExpGamingAdmin.tooltip-ban'},f end) function Admin.ban(player,by_player,reason) - local player = Game.get_player(player) + player = Game.get_player(player) local by_player_name = Game.get_player(by_player) and Game.get_player(by_player).name or '' - local reason = Admin.create_reason(reason,by_player_name) + reason = Admin.create_reason(reason,by_player_name) Admin.set_banned(player,true) - if Sync then Sync.emit_embeded{ + if Sync then Sync.emit_embedded{ title='Player Ban', color=Color.to_hex(defines.textcolor.crit), description='There was a player banned.', diff --git a/modules/ExpGamingAdmin/ClearInventory/control.lua b/modules/ExpGamingAdmin/ClearInventory/control.lua index 7b47d37a..dea36113 100644 --- a/modules/ExpGamingAdmin/ClearInventory/control.lua +++ b/modules/ExpGamingAdmin/ClearInventory/control.lua @@ -1,8 +1,8 @@ ---- Adds a function to clear a players inventoy and move the items to spawn. +--- Adds a function to clear a players inventory and move the items to spawn. -- @module ExpGamingAdmin.ClearInventory@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Admin = require('ExpGamingAdmin') @@ -13,7 +13,7 @@ local module_verbose = false local ThisModule = {} -- Function Define -local inventorys = { +local inventories = { defines.inventory.player_main, defines.inventory.player_quickbar, defines.inventory.player_trash, @@ -23,7 +23,7 @@ local inventorys = { } function Admin.move_item_to_spawn(item,surface,chests) - local chests = chests or surface.find_entities_filtered{area={{-10,-10},{10,10}},name='iron-chest'} or {} + chests = chests or surface.find_entities_filtered{area={{-10,-10},{10,10}},name='iron-chest'} or {} local chest = nil while not chest or not chest.get_inventory(defines.inventory.chest).can_insert(item) do chest = table.remove(chests,1) @@ -38,14 +38,14 @@ function Admin.move_item_to_spawn(item,surface,chests) end function Admin.move_inventory(player) - local player = Game.get_player(player) + player = Game.get_player(player) if not player then return end local chests = player.surface.find_entities_filtered{area={{-10,-10},{10,10}},name='iron-chest'} or {} - for _,_inventory in pairs(inventorys) do + for _,_inventory in pairs(inventories) do local inventory = player.get_inventory(_inventory) if inventory then for item,count in pairs(inventory.get_contents()) do - local item = {name=item,count=count} + item = {name=item,count=count} chests = Admin.move_item_to_spawn(item,player.surface,chests) end inventory.clear() diff --git a/modules/ExpGamingAdmin/Commands/src/reports.lua b/modules/ExpGamingAdmin/Commands/src/reports.lua index 491fccb3..be67e7d8 100644 --- a/modules/ExpGamingAdmin/Commands/src/reports.lua +++ b/modules/ExpGamingAdmin/Commands/src/reports.lua @@ -16,7 +16,7 @@ commands.add_command('report', 'Reports a player', { if Admin.is_banned(player) then player_return({'ExpGamingAdmin.cant-report-ban',args.player.name}) return commands.error end if Role.has_flag(player,'not_reportable') then player_return({'ExpGamingAdmin.cant-report',args.player.name}) return commands.error end for _,report in pairs(global.addons.reports.reports) do if report[1] == _player.name then player_return({'ExpGamingAdmin.cant-report',args.player.name}) return commands.error end end - for _,report in pairs(global.addons.reports.varified) do if report[1] == _player.name then player_return({'ExpGamingAdmin.cant-report',args.player.name}) return commands.error end end + for _,report in pairs(global.addons.reports.verified) do if report[1] == _player.name then player_return({'ExpGamingAdmin.cant-report',args.player.name}) return commands.error end end Admin.report(player,event.player_index,reason) end) diff --git a/modules/ExpGamingAdmin/Commands/src/warnings.lua b/modules/ExpGamingAdmin/Commands/src/warnings.lua index 073f14ce..b3796656 100644 --- a/modules/ExpGamingAdmin/Commands/src/warnings.lua +++ b/modules/ExpGamingAdmin/Commands/src/warnings.lua @@ -24,5 +24,5 @@ commands.add_command('clear-warnings', 'Clears a player\'s warnings', { }, function(event,args) local player = args.player if Admin.is_banned(player) then player_return({'ExpGamingAdmin.cant-report-ban',args.player.name}) return commands.error end - Admin.clear_warings(player,event.player_index) + Admin.clear_warnings(player,event.player_index) end) \ No newline at end of file diff --git a/modules/ExpGamingAdmin/Gui/control.lua b/modules/ExpGamingAdmin/Gui/control.lua index d26b7910..7dd8c2e7 100644 --- a/modules/ExpGamingAdmin/Gui/control.lua +++ b/modules/ExpGamingAdmin/Gui/control.lua @@ -2,7 +2,7 @@ -- @module ExpGamingAdmin.Gui@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais AdminGui +-- @alias AdminGui -- Module Require local Admin = require('ExpGamingAdmin') @@ -10,7 +10,6 @@ local Gui = require('ExpGamingCore.Gui') local Role = require('ExpGamingCore.Role') local Game = require('FactorioStdLib.Game') local playerInfo -- ExpGamingPlayer.playerInfo@^4.0.0 -local mod_gui = require('mod-gui') -- Module Define local module_verbose = false @@ -42,7 +41,7 @@ function AdminGui.add_button(name,caption,tooltip,callback) tooltip=tooltip }:on_event('click',function(event) local parent = event.element.parent - pre_select_player = parent.player and parent.player.caption or nil + local pre_select_player = parent.player and parent.player.caption or nil callback(pre_select_player,event.player_index) end) end @@ -68,12 +67,12 @@ function AdminGui.draw(frame,filter_buttons) end -- Gui Define -local function _players(_player,root_frame,state) +local function get_players(_player,root_frame,state) local players = {'Select Player'} local _players = state and game.players or game.connected_players for _,player in pairs(_players) do if player.name ~= _player.name then - if Admin.is_banned and Admin.is_banned(player) then else + if not Admin.is_banned or not Admin.is_banned(player) then table.insert(players,player.name) end end @@ -82,14 +81,14 @@ local function _players(_player,root_frame,state) end local online_check = Gui.inputs.add_checkbox('online-check-admin-commands',false,'Show Offline',false,function(player,element) - element.parent['player-drop-down-admin-commands'].items = _players(player,element.parent,true) + element.parent['player-drop-down-admin-commands'].items = get_players(player,element.parent,true) element.parent['player-drop-down-admin-commands'].selected_index = 1 end,function(player,element) - element.parent['player-drop-down-admin-commands'].items = _players(player,element.parent,false) + element.parent['player-drop-down-admin-commands'].items = get_players(player,element.parent,false) element.parent['player-drop-down-admin-commands'].selected_index = 1 end) -local player_drop_down = Gui.inputs.add_drop_down('player-drop-down-admin-commands',_players,1,function(player,selected,items,element) +local player_drop_down = Gui.inputs.add_drop_down('player-drop-down-admin-commands',get_players,1,function(player,selected,items,element) element.parent.parent.player.caption = selected local player_info_flow = element.parent.parent.info_flow player_info_flow.clear() @@ -142,7 +141,7 @@ Admin.center = Gui.center{ tooltip={'ExpGamingAdmin.tooltip'}, draw=function(self,frame,pre_select_player,pre_select_action) frame.caption={'ExpGamingAdmin.name'} - local frame = frame.add{ + frame = frame.add{ type='flow', direction='horizontal' } @@ -166,7 +165,7 @@ Admin.center = Gui.center{ online_check:draw(dropdowns) local _drop = player_drop_down:draw(dropdowns) if pre_select_player then Gui.set_dropdown_index(_drop,pre_select_player.name) end - local _drop = action_drop_down:draw(dropdowns) + _drop = action_drop_down:draw(dropdowns) Gui.set_dropdown_index(_drop,pre_select_action) local _text = reason_input:draw(dropdowns) if pre_select_action == 'Jail' or pre_select_action == 'Kick' or pre_select_action == 'Ban' then @@ -174,7 +173,7 @@ Admin.center = Gui.center{ end if pre_select_player then playerInfo(pre_select_player,player_info_flow,true) end _text.style.width = 200 - local label = dropdowns.add{ + label = dropdowns.add{ name='warning', type='label', caption='', @@ -183,17 +182,17 @@ Admin.center = Gui.center{ label.style.single_line = false label.style.width = 200 take_action:draw(dropdowns) - local _caption = pre_select_player and pre_select_player.name or '' + local caption = pre_select_player and pre_select_player.name or '' frame.add{ name='player', type='label', - caption=_caption + caption=caption }.style.visible = false - local _caption = pre_select_action or '' + caption = pre_select_action or '' frame.add{ name='action', type='label', - caption=_caption + caption=caption }.style.visible = false end } diff --git a/modules/ExpGamingAdmin/Jail/control.lua b/modules/ExpGamingAdmin/Jail/control.lua index dcdcf211..e868d943 100644 --- a/modules/ExpGamingAdmin/Jail/control.lua +++ b/modules/ExpGamingAdmin/Jail/control.lua @@ -2,14 +2,13 @@ -- @module ExpGamingAdmin.Jail@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Admin = require('ExpGamingAdmin') local AdminGui = require('ExpGamingAdmin.Gui') local Server = require('ExpGamingCore.Server') local Role = require('ExpGamingCore.Role') -local Game = require('FactorioStdLib.Game') local Color -- FactorioStdLib.Color@^0.8.0 local Sync -- ExpGamingCore.Sync@^4.0.0 @@ -28,11 +27,11 @@ AdminGui.add_button('jail','utility/clock',{'ExpGamingAdmin.tooltip-jail'},funct end) function Admin.jail(player,by_player,reason) - local player, by_player = Admin.valid_players(player,by_player) + player, by_player = Admin.valid_players(player,by_player) if not player then return end - local reason = Admin.create_reason(reason,by_player.name) + reason = Admin.create_reason(reason,by_player.name) Admin.set_banned(player,'jail') - if Sync then Sync.emit_embeded{ + if Sync then Sync.emit_embedded{ title='Player Jail', color=Color.to_hex(defines.textcolor.med), description='There was a player jailed.', diff --git a/modules/ExpGamingAdmin/Kick/control.lua b/modules/ExpGamingAdmin/Kick/control.lua index 4b13003d..e36eef2e 100644 --- a/modules/ExpGamingAdmin/Kick/control.lua +++ b/modules/ExpGamingAdmin/Kick/control.lua @@ -2,7 +2,7 @@ -- @module ExpGamingAdmin.Kick@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Admin = require('ExpGamingAdmin') @@ -26,10 +26,10 @@ AdminGui.add_button('Kick','utility/warning_icon',{'ExpGamingAdmin.tooltip-kick' end) function Admin.kick(player,by_player,reason) - local player = Game.get_player(player) + player = Game.get_player(player) + reason = Admin.create_reason(reason,by_player_name) local by_player_name = Game.get_player(by_player) and Game.get_player(by_player).name or '' - local reason = Admin.create_reason(reason,by_player_name) - if Sync then Sync.emit_embeded{ + if Sync then Sync.emit_embedded{ title='Player Kick', color=Color.to_hex(defines.textcolor.high), description='There was a player kicked.', diff --git a/modules/ExpGamingAdmin/Reports/control.lua b/modules/ExpGamingAdmin/Reports/control.lua index 9ed5df58..56fad0ba 100644 --- a/modules/ExpGamingAdmin/Reports/control.lua +++ b/modules/ExpGamingAdmin/Reports/control.lua @@ -2,11 +2,10 @@ -- @module ExpGamingAdmin.Reports@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Admin = require('ExpGamingAdmin') -local Server = require('ExpGamingCore.Server') local Role = require('ExpGamingCore.Role') local Gui = require('ExpGamingCore.Gui') local Game = require('FactorioStdLib.Game') @@ -25,22 +24,22 @@ local ThisModule = { -- Global Define local global = global{ reports={}, - varified={} + verified={} } --- Local Varibles +-- Local Variables local report_to_warnings = 1 -- used in count_reports -local varified_to_warings = 3 -- used in count_reports +local verified_to_warnings = 3 -- used in count_reports local reports_needed_for_jail = 6 -- Function Define local function report_message(player,by_player,reason) - local player, by_player = Admin.valid_players(player,by_player) + player, by_player = Admin.valid_players(player,by_player) if not player then return end if Admin.is_banned(player,true) == 'report' then return end Role.print(Role.meta.groups.User.lowest,{'ExpGamingAdmin.low-print',player.name,reason},defines.textcolor.info,true) Role.print(Role.meta.groups.Admin.lowest,{'ExpGamingAdmin.high-print',player.name,by_player.name,reason},defines.textcolor.med) - if Sync then Sync.emit_embeded{ + if Sync then Sync.emit_embedded{ title='Player Report', color=Color.to_hex(defines.textcolor.med), description='A player was reported.', @@ -51,7 +50,7 @@ local function report_message(player,by_player,reason) end local function cheak_reports(player) - local player = Game.get_player(player) + player = Game.get_player(player) if not player then return end local reports = Admin.count_reports(player) if reports >= reports_needed_for_jail and Role.get_highest(player).group.name ~= 'Jail' then @@ -60,29 +59,29 @@ local function cheak_reports(player) end function Admin.count_reports(player) - local player = Game.get_player(player) + player = Game.get_player(player) if not player then return 0 end local _count = 0 if global.reports[player.name] then - for _,report in pairs(global.reports[player.name]) do + for _ in pairs(global.reports[player.name]) do _count=_count+report_to_warnings end end - if global.varified[player.name] then - for _,report in pairs(global.varified[player.name]) do - _count=_count+varified_to_warings + if global.verified[player.name] then + for _ in pairs(global.verified[player.name]) do + _count=_count+verified_to_warnings end end return _count end function Admin.report(player,by_player,reason) - local player, by_player = Admin.valid_players(player,by_player) + player, by_player = Admin.valid_players(player,by_player) if not player or Role.has_flag(player,'not_reportable') then return end if Admin.is_banned(by_player) or Role.has_flag(by_player,'is_jail') then return end - if Role.has_flag(by_player,'is_varified') then - global.varified[player.name] = global.varified[player.name] or {} - local reports = global.varified[player.name] + if Role.has_flag(by_player,'is_verified') then + global.verified[player.name] = global.verified[player.name] or {} + local reports = global.verified[player.name] for _,value in pairs(reports) do if value[1] == by_player.name then return end end @@ -100,12 +99,12 @@ function Admin.report(player,by_player,reason) end function Admin.clear_reports(player,by_player,no_emit) - local player, by_player = Admin.valid_players(player,by_player) + player, by_player = Admin.valid_players(player,by_player) if not player then return end global.reports[player.name]={} - global.varified[player.name]={} + global.verified[player.name]={} if not no_emit and Sync then - Sync.emit_embeded{ + Sync.emit_embedded{ title='Player Clear', color=Color.to_hex(defines.textcolor.low), description='A player had their reports cleared.', @@ -160,4 +159,4 @@ Admin.report_btn = Gui.inputs{ end) -- Module Return -return ThisModule \ No newline at end of file +return ThisModule \ No newline at end of file diff --git a/modules/ExpGamingAdmin/Teleport/control.lua b/modules/ExpGamingAdmin/Teleport/control.lua index 75e9f2ca..f745add4 100644 --- a/modules/ExpGamingAdmin/Teleport/control.lua +++ b/modules/ExpGamingAdmin/Teleport/control.lua @@ -2,7 +2,7 @@ -- @module ExpGamingAdmin.Teleport@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Admin = require('ExpGamingAdmin') diff --git a/modules/ExpGamingAdmin/TempBan/control.lua b/modules/ExpGamingAdmin/TempBan/control.lua index c103ab84..5848fd5c 100644 --- a/modules/ExpGamingAdmin/TempBan/control.lua +++ b/modules/ExpGamingAdmin/TempBan/control.lua @@ -2,7 +2,7 @@ -- @module ExpGamingAdmin.KicTempBan@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Admin = require('ExpGamingAdmin') @@ -27,7 +27,7 @@ function Admin.temp_ban(player,by_player,reason) local by_player_name = Game.get_player(by_player) and Game.get_player(by_player).name or '' if not player or Admin.is_banned(player) then return end Admin.set_banned(player,'temp') - if Sync then Sync.emit_embeded{ + if Sync then Sync.emit_embedded{ title='Player Temp-Ban', color=Color.to_hex(defines.textcolor.high), description='A player was jailed.', diff --git a/modules/ExpGamingAdmin/Warnings/control.lua b/modules/ExpGamingAdmin/Warnings/control.lua index 4c85fa6f..07cd6994 100644 --- a/modules/ExpGamingAdmin/Warnings/control.lua +++ b/modules/ExpGamingAdmin/Warnings/control.lua @@ -2,7 +2,7 @@ -- @module ExpGamingAdmin.Warnings@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Admin = require('ExpGamingAdmin') @@ -12,7 +12,7 @@ local Game = require('FactorioStdLib.Game') local Color -- FactorioStdLib.Color@^0.8.0 local Sync -- ExpGamingCore.Sync@^4.0.0 --- Local Varibles +-- Local Variables local take_action = 8 -- the first admin given warning jumps to this number, this case kick-warn is giving local remove_warnings_time = {} local min_time_to_remove_warning = 18000 -- this is in ticks @@ -61,10 +61,10 @@ local global = global{} -- Function Define local function give_punishment(player,by_player,reason) - local player, by_player = Admin.valid_players(player,by_player) + player, by_player = Admin.valid_players(player,by_player) + reason = reason or 'No Other Reason' local warnings = Admin.get_warnings(player) local punishment = punishments[warnings] - local reason = reason or 'No Other Reason' if not punishment or punishment[1] == 'nothing' then return elseif punishment[1] == 'message' then local message = punishment[2] @@ -85,14 +85,14 @@ local function give_punishment(player,by_player,reason) end function Admin.get_warnings(player) - local player = Game.get_player(player) + player = Game.get_player(player) return global[player.name] or 0 end function Admin.give_warning(player,by_player,reason,min) - local player, by_player = Admin.valid_players(player,by_player) + player, by_player = Admin.valid_players(player,by_player) if not player then return end - local min = Game.get_player(by_player) and Game.get_player(by_player) ~= SERVER and take_action or min or 0 + min = Game.get_player(by_player) and Game.get_player(by_player) ~= SERVER and take_action or min or 0 local warnings = Admin.get_warnings(player) if warnings < min then warnings = min-1 end warnings = warnings+1 @@ -104,12 +104,12 @@ function Admin.give_warning(player,by_player,reason,min) give_punishment(player,by_player,reason) end -function Admin.clear_warings(player,by_player,no_emit) - local player, by_player = Admin.valid_players(player,by_player) +function Admin.clear_warnings(player,by_player,no_emit) + player, by_player = Admin.valid_players(player,by_player) if not player then return end global[player.name]=nil if not no_emit and Sync then - Sync.emit_embeded{ + Sync.emit_embedded{ title='Player Clear', color=Color.to_hex(defines.textcolor.low), description='A player had their warnings cleared.', @@ -138,4 +138,4 @@ script.on_event(defines.events.on_tick,function(event) end) -- Module Return -return ThisModule \ No newline at end of file +return ThisModule \ No newline at end of file diff --git a/modules/ExpGamingAdmin/control.lua b/modules/ExpGamingAdmin/control.lua index e5019387..4d4f20e1 100644 --- a/modules/ExpGamingAdmin/control.lua +++ b/modules/ExpGamingAdmin/control.lua @@ -2,7 +2,7 @@ -- @module ExpGamingAdmin@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais Admin +-- @alias Admin -- Module Require local Game = require('FactorioStdLib.Game') @@ -34,13 +34,13 @@ local global = global{ -- Function Define function Admin.valid_players(player,by_player) - local player = Game.get_player(player) - local by_player = Game.get_player(by_player) or SERVER + player = Game.get_player(player) + by_player = Game.get_player(by_player) or SERVER return player, by_player end function Admin.create_reason(reason,name) - local reason = reason or 'No Reason' + reason = reason or 'No Reason' if not string.find(string.lower(reason),string.lower(name)) then reason = reason..' - '..name end if Sync and Sync.info.date ~= '0000/00/00' and not string.find(string.lower(reason),Sync.info.date) then reason = reason..' - '..Sync.info.date end if not string.find(string.lower(reason),'appeal') then reason = reason..' - Vist www.explosivegaming.nl to appeal.' end @@ -48,20 +48,20 @@ function Admin.create_reason(reason,name) end function Admin.allowed(player) - local player = Game.get_player(player) + player = Game.get_player(player) if Role then return Role.allowed(player,'admin-commands') else return player.admin end end function Admin.set_banned(player,set) - local player=Game.get_player(player) + player = Game.get_player(player) if not player then return false end global.banned[player.name] = set end function Admin.is_banned(player,detail) - local player=Game.get_player(player) + player = Game.get_player(player) if not player then return false end local banned = global.banned[player.name] if banned == true then return true end @@ -82,13 +82,13 @@ function Admin.take_action(action,player,by_player,reason) end function Admin.clear_player(player,by_player) - local player, by_player = Admin.valid_players(player,by_player) + player, by_player = Admin.valid_players(player,by_player) if not player then return end if Server and Admin.is_banned(player,true) == true then Server.interface(game.unban_player,true,player) end - if Admin.clear_warings then Admin.clear_warings(player,by_player,true) end + if Admin.clear_warnings then Admin.clear_warnings(player,by_player,true) end if Admin.clear_reports then Admin.clear_reports(player,by_player,true) end if Server and Role.has_flag(player,'is_jail') then Server.interface(Role.revert,true,player,by_player,2) end - if Sync then Sync.emit_embeded{ + if Sync then Sync.emit_embedded{ title='Player Clear', color=Color.to_hex(defines.textcolor.low), description='A player had their reports and warnings cleared.', diff --git a/modules/ExpGamingBot/autoChat/control.lua b/modules/ExpGamingBot/autoChat/control.lua index fbd1b9b8..b56bc760 100644 --- a/modules/ExpGamingBot/autoChat/control.lua +++ b/modules/ExpGamingBot/autoChat/control.lua @@ -1,15 +1,15 @@ ---- Sends messages in chat in resposce to other messages +--- Sends messages in chat in response to other messages -- @module ExpGamingBot.autoChat -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Game = require('FactorioStdLib.Game') local Server = require('ExpGamingCore.Server') local Role -- ExpGamingCore.Role@^4.0.0 --- Local Varibles +-- Local Variables -- lots of these are jokes, but some have uses -- white spaces removed and made into lower @@ -34,12 +34,12 @@ local messages = { } -- white spaces removed and made into lower -- these are global chat commands that can be used --- comands start with ! (all messages are also commands) +-- commands start with ! (all messages are also commands) local command_syntax = '!' local commands = { - ['online']=function(player) return {'ExpGamingBot-autoChat.players-online',#game.connected_players} end, - ['playtime']=function(player) return {'ExpGamingBot-autoChat.map-time',tick_to_display_format(game.tick)} end, - ['players']=function(player) return {'ExpGamingBot-autoChat.players',#game.players} end, + ['online']=function() return {'ExpGamingBot-autoChat.players-online',#game.connected_players} end, + ['playtime']=function() return {'ExpGamingBot-autoChat.map-time',tick_to_display_format(game.tick)} end, + ['players']=function() return {'ExpGamingBot-autoChat.players',#game.players} end, ['dev']={'ExpGamingBot-autoChat.not-real-dev'}, ['blame']=function(player) local names = {'Cooldude2606','arty714','badgamernl',player.name} return {'ExpGamingBot-autoChat.blame',names[math.random(#names)]} end, ['readme']={'ExpGamingBot-autoChat.read-readme'}, @@ -49,15 +49,17 @@ local commands = { ['lenny']={'ExpGamingBot-autoChat.lenny'}, ['feedback']={'ExpGamingBot-autoChat.feedback'}, ['wiki']={'ExpGamingBot-autoChat.wiki'}, - ['hodor']=function(player) local options = {'?','.','!','!!!'} return {'ExpGamingBot-autoChat.hodor',options[math.random(#options)]} end, - ['evolution']=function(player) return {'ExpGamingBot-autoChat.current-evolution',string.format('%.2f',game.forces['enemy'].evolution_factor)} end, + ['hodor']=function() local options = {'?','.','!','!!!'} return {'ExpGamingBot-autoChat.hodor',options[math.random(#options)]} end, + ['evolution']=function() return {'ExpGamingBot-autoChat.current-evolution',string.format('%.2f',game.forces['enemy'].evolution_factor)} end, --Jokes about food and drink ['whattoeat']={'ExpGamingBot-autoChat.food'}, + ['makepopcorn']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data=player.name }:on_event('timeout',function(self) if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-popcorn-2',self.data}} end end):open() return {'ExpGamingBot-autoChat.get-popcorn-1'} end, + ['orderpizza']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true }:on_event('timeout',function(self) @@ -66,6 +68,7 @@ local commands = { end self.data[2]=self.data[2]+1 end):open() return {'ExpGamingBot-autoChat.order-pizza-1'} end, + ['passsomesnaps']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true }:on_event('timeout',function(self) @@ -74,6 +77,7 @@ local commands = { end self.data[2]=self.data[2]+1 end):open() return {'ExpGamingBot-autoChat.get-snaps-1'} end, + ['makecocktail']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true }:on_event('timeout',function(self) @@ -82,11 +86,13 @@ local commands = { end self.data[2]=self.data[2]+1 end):open() return {'ExpGamingBot-autoChat.get-cocktail-1'} end, + ['makecoffee']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data=player.name }:on_event('timeout',function(self) if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.make-coffee-2',self.data}} end end):open() return {'ExpGamingBot-autoChat.make-coffee-1'} end, + ['orderpizza']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true }:on_event('timeout',function(self) @@ -95,21 +101,25 @@ local commands = { end self.data[2]=self.data[2] + 1 end):open() return {'ExpGamingBot-autoChat.order-pizza-1'} end, + ['maketea']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data=player.name }:on_event('timeout',function(self) if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.make-tea-2',self.data}} end end):open() return {'ExpGamingBot-autoChat.make-tea-1'} end, + ['popcorn']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data=player.name }:on_event('timeout',function(self) if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-popcorn-2',self.data}} end end):open() return {'ExpGamingBot-autoChat.get-popcorn-1'} end, + ['meadplease']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data=player.name }:on_event('timeout',function(self) if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-mead-2',self.data}} end end):open() return {'ExpGamingBot-autoChat.get-mead-1'} end, + ['passabeer']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data=player.name }:on_event('timeout',function(self) @@ -153,4 +163,4 @@ script.on_event(defines.events.on_console_chat,function(event) end) -- Module Return -return ThisModule \ No newline at end of file +return ThisModule \ No newline at end of file diff --git a/modules/ExpGamingBot/autoMessage/control.lua b/modules/ExpGamingBot/autoMessage/control.lua index e03c9c24..b21a0f7c 100644 --- a/modules/ExpGamingBot/autoMessage/control.lua +++ b/modules/ExpGamingBot/autoMessage/control.lua @@ -2,7 +2,7 @@ -- @module ExpGamingBot.autoMessage -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Server = require('ExpGamingCore.Server') @@ -10,7 +10,7 @@ local Game = require('FactorioStdLib.Game') local Role -- ExpGamingCore.Role@4.0.0 local Sync -- ExpGamingCore.Sync@4.0.0 --- Local Varibles +-- Local Variables -- Module Define local module_verbose = false @@ -25,7 +25,7 @@ local ThisModule = { } -- Event Handlers Define -script.on_init(function(event) +script.on_init(function() Server.new_thread{ name='auto-message', timeout=54000, -- 3240000 = 15 hours dont make the mistake i did, 54000 is 15 minutes @@ -54,13 +54,12 @@ script.on_init(function(event) local data = self.data if not data.high_role or not data.low_role or not data.low then self.reopen = false return end - -- idk but this stoped working for no appent reason so i added more checks for nil values if Role and Role.get_highest(player).index <= Role.get(data.low_role).index or player.admin then return end for _,message in pairs(data.low) do player_return({'ExpGamingBot-autoMessage.message',message},nil,player) end end):on_event('error',function(self,err) - if Sync then Sync.emit_embeded{ + if Sync then Sync.emit_embedded{ title='Auto Message Error', color=Color.to_hex(defines.textcolor.bg), description='Auto Message Error - Closed Thread', @@ -72,4 +71,4 @@ script.on_init(function(event) end) -- Module Return -return ThisModule \ No newline at end of file +return ThisModule \ No newline at end of file diff --git a/modules/ExpGamingBot/discordAlerts/control.lua b/modules/ExpGamingBot/discordAlerts/control.lua index f74ccc5b..a7069d21 100644 --- a/modules/ExpGamingBot/discordAlerts/control.lua +++ b/modules/ExpGamingBot/discordAlerts/control.lua @@ -2,7 +2,7 @@ -- @module ExpGamingBot.discordAlerts@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Sync = require('ExpGamingCore.Sync') @@ -23,7 +23,7 @@ script.on_event(defines.events.on_console_command,function(event) data.by = event.player_index and game.players[event.player_index].name or '' if data.by == '' then return end if command == 'config' or command == 'banlist' then - Sync.emit_embeded{ + Sync.emit_embedded{ title='Edit To '..data.title, color=Color.to_hex(defines.textcolor.bg), description='A player edited the '..command..'.', @@ -48,7 +48,7 @@ script.on_event(defines.events.on_console_command,function(event) if not Game.get_player(data.username) then return end if string.sub(command,-1) == 'e' then data.command = command..'d' else data.command = command..'ed' end data.reason = data.reason and data.reason ~= '' and data.reason or 'No Reason Required' - Sync.emit_embeded{ + Sync.emit_embedded{ title='Player '..data.title, color=data.colour, description='There was a player '..data.command..'.', @@ -60,4 +60,4 @@ script.on_event(defines.events.on_console_command,function(event) end) -- Module Return -return ThisModule \ No newline at end of file +return ThisModule \ No newline at end of file diff --git a/modules/ExpGamingCommands/bonus/control.lua b/modules/ExpGamingCommands/bonus/control.lua index c216ebcb..e772de80 100644 --- a/modules/ExpGamingCommands/bonus/control.lua +++ b/modules/ExpGamingCommands/bonus/control.lua @@ -37,7 +37,7 @@ script.on_event(defines.events.on_player_respawned,function(event) end end) --- overided by ExpGamingCore.Role if present +-- overridden by ExpGamingCore.Role if present script.on_event(defines.events.on_pre_player_died,function(event) local player = Game.get_player(event) if player.admin then @@ -74,10 +74,10 @@ return { script.on_event(defines.events.role_change,function(event) local player = Game.get_player(event) if Role.allowed(player,'bonus') then - for _,setting in pairs(settings) do player[key] = setting*0.2 end + for key,setting in pairs(settings) do player[key] = setting*0.2 end global[player.index]=20 else - for _,setting in pairs(settings) do player[key] = 0 end + for key in pairs(settings) do player[key] = 0 end global[player.index]=nil end end) diff --git a/modules/ExpGamingCommands/cheatMode/control.lua b/modules/ExpGamingCommands/cheatMode/control.lua index f64037fe..19d05276 100644 --- a/modules/ExpGamingCommands/cheatMode/control.lua +++ b/modules/ExpGamingCommands/cheatMode/control.lua @@ -3,7 +3,7 @@ -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE ---- Toogles cheat mode for a player +--- Toggles cheat mode for a player -- @command cheat-mode -- @param[opt] player the player to toggle if nil then the player using the command commands.add_command('cheat-mode', 'Toggles cheat mode for a player', { diff --git a/modules/ExpGamingCommands/home/control.lua b/modules/ExpGamingCommands/home/control.lua index 67f4d1fc..d5c667fb 100644 --- a/modules/ExpGamingCommands/home/control.lua +++ b/modules/ExpGamingCommands/home/control.lua @@ -25,7 +25,7 @@ commands.add_command('home', 'Allows you to set, remove and goto your homes', { player_return{'ExpGamingCommands-home.set',name,pos[1],pos[2]} elseif command == 'remove' then if not homes[name] then player_return{'ExpGamingCommands-home.invalid',name} end - homes[name] = nil + homes[name] = nil homes._n=homes._n-1 player_return{'ExpGamingCommands-home.remove',name} elseif command == 'goto' then @@ -42,6 +42,6 @@ commands.add_command('home', 'Allows you to set, remove and goto your homes', { else player_return{'ExpGamingCommands-home.homes',homes._n,homes._m} local index = 1 - for name,pos in pairs(homes) do if name ~= '_n' and name ~= '_r' and name ~= '_m' then player_return{'ExpGamingCommands-home.home',index,name,pos[1],pos[2]} index=index+1 end end + for home_name,pos in pairs(homes) do if home_name ~= '_n' and home_name ~= '_r' and home_name ~= '_m' then player_return{'ExpGamingCommands-home.home',index,home_name,pos[1],pos[2]} index=index+1 end end end end) diff --git a/modules/ExpGamingCommands/repair/control.lua b/modules/ExpGamingCommands/repair/control.lua index a0ab5e53..be84b7f0 100644 --- a/modules/ExpGamingCommands/repair/control.lua +++ b/modules/ExpGamingCommands/repair/control.lua @@ -28,7 +28,7 @@ local ThisModule = { end } ---- Used so that the value can be overriden if tempban is present +--- Used so that the value can be overridden if tempban is present -- @local -- @function repairDisallow -- @param player the player who called the command @@ -41,7 +41,7 @@ end --- Used to repair and heal items in an area, different ranks get different size areas -- @command repair -- @param range the range that items are repaired in -commands.add_command('repair', 'Repairs all destoryed and damaged entites in an area.', { +commands.add_command('repair', 'Repairs all destroyed and damaged entities in an area.', { ['range']={true,'number-int'} }, function(event,args) local range = args.range diff --git a/modules/ExpGamingCore/Command/control.lua b/modules/ExpGamingCore/Command/control.lua index 4421437d..70b23fed 100644 --- a/modules/ExpGamingCore/Command/control.lua +++ b/modules/ExpGamingCore/Command/control.lua @@ -13,7 +13,7 @@ local Color = require('FactorioStdLib.Color') -- @usage return commands.error('err message') commands.error = setmetatable({},{__call=function(...) return ... end}) commands._add_command = commands.add_command -local data = {} +local commandDataStore = {} local middleware = {} --- Used to add middle ware to the command handler, functions should return true or false @@ -27,10 +27,10 @@ function commands.add_middleware(callback) if not is_type(callback,'function') t -- @tparam ?string|table|event key the command that will be returned: string is the name, table is the command data, event is event from add_command -- @treturn table the command data setmetatable(commands,{ - __index=function(tbl,key) return is_type(key,'table') and (key.command and rawget(data,key.name) or key) or key == 'data' and data or rawget(data,key) end + __index=function(tbl,key) return is_type(key,'table') and (key.command and rawget(commandDataStore,key.name) or key) or key == 'data' and commandDataStore or rawget(commandDataStore,key) end }) ---- Collection of funcations that can be used to validate inputs +--- Collection of functions that can be used to validate inputs -- @table commands.validate -- @usage commands.validate[type](value,event,...) -- @tparam string type the type that the value should be @@ -40,11 +40,11 @@ setmetatable(commands,{ -- @return[2] error constant -- @return[2] the err message -- @field __comment replace _ with - the ldoc did not like me using - in the names --- @field string basicly does nothing but a type filed is required --- @field string_inf same as string but is infite in length, must be last arg --- @field string_len same as string but can define a max lengh +-- @field string basically does nothing but a type filed is required +-- @field string_inf same as string but is infinite in length, must be last arg +-- @field string_len same as string but can define a max length -- @field number converts the input into a number --- @field number_int conerts the input to a number and floors it +-- @field number_int converts the input to a number and floors it -- @field number_range allows a number in a range min < X <= max -- @field number_range allows a number in a range after it has been floored min < math.floor(X) <= max -- @field player converts the input into a valid player @@ -54,54 +54,54 @@ setmetatable(commands,{ -- @field player_role-online converts the input to a player if the player is a lower rank than the user and online -- @field player_role_alive converts the input to a player if the player is a lower rank than the user and online and alive commands.validate = { - ['boolean']=function(value,event) local value = value.lower() if value == 'true' or valule == 'yes' or value == 'y' or value == '1' then return true else return false end end, - ['string']=function(value,event) return tostring(value) end, - ['string-inf']=function(value,event) return tostring(value) end, - ['string-list']=function(value,event,list) + ['boolean']=function(value) value = value.lower() if value == 'true' or value == 'yes' or value == 'y' or value == '1' then return true else return false end end, + ['string']=function(value) return tostring(value) end, + ['string-inf']=function(value) return tostring(value) end, + ['string-list']=function(value,event,list) local rtn = tostring(value) and table.includes(list,tostring(value)) and tostring(value) or nil if not rtn then return commands.error{'ExpGamingCore_Command.error-string-list',table.concat(list,', ')} end return rtn end, - ['string-len']=function(value,event,max) + ['string-len']=function(value,event,max) local rtn = tostring(value) and tostring(value):len() <= max and tostring(value) or nil if not rtn then return commands.error{'ExpGamingCore_Command.error-string-len',max} end return rtn end, - ['number']=function(value,event) - local rtn = tonumber(value) or nil + ['number']=function(value) + local rtn = tonumber(value) or nil if not rtn then return commands.error{'ExpGamingCore_Command.error-number'} end return rtn end, - ['number-int']=function(value,event) - local rtn = tonumber(value) and math.floor(tonumber(value)) or nil + ['number-int']=function(value) + local rtn = tonumber(value) and math.floor(tonumber(value)) or nil if not rtn then return commands.error{'ExpGamingCore_Command.error-number'} end return rtn end, - ['number-range']=function(value,event,min,max) + ['number-range']=function(value,event,min,max) local rtn = tonumber(value) and tonumber(value) > min and tonumber(value) <= max and tonumber(value) or nil if not rtn then return commands.error{'ExpGamingCore_Command.error-number-range',min,max} end return rtn end, - ['number-range-int']=function(value,event,min,max) + ['number-range-int']=function(value,event,min,max) local rtn = tonumber(value) and math.floor(tonumber(value)) > min and math.floor(tonumber(value)) <= max and math.floor(tonumber(value)) or nil if not rtn then return commands.error{'ExpGamingCore_Command.error-number-range',min,max} end return rtn end, - ['player']=function(value,event) + ['player']=function(value) local rtn = Game.get_player(value) or nil if not rtn then return commands.error{'ExpGamingCore_Command.error-player',value} end return rtn end, - ['player-online']=function(value,event) - local player,err = commands.validate['player'](value) + ['player-online']=function(value) + local player,err = commands.validate['player'](value) if err then return commands.error(err) end local rtn = player.connected and player or nil if not rtn then return commands.error{'ExpGamingCore_Command.error-player-online'} end return rtn end, - ['player-alive']=function(value,event) - local player,err = commands.validate['player-online'](value) + ['player-alive']=function(value) + local player,err = commands.validate['player-online'](value) if err then return commands.error(err) end local rtn = player.character and player.character.health > 0 and player or nil if not rtn then return commands.error{'ExpGamingCore_Command.error-player-alive'} end return rtn end, - ['player-rank']=function(value,event) - local player,err = commands.validate['player'](value) - if err then return commands.error(err) end + ['player-rank']=function(value,event) + local player,err = commands.validate['player'](value) + if err then return commands.error(err) end local rtn = player.admin and Game.get_player(event).admin and player or nil if not rtn then return commands.error{'ExpGamingCore_Command.error-player-rank'} end return rtn end, - ['player-rank-online']=function(value,event) - local player,err = commands.validate['player-online'](value) - if err then return commands.error(err) end - local player,err = commands.validate['player-rank'](player) + ['player-rank-online']=function(value) + local player,err = commands.validate['player-online'](value) + if err then return commands.error(err) end + local player,err = commands.validate['player-rank'](player) if err then return commands.error(err) end return player end, - ['player-rank-alive']=function(value,event) - local player,err = commands.validate['player-alive'](value) - if err then return commands.error(err) end - local player,err = commands.validate['player-rank'](player) + ['player-rank-alive']=function(value) + local player,err = commands.validate['player-alive'](value) + if err then return commands.error(err) end + local player,err = commands.validate['player-rank'](player) if err then return commands.error(err) end return player end, } --- Adds a function to the validation list @@ -114,7 +114,7 @@ function commands.add_validation(name,callback) if not is_type(callback,'functio -- @tparam ?string|table|event command the command to get the inputs of -- @treturn string the formated string for the inputs function commands.format_inputs(command) - local command = commands[command] + command = commands[command] if not is_type(command,'table') then error('Command is not valid',2) end local rtn = '' for name,data in pairs(command.inputs) do @@ -136,13 +136,13 @@ function commands.validate_args(event) local rtn = {} local count = 0 local count_opt = 0 - for name,data in pairs(command.inputs) do count = count + 1 if data[1] == false then count_opt = count_opt + 1 end end - -- checks that there is some args given if there is ment to be + for _,data in pairs(command.inputs) do count = count + 1 if data[1] == false then count_opt = count_opt + 1 end end + -- checks that there is some args given if there is meant to be if not event.parameter then if count == count_opt then return rtn else return commands.error('invalid-inputs') end end - -- splits the args into words so that it can be used to asign values + -- splits the args into words so that it can be used to assign values local words = string.split(event.parameter,' ') local index = 0 for _,word in pairs(words) do @@ -158,7 +158,7 @@ function commands.validate_args(event) end end -- assigns the values from the words to the args - local index = 0 + index = 0 for name,data in pairs(command.inputs) do index = index+1 local arg = words[index] @@ -178,10 +178,10 @@ end -- @tparam ?index|name|player| player the player to test as -- @treturn table a table containg all the commands the player can use function commands.get_commands(player) + player = Game.get_player(player) local commands = {} - local player = Game.get_player(player) if not player then return error('Invalid player',2) end - for name,data in pairs(data) do + for name,data in pairs(commandDataStore) do if #middleware > 0 then for _,callback in pairs(middleware) do local success, err = pcall(callback,player,name,data) if not success then error(err) @@ -207,7 +207,7 @@ end local function run_custom_command(command) local data = commands.data[command.name] local player = Game.get_player(command) or SERVER - -- runs all middle ware if any, if there is no middle where then it relyis on .default_admin_only + -- runs all middle ware if any, if there is no middle where then it relies on .default_admin_only if #middleware > 0 then for _,callback in pairs(middleware) do local success, err = pcall(callback,player,command.name,command) if not success then error(err) @@ -243,7 +243,7 @@ end -- @usage --see examples in file -- @tparam string name the name of the command -- @tparam[opt='No Description'] string description the description of the command --- @tparam[opt=an infite string] table inputs a table of the inputs to be used, last index being true makes the last parameter open ended (longer than one word) +-- @tparam[opt=an infinite string] table inputs a table of the inputs to be used, last index being true makes the last parameter open ended (longer than one word) -- @tparam function callback the function to call on the event commands.add_command = function(name, description, inputs, callback) if commands[name] then error('That command is already registered',2) end @@ -254,11 +254,11 @@ commands.add_command = function(name, description, inputs, callback) end verbose('Created Command: '..name) -- test for string and then test for locale string - local description = is_type(description,'string') and description + description = is_type(description,'string') and description or is_type(description,'table') and is_type(description[1],'string') and string.find(description[1],'.+[.].+') and {description,''} or 'No Description' - local inputs = is_type(inputs,'table') and inputs or {['param']={false,'string-inf'}} - data[name] = { + inputs = is_type(inputs,'table') and inputs or {['param']={false,'string-inf'}} + commandDataStore[name] = { name=name, description=description, inputs=inputs, @@ -268,12 +268,12 @@ commands.add_command = function(name, description, inputs, callback) local help = is_type(description,'string') and commands.format_inputs(name)..'- '..description or is_type(description,'table') and is_type(description[1],'string') and string.find(description[1],'.+[.].+') and {description,commands.format_inputs(name)..'- '} or commands.format_inputs(name) - data[name].help = help + commandDataStore[name].help = help commands._add_command(name,help,function(...) local success, err = Manager.sandbox(run_custom_command,{},...) if not success then error(err) end end) - return data[name] + return commandDataStore[name] end return commands @@ -289,8 +289,8 @@ return commands commands.add_command('foo',{'foo.description'},{ ['player']={true,'player'}, -- a required arg that must be a valid player ['number']={true,'number-range',0,10}, -- a required arg that must be a number 0= #global.cams then global.cam_index = 1 end if update > #global.cams then update = #global.cams end for cam_offset = 0,update do - local _cam = global.cams[global.cam_index] + local _cam = global.cams[global.cam_index+cam_offset] if not _cam then break end if not _cam.cam.valid then table.remove(global.cams,global.cam_index) elseif not _cam.entity.valid then table.remove(global.cams,global.cam_index) @@ -162,6 +162,7 @@ script.on_event('on_player_respawned',function(event) if loaded_modules['ExpGamingCore.Server'] then return end if global.players and is_type(global.players,'table') and #global.players > 0 and global.players[event.player_index] then local remove = {} + local player = Game.get_player(event) for index,cam in pairs(global.players[event.player_index]) do if cam.valid then table.insert(global.cams,{cam=cam,entity=player.character,surface=player.surface}) else table.insert(remove,index) end @@ -173,14 +174,14 @@ script.on_event('on_player_respawned',function(event) end) function Gui:on_init() - if loaded_modules['ExpGamingCore.Server'] then - Server = require('ExpGamingCore.Server') - verbose('ExpGamingCore.Server is installed; Loading server src') - script.on_init(require(module_path..'/src/server',{Gui=self})) + if loaded_modules['ExpGamingCore.Server'] then + Server = require('ExpGamingCore.Server') + verbose('ExpGamingCore.Server is installed; Loading server src') + script.on_init(require(module_path..'/src/server',{Gui=self})) end end -function Gui:on_post() +function Gui.on_post() Gui.test = require(module_path..'/src/test',{Gui=Gui}) end diff --git a/modules/ExpGamingCore/Gui/inputs/control.lua b/modules/ExpGamingCore/Gui/inputs/control.lua index 3785c277..54abfe48 100644 --- a/modules/ExpGamingCore/Gui/inputs/control.lua +++ b/modules/ExpGamingCore/Gui/inputs/control.lua @@ -78,8 +78,8 @@ function inputs._prototype:draw(root) local success, err = pcall(self.data._items,player,root) if success then data.items = err else error(err) end if is_type(self.data._index,'function') then - local success, err = pcall(self.data._index,player,root) - if success then data.selected_index = err else error(err) end + local _success, _err = pcall(self.data._index,player,root) + if _success then data.selected_index = _err else error(_err) end end return root.add(data) else @@ -87,25 +87,25 @@ function inputs._prototype:draw(root) end end ---- Add a new input, this is the same as doing frame.add{} but returns a diffrent object +--- Add a new input, this is the same as doing frame.add{} but returns a different object -- @usage Gui.inputs.add{type='button',name='test',caption='Test'} -- @usage return_value(frame) -- draws the button onto that frame -- @tparam table obj the new element to add if caption is a sprite path then sprite is used --- @treturn table the custom input object, calling the returned calue will draw the button +-- @treturn table the custom input object, calling the returned value will draw the button function inputs.add(obj) if not is_type(obj,'table') then return end if not is_type(obj.type,'string') then return end local type = obj.type - if type == 'button' or - type == 'sprite-button' or - type == 'choose-elem-button' or - type == 'checkbox' or - type == 'radiobutton' or - type == 'textfield' or - type == 'text-box' or - type == 'slider' or - type == 'drop-down' - then else return end + if type ~= 'button' + and type ~= 'sprite-button' + and type ~= 'choose-elem-button' + and type ~= 'checkbox' + and type ~= 'radiobutton' + and type ~= 'textfield' + and type ~= 'text-box' + and type ~= 'slider' + and type ~= 'drop-down' + then return end verbose('Created Input: '..obj.name..' ('..obj.type..')') if obj.type == 'button' or obj.type == 'sprite-button' then obj.style = mod_gui.button_style end obj.draw_data = table.deepcopy(obj) @@ -139,23 +139,23 @@ end script.on_event(inputs.events,inputs._event_handler) inputs.events.error = {} --- the folwing functions are just to make inputs easier but if what you want is not include use inputs.add(obj) +-- the following functions are just to make inputs easier but if what you want is not include use inputs.add(obj) --- Used to define a button, can have many function -- @usage Gui.inputs.add_button('test','Test','Just for testing',{{condition,callback},...}) -- @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 --- @param callbacks can either be a single function or a list of function pairs see exaplmes at bottom +-- @param callbacks can either be a single function or a list of function pairs see examples at bottom -- @treturn table the button object that was made, to allow a custom error event if wanted function inputs.add_button(name,display,tooltip,callbacks) - local button = inputs.add{ + local rtn_button = inputs.add{ type='button', name=name, caption=display, tooltip=tooltip } - button.data._callbacks = callbacks - button:on_event('click',function(event) + rtn_button.data._callbacks = callbacks + rtn_button:on_event('click',function(event) local elements = Gui.data['inputs_'..event.element.type] or {} local button = elements[event.element.name] if not button and event.element.type == 'sprite-button' then @@ -166,19 +166,19 @@ function inputs.add_button(name,display,tooltip,callbacks) local mouse = event.button local keys = {alt=event.alt,ctrl=event.control,shift=event.shift} local element = event.element - local callbacks = button.data._callbacks - if is_type(callbacks,'function') then callbacks = {{function(...) return true end,callbacks}} end - for _,data in pairs(callbacks) do + local btn_callbacks = button.data._callbacks + if is_type(btn_callbacks,'function') then btn_callbacks = {{function() return true end,btn_callbacks}} end + for _,data in pairs(btn_callbacks) do if is_type(data[1],'function') and is_type(data[2],'function') then local success, err = pcall(data[1],player,mouse,keys,event) if success and err == true then - local success, err = pcall(data[2],player,element,event) - if not success then error(err) end + local _success, _err = pcall(data[2],player,element,event) + if not _success then error(_err) end elseif not success then error(err) end else error('Invalid Callback Condition Format') end - end + end end) - return button + return rtn_button end --- Used to define a choose-elem-button callback only on elem_changed @@ -221,20 +221,19 @@ end function inputs.add_checkbox(name,radio,display,default,callback_true,callback_false) local type = 'checkbox'; if radio then type='radiobutton' end local state = false; if is_type(default,'boolean') then state = default end - local checkbox = inputs.add{ + local rtn_checkbox = inputs.add{ type=type, name=name, caption=display, state=state } - if is_type(default,'function') then checkbox.data._state = default end - checkbox.data._true = callback_true - checkbox.data._false = callback_false - checkbox:on_event('state',function(event) + if is_type(default,'function') then rtn_checkbox.data._state = default end + rtn_checkbox.data._true = callback_true + rtn_checkbox.data._false = callback_false + rtn_checkbox:on_event('state',function(event) local checkbox = Gui.data['inputs_'..event.element.type][event.element.name] local player = Game.get_player(event) - local state = event.element.state - if state then + if event.element.state then if is_type(checkbox.data._true,'function') then local success, err = pcall(checkbox.data._true,player,event.element) if not success then error(err) end @@ -246,10 +245,10 @@ function inputs.add_checkbox(name,radio,display,default,callback_true,callback_f else error('Invalid Callback') end end end) - return checkbox + return rtn_checkbox end ---- Used to reset the state of radio buttons, recomened to be called on_state_change to reset any radio buttons it is ment to work with. +--- Used to reset the state of radio buttons, recommended to be called on_state_change to reset any radio buttons it is meant to work with. -- @usage Gui.inputs.reset_radio{radio1,radio2,...} -- @param elements can be a list of elements or a single element function inputs.reset_radio(elements) @@ -287,23 +286,23 @@ end -- @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 - local textbox = inputs.add{ + local rtn_textbox = inputs.add{ type=type, name=name, text=text } - textbox.data._callback = callback - textbox:on_event('text',function(event) + rtn_textbox.data._callback = callback + rtn_textbox:on_event('text',function(event) local textbox = Gui.data['inputs_'..event.element.type][event.element.name] local player = Game.get_player(event) local element = event.element - local callback = textbox.data._callback - if is_type(callback,'function') then - local success, err = pcall(callback,player,element.text,element) + local event_callback = textbox.data._callback + if is_type(event_callback,'function') then + local success, err = pcall(event_callback,player,element.text,element) if not success then error(err) end else error('Invalid Callback Condition Format') end end) - return textbox + return rtn_textbox end --- Used to define a slider callback only on value_changed @@ -348,28 +347,28 @@ end -- @tparam function callback the callback which is called when a new index is selected function(player,selected,items,element) -- @treturn table the drop-down object that was made, to allow a custom error event if wanted function inputs.add_drop_down(name,items,index,callback) - local drop_down = inputs.add{ + local rtn_dropdown = inputs.add{ type='drop-down', name=name, items=items, selected_index=index } - drop_down.data._items = items - drop_down.data._index = index - drop_down.data._callback = callback - drop_down:on_event('selection',function(event) - local drop_down = Gui.data['inputs_'..event.element.type][event.element.name] + rtn_dropdown.data._items = items + rtn_dropdown.data._index = index + rtn_dropdown.data._callback = callback + rtn_dropdown:on_event('selection',function(event) + local dropdown = Gui.data['inputs_'..event.element.type][event.element.name] local player = Game.get_player(event) local element = event.element - local items = element.items - local selected = items[element.selected_index] - local callback = drop_down.data._callback - if is_type(callback,'function') then - local success, err = pcall(callback,player,selected,items,element) + local drop_items = element.items + local selected = drop_items[element.selected_index] + local drop_callback = dropdown.data._callback + if is_type(drop_callback,'function') then + local success, err = pcall(drop_callback,player,selected,drop_items,element) if not success then error(err) end else error('Invalid Callback Condition Format') end end) - return drop_down + return rtn_dropdown end -- calling will attempt to add a new input diff --git a/modules/ExpGamingCore/Gui/left/control.lua b/modules/ExpGamingCore/Gui/left/control.lua index b3c3510d..7de7a904 100644 --- a/modules/ExpGamingCore/Gui/left/control.lua +++ b/modules/ExpGamingCore/Gui/left/control.lua @@ -1,4 +1,4 @@ ---- Adds a organiser for left gui ellements which will automaticaly update there information and have open requirements +--- Adds a organiser for left gui elements which will automatically update there information and have open requirements -- @module ExpGamingCore.Gui.Left -- @alias left -- @author Cooldude2606 @@ -12,7 +12,7 @@ local Color = require('FactorioStdLib.Color') local mod_gui = require('mod-gui') local Gui = require('ExpGamingCore.Gui') local order_config = require(module_path..'/order_config') -local Role -- this is optional and is hanndled by it being present, it is loaded on init +local Role -- this is optional and is handled by it being present, it is loaded on init local left = {} left._prototype = {} @@ -35,11 +35,11 @@ function left.override_open(state) end --- Used to add a left gui frame -- @usage Gui.left.add{name='foo',caption='Foo',tooltip='just testing',open_on_join=true,can_open=function,draw=function} --- @usage return_value(player) -- toggles visiblity for that player, if no player then updates for all players --- @param obj this is what will be made, needs a name and a draw function(root_frame), open_on_join can be used to set the deaful state true/false, can_open is a test to block it from opening but is not needed --- @return the object that is made, calling the returned value with out a param will update the gui, else will toggle visiblity for that player +-- @usage return_value(player) -- toggles visibility for that player, if no player then updates for all players +-- @param obj this is what will be made, needs a name and a draw function(root_frame), open_on_join can be used to set the default state true/false, can_open is a test to block it from opening but is not needed +-- @return the object that is made, calling the returned value with out a param will update the gui, else will toggle visibility for that player function left.add(obj) - if not is_type(obj,'table') then return end + if not is_type(obj,'table') then return end if not is_type(obj.name,'string') then return end verbose('Created Left Gui: '..obj.name) setmetatable(obj,{__index=left._prototype,__call=function(self,player) if player then return self:toggle(player) else return left.update(self.name) end end}) @@ -54,18 +54,18 @@ end -- @param[opt] players the player to update for, if not given all players are updated, can be one player function left.update(frame,players) if not Server or not Server._thread then - local players = is_type(players,'table') and #players > 0 and {unpack(players)} or is_type(players,'table') and {players} or Game.get_player(players) and {Game.get_player(players)} or game.connected_players + players = is_type(players,'table') and #players > 0 and {unpack(players)} or is_type(players,'table') and {players} or Game.get_player(players) and {Game.get_player(players)} or game.connected_players for _,player in pairs(players) do local frames = Gui.data.left or {} if frame then frames = {[frame]=frames[frame]} or {} end - for name,left in pairs(frames) do - if _left then left:first_open(player) end + for _,left_frame in pairs(frames) do + if left_frame then left_frame:first_open(player) end end end else local frames = Gui.data.left or {} if frame then frames = {[frame]=frames[frame]} or {} end - local players = is_type(players,'table') and #players > 0 and {unpack(players)} or is_type(players,'table') and {players} or Game.get_player(players) and {Game.get_player(players)} or game.connected_players + players = is_type(players,'table') and #players > 0 and {unpack(players)} or is_type(players,'table') and {players} or Game.get_player(players) and {Game.get_player(players)} or game.connected_players Server.new_thread{ data={players=players,frames=frames} }:on_event('tick',function(thread) @@ -74,8 +74,8 @@ function left.update(frame,players) Server.new_thread{ data={player=player,frames=thread.data.frames} }:on_event('resolve',function(thread) - for name,left in pairs(thread.data.frames) do - if left then left:first_open(thread.data.player) end + for _,left_frame in pairs(thread.data.frames) do + if left_frame then left_frame:first_open(thread.data.player) end end end):queue() end):open() @@ -91,14 +91,14 @@ function left.open(left_name,player) local _left = Gui.data.left[left_name] if not _left then return end if not Server or not Server._thread then - for _,player in pairs(players) do _left:open(player) end + for _,next_player in pairs(players) do _left:open(next_player) end else Server.new_thread{ data={players=players} }:on_event('tick',function(thread) if #thread.data.players == 0 then thread:close() return end - local player = table.remove(thread.data.players,1) - _left:open(player) + local next_player = table.remove(thread.data.players,1) + _left:open(next_player) end):open() end end @@ -112,14 +112,14 @@ function left.close(left_name,player) local _left = Gui.data.left[left_name] if not _left then return end if not Server or not Server._thread or player then - for _,player in pairs(players) do _left:close(player) end + for _,next_player in pairs(players) do _left:close(next_player) end else Server.new_thread{ data={players=players} }:on_event('tick',function(thread) if #thread.data.players == 0 then thread:close() return end - local player = table.remove(thread.data.players,1) - _left:close(player) + local next_player = table.remove(thread.data.players,1) + _left:close(next_player) end):open() end end @@ -129,7 +129,7 @@ end -- @usage left:open(player) -- @tparam luaPlayer player the player to open the gui for function left._prototype:open(player) - local player = Game.get_player(player) + player = Game.get_player(player) if not player then error('Invalid Player') end local left_flow = mod_gui.get_frame_flow(player) if not left_flow[self.name] then self:first_open(player) end @@ -141,7 +141,7 @@ end -- @usage left:open(player) -- @tparam luaPlayer player the player to close the gui for function left._prototype:close(player) - local player = Game.get_player(player) + player = Game.get_player(player) if not player then error('Invalid Player') end local left_flow = mod_gui.get_frame_flow(player) if not left_flow[self.name] then self:first_open(player) end @@ -156,11 +156,11 @@ end -- @tparam LuaPlayer player the player to draw the gui for -- @treturn LuaFrame the frame made/updated function left._prototype:first_open(player) - local player = Game.get_player(player) + player = Game.get_player(player) local left_flow = mod_gui.get_frame_flow(player) - local frame = nil - if left_flow[self.name] then - frame = left_flow[self.name] + local frame + if left_flow[self.name] then + frame = left_flow[self.name] frame.clear() else if not left_flow['gui-left-hide'] then left.hide(left_flow).style.maximal_width=15 end @@ -172,15 +172,15 @@ function left._prototype:first_open(player) return frame end ---- Toggles the visiblity of the gui based on some conditions +--- Toggles the visibility of the gui based on some conditions -- @usage left:toggle(player) -- returns new state -- @tparam LuaPlayer player the player to toggle the gui for, remember there are condition which need to be met -- @treturn boolean the new state that the gui is in function left._prototype:toggle(player) - local player = Game.get_player(player) + player = Game.get_player(player) local left_flow = mod_gui.get_frame_flow(player) if not left_flow[self.name] then self:first_open(player) end - local left = left_flow[self.name] + local left_frame = left_flow[self.name] local open = false if is_type(self.can_open,'function') then local success, err = pcall(self.can_open,player) @@ -198,18 +198,18 @@ function left._prototype:toggle(player) else open = {'ExpGamingCore_Gui.unauthorized'} end else open = true end end - if open == true and left.style.visible ~= true then - left.style.visible = true + if open == true and left_frame.style.visible ~= true then + left_frame.style.visible = true left_flow['gui-left-hide'].style.visible = true else - left.style.visible = false + left_frame.style.visible = false local count = 0 for _,child in pairs(left_flow.children) do if child.style.visible then count = count+1 end if count > 1 then break end end if count == 1 and left_flow['gui-left-hide'] then left_flow['gui-left-hide'].style.visible = false end end if open == false then player_return({'ExpGamingCore_Gui.cant-open-no-reason'},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} elseif open ~= true then player_return({'ExpGamingCore_Gui.cant-open',open},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} end - return left.style.visible + return left_frame.style.visible end script.on_event(defines.events.on_player_joined_game,function(event) @@ -220,14 +220,14 @@ script.on_event(defines.events.on_player_joined_game,function(event) if not left_flow['gui-left-hide'] then left.hide(left_flow).style.maximal_width=15 end local done = {} for _,name in pairs(order_config) do - local left = Gui.data.left[name] - if left then + local left_frame = Gui.data.left[name] + if left_frame then done[name] = true - left:first_open(player) + left_frame:first_open(player) end end - for name,left in pairs(frames) do - if not done[name] then left:first_open(player) end + for name,left_frame in pairs(frames) do + if not done[name] then left_frame:first_open(player) end end end) @@ -237,7 +237,7 @@ script.on_event(defines.events.on_tick,function(event) end end) -function left:on_init() +function left.on_init() if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end end diff --git a/modules/ExpGamingCore/Gui/popup/control.lua b/modules/ExpGamingCore/Gui/popup/control.lua index cbb7682b..7a49bae3 100644 --- a/modules/ExpGamingCore/Gui/popup/control.lua +++ b/modules/ExpGamingCore/Gui/popup/control.lua @@ -33,7 +33,7 @@ end -- this is used by the script to find the popup flow function popup.flow(player) - local player = Game.get_player(player) + player = Game.get_player(player) if not player then error('Invalid Player',2) end local flow = mod_gui.get_frame_flow(player).popups if not flow then flow = mod_gui.get_frame_flow(player).add{name='popups',type='flow',direction='vertical'} flow.style.visible=false end @@ -47,8 +47,8 @@ end -- @tparam[opt=game.connected_players] table players the players to open the popup for function popup.open(style,data,players) local _popup = Gui.data.popup[style] - local players = players or game.connected_players - local data = data or {} + players = players or game.connected_players + data = data or {} if not _popup then return end if not Server or not Server._thread then for _,player in pairs(players) do @@ -107,11 +107,11 @@ function popup._prototype:add_left(obj) self.left = Gui.left(obj) end -function popup:on_init() +function popup.on_init() if loaded_modules['ExpGamingCore.Server'] then Server = require('ExpGamingCore.Server') end end -function popup:on_post() +function popup.on_post() popup._prototype.close = Gui.inputs.add{ type='button', name='popup-close', diff --git a/modules/ExpGamingCore/Gui/src/server.lua b/modules/ExpGamingCore/Gui/src/server.lua index 8e901ae0..1b613e11 100644 --- a/modules/ExpGamingCore/Gui/src/server.lua +++ b/modules/ExpGamingCore/Gui/src/server.lua @@ -7,7 +7,7 @@ local Server = require('ExpGamingCore.Server') Server.add_module_to_interface('ExpGui','ExpGamingCore.Gui') --- Adds a server thread that allows the camera follows to be toggled off and on -return function(event) +return function() Server.new_thread{ name='camera-follow', data={cams={},cam_index=1,players={}} diff --git a/modules/ExpGamingCore/Gui/src/test.lua b/modules/ExpGamingCore/Gui/src/test.lua index 7ad7c724..9ba60632 100644 --- a/modules/ExpGamingCore/Gui/src/test.lua +++ b/modules/ExpGamingCore/Gui/src/test.lua @@ -53,30 +53,30 @@ local input_test = Gui.inputs.add_button('test-inputs','Try RMB','alt,ctrl,shift function(player,mouse,keys) return mouse == defines.mouse_button_type.right and keys.shift end, function(player,element) player_return('Right: Shift',nil,player) end } -}):on_event('error',function(err) game.print('this is error handliling') end) +}):on_event('error',function(err) game.print('this is error handling') end) local elem_test = Gui.inputs.add_elem_button('test-elem','item','Testing Elems',function(player,element,elem) player_return(elem.type..' '..elem.value,nil,player) end) -local check_test = Gui.inputs.add_checkbox('test-check',false,'Cheat Mode',function(player,parent) - return game.players[parent.player_index].cheat_mode -end,function(player,element) - player.cheat_mode = true +local check_test = Gui.inputs.add_checkbox('test-check',false,'Cheat Mode',function(player,parent) + return game.players[parent.player_index].cheat_mode +end,function(player,element) + player.cheat_mode = true end,function(player,element) player.cheat_mode = false end) -local radio_test = Gui.inputs.add_checkbox('test-radio',true,'Kill Self',function(player,parent) +local radio_test = Gui.inputs.add_checkbox('test-radio',true,'Kill Self',function(player,parent) return false -end,function(player,element) +end,function(player,element) if player.character then player.character.die() end Gui.inputs.reset_radio(element.parent['test-radio-reset']) end) -local radio_test_reset = Gui.inputs.add_checkbox('test-radio-reset',true,'Reset Kill Self',function(player,parent) +local radio_test_reset = Gui.inputs.add_checkbox('test-radio-reset',true,'Reset Kill Self',function(player,parent) return not parent['test-radio'].state -end,function(player,element) +end,function(player,element) Gui.inputs.reset_radio(element.parent['test-radio']) end) diff --git a/modules/ExpGamingCore/Gui/toolbar/control.lua b/modules/ExpGamingCore/Gui/toolbar/control.lua index 6ce6a159..cae2f467 100644 --- a/modules/ExpGamingCore/Gui/toolbar/control.lua +++ b/modules/ExpGamingCore/Gui/toolbar/control.lua @@ -11,7 +11,7 @@ local Game = require('FactorioStdLib.Game') local mod_gui = require('mod-gui') local Gui = require('ExpGamingCore.Gui') local order_config = require(module_path..'/order_config') -local Role -- this is optional and is hanndled by it being present, it is loaded on init +local Role -- this is optional and is handled by it being present, it is loaded on init local toolbar = {} @@ -52,7 +52,7 @@ end -- @usage toolbar.draw(1) -- @param player the player to draw the tool bar of function toolbar.draw(player) - local player = Game.get_player(player) + player = Game.get_player(player) if not player then return end local toolbar_frame = mod_gui.get_button_flow(player) toolbar_frame.clear() @@ -81,7 +81,7 @@ function toolbar.draw(player) end end -function toolbar:on_init() +function toolbar.on_init() if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end end diff --git a/modules/ExpGamingCore/Role/config.lua b/modules/ExpGamingCore/Role/config.lua index c1a6b798..d755336e 100644 --- a/modules/ExpGamingCore/Role/config.lua +++ b/modules/ExpGamingCore/Role/config.lua @@ -1,17 +1,17 @@ -Role.add_flag('is_default') -- this must be included in atleast one role +Role.add_flag('is_default') -- this must be included in at least one role Role.add_flag('is_root',function(player,state) if state then game.print('--- !!!ALERT!!! --- '..player.name..' has been given a role with ROOT ACCESS --- !!!ALERT!!! ---') end if player.character then player.character.destructible = not state end end) -- the SERVER role will have root but you may assign this to other roles --- the two above and used internaly and should NOT have their names changed and should NOT be removed but the state function MAY be changed +-- the two above and used internally and should NOT have their names changed and should NOT be removed but the state function MAY be changed Role.add_flag('is_antiroot',function(player,state) if player.character then player.character.destructible = not state end end) -- not required but setting true will disallow everything for that role -Role.add_flag('is_admin',function(player,state) player.admin = state end) -- highly recomented but not required +Role.add_flag('is_admin',function(player,state) player.admin = state end) -- highly recommenced but not required Role.add_flag('is_spectator',function(player,state) player.spectator = state end) Role.add_flag('is_jail',function(player,state) if player.character then player.character.active = not state end end) Role.add_flag('allow_afk_kick') Role.add_flag('is_donator') Role.add_flag('is_timed') -Role.add_flag('is_varified') +Role.add_flag('is_verified') Role.add_flag('not_reportable') -- Root @@ -64,7 +64,7 @@ Role{ colour={r=233,g=63,b=233}, is_admin=true, is_spectator=true, - is_varified=true, + is_verified=true, not_reportable=true, allow={ ['game-settings']=true, @@ -80,7 +80,7 @@ Role{ colour={r=0,g=170,b=0}, is_admin=true, is_spectator=true, - is_varified=true, + is_verified=true, not_reportable=true, allow={ ['set-home']=true, @@ -97,7 +97,7 @@ Role{ group='Admin', colour={r=0,g=196,b=137}, is_spectator=true, - is_varified=true, + is_verified=true, not_reportable=true, allow={ ['go-to']=true, @@ -173,7 +173,7 @@ Role{ group='HiMember', colour={r=140,g=120,b=200}, is_timed=true, - is_varified=true, + is_verified=true, allow_afk_kick=true, time=600, -- 10 hours allow={ @@ -190,13 +190,13 @@ Role{ tag='[Member]', group='Member', colour={r=24,g=172,b=188}, - is_varified=true, + is_verified=true, allow_afk_kick=true, allow={ ['edit-tasklist']=true, ['make-warp']=true, ['nuke']=true, - ['varified']=true + ['verified']=true } } Role{ diff --git a/modules/ExpGamingCore/Role/control.lua b/modules/ExpGamingCore/Role/control.lua index aef02653..364bc995 100644 --- a/modules/ExpGamingCore/Role/control.lua +++ b/modules/ExpGamingCore/Role/control.lua @@ -2,17 +2,18 @@ -- @module ExpGamingCore.Role@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais Role +-- @alias Role -- Module Require local Group = require('ExpGamingCore.Group') local Game = require('FactorioStdLib.Game') --- Local Varibles +-- Local Variables local role_change_event_id = script.generate_event_name('on_role_change') local RoleGlobal -- Module Define +local _RoleSelfReference local module_verbose = false local Role = { _prototype={}, @@ -24,7 +25,7 @@ local Role = { roles=setmetatable({},{ __index=table.autokey, __newindex=function(tbl,key,value) - rawset(tbl,key,Role.define(value)) + rawset(tbl,key,_RoleSelfReference.define(value)) end }), on_init=function(self) @@ -57,10 +58,11 @@ local Role = { else error('Invalid roles, no roles to load.') end end } +_RoleSelfReference=Role -- Global Define local global = global{ - change_chache_length=15, + change_cache_length=15, changes={}, latest_change={}, preassign={}, @@ -79,7 +81,7 @@ function Role.set_preassign(tbl) if game then global.preassign = tbl else Role.p -- @usage Role{name='Root',short_hand='Root',tag='[Root]',group='Root',colour={r=255,b=255,g=255},is_root=true,allow={}} -- returns new role -- @tparam table obj contains the strings: name,short_hand,tag a table called allow a table called colour and a pointer to a permission group -- @treturn Role the role which has been made -function Role.define(obj) +function Role.define(obj) if not type_error(game,nil,'Cant define Role during runtime.') then return end if not type_error(obj.name,'string','Role creation is invalid: role.name is not a string') then return end if not is_type(obj.short_hand,'string') then obj.short_hand = obj.name:sub(1,3) end @@ -101,19 +103,19 @@ end --- Used to get the role of a player or the role by name -- @usage Role.get('foo') -- returns group foo -- @usage Role.get(player) -- returns group of player --- @tparam ?LuaPlayer|pointerToPlayer|string mixed can either be the name of the role or a player indenifier +-- @tparam ?LuaPlayer|pointerToPlayer|string mixed can either be the name of the role or a player identifier -- @treturn table the group which was found or nil function Role.get(mixed,forceIsRole) local player = game and Game.get_player(mixed) if player == SERVER then return {Role.meta.server} end - if not forceIsRole and player then + if not forceIsRole and player then local rtn = {} if not global.players[player.index] then return Role.meta.default and {Role.meta.default} or {} end for _,role in pairs(global.players[player.index]) do table.insert(rtn,Role.get(role)) end return rtn elseif is_type(mixed,'table') and mixed.group then return mixed elseif is_type(mixed,'string') then return Role.roles[mixed] - elseif is_type(mixed,'number') then + elseif is_type(mixed,'number') then for _,role in pairs(Role.roles) do if role.index == mixed then return role end end @@ -124,25 +126,25 @@ end -- @usage Role.assign(player,'Root') -- @usage Role.assign(player,{'Root','Foo'}) -- @tparam ?LuaPlayer|pointerToPlayer player the player to assign the role to --- @tparam ?string|role|table the role to add the player to, if its a table then it will act recursly though the table +-- @tparam ?string|role|table the role to add the player to, if its a table then it will act recursively though the table -- @tparam[opt=''] ?LuaPlayer|pointerToPlayer by_player the player who assigned the roles to the player --- @tparam[opt] table batch this is used internally to provent multiple event calls, conatins {role_index_in_batch,batch} +-- @tparam[opt] table batch this is used internally to prevent multiple event calls, contains {role_index_in_batch,batch} -- @treturn boolean was the player assigned the roles function Role.assign(player,role,by_player,batch) - local player = Game.get_player(player) + player = Game.get_player(player) if not player then error('Invalid player #1 given to Role.assign.',2) return end verbose('Assigning Roles: '..serpent.line(role)..' to: '..player.name) - -- this loops over a table of role if given; will return if ipairs returns, else will asume it was ment to be a role and error - if is_type(role,'table') and not role.name then - local ctn = 0 + -- this loops over a table of role if given; will return if ipairs returns, else will assume it was meant to be a role and error + if is_type(role,'table') and not role.name then + local ctn = 0 for n,_role in ipairs(role) do ctn=ctn+1 Role.assign(player,_role,by_player,{n,role}) end - if ctn > 0 then if not batch then table.insert(global.changes[player.index],{'assign',role}) global.latest_change = {player.index,'assign',role} end return end + if ctn > 0 then if not batch then table.insert(global.changes[player.index],{'assign',role}) global.latest_change = {player.index,'assign',role} end return end end - local role = Role.get(role) + role = Role.get(role) if not role then error('Invalid role #2 given to Role.assign.',2) return end - -- this acts as a way to provent the global table getting too full + -- this acts as a way to prevent the global table getting too full if not global.changes[player.index] then global.changes[player.index]={} end - if #global.changes[player.index] > global.change_chache_length then table.remove(global.changes[player.index],1) end + if #global.changes[player.index] > global.change_cache_length then table.remove(global.changes[player.index],1) end if not batch then table.insert(global.changes[player.index],{'assign',role.name}) global.latest_change = {player.index,'assign',role.name} end return role:add_player(player,by_player,batch) end @@ -150,31 +152,31 @@ end --- Used to remove a player from a role(s) -- @usage Role.unassign(player,'Root') -- @tparam ?LuaPlayer|pointerToPlayer player the player to unassign the role to --- @tparam ?string|role|table role the role to remove the player from, if its a table then it will act recursly though the table +-- @tparam ?string|role|table role the role to remove the player from, if its a table then it will act recursively though the table -- @tparam[opt=''] ?LuaPlayer|pointerToPlayer by_player the player who unassigned the roles from the player --- @tparam[opt] table batch this is used internally to provent multiple event calls +-- @tparam[opt] table batch this is used internally to prevent multiple event calls -- @treturn boolean was the player unassigned the roles function Role.unassign(player,role,by_player,batch) - local player = Game.get_player(player) + player = Game.get_player(player) if not player then error('Invalid player #1 given to Role.unassign.',2) return end verbose('Assigning Roles: '..serpent.line(role)..' to: '..player.name) - -- this loops over a table of role if given; will return if ipairs returns, else will asume it was ment to be a role and error + -- this loops over a table of role if given; will return if ipairs returns, else will assume it was meant to be a role and error if is_type(role,'table') and not role.name then local ctn = 0 for n,_role in ipairs(role) do ctn=ctn+1 Role.unassign(player,_role,by_player,{n,role}) end if ctn > 0 then if not batch then table.insert(global.changes[player.index],{'unassign',role}) global.latest_change = {player.index,'unassign',role} end return end end - local role = Role.get(role) + role = Role.get(role) if not role then error('Invalid role #2 given to Role.unassign.',2) return end if not global.changes[player.index] then global.changes[player.index]={} end - -- this acts as a way to provent the global table getting too full - if #global.changes[player.index] > global.change_chache_length then table.remove(global.changes[player.index],1) end + -- this acts as a way to prevent the global table getting too full + if #global.changes[player.index] > global.change_cache_length then table.remove(global.changes[player.index],1) end if not batch then table.insert(global.changes[player.index],{'unassign',role.name}) global.latest_change = {player.index,'unassign',role.name} end return role:remove_player(player,by_player,batch) end --- Returns the highest role given in a list, if a player is passed then it returns the highest role of the player --- @usage Role.get_highest{'Root','Admin','Mod'} -- retuns Root (given that root is highest) +-- @usage Role.get_highest{'Root','Admin','Mod'} -- returns Root (given that root is highest) -- @usage Role.get_highest(player) -- returns the players highest role -- @tparam ?table|LuaPlayer|pointerToPlayer options table of options or a player -- @treturn role the highest role given in the options @@ -192,19 +194,19 @@ function Role.get_highest(options) return highest end ---- Uses the change chache to revert changes to players roles +--- Uses the change cache to revert changes to players roles -- @usage Role.revert(player) -- reverts the last change to the players roles -- @tparam ?LuaPlayer|pointerToPlayer player the player to revert the changes of --- @tparam[opt] ?LuaPlayer|pointerToPlayer the player who proformed the role revert --- @tparam[opt=1] count the number of reverts to do, if 0 all changes chached are reverted --- @treturn number the number of changes that occured +-- @tparam[opt] ?LuaPlayer|pointerToPlayer the player who preformed the role revert +-- @tparam[opt=1] count the number of reverts to do, if 0 all changes cached are reverted +-- @treturn number the number of changes that occurred function Role.revert(player,by_player,count) - local player = Game.get_player(player) + player = Game.get_player(player) if not player then error('Invalid player #1 given to Role.revert.',2) return end if count and not type_error(count,'number','Invalid argument #2 to Role.revert, count is not a number.') then return end local changes = global.changes[player.index] or {} if #changes == 0 then error('Player has no role changes logged, can not revert.') end - local count = count or 1 + count = count or 1 local ctn = 0 if count > #changes or count == 0 then count = #changes end for i = 1,count do @@ -220,7 +222,7 @@ end --- Adds a flag which can be set on roles; these flags act as a quick way to access general role changes -- @usage Role.add_flag('is_admin',function(player,state) player.admin = state end) -- the function is passed player and if the flag is true or false --- @tparam string flag the name of the falg that is being added +-- @tparam string flag the name of the flag that is being added -- @tparam[opt] function callback the function(player,state) which is called when a player loses or gains a flag, if nil no function is called function Role.add_flag(flag,callback) if not type_error(flag,'string','Invalid argument #1 to Role.add_flag, flag is not a string.') then return end @@ -229,7 +231,7 @@ function Role.add_flag(flag,callback) Role.flags[flag] = callback or true end ---- Checks if a player or role has the requested flag, if player all roles of player are checked (true has pirortiy) +--- Checks if a player or role has the requested flag, if player all roles of player are checked (true has priority) -- @usage Role.has_flag(role,'is_admin') -- returns true if this role has is_admin set -- @tparam role|LuaPlayer|pointerToPlayer mixed the player or role that will be tested -- @tparam string flag the flag to test for @@ -253,7 +255,7 @@ function Role.add_action(action) table.insert(Role.actions,action) end ---- Checks if a player or role is allowed the requested action, if player all roles of player are checked (true has pirortiy) +--- Checks if a player or role is allowed the requested action, if player all roles of player are checked (true has priority) -- @usage Role.allowed(role,'foo') -- returns true if this role is allowed 'foo' -- @tparam ?role|LuaPlayer|pointerToPlayer mixed the player or role that will be tested -- @tparam string action the action to test for @@ -269,14 +271,14 @@ function Role.allowed(mixed,action) end --- Prints to all roles and players of those roles which are greater than the given role (or if inv then all below) --- @usage Role.print('Admin','Hello, World!') -- returns the number of players who recived the message +-- @usage Role.print('Admin','Hello, World!') -- returns the number of players who received the message -- @tparam ?role|string role the role which acts as the turning point of the print (always included regardless of inv value) -- @param rtn the value that will be returned to the players -- @tparam[opt] table colour the colour that you want the message printed in -- @tparam[opt=false] boolean inv true to print to roles below, false to print to roles above --- @treturn number the number of players who recived the message +-- @treturn number the number of players who received the message function Role.print(role,rtn,colour,inv) - local role = Role.get(role,true) + role = Role.get(role,true) if not type_error(role,'table','Invalid argument #1 to Role.print, role is invalid.') then return end if colour and not type_error(colour,'table','Invalid argument #3 to Role.print, colour is not a table.') then return end if inv and not type_error(inv,'boolean','Invalid argument #4 to Role.print, inv is not a boolean.') then return end @@ -293,11 +295,11 @@ function Role.print(role,rtn,colour,inv) return ctn end ---- Prints all registed roles and there important infomation (debug) +--- Prints all registered roles and there important information (debug) -- @tparam[opt] ?role|string the role to print the info of, if nil then all roles are printed in order of power -- @tparam[opt=game.player] ?LuaPlayer|pointerToPlayer the player to print the info to, default the player who ran command function Role.debug_output(role,player) - local player = Game.get_player(player) or game.player + player = Game.get_player(player) or game.player if not player then error('Invalid player #2 given to Role.debug_output.',2) return end local function _output(_role) local flags = {};for flag in pairs(Role.flags) do if _role:has_flag(flag) then table.insert(flags,flag) end end @@ -306,7 +308,7 @@ function Role.debug_output(role,player) player_return(rtn,_role.colour,player) end if role then - local role = Role.get(mixed) + role = Role.get(role) if not type_error(role,'table','Invalid argument #1 to Role.print, role is invalid.') then return end _output(role) else for index,_role in pairs(Role.roles) do _output(_role) end end @@ -354,18 +356,18 @@ end -- this is used to create a connected_players table Role._prototype.players_mt = { __call=function(tbl) return tbl.self:get_players(tbl.connected) end, - __pairs=function(tbl) - local players = tbl.self:get_players(tbl.connected) - local function next_pair(tbl,k) - k, v = next(players, k) + __pairs=function(tbl) + local players = tbl.self:get_players(tbl.connected) + local function next_pair(tbl,key) + local k, v = next(players, key) if v then return k,v end end return next_pair, players, nil end, __ipairs=function(tbl) - local players = tbl.self:get_players(tbl.connected) - local function next_pair(tbl,k) - k, v = next(players, k) + local players = tbl.self:get_players(tbl.connected) + local function next_pair(tbl,key) + local k, v = next(players, key) if v then return k,v end end return next_pair, players, nil @@ -374,10 +376,10 @@ Role._prototype.players_mt = { --- Prints a message to all players who have this role --- @usage role:print('Hello, World!') -- retuns number of players who recived the message +-- @usage role:print('Hello, World!') -- returns number of players who received the message -- @param rtn the message to print to the players -- @tparam[opt] table colour the colour to print the message in --- @treturn number the number of players who recived the message +-- @treturn number the number of players who received the message function Role._prototype:print(rtn,colour) if not self_test(self,'role','print') then return end if colour and not type_error(colour,'table','Invalid argument #2 to Role.print, colour is not a table.') then return end @@ -387,8 +389,8 @@ function Role._prototype:print(rtn,colour) end --- Returns a table that describes all the permissions and which this role is allowed --- @usage role:get_permissions() -- retuns table of permissions --- @treturn table a table of permisions, only includes ones which were defined with Role.add_action +-- @usage role:get_permissions() -- returns table of permissions +-- @treturn table a table of permissions, only includes ones which were defined with Role.add_action function Role._prototype:get_permissions() if not self_test(self,'role','get_permissions') then return end local rtn = {} @@ -400,12 +402,12 @@ end -- @usage role:add_player(player) -- @tparam ?LuaPlayer|PointerToPlayer player the player to add -- @tparam[opt] ?LuaPlayer|PointerToPlayer by_player the player who ran the command --- @tparam[opt] table batch this is used internally to provent multiple event calls +-- @tparam[opt] table batch this is used internally to prevent multiple event calls function Role._prototype:add_player(player,by_player,batch) if not self_test(self,'role','add_player') then return end - local player = Game.get_player(player) + player = Game.get_player(player) if not player then error('Invalid player #1 given to role:add_player.',2) return end - local by_player = Game.get_player(by_player) or SERVER + by_player = Game.get_player(by_player) or SERVER if not global.roles[self.name] then global.roles[self.name] = {} end if not global.players[player.index] then global.players[player.index] = {} end local highest = Role.get_highest(player) or Role.meta.default @@ -429,12 +431,12 @@ end -- @usage role:remove_player(player) -- @tparam ?LuaPlayer|PointerToPlayer player the player to remove -- @tparam[opt] ?LuaPlayer|PointerToPlayer by_player the player who ran the command --- @tparam[opt] table batch this is used internally to provent multiple event calls +-- @tparam[opt] table batch this is used internally to prevent multiple event calls function Role._prototype:remove_player(player,by_player,batch) if not self_test(self,'role','add_player') then return end - local player = Game.get_player(player) + player = Game.get_player(player) if not player then error('Invalid player #1 given to role:remove_player.',2) return end - local by_player = Game.get_player(by_player) or SERVER + by_player = Game.get_player(by_player) or SERVER if not global.roles[self.name] then global.roles[self.name] = {} end if not global.players[player.index] then global.players[player.index] = {} end local highest = Role.get_highest(player) or Role.meta.default @@ -458,13 +460,13 @@ end -- Event Handlers Define script.on_event(role_change_event_id,function(event) - -- varible init + -- variable init local player = Game.get_player(event) local by_player = Game.get_player(event.by_player_index) or SERVER - local role = Role.get(event.role_name) + local role = Role.get(event.role_name) local highest = Role.get_highest(player) if not highest then Role.meta.default:add_player(player) highest = Role.meta.default end - -- gets the falgs the player currently has + -- gets the flags the player currently has for flag,callback in pairs(Role.flags) do if is_type(callback,'function') then callback(player,Role.has_flag(player,flag)) end end -- assign new tag and group of highest role Group.assign(player,highest.group) @@ -476,7 +478,7 @@ script.on_event(role_change_event_id,function(event) -- send a message to other players if event.batch_index == 1 then local names = {} - for _,name in pairs(event.batch) do local role = Role.get(name) if role then table.insert(names,role.name) end end + for _,name in pairs(event.batch) do local next_role = Role.get(name) if next_role then table.insert(names,next_role.name) end end if event.effect == 'assign' then if not role.is_jail then player.play_sound{path='utility/achievement_unlocked'} end game.print{'ExpGamingCore-Role.default-print',{'ExpGamingCore-Role.assign',player.name,table.concat(names,', '),by_player.name}} @@ -524,4 +526,4 @@ end) -- Module Return -- calling will attempt to define a new role -return setmetatable(Role,{__call=function(tbl,...) return tbl.define(...) end}) \ No newline at end of file +return setmetatable(Role,{__call=function(tbl,...) return tbl.define(...) end}) \ No newline at end of file diff --git a/modules/ExpGamingCore/Role/src/sync.lua b/modules/ExpGamingCore/Role/src/sync.lua index af6b3e39..36f0fdbe 100644 --- a/modules/ExpGamingCore/Role/src/sync.lua +++ b/modules/ExpGamingCore/Role/src/sync.lua @@ -43,7 +43,7 @@ end Sync.add_update('roles',function() if not game then return {'Offline'} end local _rtn = {} - for name,role in pairs(Role.roles) do + for _,role in pairs(Role.roles) do local players = role:get_players() local _players = {} for k,player in pairs(players) do _players[k] = player.name end @@ -57,20 +57,20 @@ end) -- Adds a caption to the info gui that shows the rank given to the player if Sync.add_to_gui then - Sync.add_to_gui(function(player,frame) + Sync.add_to_gui(function(player) local names = {} for _,role in pairs(Role.get(player)) do table.insert(names,role.name) end return 'You have been assigned the roles: '..table.concat(names,', ') end) end --- adds a discord emit for rank chaning +-- adds a discord emit for rank changing script.on_event('on_role_change',function(event) local role = Role.get(event.role_name) local player = Game.get_player(event) local by_player = Game.get_player(event.by_player_index) or SERVER if role.is_jail and RoleGlobal.last_change[1] ~= player.index then - Sync.emit_embeded{ + Sync.emit_embedded{ title='Player Jail', color=Color.to_hex(defines.textcolor.med), description='There was a player jailed.', diff --git a/modules/ExpGamingCore/Server/control.lua b/modules/ExpGamingCore/Server/control.lua index 57f46fdf..82f0ec68 100644 --- a/modules/ExpGamingCore/Server/control.lua +++ b/modules/ExpGamingCore/Server/control.lua @@ -17,7 +17,7 @@ local module_verbose = false --true|false -- @field tick an index for threads which will run every tick (contains uuids) -- @field timeout an index for threads which will timeout (contains uuids) -- @field events an index of threads based on event ids (contains uuids) --- @field paused an index of pasued threads (contains uuids) +-- @field paused an index of paused threads (contains uuids) -- @field named a name index for thread uuids -- @field print_to contains players that event details will be printed to -- @field uuid contains the random number generator for the uuid system @@ -39,7 +39,7 @@ local global = global{ -- @treturn string the new uuid Server.uuid = add_metatable({},function() -- when it is called as a function - local uuid = 0 + local uuid if game then global.uuid=global.uuid+1 uuid=global.uuid+pre_load_uuid @@ -68,8 +68,8 @@ Server.threads = setmetatable({},{ __newindex=function(tbl,key,value) rawset(global.all,key,value) end, __pairs=function(tbl) local tbl = global.all - local function next_pair(tbl,k) - k, v = next(tbl, k) + local function next_pair(tbl,key) + local k, v = next(tbl, key) if type(v) ~= nil and k ~= '_n' then return k,v else return next(tbl, k) end end @@ -79,15 +79,15 @@ Server.threads = setmetatable({},{ --- Generates a new thread object -- @usage Server.new_thread{name='foo',data={}} --- @tparam table obj the atributes to give to the thread +-- @tparam table obj the attributes to give to the thread -- @treturn Server._thread the new thread created function Server.new_thread(obj) return Server._thread:create(obj) end ---- Used to get a thread via uuid or name (if one is assied) +--- Used to get a thread via uuid or name (if one is assigned) -- @usage Server.get_thread('decon') -- return thread -- @param mixed either a uuid or the name given to a thread -- @treturn[1] Server._thread the thread by that name or uuid --- @treturn[2] boolean if false is returned then no thread existes +-- @treturn[2] boolean if false is returned then no thread exists function Server.get_thread(mixed) local threads = global if threads.named[mixed] then return threads.all[threads.named[mixed]] @@ -99,7 +99,7 @@ end --- Adds a thread into the resolve queue, can be used to lower lag -- @usage Server.queue_thread(thread) -- return true/false -- @tparam Server._thread thread_to_queue the thread to be added to the queue, must be open and have a on_resolve function --- @treturn boolean was it added successfuly +-- @treturn boolean was it added successfully 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 @@ -109,15 +109,15 @@ end --- Closes all active threads, can use force if it causes errors -- @usage Server.close_all_threads() -- asks all threads to close --- @usage Server.close_all_threads(true) -- forcefuly close all threads --- @tparam bolean with_force use force when closing +-- @usage Server.close_all_threads(true) -- forcefully close all threads +-- @tparam boolean with_force use force when closing function Server.close_all_threads(with_force) if not with_force then for uuid,thread in pairs(Server.threads) do thread:close() end - else global.Server(true) end -- idk why you cant just use global even when global is defined at the top to be over ridren + else global.Server(true) end -- idk why you cant just use global even when global is defined at the top to be overridden end ---- Runs all the theads which have opened with an on_tick event +--- Runs all the threads which have opened with an on_tick event -- @usage Server.run_tick_threads() function Server.run_tick_threads() table.each(global.tick,function(uuid) @@ -146,8 +146,8 @@ end -- @tparam ?name|index event the event that info will be returned fo -- @tparam[opt=toggle] boolean state will info be returned, nil to toggle current state function Server._thread_debuger(player,event,state) - local player = Game.get_player(player) - local event = tonumber(event) or Manager.event.names[event] + player = Game.get_player(player) + event = tonumber(event) or Manager.event.names[event] local print_to = global.print_to print_to[player.index] = print_to[player.index] or {} if state then print_to[player.index][event] = state @@ -155,12 +155,12 @@ function Server._thread_debuger(player,event,state) else print_to[player.index][event] = true end end ---- Calles all threads on a certain game event (used with script.on_event) +--- Calls all threads on a certain game event (used with script.on_event) -- @local Server._thread_handler -- @usage script.on_event(defines.events,Server._thread_handler) -- adds this handler -- @tparam table event the event that is called function Server._thread_handler(event) - -- returns to players who have set _thread_debuger to trye + -- returns to players who have set _thread_debuger to true table.each(global.print_to,function(print_to,player_index,event) if event.name == defines.events.on_tick then return true end if print_to[event.name] then @@ -189,7 +189,7 @@ end --- Adds a event handler to tell threads about events -- @usage Server.add_thread_handler(defines.event) -- @tparam number event the event to run the thread handler on` --- @treturn bolean if the handler was added +-- @treturn boolean if the handler was added function Server.add_thread_handler(event) if not is_type(event,'number') then return false end local threads = global @@ -204,9 +204,9 @@ end --- Acts as a bypass for running functions, can accept a string -- @usage Server.interface('local x = 1+1 print(x) return x') -- return 2 --- @usage Server.interface('local x = 1+1 print(x)',true) -- will creat a thread to run as root (this is the bypass) +-- @usage Server.interface('local x = 1+1 print(x)',true) -- will create a thread to run as root (this is the bypass) -- @tparam ?string|function callback function to be ran --- @tparam[opt] ?Server._thread|true use_thread run the command on a premade thread or let it make its own +-- @tparam[opt] ?Server._thread|true use_thread run the command on a pre-made thread or let it make its own -- @tparam[opt] table env run the env to run the command in must have _env key as true to be -- @param[opt] ... any args you want to pass to the function -- @treturn[1] boolean if no thread then it will return a true for the success @@ -219,15 +219,15 @@ function Server.interface(callback,use_thread,env,...) if use_thread == true then use_thread = Server.new_thread{data={callback,env,...}} end -- creates the resolve function for the thread use_thread:on_event('resolve',function(thread) - local callback = table.remove(thread.data,1) - callback = is_type(callback,'function') and callback or loadstring(callback) - local env = table.remove(thread.data,1) - if is_type(env,'table') and not is_type(env.__self,'userdata') and env._env == true then - local success, err = Manager.sandbox(callback,env,unpack(thread.data)) + local thread_callback = table.remove(thread.data,1) + thread_callback = is_type(thread_callback,'function') and thread_callback or loadstring(thread_callback) + local thread_env = table.remove(thread.data,1) + if is_type(thread_env,'table') and not is_type(thread_env.__self,'userdata') and thread_env._env == true then + local success, err = Manager.sandbox(thread_callback,thread_env,unpack(thread.data)) if not success then error(err) end return err else - local success, err = Manager.sandbox(callback,{},env,unpack(thread.data)) + local success, err = Manager.sandbox(thread_callback,{},env,unpack(thread.data)) if not success then error(err) end return err end @@ -254,13 +254,13 @@ function Server.interface(callback,use_thread,env,...) end end ---- The class for the server threads, allows abbilty to run async function +--- The class for the server threads, allows ability to run async function -- @type Thread -- @alias Server._thread -- @field name the name that is given to the thread, use for easy later indexing -- @field timeout the time in ticks that the thread will have before it times out --- @field reopen when true the thread will reopen itself untill set to false, combine with timeout to create a long on_nth_tick wait --- @field data any data that the thread will beable to access +-- @field reopen when true the thread will reopen itself until set to false, combine with timeout to create a long on_nth_tick wait +-- @field data any data that the thread will be able to access Server._thread = {} local _env_metatable = { @@ -271,15 +271,15 @@ local _env_metatable = { -- @usage new_thread = thread:create() -- @tparam[opt={}] table obj all values are opt {timeout=int,name=str,data=any} -- @treturn Server._thread the new thread object -function Server._thread:create(obj) - local obj = obj or {} +function Server._thread.create(obj) + obj = obj or {} setmetatable(obj,{__index=Server._thread}) obj.uuid = tostring(Server.uuid) - -- creates a varible containg all upvalus for the thread (stops desyncs) + -- creates a variable containing all upvalus for the thread (stops desyncs) obj._env = get_upvalues(2) obj._env._env = true - obj._env._ENV = nil -- provents infinte recusion - -- removes any modules from the _env to save space in global (less time to serizle) + obj._env._ENV = nil -- prevents infinite recursion + -- removes any modules from the _env to save space in global (less time to serialize) obj._env._modules = {} for name,value in pairs(obj._env) do if is_type(value,'table') and value._moduleName and loaded_modules[value._moduleName] == value then obj._env._modules[name] = value._moduleName obj._env[name] = nil end end setmetatable(obj._env,_env_metatable) @@ -288,21 +288,21 @@ function Server._thread:create(obj) return obj end ---- Opens and queses a thread +--- Opens and queues a thread -- @usage Server._thread:queue() -- returns true/false --- @treturn boolean was the thread queued successfuly +-- @treturn boolean was the thread queued successfully -- @see Server.queue_thread function Server._thread:queue() self:open() return Server.queue_thread(self) end ---- Test if the thread has all requied parts +--- Test if the thread has all required parts -- @usage if thread:valid() then end -- basic test for valid --- @tparam[opt=false] bolean skip_location_check true to skip the location checking +-- @tparam[opt=false] boolean skip_location_check true to skip the location checking -- @treturn boolean is the thread valid function Server._thread:valid(skip_location_check) - local skip_location_check = skip_location_check or false + skip_location_check = skip_location_check or false if is_type(self.uuid,'string') and skip_location_check or is_type(self.opened,'number') and skip_location_check or is_type(global.all[self.uuid],'table') and @@ -314,34 +314,34 @@ function Server._thread:valid(skip_location_check) is_type(self._resolve) or is_type(self._resolve,'function') and is_type(self._success) or is_type(self._success,'function') and is_type(self._error) or is_type(self._error,'function') then - -- all above must be true to be vaild, must accept nil and function + -- all above must be true to be valid, must accept nil and function return true end return false end ---- Opens the thread; indexs this thread in the global index +--- Opens the thread; indexes this thread in the global index -- @usage thread:open() -- return true --- @treturn bolean if the thread was opened successfuly +-- @treturn boolean if the thread was opened successfully function Server._thread:open() - -- if the thread is valid and not already opended + -- if the thread is valid and not already opened if not self:valid(true) or self.opened then return false end local uuid = self.uuid -- sets the thread to open, this is the tick it was opened self.opened = game.tick - -- creats the global index + -- creates the global index global.all[uuid] = global.all[uuid] or self global.all._n = global.all._n+1 - -- indexs the thread in other places if it has more function + -- indexes the thread in other places if it has more function -- if it was paused before (ie did not run any events) then the index is removed from the paused index if global.paused[self.name] then global.paused[self.name] = nil end - -- if it has a timeout or on_tick handler then it is indexed in those indexs + -- if it has a timeout or on_tick handler then it is indexed in those indexes if is_type(self.timeout,'number') then table.insert(global.timeout,uuid) end if is_type(self._tick,'function') then table.insert(global.tick,uuid) end -- if the thread is given a name then a index from the name to uuid is made if is_type(self.name,'string') then global.named[self.name] = global.named[self.name] or self.uuid end -- if there are event handlers then it will loop over them and add them to the event index - if is_type(self._events,'table') then + if is_type(self._events,'table') then table.each(self._events,function(callback,event,global,uuid) -- cant be used V --Server.add_thread_handler(event) @@ -354,7 +354,7 @@ function Server._thread:open() return true end ---- Inverse of thread:open() - Removes all indexs to this thread, most cases this will cause it to become inassible +--- Inverse of thread:open() - Removes all indexes to this thread, most cases this will cause it to become inaccessible -- @usage thread:close() -- return true -- @treturn boolean if the thread had a on_close function function Server._thread:close() @@ -363,17 +363,17 @@ function Server._thread:close() -- if there is a call to the threads on close event, will later return true if is_type(self._close,'function') then Manager.sandbox(self._close,self._env,self) _return = true end -- will search every possible location for this thread and remove it - local value,key = table.find(global.queue,function(v,k,uuid) return v == uuid end,uuid) + local _,key = table.find(global.queue,function(v,k,uuid) return v == uuid end,uuid) if key then table.remove(global.queue,key) end -- queue - local value,key = table.find(global.timeout,function(v,k,uuid) return v == uuid end,uuid) + _,key = table.find(global.timeout,function(v,k,uuid) return v == uuid end,uuid) if key then table.remove(global.timeout,key) end -- timeouts - local value,key = table.find(global.tick,function(v,k,uuid) return v == uuid end,uuid) + _,key = table.find(global.tick,function(v,k,uuid) return v == uuid end,uuid) if key then table.remove(global.tick,key) end -- on_tick -- then will look for it in the event handlers and remove it if found if is_type(self._events,'table') then table.each(self._events,function(callback,event) if global.events[event] then - local value,key = table.find(global.events[event],function(v,k,uuid) return v == uuid end,uuid) + local _,key = table.find(global.events[event],function(v,k,uuid) return v == uuid end,uuid) if key then table.remove(global.events[event],key) end -- cant be used V --if #global.events[event] == 0 then Event.remove(event,Server.game_event) global.events[event] = nil end @@ -382,9 +382,9 @@ function Server._thread:close() end -- sets the thread to closed self.opened=nil - -- unless the thread has a name or is assied to be reopened + -- unless the thread has a name or is assigned to be reopened if self.reopen == true then self:open() else - -- if it has a name but not assied to reopen then it will become 'pasued' + -- if it has a name but not assigned to reopen then it will become 'paused' if is_type(self.name,'string') then global.paused[self.name]=self.uuid -- else it will just be wiped from the global index else global.all[uuid] = nil global.all._n = global.all._n-1 end @@ -397,19 +397,19 @@ end --- Trigger the on_resolve function and closes the thread - error and success called based on result of pcall (useful for async) -- @usage thread:resolve(x,y,z) -- return true -- @param[opt] ... any arguments you want to pass to the resolve function --- @treturn bolean true if the thread called on_success or on_error +-- @treturn boolean true if the thread called on_success or on_error function Server._thread:resolve(...) local _return = false - -- checks if the resolve haddler is still present - if is_type(self._resolve,'function') then + -- checks if the resolve handler is still present + if is_type(self._resolve,'function') then local success, err = Manager.sandbox(self._resolve,self._env,self,...) if success then - -- if it was successful then it will attemp to call the success handler + -- if it was successful then it will attempt to call the success handler if is_type(self._success,'function') then -- interface is used as a way to delay the success call till the next tick Server.interface(function(thread,err) - local success, err = Manager.sandbox(thread._success,thread._env,thread,err) - if not success then thread:error(err) end + local _success, _err = Manager.sandbox(thread._success,thread._env,thread,err) + if not _success then thread:error(_err) end end,true,self,err) -- later returns true if there was a call to the success handler _return = true @@ -422,9 +422,9 @@ function Server._thread:resolve(...) return _return end ---- Checks the timeout on a thread - if timed out then it calles on_timeout and closes +--- Checks the timeout on a thread - if timed out then it calls on_timeout and closes -- @usage thread:check_timeout() -- return true --- @treturn bolean if the thread timed out +-- @treturn boolean if the thread timed out function Server._thread:check_timeout() local _return = false -- makes sure the thread is still valid @@ -436,7 +436,7 @@ function Server._thread:check_timeout() Manager.sandbox(self._timeout,self._env,self) end _return = true - -- closes the thread to provent any further event calls + -- closes the thread to prevent any further event calls self:close() end return _return @@ -444,7 +444,7 @@ end --- Used to check and raise the error handler of the thread, if not present it raises an error -- @usage thread:error(err) -- return true --- @tparam string err the err to be rasied +-- @tparam string err the err to be raised -- @treturn boolean did the thread have an error handler function Server._thread:error(err) local _return = false @@ -453,12 +453,12 @@ function Server._thread:error(err) _return = true else self:close() -- no matter what happens next this thread will be closed - error('Thread Error (no handler): '..err) + error('Thread Error (no handler): '..err) end return _return end ---- Set function to run then an event is triggered, none of them are 'needed' but you are advised to have atleast one +--- Set function to run then an event is triggered, none of them are 'needed' but you are advised to have at least one -- @usage thread:on_event('close',function) -- if event is not one below then a game event is used -- @usage thread_only_events = ['close','timeout','tick','resolve','success','error'] -- @tparam ?string|index event the name of the event that the function should be called on @@ -466,7 +466,7 @@ end -- @treturn table returns self so that they can be chained together function Server._thread:on_event(event,callback) local events = {'close','timeout','tick','resolve','success','error'} - -- seaches the above list for the event + -- searches the above list for the event local value = table.find(events,function(v,k,find) return v == string.lower(find) end,event) if value and is_type(callback,'function') then -- if it is a thread_only_event then it will add it to its core values @@ -492,7 +492,7 @@ script.on_event(defines.events.on_tick,function(event) end) script.on_load(function(event) - -- sets up metatable again so that threads contiune to work + -- sets up metatable again so that threads continue to work for uuid,thread in pairs(Server.threads) do setmetatable(thread,{__index=Server._thread}) setmetatable(thread._env,_env_metatable) @@ -535,7 +535,7 @@ return Server end) thread:open() - all on_event functions can be chained from the thread creation rather than use varibles eg: + all on_event functions can be chained from the thread creation rather than use variables eg: Server.new_thread{ name='tree-decon', data={} diff --git a/modules/ExpGamingCore/Server/src/commands.lua b/modules/ExpGamingCore/Server/src/commands.lua index 2155eede..4a0abf28 100644 --- a/modules/ExpGamingCore/Server/src/commands.lua +++ b/modules/ExpGamingCore/Server/src/commands.lua @@ -7,7 +7,6 @@ --- This file will be loaded when ExpGamingCore.Command is present -- @function _comment -local Game = require('FactorioStdLib.Game') local Server = Server Server.interfaceCallbacks = {} @@ -40,7 +39,7 @@ commands.add_command('interface','Runs the given input from the script', { env.tile = game.player.surface.get_tile(game.player.position) end -- adds custom callbacks to the interface - for name,callback in pairs(Server.interfaceCallbacks) do env[name] = callback() end + for name,custom_callback in pairs(Server.interfaceCallbacks) do env[name] = custom_callback() end -- runs the function local success, err = Server.interface(callback,false,env) -- if there is an error then it will remove the stacktrace and return the error diff --git a/modules/ExpGamingCore/Sync/control.lua b/modules/ExpGamingCore/Sync/control.lua index 720e4100..bfd91b43 100644 --- a/modules/ExpGamingCore/Sync/control.lua +++ b/modules/ExpGamingCore/Sync/control.lua @@ -1,4 +1,4 @@ ---- Allows syncing with an outside server and info panle. +--- Allows syncing with an outside server and info panel. -- @module ExpGamingCore.Sync -- @alias Sync -- @author Cooldude2606 @@ -16,10 +16,10 @@ local module_verbose = false --true|false -- @field server_name the server name -- @field server_description a short description of the server -- @field reset_time the reset time of the server --- @field time the last knowen irl time +-- @field time the last known irl time -- @field time_set the last in game time that the time was set -- @field last_update the last time that this info was updated --- @field time_period how often this infomation is updated +-- @field time_period how often this information is updated -- @field players a list of different player related states -- @field ranks a list of player ranks -- @field rockets the number of rockets launched @@ -58,9 +58,9 @@ local global = global{ -- @field afk_players the number of afk players -- @field times the play times of every player ---- Used to standidise the tick format for any sync info +--- Used to standardise the tick format for any sync info -- @usage Sync.tick_format(60) -- return {60,'1.00M'} --- @treturn {number,string} table containg both the raw number and clean version of a time +-- @treturn {number,string} table containing both the raw number and clean version of a time function Sync.tick_format(tick) if not is_type(tick,'number') then error('Tick was not given to Sync.tick_format',2) end return {tick,tick_to_display_format(tick)} @@ -70,7 +70,7 @@ end -- @usage Sync.print('Test','Cooldude2606') -- @tparam string player_message the message to be printed in chat -- @tparam string player_name the name of the player sending the message --- @tparam[opt] string player_tag the tag apllied to the player's name +-- @tparam[opt] string player_tag the tag applied to the player's name -- @tparam[opt] string player_colour the colour of the message, either hex or named colour -- @tparam[opt] string prefix add a prefix before the chat eg [IRC] function Sync.print(player_message,player_name,player_tag,player_colour,prefix) @@ -78,8 +78,8 @@ function Sync.print(player_message,player_name,player_tag,player_colour,prefix) local player = game.player or game.players[player_name] local tag = player_tag and player_tag ~= '' and ' '..player_tag or '' local colour = type(player_colour) == 'string' and player_colour or '#FFFFFF' - local prefix = prefix and prefix..' ' or '' - -- if it is an ingame player it will over ride the given params + prefix = prefix and prefix..' ' or '' + -- if it is an in game player it will over ride the given params if player then tag = ' '..player.tag colour = player.chat_color @@ -92,7 +92,7 @@ function Sync.print(player_message,player_name,player_tag,player_colour,prefix) game.print(prefix..player_name..tag..': '..player_message,colour) end ---- Outline of the paramaters accepted by Sync.emit_embeded +--- Outline of the parameters accepted by Sync.emit_embedded -- @table EmitEmbededParamaters -- @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} @@ -102,11 +102,11 @@ end -- @field fieldtwo the filed to add to the embed (key is name) (value is text) (start value with <<inline>> to make inline) --- 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 args a table which contains everything that the embeded will use +-- @usage Sync.emit_embedded{title='BAN',color='0x0',description='A player was banned' ... } +-- @tparam table args a table which contains everything that the embedded will use -- @see EmitEmbededParamaters -function Sync.emit_embeded(args) - if not is_type(args,'table') then error('Args table not given to Sync.emit_embeded',2) end +function Sync.emit_embedded(args) + if not is_type(args,'table') then error('Args table not given to Sync.emit_embedded',2) end if not game then error('Game has not loaded',2) end local title = is_type(args.title,'string') and args.title or '' local color = is_type(args.color,'string') and args.color:find("0x") and args.color or '0x0' @@ -130,14 +130,14 @@ function Sync.emit_embeded(args) table.insert(fields,f) end end - -- forms the data that will be emited to the file + -- forms the data that will be emitted to the file local log_data = { title=title, description=description, color=color, fields=fields } - game.write_file('embeded.json',table.json(log_data)..'\n',true,0) + game.write_file('embedded.json',table.json(log_data)..'\n',true,0) end --- The error handle setup by sync to emit a discord embed for any errors @@ -147,7 +147,7 @@ end error.addHandler('Discord Emit',function(err) if not game then return error(error()) end local color = Color and Color.to_hex(defines.textcolor.bg) or '0x0' - Sync.emit_embeded{title='SCRIPT ERROR',color=color,description='There was an error in the script @Developers ',Error=err} + Sync.emit_embedded{title='SCRIPT ERROR',color=color,description='There was an error in the script @Developers ',Error=err} end) --- Used to get the number of admins currently online @@ -169,7 +169,7 @@ end -- @treturn number the number of afk players function Sync.count_afk_times(time) if not game then return 0 end - local time = time or 7200 + time = time or 7200 local rtn = {} for _,player in pairs(game.connected_players) do if player.afk_time > time then rtn[player.name] = Sync.tick_format(player.afk_time) end @@ -236,15 +236,15 @@ Sync.info = setmetatable({},{ return true end, __pairs=function(tbl) - local tbl = global - local function next_pair(tbl,k) - k, v = next(tbl, k) + tbl = global + local function next_pair(tbl,key) + local k, v = next(tbl, key) if type(v) ~= nil then return k,v end end return next_pair, tbl, nil end, __ipairs=function(tbl) - local tbl = global + tbl = global local function next_pair(tbl, i) i = i + 1 local v = tbl[i] @@ -305,7 +305,7 @@ end -- @usage Sync.time('Sun Apr 1 18:44:30 UTC 2018') -- @usage Sync.time -- string -- @tparam[opt=nil] string set the date time to be set --- @treturn boolean if the datetime set was successful +-- @treturn boolean if the date time set was successful Sync.time=add_metatable({},function(full,date) local info = Sync.info if not is_type(full,'string') then return false end diff --git a/modules/ExpGamingCore/Sync/src/gui.lua b/modules/ExpGamingCore/Sync/src/gui.lua index 51ea6121..f01ebf2a 100644 --- a/modules/ExpGamingCore/Sync/src/gui.lua +++ b/modules/ExpGamingCore/Sync/src/gui.lua @@ -1,4 +1,4 @@ ---- Allows syncing with an outside server and info panle. +--- Allows syncing with an outside server and info panel. -- @submodule ExpGamingCore.Sync -- @alias Sync -- @author Cooldude2606 @@ -7,17 +7,16 @@ --- This file will be loaded when ExpGamingCore.Gui is present -- @function _comment -local Game = require('FactorioStdLib.Game') local Gui = require('ExpGamingCore.Gui') local Sync = Sync -- this is to force sync to remain in the ENV local Sync_gui_functions = {} local logo_sprite_path = 'file'..string.sub(module_path,2)..'/src/logo.png' ---- Adds a emeltent to the sever info gui +--- Adds a element to the sever info gui -- @usage Sync.add_to_gui('string') -- return true -- @param element see examples before for what can be used, it can also be a return from Gui.inputs.add --- @treturn bolean based on weather it was successful or not +-- @treturn boolean based on weather it was successful or not function Sync.add_to_gui(element,...) if game then return false end if is_type(element,'function') then @@ -29,10 +28,10 @@ function Sync.add_to_gui(element,...) return true end -Sync.add_to_gui('Welcome to the Explosive Gaming comunity! This is one of many servers which we host.') +Sync.add_to_gui('Welcome to the Explosive Gaming community! This is one of many servers which we host.') Sync.add_to_gui(function(player,frame) return 'This server\'s next reset: '..Sync.info.reset_time end) ---- Formats a lable to be a certain format +--- Formats a label to be a certain format -- @local label_format local function label_format(label,width) label.style.width = width @@ -49,7 +48,7 @@ Sync.info_gui = Gui.center{ draw=function(self,frame) frame.caption = '' local info = Sync.info - local frame = frame.add{type='flow',direction='vertical'} + frame = frame.add{type='flow',direction='vertical'} local h_flow = frame.add{type='flow'} h_flow.add{type='sprite',sprite=logo_sprite_path} local v_flow = h_flow.add{type='flow',direction='vertical'} @@ -68,7 +67,7 @@ Sync.info_gui = Gui.center{ Gui.bar(_flow,110) Gui.bar(frame,600) local _frame = frame - local frame = frame.add{ + frame = frame.add{ type='frame', direction='vertical', style='image_frame' diff --git a/modules/ExpGamingInfo/Readme/control.lua b/modules/ExpGamingInfo/Readme/control.lua index 9bdbe504..55365037 100644 --- a/modules/ExpGamingInfo/Readme/control.lua +++ b/modules/ExpGamingInfo/Readme/control.lua @@ -2,11 +2,10 @@ -- @module ExpGamingInfo.Readme -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Gui = require('ExpGamingCore.Gui') -local Game = require('FactorioStdLib.Game') -- Module Define local module_verbose = false @@ -65,12 +64,12 @@ end):add_tab('commands',{'ExpGamingInfo-Readme.commands-name'},{'ExpGamingInfo-R type='label', caption='/'..command.name } - local discription = table.add{ + local description = table.add{ type='label', caption=command.description, } - discription.style.maximal_width = 400 - discription.style.single_line = false + description.style.maximal_width = 400 + description.style.single_line = false end end):add_tab('links',{'ExpGamingInfo-Readme.links-name'},{'ExpGamingInfo-Readme.links-tooltip'},function(frame) local links={ @@ -87,7 +86,7 @@ end):add_tab('links',{'ExpGamingInfo-Readme.links-name'},{'ExpGamingInfo-Readme. text_box.selectable = true end for i,link in pairs(links) do - frame.add{ + frame.add{ type="label", caption={'ExpGamingInfo-Readme.links-cap'..tostring(i)}, style='caption_label' diff --git a/modules/ExpGamingInfo/Rockets/control.lua b/modules/ExpGamingInfo/Rockets/control.lua index 243514e8..6edd2130 100644 --- a/modules/ExpGamingInfo/Rockets/control.lua +++ b/modules/ExpGamingInfo/Rockets/control.lua @@ -2,7 +2,7 @@ -- @module ExpGamingInfo.Rockets -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Gui = require('ExpGamingCore.Gui') @@ -74,20 +74,20 @@ ThisModule.Gui = Gui.left{ type='flow', direction='vertical' } - for milestone,time in pairs(global.milestones) do - local milestone = tonumber(milestone:match('%d+')) - if time == 0 and satellites == milestone then + for milestone,next_time in pairs(global.milestones) do + milestone = tonumber(milestone:match('%d+')) + if next_time == 0 and satellites == milestone then global.milestones['m'..milestone] = global.last - time = global.last + next_time = global.last Gui.left.open('rockets') end local _time = {'ExpGamingInfo-Rockets.nan'} - if time > 0 then _time = tick_to_display_format(time) end + if next_time > 0 then _time = tick_to_display_format(next_time) end milestones.add{ type='label', caption={'ExpGamingInfo-Rockets.format',tostring(milestone),_time} } - if time == 0 then break end + if next_time == 0 then break end end end, can_open=function(player) diff --git a/modules/ExpGamingInfo/Rockets/src/sync.lua b/modules/ExpGamingInfo/Rockets/src/sync.lua index ce050aa6..82482eac 100644 --- a/modules/ExpGamingInfo/Rockets/src/sync.lua +++ b/modules/ExpGamingInfo/Rockets/src/sync.lua @@ -13,8 +13,8 @@ Sync.add_update('rockets',function() _return.time = Sync.tick_format(time) _return.fastest = Sync.tick_format(global.fastest) _return.milestones = {} - for milestone,time in pairs(global.milestones) do - _return.milestones[milestone] = Sync.tick_format(time) + for milestone,next_time in pairs(global.milestones) do + _return.milestones[milestone] = Sync.tick_format(next_time) end return _return end) \ No newline at end of file diff --git a/modules/ExpGamingInfo/Science/control.lua b/modules/ExpGamingInfo/Science/control.lua index dd7f4880..74118960 100644 --- a/modules/ExpGamingInfo/Science/control.lua +++ b/modules/ExpGamingInfo/Science/control.lua @@ -1,14 +1,14 @@ ---- Adds a science count gui to the game that shows toatal made and per minute +--- Adds a science count gui to the game that shows total made and per minute -- @module ExpGamingInfo.Science -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Gui = require('ExpGamingCore.Gui') local Game = require('FactorioStdLib.Game') --- Local Varibles +-- Local Variables local science_packs = { 'science-pack-1', 'science-pack-2', @@ -23,7 +23,7 @@ local science_packs = { local module_verbose = false local ThisModule = { on_init=function() - if loaded_modules['ExpGamingCore.Sync^4.0.0'] then require(module_path..'/src/sync') end + if loaded_modules['ExpGamingCore.Sync^4.0.0'] then require(module_path..'/src/sync',{science_packs=science_packs}) end end } @@ -48,7 +48,7 @@ ThisModule.Gui = Gui.left{ verbose('Added Science Global for: '..player.force.name) global[player.force.name] = table.deepcopy(global._base) end - force_data = global[player.force.name] + local force_data = global[player.force.name] frame.caption = {'ExpGamingInfo-Science.name'} frame.add{ type='label', @@ -101,5 +101,5 @@ ThisModule.Gui = Gui.left{ script.on_event(defines.events.on_research_finished,function(event) Gui.left.update('science') end) -- Module Return --- when called will toogle the gui for that player, if no player it will update the gui +-- when called will toggle the gui for that player, if no player it will update the gui return setmetatable(ThisModule,{_call=function(self,...) self.Gui(...) end}) \ No newline at end of file diff --git a/modules/ExpGamingInfo/Science/src/sync.lua b/modules/ExpGamingInfo/Science/src/sync.lua index fd3993c7..6f624d4f 100644 --- a/modules/ExpGamingInfo/Science/src/sync.lua +++ b/modules/ExpGamingInfo/Science/src/sync.lua @@ -1,5 +1,6 @@ local Sync = require('ExpGamingCore.Sync') local data = global['ExpGamingInfo.Science'] +local science_packs = science_packs Sync.add_update('science',function() local _return = {} diff --git a/modules/ExpGamingInfo/Tasklist/control.lua b/modules/ExpGamingInfo/Tasklist/control.lua index 49be90ca..5754742d 100644 --- a/modules/ExpGamingInfo/Tasklist/control.lua +++ b/modules/ExpGamingInfo/Tasklist/control.lua @@ -2,7 +2,7 @@ -- @module ExpGamingInfo.Tasklist -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Gui = require('ExpGamingCore.Gui') @@ -102,26 +102,26 @@ local add = Gui.inputs{ end) local function _tasks(player) - local player = Game.get_player(player) + player = Game.get_player(player) local data = global._edit[player.index] if not data then return global.tasks end - local _edit = false + local editing = false for _,v in pairs(data._editing) do if v == true then - _edit = true + editing = true break end end - if data._edit and not _edit then + if data._edit and not editing then global.tasks = table.deepcopy(data._tasks) global._edit[player.index] = table.deepcopy(global._base) Gui.left.update('tasklist') return global.tasks - elseif not data._edit and _edit then + elseif not data._edit and editing then data._edit = true for key,_ in pairs(data._tasks) do if not data._editing[key] then data._editing[key] = false end end return data._tasks - elseif _edit then return data._tasks + elseif editing then return data._tasks else return global.tasks end end diff --git a/modules/ExpGamingLib/control.lua b/modules/ExpGamingLib/control.lua index 7ec4841b..b68fb4a3 100644 --- a/modules/ExpGamingLib/control.lua +++ b/modules/ExpGamingLib/control.lua @@ -10,7 +10,7 @@ local Color = require('FactorioStdLib.Color') 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 +--- Loads a table into _G even when sandboxes; 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) @@ -25,7 +25,7 @@ end -- @treturn table the env table with _G keys removed -- @warning does not work from console function ExpLib.get_env(level) - local level = level and level+1 or 2 + level = level and level+1 or 2 local env = setmetatable({},{__index=_G}) while true do if not debug.getinfo(level) then break end @@ -46,7 +46,7 @@ end -- @warning does not work from console function ExpLib.get_upvalues(level) local func = level and ExpLib.is_type(level,'function') and level or nil - local level = level and ExpLib.is_type(level,'number') and level+1 or 2 + level = level and ExpLib.is_type(level,'number') and level+1 or 2 func = func or debug.getinfo(level).func local upvalues = setmetatable({},{__index=_G}) local i = 1 @@ -58,7 +58,7 @@ function ExpLib.get_upvalues(level) return upvalues end ---- Creats a table that will act like a string and a function +--- Creates a table that will act like a string and a function -- @usage add_metatable({},function) -- returns table -- @tparam table tbl the table that will have its metatable set -- @tparam[opt=tostring] function callback the function that will be used for the call @@ -66,8 +66,8 @@ end -- @treturn table the new table with its metatable set function ExpLib.add_metatable(tbl,callback,string) if not ExpLib.is_type(tbl,'table') then error('No table given to add_metatable',2) end - local callback = ExpLib.is_type(callback,'function') and callback or tostring - local string = ExpLib.is_type(string,'function') and string or ExpLib.is_type(string,'string') and function() return string end or table.tostring + callback = ExpLib.is_type(callback,'function') and callback or tostring + string = ExpLib.is_type(string,'function') and string or ExpLib.is_type(string,'string') and function() return string end or table.tostring return setmetatable(tbl,{ __tostring=string, __concat=function(val1,val2) return type(val1) == 'string' and val1..string(val2) or string(val1)..val2 end, @@ -75,17 +75,17 @@ function ExpLib.add_metatable(tbl,callback,string) }) end ---- Compear types faster for faster valadation of prams +--- Compare types faster for faster validation 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 +-- @treturn boolean 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 ---- Compear types faster for faster valadation of prams, including giving an error if incorrect +--- Compare types faster for faster validation of prams, including giving an error if incorrect -- @usage type_error('foo','string','Value is not a string') -- return true -- @usage type_error('foo','table','Value is not a string') -- return error -- @param value the value to be tested @@ -96,7 +96,7 @@ function ExpLib.type_error(value,type,error_message) return ExpLib.is_type(value,type) or error(error_message,3) end ---- A speailsied verion of type_error to test for self +--- A specialised version of type_error to test for self -- @usage self_test(self,'Object','get_name') -- @tparam table self the table that is the object -- @tparam string prototype_name the name of the class @@ -110,11 +110,11 @@ end -- @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=defines.colour.white] ?defines.color|string colour the colour of the text for the player, ignored 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.textcolor[colour] ~= defines.color.white and defines.textcolor[colour] or defines.color[colour] - local player = player or game.player + colour = ExpLib.is_type(colour,'table') and colour or defines.textcolor[colour] ~= defines.color.white and defines.textcolor[colour] or defines.color[colour] + 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 @@ -128,8 +128,8 @@ function ExpLib.player_return(rtn,colour,player) else callback(tostring(rtn),colour) end end if player then - -- allows any vaild player identifier to be used - local player = Game.get_player(player) + -- allows any valid player identifier to be used + 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'} @@ -175,8 +175,8 @@ function ExpLib.tick_to_display_format(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 +--- Used as a way to view the structure of a gui, used for debugging +-- @usage Gui_tree(root) returns all children of gui recursively -- @tparam LuaGuiElement root the root to start the tree from -- @treturn table the table that describes the gui function ExpLib.gui_tree(root) @@ -249,13 +249,13 @@ function table.tostring(tbl) return "{"..table.concat(result,",") .."}" end ---- Simmilar to table.tostring but converts a lua table to a json one --- @usage talbe.json{k1='foo',k2='bar'} -- return '{"k1":"foo","k2":"bar"}' +--- Similar to table.tostring but converts a lua table to a json one +-- @usage table.json{k1='foo',k2='bar'} -- return '{"k1":"foo","k2":"bar"}' -- @tparam table lua_table the table to convert -- @treturn string the table in a json format function table.json(lua_table) --if game and game.table_to_json then return game.table_to_json(lua_table) end - local result, done, only_indexs = {}, {}, true + local result, done, only_indexes = {}, {}, true for key,value in ipairs(lua_table) do done[key] = true if type(value) == 'table' then table.insert(result,table.json(value,true)) @@ -265,14 +265,14 @@ function table.json(lua_table) end for key,value in pairs(lua_table) do if not done[key] then - only_indexs = false + only_indexes = false if type(value) == 'table' then table.insert(result,table.val_to_str(key)..':'..table.json(value,true)) elseif not value then table.insert(result,table.val_to_str(key)..':null') else table.insert(result,table.val_to_str(key)..':'..table.val_to_str(value)) end end end - if only_indexs then return "["..table.concat(result,",").."]" + if only_indexes then return "["..table.concat(result,",").."]" else return "{"..table.concat(result,",").."}" end end diff --git a/modules/ExpGamingPlayer/afkKick/control.lua b/modules/ExpGamingPlayer/afkKick/control.lua index 0df78969..aa8f1c11 100644 --- a/modules/ExpGamingPlayer/afkKick/control.lua +++ b/modules/ExpGamingPlayer/afkKick/control.lua @@ -8,13 +8,13 @@ local Role -- ExpGamingCore.Role@^4.0.0 local Sync -- ExpGamingCore.Sync@^4.0.0 local function get_allowed_afk_time(player) - local player = Game.get_player(player) + player = Game.get_player(player) local role = Role and Role.get_highest(player) or {index=1,allow_afk_kick=not player.admin} local player_count = #game.connected_players local role_count = Role and Role.meta.count or 1 local role_index = role.allow_afk_kick and role.index or false - if not base then return false end - return (role_count/role_index)*count + if not role_index then return false end + return (role_count/role_index)*player_count end script.on_event(defines.events.on_tick,function(event) diff --git a/modules/ExpGamingPlayer/afkKick/src/server.lua b/modules/ExpGamingPlayer/afkKick/src/server.lua index 7db1970c..ed6bcf00 100644 --- a/modules/ExpGamingPlayer/afkKick/src/server.lua +++ b/modules/ExpGamingPlayer/afkKick/src/server.lua @@ -17,7 +17,7 @@ script.on_init(function(event) end end):on_event('error',function(self,err) if Sync then - Sync.emit_embeded{ + Sync.emit_embedded{ title='Auto Kick Error', color=Color.to_hex(defines.textcolor.bg), description='Auto Kick Error - Closed Thread', diff --git a/modules/ExpGamingPlayer/inventorySearch/control.lua b/modules/ExpGamingPlayer/inventorySearch/control.lua index 7862c19e..12318f15 100644 --- a/modules/ExpGamingPlayer/inventorySearch/control.lua +++ b/modules/ExpGamingPlayer/inventorySearch/control.lua @@ -1,15 +1,14 @@ ---- Adds an inventory search that is proformed on a random player every 15 seconds +--- Adds an inventory search that is preformed on a random player every 15 seconds -- @module ExpGamingPlayer.inventorySearch@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Admin = require('ExpGamingAdmin') -local Game = require('FactorioStdLib.Game') local Role -- ExpGamingCore.Role@^4.0.0 --- Local Varibles +-- Local Variables -- removed from none admin ranks, no further action local low_items = { 'loader', @@ -36,7 +35,7 @@ local high_items = { } -- inventories which are searched -local inventorys = { +local inventories = { defines.inventory.player_main, defines.inventory.player_quickbar, defines.inventory.player_trash @@ -63,7 +62,7 @@ end function ThisModule.search_player(player) for category,items in pairs(_root_tree) do if not Role or category ~= 'low_items' and not Role.allowed(player,'admin-items') then - for _,_inventory in pairs(inventorys) do + for _,_inventory in pairs(inventories) do local inventory = player.get_inventory(_inventory) if inventory then for _,item in pairs(items) do diff --git a/modules/ExpGamingPlayer/playerInfo/control.lua b/modules/ExpGamingPlayer/playerInfo/control.lua index b4a4a4d4..cd68d962 100644 --- a/modules/ExpGamingPlayer/playerInfo/control.lua +++ b/modules/ExpGamingPlayer/playerInfo/control.lua @@ -9,7 +9,7 @@ local Role -- ExpGamingCore.Role@^4.0.0 local Group -- ExpGamingCore.Group@^4.0.0 local function get_player_info(player,frame,add_cam) - local player = Game.get_player(player) + player = Game.get_player(player) if not player then return {} end local _player = {} _player.index = player.index @@ -26,7 +26,7 @@ local function get_player_info(player,frame,add_cam) _player.roles = roles end if frame then - local frame = frame.add{type='frame',direction='vertical',style='image_frame'} + frame = frame.add{type='frame',direction='vertical',style='image_frame'} frame.style.width = 200 if Role then frame.style.height = 300 else frame.style.height = 260 end diff --git a/modules/ExpGamingPlayer/playerList/control.lua b/modules/ExpGamingPlayer/playerList/control.lua index 5af46bfb..886e3139 100644 --- a/modules/ExpGamingPlayer/playerList/control.lua +++ b/modules/ExpGamingPlayer/playerList/control.lua @@ -8,7 +8,7 @@ local Gui = require('ExpGamingCore.Gui') local Admin -- ExpGamingAdmin@^4.0.0 local AdminGui -- ExpGamingAdmin.Gui@^4.0.0 --- Local Varibles +-- Local Variables local playerInfo = function(player,frame) frame.add{ type='label', @@ -40,12 +40,12 @@ local ThisModule = { local global = global{ update=0, delay=10, - intervial=54000 + interval=54000 } function ThisModule.update(tick) local tick = is_type(tick,'table') and tick.tick or is_type(tick,'number') and tick or game.tick - if tick + global.delay > global.update - global.intervial then + if tick + global.delay > global.update - global.interval then global.update = tick + global.delay end end @@ -113,7 +113,7 @@ ThisModule.Gui = Gui.left{ script.on_event(defines.events.on_tick,function(event) if event.tick > global.update then ThisModule.Gui() - global.update = event.tick + global.intervial + global.update = event.tick + global.interval end end) diff --git a/modules/ExpGamingPlayer/polls/control.lua b/modules/ExpGamingPlayer/polls/control.lua index 3e6b8301..1f187437 100644 --- a/modules/ExpGamingPlayer/polls/control.lua +++ b/modules/ExpGamingPlayer/polls/control.lua @@ -8,7 +8,7 @@ local Server = require('ExpGamingCore.Server') local Gui = require('ExpGamingCore.Gui') local Role -- ExpGamingCore.Server@^4.0.0 --- Local Varibles +-- Local Variables local poll_time_out = 90 -- In seconds -- Module Define @@ -27,7 +27,7 @@ local global = global{ -- Function Define local function _poll_data(question,answers) - local poll = { + local rtn_poll = { uuid=Server.uuid(), question=question, answers=answers or {'None'}, @@ -35,7 +35,7 @@ local function _poll_data(question,answers) voted={} } Server.new_thread{ - data={poll_uuid=poll.uuid}, + data={poll_uuid=rtn_poll.uuid}, timeout=poll_time_out*60 }:on_event('timeout',function(self) local uuid = tostring(self.data.poll_uuid) @@ -58,9 +58,9 @@ local function _poll_data(question,answers) game.print({'ExpGamingPlayer-polls.winner',highest[1]},defines.textcolor.info) verbose('Ended Poll: '..poll.question..' ('..uuid..') Highest: '..highest[1]) end):open() - global.active[tostring(poll.uuid)]=poll - verbose('Created Poll: '..question..' ('..poll.uuid..')') - return poll.uuid + global.active[tostring(rtn_poll.uuid)]=rtn_poll + verbose('Created Poll: '..question..' ('..rtn_poll.uuid..')') + return rtn_poll.uuid end local function draw_poll(frame) @@ -86,18 +86,18 @@ local function draw_poll(frame) end end -local function _opptions(player,root_frame) - local opptions = {'Please Select An Opption'} +local function _options(player,root_frame) + local options = {'Please Select An option'} local uuid = root_frame.name local poll = global.active[uuid] if not poll then return {'Invalid Poll'} end for _,answer in pairs(poll.answers) do - table.insert(opptions,answer) + table.insert(options,answer) end - return opptions + return options end -local opption_drop_down = Gui.inputs.add_drop_down('opption-drop-down-polls',_opptions,1,function(player,selected,items,element) +local option_drop_down = Gui.inputs.add_drop_down('option-drop-down-polls',_options,1,function(player,selected,items,element) local uuid = element.parent.name local poll = global.active[uuid] if not poll then return end @@ -146,17 +146,17 @@ local poll_question_input = Gui.inputs.add_text('poll-question-input',true,'Ques else options.question.caption = text end end) -local _self_referace_poll_option_input = nil +local _self_reference_poll_option_input = nil local poll_option_input = Gui.inputs.add_text('poll-option-input',true,'Enter Option',function(player,text,element) local options = element.parent.parent.parent.options if not options[element.parent.name] then options.add{type='label',name=element.parent.name,caption=text} else options[element.parent.name].caption = text end if options.last.caption == element.parent.name then options.last.caption = tonumber(options.last.caption)+1 - _self_referace_poll_option_input(element.parent.parent.add{type='flow',name=options.last.caption}).style.minimal_width = 200 + _self_reference_poll_option_input(element.parent.parent.add{type='flow',name=options.last.caption}).style.minimal_width = 200 end end) -_self_referace_poll_option_input = poll_option_input +_self_reference_poll_option_input = poll_option_input local function poll_assembler(frame) frame.clear() @@ -220,7 +220,7 @@ ThisModule.Gui = Gui.popup{ flow.add{type='label',caption={'ExpGamingPlayer-polls.time-left',poll_time_out}} flow.add{type='label',caption='Question: '..poll.question} flow.add{type='label',name='answer',caption='Your Answer: None'} - opption_drop_down(flow) + option_drop_down(flow) end }:add_left{ caption='utility/item_editor_icon', @@ -245,11 +245,11 @@ ThisModule.Gui = Gui.popup{ caption='Viewing Poll: 1', style='caption_label' } - local btn = next:draw(title) + btn = next:draw(title) btn.style.width = 20 btn.style.height = 20 if Role and Role.allowed(frame.player_index,'create-poll') or game.players[frame.player_index].admin then - local btn = create_poll:draw(title) + btn = create_poll:draw(title) btn.style.width = 20 btn.style.height = 20 end @@ -269,5 +269,5 @@ ThisModule.Gui = Gui.popup{ -- Event Handlers Define -- Module Return --- when called it will toogle the left gui for this player +-- when called it will toggle the left gui for this player return setmetatable(ThisModule,{__call=function(self,...) self.Gui(...) end}) \ No newline at end of file diff --git a/modules/GameSettingsGui/control.lua b/modules/GameSettingsGui/control.lua index 8499fcf0..2a447482 100644 --- a/modules/GameSettingsGui/control.lua +++ b/modules/GameSettingsGui/control.lua @@ -7,7 +7,7 @@ local Server = require('ExpGamingCore.Server') local Gui = require('ExpGamingCore.Gui') --- Local Varibles +-- Local Variables --{type='slider',object='',key='',name='',min=x,max=y} --{type='function',object='',key='',name='',param={}} local basic_settings = { @@ -122,8 +122,7 @@ local are_you_sure = Gui.inputs.add_checkbox('game-settings-are-you-sure',true,n end) local function _draw_setting(frame,setting) - local frame = frame.add{type='flow'} - local frame = frame.add{ + frame = frame.add{type='flow'}.add{ type='flow', name=setting._group } diff --git a/modules/GuiAnnouncements/control.lua b/modules/GuiAnnouncements/control.lua index 144eed14..d1a434d2 100644 --- a/modules/GuiAnnouncements/control.lua +++ b/modules/GuiAnnouncements/control.lua @@ -1,10 +1,10 @@ ---- Creates a gui for making and reciving announcements +--- Creates a gui for making and receiving announcements -- @module GuiAnnouncements@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule --- maybe make this not require Role and have it optinal +-- maybe make this not require Role and have it optional -- Module Require local Game = require('FactorioStdLib.Game') @@ -27,15 +27,15 @@ local function _roles(player) return roles end -local role_drop_down = Gui.inputs.add_drop_down('rank-drop-down-annoncements',_roles,1,function(player,selected,items,element) +local role_drop_down = Gui.inputs.add_drop_down('rank-drop-down-announcements',_roles,1,function(player,selected,items,element) element.parent.role.caption = selected - if selected == 'Select Role' then element.parent['send-annoncement'].style.visible = false - else element.parent['send-annoncement'].style.visible = true end + if selected == 'Select Role' then element.parent['send-announcement'].style.visible = false + else element.parent['send-announcement'].style.visible = true end end) local send_popup = Gui.inputs{ type='button', - name='send-annoncement', + name='send-announcement', caption='utility/export_slot' }:on_event('click',function(event) local player = Game.get_player(event) @@ -74,7 +74,7 @@ ThisModule.Gui = Gui.popup{ tooltip={'GuiAnnouncements.tooltip'}, draw=function(self,frame) frame.caption = {'GuiAnnouncements.name'} - local frame = frame.add{ + frame = frame.add{ type='flow', direction='vertical' } diff --git a/modules/PlayerAutoColor/control.lua b/modules/PlayerAutoColor/control.lua index 5cbcfade..b4776c9e 100644 --- a/modules/PlayerAutoColor/control.lua +++ b/modules/PlayerAutoColor/control.lua @@ -2,7 +2,7 @@ -- @module PlayerAutoColor@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Color = require('FactorioStdLib.Color') @@ -28,7 +28,7 @@ local global = global{ } -- Event Handlers Define -Event.register(defines.events.on_player_created, function(event) +script.on_event(defines.events.on_player_created, function(event) local player = game.players[event.player_index] local colours = table.keys(defines.color) player.color = defines.color.black @@ -44,4 +44,4 @@ Event.register(defines.events.on_player_created, function(event) end) -- Module Return -return ThisModule \ No newline at end of file +return ThisModule \ No newline at end of file diff --git a/modules/SpawnArea/control.lua b/modules/SpawnArea/control.lua index 9c731ec7..d32258fd 100644 --- a/modules/SpawnArea/control.lua +++ b/modules/SpawnArea/control.lua @@ -2,12 +2,12 @@ -- @module SpawnArea@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Game = require('FactorioStdLib.Game') --- Local Varibles +-- Local Variables local turret_enabled = true local turret_ammo = 'uranium-rounds-magazine' @@ -17,8 +17,8 @@ local entity_positions = require(module_path..'/src/spawn_entities') local global_offset = {x=0,y=-2} local decon_radius = 20 local decon_tile = 'concrete' -local partern_radius = 50 -local partern_tile = 'stone-path' +local pattern_radius = 50 +local pattern_tile = 'stone-path' -- Module Define local module_verbose = false @@ -45,10 +45,10 @@ end function ThisModule.auto_turret(surface,pos) if not turret_enabled then error('Auto Turrets are disabled.') end - -- adds a new turrent to the global list, returns index + -- adds a new turret to the global list, returns index local _return if surface then - local surface = Game.get_surface(surface) + surface = Game.get_surface(surface) if not surface then error('Surface is not valid.') end local posx = pos.x or pos[1] or error('Position is not valid.') local posy = pos.y or pos[2] or error('Position is not valid.') @@ -57,7 +57,7 @@ function ThisModule.auto_turret(surface,pos) -- spawns turrets and refills them if not game.forces['spawn'] then game.create_force('spawn').set_cease_fire('player',true) game.forces['player'].set_cease_fire('spawn',true) end for _,pos in pairs(global) do - local surface = game.surfaces[pos[1]] + surface = game.surfaces[pos[1]] local turret = surface.find_entity('gun-turret',{pos[2],pos[3]}) if not turret then turret = surface.create_entity{name='gun-turret',position={pos[2],pos[3]},force='spawn'} @@ -83,34 +83,34 @@ script.on_event(defines.events.on_player_created, function(event) local player = Game.get_player(event) local surface = player.surface local offset = {x=0,y=0} - local partern_base_tile = surface.get_tile(player.position).name - if partern_base_tile == 'deepwater' or partern_base_tile == 'water' then partern_base_tile = 'grass-1' end + local pattern_base_tile = surface.get_tile(player.position).name + if pattern_base_tile == 'deepwater' or pattern_base_tile == 'water' then pattern_base_tile = 'grass-1' end local base_tiles = {} local tiles = {} - -- generates a safe area of land and removes all entites - for x = -partern_radius, partern_radius do - for y = -partern_radius, partern_radius do + -- generates a safe area of land and removes all entities + for x = -pattern_radius, pattern_radius do + for y = -pattern_radius, pattern_radius do if x^2+y^2 < decon_radius^2 then table.insert(base_tiles,{name=decon_tile,position={x+offset.x,y+offset.y}}) local entities = surface.find_entities_filtered{area={{x+offset.x-1,y+offset.y-1},{x+offset.x,y+offset.y}}} for _,entity in pairs(entities) do if entity.name ~= 'player' then entity.destroy() end end - elseif x^2+y^2 < partern_radius^2 then - table.insert(base_tiles,{name=partern_base_tile,position={x+offset.x,y+offset.y}}) + elseif x^2+y^2 < pattern_radius^2 then + table.insert(base_tiles,{name=pattern_base_tile,position={x+offset.x,y+offset.y}}) end end end surface.set_tiles(base_tiles) - -- creates the partern in the spawn + -- creates the pattern in the spawn for _,position in pairs(tile_positions) do - table.insert(tiles,{name=partern_tile,position={position[1]+offset.x+global_offset.x,position[2]+offset.y+global_offset.y}}) + table.insert(tiles,{name=pattern_tile,position={position[1]+offset.x+global_offset.x,position[2]+offset.y+global_offset.y}}) end surface.set_tiles(tiles) - -- spawns all the entites in spawn + -- spawns all the entities in spawn for _,entity in pairs(entity_positions) do - local entity = surface.create_entity{name=entity[1],position={entity[2]+offset.x+global_offset.x,entity[3]+offset.y+global_offset.y},force='neutral'} + entity = surface.create_entity{name=entity[1],position={entity[2]+offset.x+global_offset.x,entity[3]+offset.y+global_offset.y},force='neutral'} entity.destructible = false; entity.health = 0; entity.minable = false; entity.rotatable = false end - -- generates spawn turrents and afk belts + -- generates spawn turrets and afk belts if turret_enabled then ThisModule.auto_turret() end ThisModule.afk_belt(surface,{offset.x-5,offset.y-5}) ThisModule.afk_belt(surface,{offset.x+5,offset.y-5}) @@ -123,4 +123,4 @@ script.on_event(defines.events.on_player_created, function(event) end) -- Module Return -return ThisModule \ No newline at end of file +return ThisModule \ No newline at end of file diff --git a/modules/WarpPoints/control.lua b/modules/WarpPoints/control.lua index 42b449bc..42874bd4 100644 --- a/modules/WarpPoints/control.lua +++ b/modules/WarpPoints/control.lua @@ -2,14 +2,14 @@ -- @module WarpPoints@4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Gui = require('ExpGamingCore.Gui') local Game = require('FactorioStdLib.Game') local Role -- ExpGamingCore.Role@^4.0.0 --- Local Varibles +-- Local Variables local warp_tiles = require(module_path..'/src/warp_tiles') local warp_entities = require(module_path..'/src/warp_entities') @@ -49,7 +49,6 @@ function ThisModule.remove_warp_point(name) local surface = game.surfaces[warp.surface] local offset = warp.position local tiles = {} - local tiles = {} -- clears the area where the warp was for x = -warp_radius, warp_radius do for y = -warp_radius, warp_radius do @@ -72,9 +71,9 @@ end -- @tparam surface surface the surface that the warp point is on -- @tparam force force the force that the warp point will belong to -- @tparam string name the name of the warp point to be made -function ThisModule.make_warp_point(position,surface,force,name) - local warp = global.warps[name] - if warp then return end; warp = nil +function ThisModule.make_warp_point(position,surface,force,warpName) + local warp = global.warps[warpName] + if warp then return end local offset = {x=math.floor(position.x),y=math.floor(position.y)} local old_tile = surface.get_tile(offset).name local base_tiles = {} @@ -88,22 +87,22 @@ function ThisModule.make_warp_point(position,surface,force,name) end end surface.set_tiles(base_tiles) - -- this adds the patern and entities - for _,position in pairs(warp_tiles) do - table.insert(tiles,{name=warp_tile,position={position[1]+offset.x+global_offset.x,position[2]+offset.y+global_offset.y}}) + -- this adds the pattern and entities + for _,pos in pairs(warp_tiles) do + table.insert(tiles,{name=warp_tile,position={pos[1]+offset.x+global_offset.x,pos[2]+offset.y+global_offset.y}}) end surface.set_tiles(tiles) for _,entity in pairs(warp_entities) do - local entity = surface.create_entity{name=entity[1],position={entity[2]+offset.x+global_offset.x,entity[3]+offset.y+global_offset.y},force='neutral'} + entity = surface.create_entity{name=entity[1],position={entity[2]+offset.x+global_offset.x,entity[3]+offset.y+global_offset.y},force='neutral'} entity.destructible = false; entity.health = 0; entity.minable = false; entity.rotatable = false end -- creates a tag on the map for the wap point local tag = force.add_chart_tag(surface,{ position={offset.x+0.5,offset.y+0.5}, - text='Warp: '..name, + text='Warp: '..warpName, icon={type='item',name=warp_item} }) - global.warps[name] = {tag=tag,surface=surface.index,position=tag.position,old_tile=old_tile} + global.warps[warpName] = {tag=tag,surface=surface.index,position=tag.position,old_tile=old_tile} local _temp = {Spawn=global.warps.Spawn} global.warps.Spawn = nil for name,data in pairs(table.keysort(global.warps)) do _temp[name] = data end @@ -190,7 +189,7 @@ ThisModule.Gui = Gui.left{ if cooldown > 0 then frame.style.visible = false return elseif not Role and player.admin or Role and Role.allowed(player,'always-warp') then return elseif player.surface.get_tile(player.position).name == warp_tile - and player.surface.name == 'nauvis' + and player.surface.name == 'nauvis' then return elseif player.position.x^2+player.position.y^2 < (warp_radius*spawn_warp_scale)^2 then return else frame.style.visible = false end @@ -199,7 +198,7 @@ ThisModule.Gui = Gui.left{ local cooldown = global.cooldowns[player.index] or 0 if not Role and player.admin or Role and Role.allowed(player,'always-warp') then return true elseif player.surface.get_tile(player.position).name == warp_tile - and player.surface.name == 'nauvis' + and player.surface.name == 'nauvis' then return true elseif player.position.x^2+player.position.y^2 < (warp_radius*spawn_warp_scale)^2 then return true elseif cooldown > 0 then return {'WarpPoints.cooldown',cooldown} @@ -213,7 +212,7 @@ script.on_event(defines.events.on_tick,function(event) if not (event.tick % 60 == 0) then return end for index,time in pairs(global.cooldowns) do if time > 0 then - global.cooldowns[index] = time-1 + global.cooldowns[index] = time-1 if global.cooldowns[index] == 0 then player_return({'WarpPoints.cooldown-zero'},defines.textcolor.low,index) end end end @@ -224,9 +223,9 @@ script.on_event(defines.events.on_player_changed_position, function(event) local cooldown = global.cooldowns[player.index] or 0 local tile = player.surface.get_tile(player.position).name if not Role and player.admin or Role and not Role.allowed(player,'always-warp') and cooldown == 0 then - if tile == warp_tile and player.surface.name == 'nauvis' then + if tile == warp_tile and player.surface.name == 'nauvis' then ThisModule.Gui:open(player) - elseif player.position.x^2+player.position.y^2 < (warp_radius*spawn_warp_scale)^2 then + elseif player.position.x^2+player.position.y^2 < (warp_radius*spawn_warp_scale)^2 then ThisModule.Gui:open(player) else ThisModule.Gui:close(player) end end @@ -246,4 +245,4 @@ script.on_event(defines.events.on_player_created, function(event) end) -- Module Return -return ThisModule \ No newline at end of file +return ThisModule \ No newline at end of file diff --git a/modules/WornPaths/control.lua b/modules/WornPaths/control.lua index 6596cf45..1ccf1830 100644 --- a/modules/WornPaths/control.lua +++ b/modules/WornPaths/control.lua @@ -1,19 +1,19 @@ ---- Makes paths which wear down and paths where entites are placed. +--- Makes paths which wear down and paths where entities are placed. -- @module WornPaths@^4.0.0 -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE --- @alais ThisModule +-- @alias ThisModule -- Module Require local Game = require('FactorioStdLib.Game') --- Local Varibles -local entites = require(module_path..'/src/entites') +-- Local Variables +local entities = require(module_path..'/src/entites') local paths = require(module_path..'/src/paths') -for tile,value in pairs(paths) do value[1]=-1/value[1] end +for _,value in pairs(paths) do value[1]=-1/value[1] end local placed_paths = require(module_path..'/src/placed') -local adjacency_boost = 2 -- makes paths more lickly to be next to each other; must be greater than 0 +local adjacency_boost = 2 -- makes paths more likely to be next to each other; must be greater than 0 adjacency_boost = 10/adjacency_boost -- dont change this line -- Module Define @@ -28,7 +28,7 @@ local function global_key(surface,pos) return 'S'..surface.name..'X'..math.floor(pos.x)..'Y'..math.floor(pos.y) end ---- Downgrads a tile in this position +--- Downgrades a tile in this position -- @usage ThisModule.down_grade(surface,{x=10,y=10}) -- @tparam surface surface the surface the tile is on -- @tparam table pos the position of the tile to change @@ -36,7 +36,7 @@ function ThisModule.down_grade(surface,pos) local tile = surface.get_tile(pos).name local new_tile = paths[tile][2] if new_tile == 'world-gen' then - new_tile = global[global_key(surface,pos)] or 'grass-1' + new_tile = global[global_key(surface,pos)] or 'grass-1' end surface.set_tiles{{name=new_tile,position=pos}} end @@ -46,15 +46,15 @@ script.on_event({defines.events.on_player_built_tile,defines.events.on_robot_bui local surface = event.surface_index and game.surfaces[event.surface_index] or event.robot and event.robot.surface local old_tiles = event.tiles for _,old_tile in pairs(old_tiles) do - if placed_paths[old_tile.old_tile.name] or old_tile.old_tile.name == 'water' or old_tile.old_tile.name == 'deepwater' then else - global[global_key(surface,old_tile.position)]=old_tile.old_tile.name -- not a mistake, this makes it have dimising returns + if not placed_paths[old_tile.old_tile.name] and old_tile.old_tile.name ~= 'water' and old_tile.old_tile.name ~= 'deepwater' then + global[global_key(surface,old_tile.position)]=old_tile.old_tile.name -- not a mistake, this makes it have demising returns end end end) script.on_event(defines.events.on_player_changed_position, function(event) local player = Game.get_player(event) - if player and player.valid and game.tick > 10 then else return end + if not player or not player.valid or game.tick < 10 then return end if player.afk_time > 300 then return end local surface = player.surface local pos = player.position @@ -76,7 +76,7 @@ end) script.on_event({defines.events.on_built_entity,on_robot_built_entity}, function(event) local entity = event.created_entity local surface = entity.surface - if entites[entity.name] then + if entities[entity.name] then local box = entity.prototype.collision_box for x = box.left_top.x,box.right_bottom.x do for y = box.left_top.y,box.right_bottom.y do local pos = {x=entity.position.x+x,y=entity.position.y+y} @@ -87,17 +87,17 @@ script.on_event({defines.events.on_built_entity,on_robot_built_entity}, function end) -- Module Return -- when called it will downgrade a tile -return setmetatable(ThisModule,{__call=function(self,...) self.down_grade(...) end}) +return setmetatable(ThisModule,{__call=function(self,...) self.down_grade(...) end}) --[[ -/interface -local tile_name = surface.get_tile(position).name +/interface +local tile_name = surface.get_tile(position).name if not paths[tile_name] then return end local count = -9 -- this value is important for x = -1,1 do for y = -1,1 do local _pos = {position.x+x,position.y+y} - if placed_paths[tile_name] and not placed_paths[surface.get_tile(_pos).name] - or surface.get_tile(_pos).name == paths[tile_name][2] + if placed_paths[tile_name] and not placed_paths[surface.get_tile(_pos).name] + or surface.get_tile(_pos).name == paths[tile_name][2] then count=count+1 end end end return paths[tile_name][1]/(count-adjacency_boost)