This commit is contained in:
Cooldude2606
2018-10-19 19:50:28 +01:00
parent b64dd778da
commit de993dc51a
15 changed files with 100 additions and 82 deletions

View File

@@ -235,7 +235,7 @@ Manager.sandbox = setmetatable({
loaded_modules={}, -- this is over riden later
module_verbose=false,
module_exports=false,
_no_error_in_sandbox=true
_no_error_verbose=true
},{
__metatable=false,
__index=ReadOnlyManager,
@@ -253,8 +253,8 @@ Manager.sandbox = setmetatable({
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,old_mt)
if success then return sandbox, success, rtn
else return sandbox, success, rtn[1] end
if success then return success, rtn, sandbox
else return success, rtn[1], sandbox end
else return setmetatable({},{__index=tbl}) end
end
})
@@ -274,7 +274,7 @@ Manager.require = setmetatable({
local raw_require = rawget(tbl,'__require')
local env = env or {}
-- runs in a sand box becuase sandbox everything
local sandbox, success, data = Manager.sandbox(raw_require,env,path)
local success, data = Manager.sandbox(raw_require,env,path)
-- if there was no error then it assumed the path existed and returns the data
if success then return unpack(data)
else
@@ -319,7 +319,7 @@ Manager.loadModules = setmetatable({},
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(Manager.require.__require,{module_name=setupModuleName(module_name),module_path=path},path..'/control')
local success, module, sandbox = Manager.sandbox(Manager.require.__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
@@ -375,7 +375,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[tostring(module_name)]},data)
local 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
@@ -393,7 +393,7 @@ Manager.loadModules = setmetatable({},
if type(data) == 'table' and data.post and data.on_post == nil then data.on_post = data.post data.post = nil end
if type(data) == 'table' and data.on_post and type(data.on_post) == 'function' then
Manager.verbose('Post for module: "'..module_name..'"')
local sandbox, success, err = Manager.sandbox(data.on_post,{module_name=setupModuleName(module_name),module_path=moduleIndex[tostring(module_name)]},data)
local success, err = Manager.sandbox(data.on_post,{module_name=setupModuleName(module_name),module_path=moduleIndex[tostring(module_name)]},data)
if success then
Manager.verbose('Successful post: "'..module_name..'"')
else
@@ -446,6 +446,14 @@ Manager.error = setmetatable({
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,
in_pcall=function(level)
local level = level and level+1 or 2
while true do
if not debug.getinfo(level) then return false end
if debug.getinfo(level).name == 'pcall' then return level end
level=level+1
end
end
},{
__metatalbe=false,
@@ -453,9 +461,9 @@ Manager.error = setmetatable({
-- 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
if err == rawget(tbl,'__error_const') then Manager.verbose('Force Crash','errorCaught') rawset(tbl,'__crash',true) rawget(tbl,'__error_call')('Force Crash',2) end
-- other wise treat the call as if its been passed an err string
if _G._no_error_in_sandbox and ReadOnlyManager.currentState == 'moduleEnv' then else Manager.verbose('An error has occurred: '..err,'errorCaught') end
if not _no_error_verbose or Manager.currentState ~= 'moduleEnv' then Manager.verbose('An error has occurred: '..err,'errorCaught') end
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
@@ -476,7 +484,7 @@ Manager.error = setmetatable({
end
local args = {...}
local trace = args[1] and type(args[1]) == 'number' and args[1]+1 or 2
rawget(tbl,'__error_call')(err,trace)
if tbl.in_pcall(2) then rawget(tbl,'__error_call')(err,trace) end
end,
__index=function(tbl,key)
-- this allows the __error_handler to be called from many different names
@@ -503,7 +511,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' or k == '__crash' then return next_pair(tbl,k) end
if k == '__error_call' or k == '__error_const' or k == '__error_handler' or k == '__crash' or k == 'in_pcall' then return next_pair(tbl,k) end
if type(v) == 'function' then return k,v end
end
return next_pair, tbl, nil
@@ -560,7 +568,7 @@ Manager.event = setmetatable({
for module_name,callback in pairs(event_functions) 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[tostring(module_name)]},new_callback,...)
local success, err = Manager.sandbox(callback,{module_name=setupModuleName(module_name),module_path=moduleIndex[tostring(module_name)]},new_callback,...)
if not success then
local chache = tbl.error_chache
local error_message = 'Event Failed: "'..module_name..'/'..tbl.names[event_name]..'" ('..err..')'

View File

@@ -6,7 +6,7 @@ Manager.setVerbose{
moduleLoad=false, -- when a module is required by the manager
moduleInit=false, -- when and within the initation of a module
modulePost=false, -- when and within the post of a module
moduleEnv=false, -- during module runtime, this is a global option set within each module for fine control
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
errorCaught=true, -- when an error is caught during runtime
output=Manager._verbose -- can be: can be: print || log || other function

View File

@@ -6,6 +6,7 @@
-- Module Require
local Game = require('FactorioStdLib.Game@^0.8.0')
local Server = require('ExpGamingCore.Server@^4.0.0')
local Role -- ExpGamingCore.Role@^4.0.0
-- Local Varibles
@@ -36,84 +37,84 @@ local messages = {
-- comands start with ! (all messages are also commands)
local command_syntax = '!'
local commands = {
['online']=function(player) return {'chat-bot.players-online',#game.connected_players} end,
['playtime']=function(player) return {'chat-bot.map-time',tick_to_display_format(game.tick)} end,
['players']=function(player) return {'chat-bot.players',#game.players} end,
['dev']={'chat-bot.not-real-dev'},
['blame']=function(player) local names = {'Cooldude2606','arty714','badgamernl',player.name} return {'chat-bot.blame',names[math.random(#names)]} end,
['readme']={'chat-bot.read-readme'},
['magic']={'chat-bot.magic'},
['aids']={'chat-bot.aids'},
['riot']={'chat-bot.riot'},
['lenny']={'chat-bot.lenny'},
['feedback']={'chat-bot.feedback'},
['wiki']={'chat-bot.wiki'},
['hodor']=function(player) local options = {'?','.','!','!!!'} return {'chat-bot.hodor',options[math.random(#options)]} end,
['evolution']=function(player) return {'chat-bot.current-evolution',string.format('%.2f',game.forces['enemy'].evolution_factor)} end,
['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,
['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'},
['magic']={'ExpGamingBot-autoChat.magic'},
['aids']={'ExpGamingBot-autoChat.aids'},
['riot']={'ExpGamingBot-autoChat.riot'},
['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,
--Jokes about food and drink
['whattoeat']={'chat-bot.food'},
['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{'chat-bot.message',{'chat-bot.get-popcorn-2',self.data}} end
end):open() return {'chat-bot.get-popcorn-1'} end,
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)
if self.data[2]==0 then game.print{'chat-bot.message',{'chat-bot.order-pizza-2',self.data[1]}}
elseif self.data[2]==1 then game.print{'chat-bot.message',{'chat-bot.order-pizza-3',self.data[1]}} self.reopen = false
if self.data[2]==0 then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.order-pizza-2',self.data[1]}}
elseif self.data[2]==1 then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.order-pizza-3',self.data[1]}} self.reopen = false
end
self.data[2]=self.data[2]+1
end):open() return {'chat-bot.order-pizza-1'} end,
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)
if self.data[2]==0 then game.print{'chat-bot.message',{'chat-bot.get-snaps-2',self.data[1]}}
elseif self.data[2]==1 then game.print{'chat-bot.message',{'chat-bot.get-snaps-3',self.data[1]}} self.reopen = false
if self.data[2]==0 then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-snaps-2',self.data[1]}}
elseif self.data[2]==1 then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-snaps-3',self.data[1]}} self.reopen = false
end
self.data[2]=self.data[2]+1
end):open() return {'chat-bot.get-snaps-1'} end,
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)
if self.data[2]==0 then game.print{'chat-bot.message',{'chat-bot.get-cocktail-2',self.data[1]}}
elseif self.data[2]==1 then game.print{'chat-bot.message',{'chat-bot.get-cocktail-3',self.data[1]}} self.reopen = false
if self.data[2]==0 then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-cocktail-2',self.data[1]}}
elseif self.data[2]==1 then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-cocktail-3',self.data[1]}} self.reopen = false
end
self.data[2]=self.data[2]+1
end):open() return {'chat-bot.get-cocktail-1'} end,
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{'chat-bot.message',{'chat-bot.make-coffee-2',self.data}} end
end):open() return {'chat-bot.make-coffee-1'} end,
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)
if self.data[2]==0 then game.print{'chat-bot.message',{'chat-bot.order-pizza-2',self.data[1]}}
elseif self.data[2]==1 then game.print{'chat-bot.message',{'chat-bot.order-pizza-3',self.data[1]}} self.reopen = false
if self.data[2]==0 then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.order-pizza-2',self.data[1]}}
elseif self.data[2]==1 then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.order-pizza-3',self.data[1]}} self.reopen = false
end
self.data[2]=self.data[2] + 1
end):open() return {'chat-bot.order-pizza-1'} end,
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{'chat-bot.message',{'chat-bot.make-tea-2',self.data}} end
end):open() return {'chat-bot.make-tea-1'} end,
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{'chat-bot.message',{'chat-bot.get-popcorn-2',self.data}} end
end):open() return {'chat-bot.get-popcorn-1'} end,
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{'chat-bot.message',{'chat-bot.get-mead-2',self.data}} end
end):open() return {'chat-bot.get-mead-1'} end,
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)
if self.data then game.print{'chat-bot.message',{'chat-bot.get-beer-2',self.data}} end
end):open() return {'chat-bot.get-beer-1'} end
if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-beer-2',self.data}} end
end):open() return {'ExpGamingBot-autoChat.get-beer-1'} end
}
-- Module Define

View File

@@ -12,6 +12,7 @@
],
"dependencies": {
"FactorioStdLib.Game": "^0.8.0",
"ExpGamingCore.Server": "^4.0.0",
"ExpGamingCore.Role": "?^4.0.0"
},
"collection": "ExpGamingBot_4.0.0"

View File

@@ -33,7 +33,7 @@ script.on_event(defines.events.on_player_respawned,function(event)
local player = Game.get_player(event)
local bonus = global[player.index]
if bonus then
for _,setting in pairs(settings) do player[key] = setting*math.floor(bonus)*0.01 end
for key,setting in pairs(settings) do player[key] = setting*math.floor(bonus)*0.01 end
end
end)

View File

@@ -59,7 +59,7 @@ commands.validate = {
['string-inf']=function(value,event) return tostring(value) end,
['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'} end return rtn end,
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
if not rtn then return commands.error{'ExpGamingCore_Command.error-number'} end return rtn end,
@@ -68,10 +68,10 @@ commands.validate = {
if not rtn then return commands.error{'ExpGamingCore_Command.error-number'} end return rtn end,
['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'} end return rtn end,
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)
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'} end return rtn end,
if not rtn then return commands.error{'ExpGamingCore_Command.error-number-range',min,max} end return rtn end,
['player']=function(value,event)
local rtn = Game.get_player(value) or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-player',value} end return rtn end,
@@ -266,7 +266,7 @@ commands.add_command = function(name, description, inputs, callback)
or commands.format_inputs(name)
data[name].help = help
commands._add_command(name,help,function(...)
local success, err = pcall(run_custom_command,...)
local success, err = Manager.sandbox(run_custom_command,{},...)
if not success then error(err) end
end)
return data[name]

View File

@@ -2,7 +2,7 @@
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
error-string-len=Invalid Length, Max: __1__
error-number=Invalid Number: Command failed to run
error-number-range=Invalid Range, Min: __1__, Max: __2__
error-number-range=Invalid Range, Min (exclusive): __1__, Max (inclusive): __2__
error-player=Invaild Player Name, __1__ ,try using tab key to auto-complete the name
error-player-online=Player is offline: Command failed to run
error-player-alive=Player is dead: Command failed to run

View File

@@ -38,7 +38,7 @@ Gui.inputs = require(module_path..'/src/inputs',{Gui=Gui})
table.merge(events,Gui.inputs._events)
Gui.inputs._events = nil
Gui.left = require(module_path..'/src/left',{Gui=Gui,order_config=order_config})
Gui.left = require(module_path..'/src/left',{Gui=Gui,order_config=order_config,self_global=global})
Gui.popup = require(module_path..'/src/popup',{Gui=Gui})
Gui.toolbar = require(module_path..'/src/toolbar',{Gui=Gui,order_config=order_config})

View File

@@ -128,7 +128,7 @@ function inputs._event_handler(event)
if element then
verbose('There was a gui event ('..Event.names[event.name]..') with element: '..event.element.name)
if not is_type(element.events[event.name],'function') then return end
local success, err = pcall(element.events[event.name],event)
local success, err = Manager.sandbox(element.events[event.name],{},event)
if not success then
if is_type(element._error,'function') then pcall(element._error)
else error(err) end

View File

@@ -28,6 +28,8 @@ left.hide = Gui.inputs{
end
end)
local global = self_global
-- used for debugging
function left.override_open(state)
global.over_ride_left_can_open = state

View File

@@ -177,7 +177,7 @@ function Server._thread_handler(event)
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)
local 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
@@ -223,11 +223,11 @@ function Server.interface(callback,use_thread,env,...)
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))
local success, err = Manager.sandbox(callback,env,unpack(thread.data))
if not success then error(err) end
return err
else
local sandbox, success, err = Manager.sandbox(callback,{},env,unpack(thread.data))
local success, err = Manager.sandbox(callback,{},env,unpack(thread.data))
if not success then error(err) end
return err
end
@@ -243,11 +243,11 @@ function Server.interface(callback,use_thread,env,...)
_callback = rtn
end
if is_type(env,'table') and env._env == true then
local sandbox, success, err = Manager.sandbox(_callback,env,...)
local success, err = Manager.sandbox(_callback,env,...)
if not success then return success,err
else return success, unpack(err) end
else
local sandbox, success, err = Manager.sandbox(_callback,{},env,...)
local success, err = Manager.sandbox(_callback,{},env,...)
if not success then return success,err
else return success, unpack(err) end
end
@@ -392,13 +392,13 @@ function Server._thread:resolve(...)
local _return = false
-- checks if the resolve haddler is still present
if is_type(self._resolve,'function') then
local sandbox, success, err = Manager.sandbox(self._resolve,self._env,self,...)
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 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 sandbox, success, err = Manager.sandbox(thread._success,thread._env,thread,err)
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

View File

@@ -24,8 +24,8 @@ end
-- @usage get_env() returns current ENV with _G keys removed
-- @treturn table the env table with _G keys removed
-- @warning does not work from console
function ExpLib.get_env()
local level = 2
function ExpLib.get_env(level)
local level = level and level+1 or 2
local env = setmetatable({},{__index=_G})
while true do
if not debug.getinfo(level-1) then break end
@@ -53,7 +53,7 @@ function ExpLib.add_metatable(tbl,callback,string)
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,
__concat=function(val1,val2) return type(val1) == 'string' and val1..string(val2) or string(val1)..val2 end,
__call=callback
})
end

View File

@@ -27,7 +27,7 @@ local global = global{
-- Function Define
local function _poll_end(self)
local uuid = self.data.poll_uuid
local uuid = tostring(self.data.poll_uuid)
local poll = global.active[uuid]
if not poll then return end
local highest = {nil,-1}
@@ -37,7 +37,6 @@ local function _poll_end(self)
if _result > highest[2] then highest = {answer,_result} end
_votes[answer] = _result
end
local uuid = poll.uuid
poll.uuid = nil
poll.votes = _votes
poll.answers = nil
@@ -46,6 +45,7 @@ local function _poll_end(self)
global.active[uuid] = nil
game.print({'ExpGamingPlayer-polls.end',poll.question},defines.textcolor.info)
game.print({'ExpGamingPlayer-polls.winner',highest[1]},defines.textcolor.info)
verbose('Ended Poll: '..poll.question..' ('..uuid..') Highest: '..highest[1])
end
local function _poll_data(question,answers)
@@ -61,7 +61,8 @@ local function _poll_data(question,answers)
timeout=poll_time_out*60
}:on_event('timeout',_poll_end):open()
-- This time out is known to cause desyncs and so I have moved it to a hard coded function
global.active[poll.uuid]=poll
global.active[tostring(poll.uuid)]=poll
verbose('Created Poll: '..question..' ('..poll.uuid..')')
return poll.uuid
end
@@ -212,17 +213,17 @@ ThisModule.Gui = Gui.popup{
frame.style.right_padding = 5
frame.style.bottom_padding = 5
local uuid = data.uuid
local poll = global.active[uuid]
local poll = global.active[tostring(uuid)]
if not poll then return end
local flow = frame.add{
type='flow',
name=uuid,
name=tostring(uuid),
direction='vertical'
}
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:draw(flow)
opption_drop_down(flow)
end
}:add_left{
caption='utility/item_editor_icon',

View File

@@ -42,11 +42,16 @@ local send_popup = Gui.inputs{
local role = Role.get_highest(player)
local _role = Role.get(event.element.parent.role.caption); if not _role then return end
local sent_by = {'GuiAnnouncements.sent-by',player.name,role.name}
local role_name = _role.name..'s'; if rank_name == Role.meta.default.name..'s' then rank_name = 'Everyone' end
local sent_to = {'GuiAnnouncements.sent-to',rank_name}
local role_name = _role.name..'s'; if role_name == Role.meta.default.name..'s' then role_name = 'Everyone' end
local sent_to = {'GuiAnnouncements.sent-to',role_name}
local message = event.element.parent.parent.message.text
Gui.popup.open('announcements',{sent_by=sent_by,sent_to=sent_to,message=message},_role:get_players(true))
local players = _role:get_players(true)
if _role.index == Role.meta.default.index then players = game.connected_players end
Gui.popup.open('announcements',{sent_by=sent_by,sent_to=sent_to,message=message},players)
player_return('Announcement sent to '..#players..' players ('..role_name..')',defines.textcolor.info,player)
verbose('Announcement sent to '..#players..' players ('..role_name..') by '..player.name..'('..role.name..') with message: '..message)
event.element.parent.parent.message.text = ''
Gui.left.close('announcements',player)
end)
ThisModule.Gui = Gui.popup{

View File

@@ -7,9 +7,9 @@ commands.add_command('make-warp', 'Make a warp point at your location', {
if not game.player then return end
local position = game.player.position
local name = args.name
if game.player.gui.top[name] then player_return({'warp-system.name-used'},defines.textcolor.med) return commands.error end
if warps.warps[name] then player_return({'warp-system.name-used'},defines.textcolor.med) return commands.error end
if position.x^2 + position.y^2 < 100 then player_return({'warp-system.too-close'},defines.textcolor.med) return commands.error end
if game.player.gui.top[name] then player_return({'WarpPoints.name-used'},defines.textcolor.med) return commands.error end
if warps.warps[name] then player_return({'WarpPoints.name-used'},defines.textcolor.med) return commands.error end
if position.x^2 + position.y^2 < 100 then player_return({'WarpPoints.too-close'},defines.textcolor.med) return commands.error end
-- to do add a test for all warps
self.make_warp_point(position,game.player.surface,game.player.force,name)
end)