From d554255d0b4c2836c3b57550d71ad5b0a3933c3e Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Wed, 12 Sep 2018 23:26:17 +0100 Subject: [PATCH] Few minor bug fixes --- FactorioSoftmodManager.lua | 7 +++-- modules/ExpGamingAdmin/AdminLib/control.lua | 4 +-- modules/ExpGamingCommands/admin/control.lua | 2 +- modules/ExpGamingCore/Commands/control.lua | 7 ++--- modules/ExpGamingCore/Gui/control.lua | 19 ++++++++---- modules/ExpGamingCore/Gui/src/server.lua | 30 +++++++++++-------- modules/ExpGamingCore/Ranking/src/server.lua | 2 +- modules/ExpGamingCore/Server/src/commands.lua | 4 ++- modules/ExpGamingCore/Sync/control.lua | 2 +- .../ExpGamingPlayer/playerList/control.lua | 4 +-- .../ExpGamingPlayer/playerList/softmod.json | 1 + 11 files changed, 48 insertions(+), 34 deletions(-) diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index 19e2b693..94017ed8 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -257,8 +257,8 @@ Manager.require = setmetatable({ __require=require },{ __metatable=false, - __index=function(tbl,key) return tbl(key) end, - __call=function(tbl,path,env) + __index=function(tbl,key) return tbl(key,nil,true) end, + __call=function(tbl,path,env,mute) local raw_require = rawget(tbl,'__require') local env = env or {} -- runs in a sand box becuase sandbox everything @@ -266,6 +266,7 @@ Manager.require = setmetatable({ -- if there was no error then it assumed the path existed and returns the data if success then return unpack(data) else + if type(path) ~= 'string' then error('Path supplied must be a string; got: '..type(path),2) return end -- else it assums the path was a module name and checks index for the module if moduleIndex[path] then return rawget(Manager.loadModules,path) end if moduleIndex[path:gsub('?','')] then return rawget(Manager.loadModules,path) end @@ -283,7 +284,7 @@ Manager.require = setmetatable({ end -- if there is any keys in the collection the collection is returned else the errors with the require error for _ in pairs(collection) do return collection end - error(data,2) + if mute then return false else error(data,2) end end end }) diff --git a/modules/ExpGamingAdmin/AdminLib/control.lua b/modules/ExpGamingAdmin/AdminLib/control.lua index e1e7f848..f55a220f 100644 --- a/modules/ExpGamingAdmin/AdminLib/control.lua +++ b/modules/ExpGamingAdmin/AdminLib/control.lua @@ -5,7 +5,7 @@ -- @alais Admin -- Module Require -local Game = require('FactorioStdLib@^0.8.0') +local Game = require('FactorioStdLib.Game@^0.8.0') local Ranking -- ExpGamingCore.Ranking@^4.0.0 local Sync -- ExpGamingCore.Sync@^4.0.0 @@ -15,7 +15,7 @@ local Admin = { on_init=function() if loaded_modules['ExpGamingCore.Ranking@^4.0.0'] then Ranking = require('ExpGamingCore.Ranking@^4.0.0') end if loaded_modules['ExpGamingCore.Sync@^4.0.0'] then Sync = require('ExpGamingCore.Sync@^4.0.0') end - if loaded_modules['ExoGamingCore.Server'] then Server.add_module_to_interface('Admin','ExpGamingAdmin') end + if loaded_modules['ExpGamingCore.Server@^4.0.0'] then require('ExpGamingCore.Server@^4.0.0').add_module_to_interface('Admin','ExpGamingAdmin.AdminLib') end end, actions={}, action_names={} diff --git a/modules/ExpGamingCommands/admin/control.lua b/modules/ExpGamingCommands/admin/control.lua index 25c2d4a9..d243f44c 100644 --- a/modules/ExpGamingCommands/admin/control.lua +++ b/modules/ExpGamingCommands/admin/control.lua @@ -5,7 +5,7 @@ -- this file should be replaced with a collection but idk if fsm can hanndle collections in a collection -local Admin = require('ExpGamingAdmin') +local Admin = require('ExpGamingAdmin.AdminLib') --- Used to clear all parts of a player, removing warnings, reports, jail and temp ban -- @command clear-all diff --git a/modules/ExpGamingCore/Commands/control.lua b/modules/ExpGamingCore/Commands/control.lua index 4ffc5da2..3f02439b 100644 --- a/modules/ExpGamingCore/Commands/control.lua +++ b/modules/ExpGamingCore/Commands/control.lua @@ -151,7 +151,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 no ExpGamingCore.Ranking then this is ingroned if Ranking and Ranking.meta and Ranking.meta.rank_count > 0 and not Ranking.get_rank(player_name):allowed(command.name) - or not Ranking and data.setAdminOnly == true and game.player and not game.player.admin then + or not Ranking and data.admin_only == true and game.player and not game.player.admin then 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', @@ -214,10 +214,7 @@ commands.add_command = function(name, description, inputs, callback) description=description, inputs=inputs, callback=callback, - setAdminOnly=function(tbl,value) - if is_type(tbl,'table') then if is_type(value,'boolean') then tbl.setAdminOnly = value else tbl.setAdminOnly = true end - else if is_type(tbl,'boolean') then data[name].setAdminOnly = value else data[name].setAdminOnly = true end - end + admin_only=false } 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)..'- '} diff --git a/modules/ExpGamingCore/Gui/control.lua b/modules/ExpGamingCore/Gui/control.lua index c531e4a8..fb889806 100644 --- a/modules/ExpGamingCore/Gui/control.lua +++ b/modules/ExpGamingCore/Gui/control.lua @@ -132,18 +132,25 @@ script.on_event('on_tick', function(event) if Gui.left and ((event.tick+10)/(3600*game.speed)) % 15 == 0 then Gui.left.update() end + if loaded_modules['ExpGamingCore.Server'] then return end if global.cams and is_type(global.cams,'table') and #global.cams > 0 then - local _cam = global.cams[global.cam_index] - if not _cam then global.cam_index = 1 _cam = global.cams[global.cam_index] end - if not _cam then return 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) - else _cam.cam.position = _cam.entity.position if not _cam.surface then _cam.cam.surface_index = _cam.entity.surface.index end global.cam_index = global.cam_index+1 + local update = 4 + if global.cam_index >= #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] + if not _cam then return 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) + else _cam.cam.position = _cam.entity.position if not _cam.surface then _cam.cam.surface_index = _cam.entity.surface.index end global.cam_index = global.cam_index+1 + end end + global.cam_index = global.cam_index+update end end) 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 = {} for index,cam in pairs(global.players[event.player_index]) do diff --git a/modules/ExpGamingCore/Gui/src/server.lua b/modules/ExpGamingCore/Gui/src/server.lua index 30977e8f..b41f65f5 100644 --- a/modules/ExpGamingCore/Gui/src/server.lua +++ b/modules/ExpGamingCore/Gui/src/server.lua @@ -17,29 +17,35 @@ script.on_event(-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 + }:on_event('tick',function(self) + local update = 4 + if self.data.cam_index >= #self.data.cams then self.data.cam_index = 1 end + if update > #self.data.cams then update = #self.data.cams end + for cam_offset = 0,update do + local _cam = self.data.cams[self.data.cam_index+cam_offset] + if not _cam then break 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 + end end + self.data.cam_index = self.data.cam_index+update 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 = {} + local player = Game.get_player(event) 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 + if cam.valid then table.insert(self.data.cams,{cam=cam,entity=player.character,surface=player.surface}) + else table.insert(remove,index) end end - for _,index in pairs(remove) do - table.remove(self.data.players[event.player_index],index) + for n,index in pairs(remove) do + table.remove(self.data.players[event.player_index],index-n+1) end end end):open() end) -Server.add_module_to_interface('ExpGui') \ No newline at end of file +Server.add_module_to_interface('ExpGui','ExpGamingCore.Gui') \ No newline at end of file diff --git a/modules/ExpGamingCore/Ranking/src/server.lua b/modules/ExpGamingCore/Ranking/src/server.lua index c8c3261b..ca50bf62 100644 --- a/modules/ExpGamingCore/Ranking/src/server.lua +++ b/modules/ExpGamingCore/Ranking/src/server.lua @@ -48,4 +48,4 @@ script.on_event('on_tick',function(event) end) Server.add_to_interface('rank',function() return Ranking.get_rank(game.player) end) -Server.add_module_to_interface('Ranking') \ No newline at end of file +Server.add_module_to_interface('Ranking','ExpGamingCore.Ranking') \ No newline at end of file diff --git a/modules/ExpGamingCore/Server/src/commands.lua b/modules/ExpGamingCore/Server/src/commands.lua index 75af3a8f..b626c1aa 100644 --- a/modules/ExpGamingCore/Server/src/commands.lua +++ b/modules/ExpGamingCore/Server/src/commands.lua @@ -14,9 +14,11 @@ Server.interfaceCallbacks = {} function Server.add_to_interface(loadAs,callback) Server.interfaceCallbacks[loadAs] = callback end function Server.add_module_to_interface(loadAs,moduleName,version) - local moduleName = module_name or version and moduleName..'@'..version or moduleName or error('No module name supplied') + local moduleName = _G.moduleName or version and moduleName..'@'..version or moduleName or nil + if not moduleName then error('No module name supplied for: '..loadAs,2) return end Server.add_to_interface(loadAs,function() return require(moduleName) end) end +Server.add_module_to_interface('Server','ExpGamingCore.Server') --- Runs the given input from the script -- @command interface diff --git a/modules/ExpGamingCore/Sync/control.lua b/modules/ExpGamingCore/Sync/control.lua index 8a1b522e..f60bddd2 100644 --- a/modules/ExpGamingCore/Sync/control.lua +++ b/modules/ExpGamingCore/Sync/control.lua @@ -311,7 +311,7 @@ script.on_event('on_rocket_launched',Sync.emit_update) function Sync:on_init() if loaded_modules['ExpGamingCore.Gui'] then verbose('ExpGamingCore.Gui is installed; Loading gui src') require(module_path..'/src/gui',{Sync=Sync}) end if loaded_modules['ExpGamingCore.Ranking'] then verbose('ExpGamingCore.Ranking is installed; Loading ranking src') require(module_path..'/src/ranking',{Sync=Sync}) end - if loaded_modules['ExoGamingCore.Server'] then Server.add_module_to_interface('Sync') end + if loaded_modules['ExpGamingCore.Server'] then require('ExpGamingCore.Server').add_module_to_interface('Sync','ExpGamingCore.Sync') end end function Sync:on_post() diff --git a/modules/ExpGamingPlayer/playerList/control.lua b/modules/ExpGamingPlayer/playerList/control.lua index bf9bc889..841921a8 100644 --- a/modules/ExpGamingPlayer/playerList/control.lua +++ b/modules/ExpGamingPlayer/playerList/control.lua @@ -114,7 +114,7 @@ script.on_event(defines.events.on_gui_click,function(event) back_btn:draw(flow) playerInfo(event.element.name,flow,true) if Game.get_player(event.element.name) and event.player_index == Game.get_player(event.element.name).index then return end - if Admin and Admin.allowed(event.player_index) then Admin.btn_flow(flow).caption = event.element.name end + if Admin and Admin.allowed and Admin.allowed(event.player_index) then Admin.btn_flow(flow).caption = event.element.name end end) script.on_event(defines.events.on_player_joined_game,queue_update) @@ -126,6 +126,6 @@ return { update=queue_update, on_init=function(self) if loaded_modules['ExpGamingPlayer.playerInfo'] then playerInfo = require('ExpGamingPlayer.playerInfo') end - if loaded_modules['ExpGamingAdmin'] then Admin = require('ExpGamingAdmin') end + if loaded_modules['ExpGamingAdmin.AdminLib'] then Admin = require('ExpGamingAdmin.AdminLib') end end } \ No newline at end of file diff --git a/modules/ExpGamingPlayer/playerList/softmod.json b/modules/ExpGamingPlayer/playerList/softmod.json index e5ae20bf..72dab8ba 100644 --- a/modules/ExpGamingPlayer/playerList/softmod.json +++ b/modules/ExpGamingPlayer/playerList/softmod.json @@ -14,6 +14,7 @@ "FactorioStdLib.Game": "^0.8.0", "ExpGamingCore.Gui": "^4.0.0", "ExpGamingCore.Ranking": "?^4.0.0", + "ExpGamingAdmin.AdminLib": "?^4.0.0", "ExpGamingAdmin.buttonFlow": "?^4.0.0", "ExpGamingAdmin.reports": "?^4.0.0", "ExpGamingPlayer.playerInfo": "?^4.0.0"