Added way to load modules to /interface

This commit is contained in:
Cooldude2606
2018-09-07 17:54:01 +01:00
parent e14c3a68b9
commit cd5abfc225
5 changed files with 20 additions and 4 deletions

View File

@@ -15,6 +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
end,
actions={},
action_names={}

View File

@@ -40,4 +40,6 @@ script.on_event(-1,function(event)
end
end
end):open()
end)
end)
Server.add_module_to_interface('ExpGui')

View File

@@ -10,6 +10,7 @@
local Game = require('FactorioStdLib.Game')
local Color = require('FactorioStdLib.Color')
local Server = require('ExpGamingCore.Server')
local Ranking = Ranking
--- Print a message to all players of this rank
-- @usage rank:print('foo') -- prints to all members of this rank
@@ -44,4 +45,7 @@ script.on_event('on_tick',function(event)
Ranking.find_preset(player,tick)
end):open()
end
end)
end)
Server.add_to_interface('rank',function() return Ranking.get_rank(game.player) end)
Server.add_module_to_interface('Ranking')

View File

@@ -10,6 +10,14 @@
local Game = require('FactorioStdLib.Game')
local Server = Server
Server.interface = {}
function Server.add_to_interface(loadAs,callback) Server.interface[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')
Server.add_to_interface(loadAs,function() return require(moduleName) end)
end
--- Runs the given input from the script
-- @command interface
-- @param code The code that will be ran
@@ -28,9 +36,9 @@ commands.add_command('interface',{'Server.interface-description'}, {
env.position = game.player.position
env.entity = game.player.selected
env.tile = game.player.surface.get_tile(game.player.position)
-- this works if loaded modules is not present as Mamager will always have the modules
if Manager['ExpGamingCore.Ranking'] then env.rank = Manager['ExpGamingCore.Ranking'].get_rank(game.player) end
end
-- adds custom callbacks to the interface
for name,callback in pairs(Server.interface) do env[name] = 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

View File

@@ -311,6 +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
end
function Sync:on_post()