From 24598e594a28a9098592e9af2c03ac4e25065e54 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Wed, 30 May 2018 13:50:38 +0100 Subject: [PATCH] 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