Few minor bug fixes

This commit is contained in:
Cooldude2606
2018-09-12 23:26:17 +01:00
parent 1971e56c02
commit d554255d0b
11 changed files with 48 additions and 34 deletions

View File

@@ -257,8 +257,8 @@ Manager.require = setmetatable({
__require=require __require=require
},{ },{
__metatable=false, __metatable=false,
__index=function(tbl,key) return tbl(key) end, __index=function(tbl,key) return tbl(key,nil,true) end,
__call=function(tbl,path,env) __call=function(tbl,path,env,mute)
local raw_require = rawget(tbl,'__require') local raw_require = rawget(tbl,'__require')
local env = env or {} local env = env or {}
-- runs in a sand box becuase sandbox everything -- 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 there was no error then it assumed the path existed and returns the data
if success then return unpack(data) if success then return unpack(data)
else 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 -- 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] then return rawget(Manager.loadModules,path) end
if moduleIndex[path:gsub('?','')] 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 end
-- if there is any keys in the collection the collection is returned else the errors with the require error -- 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 for _ in pairs(collection) do return collection end
error(data,2) if mute then return false else error(data,2) end
end end
end end
}) })

View File

@@ -5,7 +5,7 @@
-- @alais Admin -- @alais Admin
-- Module Require -- 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 Ranking -- ExpGamingCore.Ranking@^4.0.0
local Sync -- ExpGamingCore.Sync@^4.0.0 local Sync -- ExpGamingCore.Sync@^4.0.0
@@ -15,7 +15,7 @@ local Admin = {
on_init=function() on_init=function()
if loaded_modules['ExpGamingCore.Ranking@^4.0.0'] then Ranking = require('ExpGamingCore.Ranking@^4.0.0') end 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['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, end,
actions={}, actions={},
action_names={} action_names={}

View File

@@ -5,7 +5,7 @@
-- this file should be replaced with a collection but idk if fsm can hanndle collections in a collection -- 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 --- Used to clear all parts of a player, removing warnings, reports, jail and temp ban
-- @command clear-all -- @command clear-all

View File

@@ -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' 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 -- 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) 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) player_return({'commands.unauthorized'},defines.textcolor.crit)
if game.player then game.player.play_sound{path='utility/cannot_build'} end if game.player then game.player.play_sound{path='utility/cannot_build'} end
game.write_file('commands.log', game.write_file('commands.log',
@@ -214,10 +214,7 @@ commands.add_command = function(name, description, inputs, callback)
description=description, description=description,
inputs=inputs, inputs=inputs,
callback=callback, callback=callback,
setAdminOnly=function(tbl,value) admin_only=false
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
} }
local help = is_type(description,'string') and commands.format_inputs(name)..'- '..description 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 is_type(description,'table') and is_type(description[1],'string') and string.find(description[1],'.+[.].+') and {description,commands.format_inputs(name)..'- '}

View File

@@ -132,18 +132,25 @@ script.on_event('on_tick', function(event)
if Gui.left and ((event.tick+10)/(3600*game.speed)) % 15 == 0 then if Gui.left and ((event.tick+10)/(3600*game.speed)) % 15 == 0 then
Gui.left.update() Gui.left.update()
end end
if loaded_modules['ExpGamingCore.Server'] then return end
if global.cams and is_type(global.cams,'table') and #global.cams > 0 then if global.cams and is_type(global.cams,'table') and #global.cams > 0 then
local _cam = global.cams[global.cam_index] local update = 4
if not _cam then global.cam_index = 1 _cam = global.cams[global.cam_index] end if global.cam_index >= #global.cams then global.cam_index = 1 end
if not _cam then return end if update > #global.cams then update = #global.cams end
if not _cam.cam.valid then table.remove(global.cams,global.cam_index) for cam_offset = 0,update do
elseif not _cam.entity.valid then table.remove(global.cams,global.cam_index) local _cam = 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 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 end
global.cam_index = global.cam_index+update
end end
end) end)
script.on_event('on_player_respawned',function(event) 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 if global.players and is_type(global.players,'table') and #global.players > 0 and global.players[event.player_index] then
local remove = {} local remove = {}
for index,cam in pairs(global.players[event.player_index]) do for index,cam in pairs(global.players[event.player_index]) do

View File

@@ -18,28 +18,34 @@ script.on_event(-1,function(event)
name='camera-follow', name='camera-follow',
data={cams={},cam_index=1,players={}} data={cams={},cam_index=1,players={}}
}:on_event('tick',function(self) }:on_event('tick',function(self)
local _cam = self.data.cams[self.data.cam_index] local update = 4
if not _cam then self.data.cam_index = 1 _cam = self.data.cams[self.data.cam_index] end if self.data.cam_index >= #self.data.cams then self.data.cam_index = 1 end
if not _cam then return end if update > #self.data.cams then update = #self.data.cams end
if not _cam.cam.valid then table.remove(self.data.cams,self.data.cam_index) for cam_offset = 0,update do
elseif not _cam.entity.valid then table.remove(self.data.cams,self.data.cam_index) local _cam = self.data.cams[self.data.cam_index+cam_offset]
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 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 end
self.data.cam_index = self.data.cam_index+update
end):on_event('error',function(self,err) end):on_event('error',function(self,err)
-- posible error handling if needed -- posible error handling if needed
error(err) error(err)
end):on_event(defines.events.on_player_respawned,function(self,event) end):on_event(defines.events.on_player_respawned,function(self,event)
if self.data.players[event.player_index] then if self.data.players[event.player_index] then
local remove = {} local remove = {}
local player = Game.get_player(event)
for index,cam in pairs(self.data.players[event.player_index]) do for index,cam in pairs(self.data.players[event.player_index]) do
Gui.cam_link{cam=cam,entity=Game.get_player(event).character} if cam.valid then table.insert(self.data.cams,{cam=cam,entity=player.character,surface=player.surface})
if not cam.valid then table.insert(remove,index) end else table.insert(remove,index) end
end end
for _,index in pairs(remove) do for n,index in pairs(remove) do
table.remove(self.data.players[event.player_index],index) table.remove(self.data.players[event.player_index],index-n+1)
end end
end end
end):open() end):open()
end) end)
Server.add_module_to_interface('ExpGui') Server.add_module_to_interface('ExpGui','ExpGamingCore.Gui')

View File

@@ -48,4 +48,4 @@ script.on_event('on_tick',function(event)
end) end)
Server.add_to_interface('rank',function() return Ranking.get_rank(game.player) end) Server.add_to_interface('rank',function() return Ranking.get_rank(game.player) end)
Server.add_module_to_interface('Ranking') Server.add_module_to_interface('Ranking','ExpGamingCore.Ranking')

View File

@@ -14,9 +14,11 @@ Server.interfaceCallbacks = {}
function Server.add_to_interface(loadAs,callback) Server.interfaceCallbacks[loadAs] = callback end function Server.add_to_interface(loadAs,callback) Server.interfaceCallbacks[loadAs] = callback end
function Server.add_module_to_interface(loadAs,moduleName,version) 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) Server.add_to_interface(loadAs,function() return require(moduleName) end)
end end
Server.add_module_to_interface('Server','ExpGamingCore.Server')
--- Runs the given input from the script --- Runs the given input from the script
-- @command interface -- @command interface

View File

@@ -311,7 +311,7 @@ script.on_event('on_rocket_launched',Sync.emit_update)
function Sync:on_init() 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.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['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 end
function Sync:on_post() function Sync:on_post()

View File

@@ -114,7 +114,7 @@ script.on_event(defines.events.on_gui_click,function(event)
back_btn:draw(flow) back_btn:draw(flow)
playerInfo(event.element.name,flow,true) 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 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) end)
script.on_event(defines.events.on_player_joined_game,queue_update) script.on_event(defines.events.on_player_joined_game,queue_update)
@@ -126,6 +126,6 @@ return {
update=queue_update, update=queue_update,
on_init=function(self) on_init=function(self)
if loaded_modules['ExpGamingPlayer.playerInfo'] then playerInfo = require('ExpGamingPlayer.playerInfo') end 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 end
} }

View File

@@ -14,6 +14,7 @@
"FactorioStdLib.Game": "^0.8.0", "FactorioStdLib.Game": "^0.8.0",
"ExpGamingCore.Gui": "^4.0.0", "ExpGamingCore.Gui": "^4.0.0",
"ExpGamingCore.Ranking": "?^4.0.0", "ExpGamingCore.Ranking": "?^4.0.0",
"ExpGamingAdmin.AdminLib": "?^4.0.0",
"ExpGamingAdmin.buttonFlow": "?^4.0.0", "ExpGamingAdmin.buttonFlow": "?^4.0.0",
"ExpGamingAdmin.reports": "?^4.0.0", "ExpGamingAdmin.reports": "?^4.0.0",
"ExpGamingPlayer.playerInfo": "?^4.0.0" "ExpGamingPlayer.playerInfo": "?^4.0.0"