Eddit To ExpGamingCore.Gui and Added ExpGamingPlayer.Polls

This commit is contained in:
Cooldude2606
2018-10-09 18:49:40 +01:00
parent 8dffc99642
commit 6df973eb5c
42 changed files with 205 additions and 163 deletions

View File

@@ -14,8 +14,9 @@ local OptModule -- OptModule@^X.Y.Z
-- Module Define -- Module Define
local module_verbose = false local module_verbose = false
local ThisModule = { local ThisModule = {
on_init=function() on_init=function(self)
if loaded_modules['OptModule@^X.Y.Z'] then OptModule = require('OptModule@^X.Y.Z') end if loaded_modules['OptModule@^X.Y.Z'] then OptModule = require('OptModule@^X.Y.Z') end
if loaded_modules['OptModule2@^X.Y.Z'] then require(module_path..'/src/module2',{self=self}) end
--code --code
end, end,
on_post=function() on_post=function()

View File

@@ -1,4 +1,4 @@
[commands] [ExpGamingCore_Command]
unauthorized=401 - Unbefugt: Zugang verweigert. Du hast keinen Zugriff auf diese Befehle! unauthorized=401 - Unbefugt: Zugang verweigert. Du hast keinen Zugriff auf diese Befehle!
invalid-inputs=ungültige Eingabe, /__1__ __2__ invalid-inputs=ungültige Eingabe, /__1__ __2__
invalid-range=ungültige Reichweite, Min: __1__, Max: __2__ invalid-range=ungültige Reichweite, Min: __1__, Max: __2__

View File

@@ -1,4 +1,4 @@
[gui] [ExpGamingCore_Gui]
unauthorized=401 - Unbefugt: Du hast keinen Zugriff auf diese Befehle! unauthorized=401 - Unbefugt: Du hast keinen Zugriff auf diese Befehle!
cant-open=Du kannst dieses Menü nicht öffnen, Grund: __1__ cant-open=Du kannst dieses Menü nicht öffnen, Grund: __1__
cant-open-no-reason=Du kannst dieses Menü gerade nicht öffnen. cant-open-no-reason=Du kannst dieses Menü gerade nicht öffnen.

View File

@@ -1,4 +1,4 @@
[commands] [ExpGamingCore_Command]
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
error-string-len=Invalid Length, Max: __1__ error-string-len=Invalid Length, Max: __1__
error-number=Invalid Number: Command failed to run error-number=Invalid Number: Command failed to run

View File

@@ -1,4 +1,4 @@
[gui] [ExpGamingCore_Gui]
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
cant-open=You can't open this panel right now, reason: __1__ cant-open=You can't open this panel right now, reason: __1__
cant-open-no-reason=You can't open this panel right now cant-open-no-reason=You can't open this panel right now

View File

@@ -1,4 +1,4 @@
[commands] [ExpGamingCore_Command]
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
invalid-inputs=Invalid Input, /__1__ __2__ invalid-inputs=Invalid Input, /__1__ __2__
invalid-range=Invalid Range, Min: __1__, Max: __2__ invalid-range=Invalid Range, Min: __1__, Max: __2__

View File

@@ -1,4 +1,4 @@
[gui] [ExpGamingCore_Gui]
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
cant-open=You can not open this panel right now, reason: __1__ cant-open=You can not open this panel right now, reason: __1__
cant-open-no-reason=You can not open this panel right now cant-open-no-reason=You can not open this panel right now

View File

@@ -1,4 +1,4 @@
[commands] [ExpGamingCore_Command]
unauthorized=401 - Onbevoegd: toegang wordt geweigerd vanwege ongeldige inloggegevens unauthorized=401 - Onbevoegd: toegang wordt geweigerd vanwege ongeldige inloggegevens
invalid-inputs=Onjuiste invoer, /__1__ __2__ invalid-inputs=Onjuiste invoer, /__1__ __2__
invalid-range=Onjuiste radius, Min: __1__, Max: __2__ invalid-range=Onjuiste radius, Min: __1__, Max: __2__

View File

@@ -1,4 +1,4 @@
[gui] [ExpGamingCore_Gui]
unauthorized=401 - Onbevoegd: toegang wordt geweigerd vanwege ongeldige inloggegevens unauthorized=401 - Onbevoegd: toegang wordt geweigerd vanwege ongeldige inloggegevens
cant-open=Je kan dit momenteel niet openen. Reden: __1__ cant-open=Je kan dit momenteel niet openen. Reden: __1__
cant-open-no-reason=Je kan dit momenteel niet openen. cant-open-no-reason=Je kan dit momenteel niet openen.

View File

@@ -1,4 +1,4 @@
[commands] [ExpGamingCore_Command]
unauthorized=401 - Otillåten: Tillgång nekas på grund av otillräcklig säkerhetsprövning. unauthorized=401 - Otillåten: Tillgång nekas på grund av otillräcklig säkerhetsprövning.
invalid-inputs=Igiltig inmatning, /__1__ __2__ invalid-inputs=Igiltig inmatning, /__1__ __2__
invalid-range=Invalid räckvid, Min: __1__, Max: __2__ invalid-range=Invalid räckvid, Min: __1__, Max: __2__

View File

@@ -1,4 +1,4 @@
[gui] [ExpGamingCore_Gui]
unauthorized=401 -Otillåten: Tillgång nekas på grund av otillräcklig säkerhetsprövning. unauthorized=401 -Otillåten: Tillgång nekas på grund av otillräcklig säkerhetsprövning.
cant-open=Du kan inte öppna den här panelen just nu, orsak: __1__ cant-open=Du kan inte öppna den här panelen just nu, orsak: __1__
cant-open-no-reason=Du kan inte öppna den här panelen just nu cant-open-no-reason=Du kan inte öppna den här panelen just nu

View File

@@ -12,7 +12,7 @@ commands.add_command('jail', 'Jails a player', {
local player = args.player local player = args.player
local reason = args.reason local reason = args.reason
if Role.allowed(player,'no-report') then player_return{'ExpGamingAdmin.cant-report',args.player} return commands.error end if Role.allowed(player,'no-report') then player_return{'ExpGamingAdmin.cant-report',args.player} return commands.error end
if Admin.is_banned(player) then player_return{'commands.cant-report-ban',args.player} return commands.error end if Admin.is_banned(player) then player_return{'ExpGamingCore_Command.cant-report-ban',args.player} return commands.error end
Admin.jail(player,event.player_index,reason) Admin.jail(player,event.player_index,reason)
end) end)
@@ -23,6 +23,6 @@ commands.add_command('unjail', 'Returns a player\'s old rank', {
['player']={true,'player'} ['player']={true,'player'}
}, function(event,args) }, function(event,args)
local player = args.player local player = args.player
if Admin.is_banned(player) then player_return({'commands.cant-report-ban',args.player}) return commands.error end if Admin.is_banned(player) then player_return({'ExpGamingCore_Command.cant-report-ban',args.player}) return commands.error end
Server.interface(Role.revert,true,player,event.player_index,2) Server.interface(Role.revert,true,player,event.player_index,2)
end) end)

View File

@@ -50,7 +50,7 @@ commands.add_command('repair', 'Repairs all destoryed and damaged entites in an
local highest_admin_power = Role.meta.groups.Admin.highest-1 local highest_admin_power = Role.meta.groups.Admin.highest-1
local max_range = role.index-highest_admin_power > 0 and const/(role.index-highest_admin_power) or nil local max_range = role.index-highest_admin_power > 0 and const/(role.index-highest_admin_power) or nil
local center = player and player.position or {x=0,y=0} local center = player and player.position or {x=0,y=0}
if not range or max_range and range > max_range then player_return({'commands.invalid-range',0,math.floor(max_range)}) return commands.error end if not range or max_range and range > max_range then player_return({'ExpGamingCore_Command.invalid-range',0,math.floor(max_range)}) return commands.error end
local area = {{center.x-range,center.y-range},{center.x+range,center.y+range}} local area = {{center.x-range,center.y-range},{center.x+range,center.y+range}}
local max_time_to_live = 2^32 - 1 local max_time_to_live = 2^32 - 1
local sq_range = range^2 local sq_range = range^2

View File

@@ -57,15 +57,15 @@ commands.validate = {
['boolean']=function(value,event) local value = value.lower() if value == 'true' or valule == 'yes' or value == 'y' or value == '1' then return true else return false end end, ['boolean']=function(value,event) local value = value.lower() if value == 'true' or valule == 'yes' or value == 'y' or value == '1' then return true else return false end end,
['string']=function(value,event) return tostring(value) end, ['string']=function(value,event) return tostring(value) end,
['string-inf']=function(value,event) return tostring(value) end, ['string-inf']=function(value,event) return tostring(value) end,
['string-len']=function(value,event,max) return tostring(value) and tostring(value):len() <= max and tostring(value) or commands.error{'commands.error-string-len'} end, ['string-len']=function(value,event,max) return tostring(value) and tostring(value):len() <= max and tostring(value) or commands.error{'ExpGamingCore_Command.error-string-len'} end,
['number']=function(value,event) return tonumber(value) or commands.error{'commands.error-number'} end, ['number']=function(value,event) return tonumber(value) or commands.error{'ExpGamingCore_Command.error-number'} end,
['number-int']=function(value,event) return tonumber(value) and math.floor(tonumber(value)) or commands.error{'commands.error-number'} end, ['number-int']=function(value,event) return tonumber(value) and math.floor(tonumber(value)) or commands.error{'ExpGamingCore_Command.error-number'} end,
['number-range']=function(value,event,min,max) return tonumber(value) and tonumber(value) > min and tonumber(value) <= max and tonumber(value) or commands.error{'commands.error-number-range'} end, ['number-range']=function(value,event,min,max) return tonumber(value) and tonumber(value) > min and tonumber(value) <= max and tonumber(value) or commands.error{'ExpGamingCore_Command.error-number-range'} end,
['number-range-int']=function(value,event,min,max) return tonumber(value) and math.floor(tonumber(value)) > min and math.floor(tonumber(value)) <= max and math.floor(tonumber(value)) or commands.error{'commands.error-number-range'} end, ['number-range-int']=function(value,event,min,max) return tonumber(value) and math.floor(tonumber(value)) > min and math.floor(tonumber(value)) <= max and math.floor(tonumber(value)) or commands.error{'ExpGamingCore_Command.error-number-range'} end,
['player']=function(value,event) return Game.get_player(player) or commands.error{'commands.error-player'} end, ['player']=function(value,event) return Game.get_player(player) or commands.error{'ExpGamingCore_Command.error-player'} end,
['player-online']=function(value,event) local player,err = commands.validate['player'](value) return err and commands.error(err) or player.conected and player or commands.error{'commands.error-player-online'} end, ['player-online']=function(value,event) local player,err = commands.validate['player'](value) return err and commands.error(err) or player.conected and player or commands.error{'ExpGamingCore_Command.error-player-online'} end,
['player-alive']=function(value,event) local player,err = commands.validate['player-online'](value) return err and commands.error(err) or player.character and player.character.health > 0 and player or commands.error{'commands.error-player-alive'} end, ['player-alive']=function(value,event) local player,err = commands.validate['player-online'](value) return err and commands.error(err) or player.character and player.character.health > 0 and player or commands.error{'ExpGamingCore_Command.error-player-alive'} end,
['player-rank']=function(value,event) local player,err = commands.validate['player'](value) return err and commands.error(err) or not player.admin and Game.get_player(event).admin and player or commands.error{'commands.error-player-rank'} end, ['player-rank']=function(value,event) local player,err = commands.validate['player'](value) return err and commands.error(err) or not player.admin and Game.get_player(event).admin and player or commands.error{'ExpGamingCore_Command.error-player-rank'} end,
['player-rank-online']=function(value,event) local player,err = commands.validate['player-online'](value) if err then return commands.error(err) end local player,err = commands.validate['player-rank'](player) if err then return commands.error(err) end return player end, ['player-rank-online']=function(value,event) local player,err = commands.validate['player-online'](value) if err then return commands.error(err) end local player,err = commands.validate['player-rank'](player) if err then return commands.error(err) end return player end,
['player-rank-alive']=function(value,event) local player,err = commands.validate['player-alive'](value) if err then return commands.error(err) end local player,err = commands.validate['player-rank'](player) if err then return commands.error(err) end return player end, ['player-rank-alive']=function(value,event) local player,err = commands.validate['player-alive'](value) if err then return commands.error(err) end local player,err = commands.validate['player-rank'](player) if err then return commands.error(err) end return player end,
} }
@@ -176,13 +176,13 @@ local function run_custom_command(command)
local success, err = pcall(callback,player_name,command.name,command) local success, err = pcall(callback,player_name,command.name,command)
if not success then error(err) if not success then error(err)
elseif not err then elseif not err then
player_return({'commands.unauthorized'},defines.textcolor.crit) player_return({'ExpGamingCore_Command.unauthorized'},defines.textcolor.crit)
logMessage(player_name,command,'Failed to use command (Unauthorized)',commands.validate_args(command)) logMessage(player_name,command,'Failed to use command (Unauthorized)',commands.validate_args(command))
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
return return
end end
end elseif data.default_admin_only == true and game.player and not game.player.admin then end elseif data.default_admin_only == true and game.player and not game.player.admin then
player_return({'commands.unauthorized'},defines.textcolor.crit) player_return({'ExpGamingCore_Command.unauthorized'},defines.textcolor.crit)
logMessage(player_name,command,'Failed to use command (Unauthorized)',commands.validate_args(command)) logMessage(player_name,command,'Failed to use command (Unauthorized)',commands.validate_args(command))
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
return return
@@ -190,7 +190,7 @@ local function run_custom_command(command)
-- gets the args for the command -- gets the args for the command
local args, err = commands.validate_args(command) local args, err = commands.validate_args(command)
if args == commands.error then if args == commands.error then
player_return({'commands.'..err,command.name,commands.format_inputs(data)},defines.textcolor.high) player_return({'ExpGamingCore_Command.'..err,command.name,commands.format_inputs(data)},defines.textcolor.high)
logMessage(player_name,command,'Failed to use command (Invalid Args)',args) logMessage(player_name,command,'Failed to use command (Invalid Args)',args)
if game.player then game.player.play_sound{path='utility/deconstruct_big'} end if game.player then game.player.play_sound{path='utility/deconstruct_big'} end
return return
@@ -198,7 +198,7 @@ local function run_custom_command(command)
-- runs the command -- runs the command
local success, err = pcall(data.callback,command,args) local success, err = pcall(data.callback,command,args)
if not success then error(err) end if not success then error(err) end
if err ~= commands.error and player_name ~= 'server' then player_return({'commands.command-ran'},defines.textcolor.info) end if err ~= commands.error and player_name ~= 'server' then player_return({'ExpGamingCore_Command.command-ran'},defines.textcolor.info) end
logMessage(player_name,command,'Used command',args) logMessage(player_name,command,'Used command',args)
end end

View File

@@ -1,4 +1,4 @@
[commands] [ExpGamingCore_Command]
unauthorized=401 - Unbefugt: Zugang verweigert. Du hast keinen Zugriff auf diese Befehle! unauthorized=401 - Unbefugt: Zugang verweigert. Du hast keinen Zugriff auf diese Befehle!
invalid-inputs=ungültige Eingabe, /__1__ __2__ invalid-inputs=ungültige Eingabe, /__1__ __2__
invalid-range=ungültige Reichweite, Min: __1__, Max: __2__ invalid-range=ungültige Reichweite, Min: __1__, Max: __2__

View File

@@ -1,4 +1,4 @@
[commands] [ExpGamingCore_Command]
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
error-string-len=Invalid Length, Max: __1__ error-string-len=Invalid Length, Max: __1__
error-number=Invalid Number: Command failed to run error-number=Invalid Number: Command failed to run

View File

@@ -1,4 +1,4 @@
[commands] [ExpGamingCore_Command]
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
invalid-inputs=Invalid Input, /__1__ __2__ invalid-inputs=Invalid Input, /__1__ __2__
invalid-range=Invalid Range, Min: __1__, Max: __2__ invalid-range=Invalid Range, Min: __1__, Max: __2__

View File

@@ -1,4 +1,4 @@
[commands] [ExpGamingCore_Command]
unauthorized=401 - Onbevoegd: toegang wordt geweigerd vanwege ongeldige inloggegevens unauthorized=401 - Onbevoegd: toegang wordt geweigerd vanwege ongeldige inloggegevens
invalid-inputs=Onjuiste invoer, /__1__ __2__ invalid-inputs=Onjuiste invoer, /__1__ __2__
invalid-range=Onjuiste radius, Min: __1__, Max: __2__ invalid-range=Onjuiste radius, Min: __1__, Max: __2__

View File

@@ -1,4 +1,4 @@
[commands] [ExpGamingCore_Command]
unauthorized=401 - Otillåten: Tillgång nekas på grund av otillräcklig säkerhetsprövning. unauthorized=401 - Otillåten: Tillgång nekas på grund av otillräcklig säkerhetsprövning.
invalid-inputs=Igiltig inmatning, /__1__ __2__ invalid-inputs=Igiltig inmatning, /__1__ __2__
invalid-range=Invalid räckvid, Min: __1__, Max: __2__ invalid-range=Invalid räckvid, Min: __1__, Max: __2__

View File

@@ -177,4 +177,5 @@ script.on_event('on_init',function(event)
end) end)
-- Module Return -- Module Return
-- calling will attempt to define a new group
return setmetatable(Group,{__call=function(tbl,...) tbl.define(...) end}) return setmetatable(Group,{__call=function(tbl,...) tbl.define(...) end})

View File

@@ -1,4 +1,4 @@
[gui] [ExpGamingCore_Gui]
unauthorized=401 - Unbefugt: Du hast keinen Zugriff auf diese Befehle! unauthorized=401 - Unbefugt: Du hast keinen Zugriff auf diese Befehle!
cant-open=Du kannst dieses Menü nicht öffnen, Grund: __1__ cant-open=Du kannst dieses Menü nicht öffnen, Grund: __1__
cant-open-no-reason=Du kannst dieses Menü gerade nicht öffnen. cant-open-no-reason=Du kannst dieses Menü gerade nicht öffnen.

View File

@@ -1,4 +1,4 @@
[gui] [ExpGamingCore_Gui]
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
cant-open=You can't open this panel right now, reason: __1__ cant-open=You can't open this panel right now, reason: __1__
cant-open-no-reason=You can't open this panel right now cant-open-no-reason=You can't open this panel right now

View File

@@ -1,4 +1,4 @@
[gui] [ExpGamingCore_Gui]
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
cant-open=You can not open this panel right now, reason: __1__ cant-open=You can not open this panel right now, reason: __1__
cant-open-no-reason=You can not open this panel right now cant-open-no-reason=You can not open this panel right now

View File

@@ -1,4 +1,4 @@
[gui] [ExpGamingCore_Gui]
unauthorized=401 - Onbevoegd: toegang wordt geweigerd vanwege ongeldige inloggegevens unauthorized=401 - Onbevoegd: toegang wordt geweigerd vanwege ongeldige inloggegevens
cant-open=Je kan dit momenteel niet openen. Reden: __1__ cant-open=Je kan dit momenteel niet openen. Reden: __1__
cant-open-no-reason=Je kan dit momenteel niet openen. cant-open-no-reason=Je kan dit momenteel niet openen.

View File

@@ -1,4 +1,4 @@
[gui] [ExpGamingCore_Gui]
unauthorized=401 -Otillåten: Tillgång nekas på grund av otillräcklig säkerhetsprövning. unauthorized=401 -Otillåten: Tillgång nekas på grund av otillräcklig säkerhetsprövning.
cant-open=Du kan inte öppna den här panelen just nu, orsak: __1__ cant-open=Du kan inte öppna den här panelen just nu, orsak: __1__
cant-open-no-reason=Du kan inte öppna den här panelen just nu cant-open-no-reason=Du kan inte öppna den här panelen just nu

View File

@@ -13,17 +13,18 @@ local mod_gui = require("mod-gui")
local Gui = Gui -- this is to force gui to remain in the ENV local Gui = Gui -- this is to force gui to remain in the ENV
local center = {} local center = {}
center._center = {} center._prototype = {}
--- Adds a new obj to the center gui --- Adds a new obj to the center gui
-- @usage Gui.center.add{name='foo',caption='Foo',tooltip='Testing',draw=function} -- @usage Gui.center.add{name='foo',caption='Foo',tooltip='Testing',draw=function}
-- @usage return_value(player) -- opens the center gui for that player
-- @param obj contains the new object, needs name, fraw is opt and is function(root_frame) -- @param obj contains the new object, needs name, fraw is opt and is function(root_frame)
-- @return the object made, used to add tabs -- @return the object made, used to add tabs, calling the returned value will open the center for the given player
function center.add(obj) function center.add(obj)
if not is_type(obj,'table') then return end if not is_type(obj,'table') then return end
if not is_type(obj.name,'string') then return end if not is_type(obj.name,'string') then return end
verbose('Created Center Gui: '..obj.name) verbose('Created Center Gui: '..obj.name)
setmetatable(obj,{__index=center._center}) setmetatable(obj,{__index=center._prototype,__call=function(self,...) center.open(player,self.name) end})
obj.tabs = {} obj.tabs = {}
obj._tabs = {} obj._tabs = {}
Gui.data('center',obj.name,obj) Gui.data('center',obj.name,obj)
@@ -86,7 +87,7 @@ end
-- used on the button press when the toolbar button is press, can be overriden -- used on the button press when the toolbar button is press, can be overriden
-- not recomented for direct use see Gui.center.open -- not recomented for direct use see Gui.center.open
function center._center.open(event) function center._prototype.open(event)
local player = Game.get_player(event) local player = Game.get_player(event)
local _center = Gui.data.center[event.element.name] local _center = Gui.data.center[event.element.name]
local center_flow = center.get_flow(player) local center_flow = center.get_flow(player)
@@ -109,7 +110,7 @@ end
-- this is the default draw function if one is not provided, can be overriden -- this is the default draw function if one is not provided, can be overriden
-- not recomented for direct use see Gui.center.open -- not recomented for direct use see Gui.center.open
function center._center:draw(frame) function center._prototype:draw(frame)
Gui.bar(frame,510) Gui.bar(frame,510)
local tab_bar = frame.add{ local tab_bar = frame.add{
type='frame', type='frame',
@@ -161,7 +162,7 @@ function center._center:draw(frame)
local first_tab = nil local first_tab = nil
for name,button in pairs(self.tabs) do for name,button in pairs(self.tabs) do
first_tab = first_tab or name first_tab = first_tab or name
button:draw(tab_bar_scroll_flow).style.font_color = defines.color.white button(tab_bar_scroll_flow).style.font_color = defines.color.white
end end
self._tabs[self.name..'_'..first_tab](tab_scroll_flow) self._tabs[self.name..'_'..first_tab](tab_scroll_flow)
tab_bar_scroll_flow.children[1].style.font_color = defines.color.orange tab_bar_scroll_flow.children[1].style.font_color = defines.color.orange
@@ -175,7 +176,7 @@ end
-- @tparam[opt] string tooltip the tooltip that is on the button -- @tparam[opt] string tooltip the tooltip that is on the button
-- @tparam function callback this is called when button is pressed with function(root_frame) -- @tparam function callback this is called when button is pressed with function(root_frame)
-- @return self to allow chaining of _center:add_tab -- @return self to allow chaining of _center:add_tab
function center._center:add_tab(name,caption,tooltip,callback) function center._prototype:add_tab(name,caption,tooltip,callback)
verbose('Created Tab: '..self.name..'/'..name) verbose('Created Tab: '..self.name..'/'..name)
self._tabs[self.name..'_'..name] = callback self._tabs[self.name..'_'..name] = callback
self.tabs[name] = Gui.inputs.add{ self.tabs[name] = Gui.inputs.add{
@@ -210,4 +211,5 @@ center._events = {[defines.events.on_gui_closed]=function(event)
end} end}
center.on_role_change = center.clear center.on_role_change = center.clear
return center -- calling will attempt to add a new gui
return setmetatable(center,{__call=function(self,...) self.add(...) end})

View File

@@ -13,7 +13,7 @@ local mod_gui = require("mod-gui")
local Gui = Gui -- this is to force gui to remain in the ENV local Gui = Gui -- this is to force gui to remain in the ENV
local inputs = {} local inputs = {}
inputs._input = {} inputs._prototype = {}
-- these are just so you can have short cuts to this -- these are just so you can have short cuts to this
inputs.events = { inputs.events = {
error='error', error='error',
@@ -30,7 +30,7 @@ inputs.events = {
-- @param event the event to raise callback on | can be number of the event | can be a key of inputs.events -- @param event the event to raise callback on | can be number of the event | can be a key of inputs.events
-- @tparam function callback the function you want to run on the event -- @tparam function callback the function you want to run on the event
-- @treturn table returns self so you can chain together -- @treturn table returns self so you can chain together
function inputs._input:on_event(event,callback) function inputs._prototype:on_event(event,callback)
if not is_type(callback,'function') then return self end if not is_type(callback,'function') then return self end
if inputs.events[event] then event = inputs.events[event] end if inputs.events[event] then event = inputs.events[event] end
if event == 'error' then self._error = callback return self end if event == 'error' then self._error = callback return self end
@@ -42,7 +42,7 @@ end
-- @usage button:draw(frame) -- @usage button:draw(frame)
-- @param root the element you want to add the input to -- @param root the element you want to add the input to
-- @return returns the element that was added -- @return returns the element that was added
function inputs._input:draw(root) function inputs._prototype:draw(root)
local player = Game.get_player(root.player_index) local player = Game.get_player(root.player_index)
if is_type(self.draw_data.caption,'string') and player.gui.is_valid_sprite_path(self.draw_data.caption) then if is_type(self.draw_data.caption,'string') and player.gui.is_valid_sprite_path(self.draw_data.caption) then
local data = table.deepcopy(self.draw_data) local data = table.deepcopy(self.draw_data)
@@ -89,8 +89,9 @@ end
--- Add a new input, this is the same as doing frame.add{} but returns a diffrent object --- Add a new input, this is the same as doing frame.add{} but returns a diffrent object
-- @usage Gui.inputs.add{type='button',name='test',caption='Test'} -- @usage Gui.inputs.add{type='button',name='test',caption='Test'}
-- @usage return_value(frame) -- draws the button onto that frame
-- @tparam table obj the new element to add if caption is a sprite path then sprite is used -- @tparam table obj the new element to add if caption is a sprite path then sprite is used
-- @treturn table the custom input object -- @treturn table the custom input object, calling the returned calue will draw the button
function inputs.add(obj) function inputs.add(obj)
if not is_type(obj,'table') then return end if not is_type(obj,'table') then return end
if not is_type(obj.type,'string') then return end if not is_type(obj.type,'string') then return end
@@ -110,7 +111,7 @@ function inputs.add(obj)
obj.draw_data = table.deepcopy(obj) obj.draw_data = table.deepcopy(obj)
obj.data = {} obj.data = {}
obj.events = {} obj.events = {}
setmetatable(obj,{__index=inputs._input}) setmetatable(obj,{__index=inputs._prototype,__call=function(self,...) self:draw(...) end})
Gui.data('inputs_'..type,obj.name,obj) Gui.data('inputs_'..type,obj.name,obj)
return obj return obj
end end
@@ -378,7 +379,7 @@ function inputs.add_drop_down(name,items,index,callback)
return drop_down return drop_down
end end
-- second return is join event and third is rank change event -- calling will attempt to add a new input
return inputs return setmetatable(inputs,{__call=function(self,...) self.add(...) end})
-- to see examples look at GuiParts/test.lua -- to see examples look at GuiParts/test.lua

View File

@@ -15,7 +15,7 @@ local mod_gui = require("mod-gui")
local Gui = Gui -- this is to force gui to remain in the ENV local Gui = Gui -- this is to force gui to remain in the ENV
local left = {} local left = {}
left._left = {} left._prototype = {}
-- used for debugging -- used for debugging
function left.override_open(state) function left.override_open(state)
@@ -23,13 +23,14 @@ function left.override_open(state)
end end
--- Used to add a left gui frame --- Used to add a left gui frame
-- @usage Gui.left.add{name='foo',caption='Foo',tooltip='just testing',open_on_join=true,can_open=function,draw=function} -- @usage Gui.left.add{name='foo',caption='Foo',tooltip='just testing',open_on_join=true,can_open=function,draw=function}
-- @usage return_value(player) -- toggles visiblity for that player, if no player then updates for all players
-- @param obj this is what will be made, needs a name and a draw function(root_frame), open_on_join can be used to set the deaful state true/false, can_open is a test to block it from opening but is not needed -- @param obj this is what will be made, needs a name and a draw function(root_frame), open_on_join can be used to set the deaful state true/false, can_open is a test to block it from opening but is not needed
-- @return the object that is made to... well idk but for the future -- @return the object that is made, calling the returned value with out a param will update the gui, else will toggle visiblity for that player
function left.add(obj) function left.add(obj)
if not is_type(obj,'table') then return end if not is_type(obj,'table') then return end
if not is_type(obj.name,'string') then return end if not is_type(obj.name,'string') then return end
verbose('Created Left Gui: '..obj.name) verbose('Created Left Gui: '..obj.name)
setmetatable(obj,{__index=left._left}) setmetatable(obj,{__index=left._prototype,__call=function(self,player) if player then self:toggle{player=player,element={name=self.name}} else left.update(self.name) end end})
Gui.data('left',obj.name,obj) Gui.data('left',obj.name,obj)
Gui.toolbar.add(obj.name,obj.caption,obj.tooltip,obj.toggle) Gui.toolbar.add(obj.name,obj.caption,obj.tooltip,obj.toggle)
return obj return obj
@@ -122,7 +123,7 @@ function left.close(left_name)
end end
-- this is used to draw the gui for the first time (these guis are never destoryed), used by the script -- this is used to draw the gui for the first time (these guis are never destoryed), used by the script
function left._left.open(event) function left._prototype.open(event)
local player = Game.get_player(event) local player = Game.get_player(event)
local _left = Gui.data.left[event.element.name] local _left = Gui.data.left[event.element.name]
local left_flow = mod_gui.get_frame_flow(player) local left_flow = mod_gui.get_frame_flow(player)
@@ -139,7 +140,7 @@ function left._left.open(event)
end end
-- this is called when the toolbar button is pressed -- this is called when the toolbar button is pressed
function left._left.toggle(event) function left._prototype.toggle(event)
local player = Game.get_player(event) local player = Game.get_player(event)
local _left = Gui.data.left[event.element.name] local _left = Gui.data.left[event.element.name]
local left_flow = mod_gui.get_frame_flow(player) local left_flow = mod_gui.get_frame_flow(player)
@@ -167,8 +168,8 @@ function left._left.toggle(event)
else else
left.style.visible = false left.style.visible = false
end end
if open == false then player_return({'gui.cant-open-no-reason'},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} if open == false then player_return({'ExpGamingCore_Gui.cant-open-no-reason'},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'}
elseif open ~= true then player_return({'gui.cant-open',open},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} end elseif open ~= true then player_return({'ExpGamingCore_Gui.cant-open',open},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} end
end end
left.on_player_joined_game = function(event) left.on_player_joined_game = function(event)
@@ -185,4 +186,5 @@ function left:on_init()
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end
end end
return left -- calling will attempt to add a new gui
return setmetatable(left,{__call=function(self,...) self.add(...) end})

View File

@@ -12,10 +12,10 @@ local mod_gui = require("mod-gui")
local Gui = Gui -- this is to force gui to remain in the ENV local Gui = Gui -- this is to force gui to remain in the ENV
local popup = {} local popup = {}
popup._popup = {} popup._prototype = {}
function popup.load() function popup.load()
popup._popup.close = Gui.inputs.add{ popup._prototype.close = Gui.inputs.add{
type='button', type='button',
name='popup-close', name='popup-close',
caption='utility/set_bar_slot', caption='utility/set_bar_slot',
@@ -28,13 +28,14 @@ end
--- Used to add a popup gui style --- Used to add a popup gui style
-- @usage Gui.left.add{name='foo',caption='Foo',draw=function} -- @usage Gui.left.add{name='foo',caption='Foo',draw=function}
-- @usage return_value(data,player) -- opens popup for one player use popup.open to open for more than one player
-- @param obj this is what will be made, needs a name and a draw function(root_frame,data) -- @param obj this is what will be made, needs a name and a draw function(root_frame,data)
-- @return the object that is made to... well idk but for the future -- @return the object that is made, calling the returned value will open the popup for that player
function popup.add(obj) function popup.add(obj)
if not is_type(obj,'table') then return end if not is_type(obj,'table') then return end
if not is_type(obj.name,'string') then return end if not is_type(obj.name,'string') then return end
verbose('Created Popup Gui: '..obj.name) verbose('Created Popup Gui: '..obj.name)
setmetatable(obj,{__index=popup._popup}) setmetatable(obj,{__index=popup._prototype,__call=function(self,data,player) local players = player and {player} or nil popup.open(self.name,data,players) end})
local name = obj.name; obj.name = nil local name = obj.name; obj.name = nil
Gui.data('popup',name,obj) Gui.data('popup',name,obj)
obj.name = name obj.name = name
@@ -73,7 +74,7 @@ function popup.open(style,data,players)
direction='vertical', direction='vertical',
style='image_frame' style='image_frame'
} }
_popup.close:draw(_frame) _popup.close(_frame)
if is_type(_popup.draw,'function') then if is_type(_popup.draw,'function') then
local success, err = pcall(_popup.draw,frame,data) local success, err = pcall(_popup.draw,frame,data)
if not success then error(err) end if not success then error(err) end
@@ -97,7 +98,7 @@ function popup.open(style,data,players)
direction='vertical', direction='vertical',
style='image_frame' style='image_frame'
} }
thread.data.popup.close:draw(_frame) thread.data.popup.close(_frame)
if is_type(thread.data.popup.draw,'function') then if is_type(thread.data.popup.draw,'function') then
local success, err = pcall(thread.data.popup.draw,frame,thread.data.data) local success, err = pcall(thread.data.popup.draw,frame,thread.data.data)
if not success then error(err) end if not success then error(err) end
@@ -106,11 +107,12 @@ function popup.open(style,data,players)
end end
end end
function popup._popup:add_left(obj) function popup._prototype:add_left(obj)
obj.name = obj.name or self.name obj.name = obj.name or self.name
self.left = Gui.left.add(obj) self.left = Gui.left.add(obj)
end end
popup.on_player_joined_game = popup.flow popup.on_player_joined_game = popup.flow
return popup -- calling will attempt to add a new popup style
return setmetatable(popup,{__call=function(self,...) self.add(...) end})

View File

@@ -20,7 +20,7 @@ local toolbar = {}
-- @tparam string caption can be a sprite path or text to show -- @tparam string caption can be a sprite path or text to show
-- @tparam string tooltip the help to show for the button -- @tparam string tooltip the help to show for the button
-- @tparam function callback the function which is called on_click -- @tparam function callback the function which is called on_click
-- @treturn table the button object that was made -- @treturn table the button object that was made, calling the returned value will draw the toolbar button added
function toolbar.add(name,caption,tooltip,callback) function toolbar.add(name,caption,tooltip,callback)
verbose('Created Toolbar Button: '..name) verbose('Created Toolbar Button: '..name)
local button = Gui.inputs.add{type='button',name=name,caption=caption,tooltip=tooltip} local button = Gui.inputs.add{type='button',name=name,caption=caption,tooltip=tooltip}
@@ -41,9 +41,9 @@ function toolbar.draw(player)
for name,button in pairs(Gui.data.toolbar) do for name,button in pairs(Gui.data.toolbar) do
if is_type(Role,'table') then if is_type(Role,'table') then
if Role.allowed(player,name) then if Role.allowed(player,name) then
button:draw(toolbar_frame) button(toolbar_frame)
end end
else button:draw(toolbar_frame) end else button(toolbar_frame) end
end end
end end
@@ -53,4 +53,5 @@ end
toolbar.on_role_change = toolbar.draw toolbar.on_role_change = toolbar.draw
toolbar.on_player_joined_game = toolbar.draw toolbar.on_player_joined_game = toolbar.draw
return toolbar -- calling with only a player will draw the toolbar for that player, more params will attempt to add a button
return setmetatable(toolbar,{__call=function(self,player,extra,...) if extra then self.add(player,extra,...) else self.draw(player) end end})

View File

@@ -18,7 +18,7 @@ local Role = {
order={}, order={},
flags={}, flags={},
actions={}, actions={},
meta={times={},groups={}}, meta={times={},groups={},count=0},
roles=setmetatable({},{ roles=setmetatable({},{
__index=table.autokey, __index=table.autokey,
__newindex=function(tbl,key,value) __newindex=function(tbl,key,value)
@@ -43,6 +43,7 @@ local Role = {
if self.meta.groups[role.group.name].highest > index then self.meta.groups[role.group.name].highest = index end if self.meta.groups[role.group.name].highest > index then self.meta.groups[role.group.name].highest = index end
if self.meta.groups[role.group.name].lowest < index then self.meta.groups[role.group.name].lowest = index end if self.meta.groups[role.group.name].lowest < index then self.meta.groups[role.group.name].lowest = index end
if previous then setmetatable(previous.allow,{__index=role.allow}) end if previous then setmetatable(previous.allow,{__index=role.allow}) end
self.meta.count = self.meta.count+1
role.index = index role.index = index
previous = role previous = role
end end
@@ -487,4 +488,5 @@ script.on_event(defines.events.on_tick,function(event)
end) end)
-- Module Return -- Module Return
-- calling will attempt to define a new role
return setmetatable(Role,{__call=function(tbl,...) tbl.define(...) end}) return setmetatable(Role,{__call=function(tbl,...) tbl.define(...) end})

View File

@@ -4,7 +4,7 @@ commands.add_validation('player-rank',function(value,event)
local player,err = commands.validate['player'](value) local player,err = commands.validate['player'](value)
return err and commands.error(err) return err and commands.error(err)
or Role.get_highest(player).index > Role.get_highest(event).index and player or Role.get_highest(player).index > Role.get_highest(event).index and player
or commands.error{'commands.error-player-rank'} or commands.error{'ExpGamingCore_Command.error-player-rank'}
end) end)
commands.add_validation('player-rank-online',function(value,event) commands.add_validation('player-rank-online',function(value,event)

View File

@@ -1,2 +1,2 @@
[Server] [ExpGamingCore_Server]
interface-description=Runs the given input from the script interface-description=Runs the given input from the script

View File

@@ -23,7 +23,7 @@ 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
-- @param code The code that will be ran -- @param code The code that will be ran
commands.add_command('interface',{'Server.interface-description'}, { commands.add_command('interface',{'ExpGamingCore_Server.interface-description'}, {
['code']={true,'string-inf'} ['code']={true,'string-inf'}
}, function(event,args) }, function(event,args)
local callback = args.code local callback = args.code

View File

@@ -1,21 +1,21 @@
--- A full ranking system for factorio. --- A full ranking system for factorio.
-- @module ExpGamingPlayer.playerInfo -- @module ExpGamingPlayer.afkKick@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
local Game = require('FactorioStdLib.Game') local Game = require('FactorioStdLib.Game@^0.8.0')
local Gui = require('ExpGamingCore.Gui') local Gui = require('ExpGamingCore.Gui@^4.0.0')
local Role -- hanndled on load local Role -- ExpGamingCore.Role@^4.0.0
local Sync -- hanndled on load local Sync -- ExpGamingCore.Sync@^4.0.0
function get_allowed_afk_time(player) local function get_allowed_afk_time(player)
local role local role
if Role then role = Role.get_highest(player) if Role then role = Role.get_highest(player)
else if player.admin then return else rank = Role.meta.default end end else if player.admin then return else role = Role.meta.default end end
local count = #game.connected_players local count = #game.connected_players
local base = role.index or false local base = role.index or false
if not base then return false end if not base then return false end
return (10/base)*count return (Role.meta.count/base)*count
end end
script.on_event(defines.events.on_tick,function(event) script.on_event(defines.events.on_tick,function(event)
@@ -28,11 +28,11 @@ script.on_event(defines.events.on_tick,function(event)
end end
end) end)
return { return setmetatable({
get_allowed_afk_time=get_allowed_afk_time, get_allowed_afk_time=get_allowed_afk_time,
on_init=function(self) on_init=function(self)
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end if loaded_modules['ExpGamingCore.Role@^4.0.0'] then Role = require('ExpGamingCore.Role@^4.0.0') end
if loaded_modules['ExpGamingCore.Sync'] then Sync = require('ExpGamingCore.Sync') end if loaded_modules['ExpGamingCore.Sync@^4.0.0'] then Sync = require('ExpGamingCore.Sync@^4.0.0') end
if loaded_modules['ExpGamingCore.Server'] then require(module_path..'/src/server',Sync) end if loaded_modules['ExpGamingCore.Server@^4.0.0'] then require(module_path..'/src/server',Sync,self) end
end end
} },{__call=function(self,...) self.get_allowed_afk_time(...) end})

View File

@@ -1,4 +1,5 @@
local Sync = Sync local Sync = Sync
local get_allowed_afk_time = self
local Server = require('ExpGamingCore.Server@^4.0.0') local Server = require('ExpGamingCore.Server@^4.0.0')
Event[defines.events.on_tick] = nil Event[defines.events.on_tick] = nil
script.on_init(function(event) script.on_init(function(event)

View File

@@ -1,7 +1,7 @@
--- Desction <get from json> --- Adds an inventory search that is proformed on a random player every 15 seconds
-- @module ThisModule@X.Y.Z -- @module ExpGamingPlayer.inventorySearch@4.0.0
-- @author <get from json> -- @author Cooldude2606
-- @license <get from json> -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alais ThisModule
-- Module Require -- Module Require
@@ -54,9 +54,9 @@ local ThisModule = {
-- Function Define -- Function Define
local function take_action(player,item_name,category) local function take_action(player,item_name,category)
if category == 'low_items' then player_return({'inventory-search.low',item_name},defines.textcolor.med,player) if category == 'low_items' then player_return({'ExpGamingPlayer_inventorySearch.low',item_name},defines.textcolor.med,player)
elseif category == 'med_items' then player_return({'inventory-search.med',item_name},defines.textcolor.high,player) Admin.give_warning(player,'<server>','Found A Banned Item',5) elseif category == 'med_items' then player_return({'ExpGamingPlayer_inventorySearch.med',item_name},defines.textcolor.high,player) Admin.give_warning(player,'<server>','Found A Banned Item',5)
elseif category == 'high_items' then player_return({'inventory-search.high',item_name},defines.textcolor.crit,player) Admin.temp_ban(player,'<server>','Found A Banned Item') elseif category == 'high_items' then player_return({'ExpGamingPlayer_inventorySearch.high',item_name},defines.textcolor.crit,player) Admin.temp_ban(player,'<server>','Found A Banned Item')
else return end else return end
end end

View File

@@ -1,12 +1,12 @@
--- A full ranking system for factorio. --- Used to give so common info on a player as a lua table or a frame.
-- @module ExpGamingPlayer.playerInfo -- @module ExpGamingPlayer.playerInfo@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
local Game = require('FactorioStdLib.Game') local Game = require('FactorioStdLib.Game@^0.8.0')
local Gui = require('ExpGamingCore.Gui') local Gui = require('ExpGamingCore.Gui@^4.0.0')
local Role -- hanndled on load local Role -- ExpGamingCore.Role@^4.0.0
local Group -- hanndled on load local Group -- ExpGamingCore.Group@^4.0.0
local function get_player_info(player,frame,add_cam) local function get_player_info(player,frame,add_cam)
local player = Game.get_player(player) local player = Game.get_player(player)
@@ -30,15 +30,15 @@ local function get_player_info(player,frame,add_cam)
frame.style.width = 200 frame.style.width = 200
if Role then frame.style.height = 275 if Role then frame.style.height = 275
else frame.style.height = 260 end else frame.style.height = 260 end
frame.add{type='label',caption={'player-info.name',_player.index,_player.name},style='caption_label'} frame.add{type='label',caption={'ExpGamingPlayer_playerInfo.name',_player.index,_player.name},style='caption_label'}
local _online = {'player-info.no'}; if _player.online then _online = {'player-info.yes'} end local _online = {'ExpGamingPlayer_playerInfo.no'}; if _player.online then _online = {'ExpGamingPlayer_playerInfo.yes'} end
frame.add{type='label',caption={'player-info.online',_online,tick_to_display_format(_player.online_time)}} frame.add{type='label',caption={'ExpGamingPlayer_playerInfo.online',_online,tick_to_display_format(_player.online_time)}}
local _admin = {'player-info.no'}; if _player.admin then _admin = {'player-info.yes'} end local _admin = {'ExpGamingPlayer_playerInfo.no'}; if _player.admin then _admin = {'ExpGamingPlayer_playerInfo.yes'} end
frame.add{type='label',caption={'player-info.admin',_admin}} frame.add{type='label',caption={'ExpGamingPlayer_playerInfo.admin',_admin}}
if Role then if Role then
frame.add{type='label',caption={'player-info.group',_player.group}} frame.add{type='label',caption={'ExpGamingPlayer_playerInfo.group',_player.group}}
frame.add{type='label',caption={'player-info.role',_player.highest_role}} frame.add{type='label',caption={'ExpGamingPlayer_playerInfo.role',_player.highest_role}}
frame.add{type='label',caption={'player-info.roles',table.concat(_player.roles,', ')}} frame.add{type='label',caption={'ExpGamingPlayer_playerInfo.roles',table.concat(_player.roles,', ')}}
end end
if add_cam then if add_cam then
Gui.cam_link{entity=player.character,frame=frame,width=200,height=150,zoom=0.5,respawn_open=true} Gui.cam_link{entity=player.character,frame=frame,width=200,height=150,zoom=0.5,respawn_open=true}
@@ -50,8 +50,8 @@ end
return setmetatable({ return setmetatable({
get_player_info=get_player_info, get_player_info=get_player_info,
on_init=function(self) on_init=function(self)
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end if loaded_modules['ExpGamingCore.Role@^4.0.0'] then Role = require('ExpGamingCore.Role@^4.0.0') end
if loaded_modules['ExpGamingCore.Group'] then Group = require('ExpGamingCore.Group') end if loaded_modules['ExpGamingCore.Group@^4.0.0'] then Group = require('ExpGamingCore.Group@^4.0.0') end
end end
},{ },{
__call=function(self,...) self.get_player_info(...) end __call=function(self,...) self.get_player_info(...) end

View File

@@ -1,5 +1,5 @@
--- A full ranking system for factorio. --- A full ranking system for factorio.
-- @module ExpGamingPlayer.playerList -- @module ExpGamingPlayer.playerList@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE

View File

@@ -1,24 +1,34 @@
--[[ --- Adds a poll gui into the game for quick polls (default 90 seconds)
Explosive Gaming -- @module ExpGamingPlayer.polls@4.0.0
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
This file can be used with permission but this and the credit below must remain in the file. -- Module Require
Contact a member of management on our discord to seek permission to use our code. local Server = require('ExpGamingCore.Server@^4.0.0')
Any changes that you may make to the code are yours but that does not make the script yours. local Gui = require('ExpGamingCore.Gui@^4.0.0')
Discord: https://discord.gg/r6dC2uK local Role -- ExpGamingCore.Server@^4.0.0
]]
--Please Only Edit Below This Line-----------------------------------------------------------
-- Local Varibles
local poll_time_out = 90 -- In seconds local poll_time_out = 90 -- In seconds
local function _polls(reset) -- Module Define
global.addons = not reset and global.addons or {} local module_verbose = false
global.addons.polls = not reset and global.addons.polls or {active={},old={}} local ThisModule = {
return global.addons.polls on_init=function()
end if loaded_modules['ExpGamingCore.Server@^4.0.0'] then Role = require('ExpGamingCore.Server@^4.0.0') end
end
}
function _poll_end(self) -- Global Define
local global = global{
active={},
old={}
}
-- Function Define
local function _poll_end(self)
local uuid = self.data.poll_uuid local uuid = self.data.poll_uuid
local poll = _polls().active[uuid] local poll = global.active[uuid]
if not poll then return end if not poll then return end
local highest = {nil,-1} local highest = {nil,-1}
local _votes = {} local _votes = {}
@@ -32,15 +42,15 @@ function _poll_end(self)
poll.votes = _votes poll.votes = _votes
poll.answers = nil poll.answers = nil
poll.voted = nil poll.voted = nil
table.insert(_polls().old,poll) table.insert(global.old,poll)
_polls().active[uuid] = nil global.active[uuid] = nil
game.print({'polls.end',poll.question},defines.textcolor.info) game.print({'polls.end',poll.question},defines.textcolor.info)
game.print({'polls.winner',highest[1]},defines.textcolor.info) game.print({'polls.winner',highest[1]},defines.textcolor.info)
end end
local function _poll_data(question,answers) local function _poll_data(question,answers)
local poll = { local poll = {
uuid=Server.new_uuid(), uuid=Server.uuid(),
question=question, question=question,
answers=answers or {'None'}, answers=answers or {'None'},
votes={}, votes={},
@@ -51,37 +61,14 @@ local function _poll_data(question,answers)
timeout=poll_time_out*60 timeout=poll_time_out*60
}:on_event('timeout',_poll_end):open() }: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 -- This time out is known to cause desyncs and so I have moved it to a hard coded function
_polls().active[poll.uuid]=poll global.active[poll.uuid]=poll
return poll.uuid return poll.uuid
end end
local function draw_poll(frame)
frame.clear()
local index = tonumber(frame.parent.current_index.caption)
local poll = _polls().old[index]
if not poll then
frame.add{
type='label',
caption={'polls.no-poll'}
}
return
end
frame.add{
type='label',
caption='Question: '..poll.question
}
for answer,votes in pairs(poll.votes) do
frame.add{
type='label',
caption=answer..') '..votes
}
end
end
local function _opptions(player,root_frame) local function _opptions(player,root_frame)
local opptions = {'Please Select An Opption'} local opptions = {'Please Select An Opption'}
local uuid = root_frame.name local uuid = root_frame.name
local poll = _polls().active[uuid] local poll = global.active[uuid]
if not poll then return {'Invalid Poll'} end if not poll then return {'Invalid Poll'} end
for _,answer in pairs(poll.answers) do for _,answer in pairs(poll.answers) do
table.insert(opptions,answer) table.insert(opptions,answer)
@@ -91,7 +78,7 @@ end
local opption_drop_down = Gui.inputs.add_drop_down('opption-drop-down-polls',_opptions,1,function(player,selected,items,element) local opption_drop_down = Gui.inputs.add_drop_down('opption-drop-down-polls',_opptions,1,function(player,selected,items,element)
local uuid = element.parent.name local uuid = element.parent.name
local poll = _polls().active[uuid] local poll = global.active[uuid]
if not poll then return end if not poll then return end
if poll.voted[player.index] and poll.voted[player.index] > 1 then if poll.voted[player.index] and poll.voted[player.index] > 1 then
local old_vote = poll.voted[player.index] local old_vote = poll.voted[player.index]
@@ -112,7 +99,7 @@ local prev = Gui.inputs.add{
local parent = event.element.parent local parent = event.element.parent
local index = parent.parent.current_index.caption local index = parent.parent.current_index.caption
local _index = tonumber(index)-1 local _index = tonumber(index)-1
if _index < 1 then _index = #_polls().old end if _index < 1 then _index = #global.old end
parent.parent.current_index.caption = _index parent.parent.current_index.caption = _index
parent.parent.title.title.caption = 'Viewing Poll: '.._index parent.parent.title.title.caption = 'Viewing Poll: '.._index
draw_poll(parent.parent.poll_area) draw_poll(parent.parent.poll_area)
@@ -126,7 +113,7 @@ local next = Gui.inputs.add{
local parent = event.element.parent local parent = event.element.parent
local index = parent.parent.current_index.caption local index = parent.parent.current_index.caption
local _index = tonumber(index)+1 local _index = tonumber(index)+1
if _index > #_polls().old then _index = 1 end if _index > #global.old then _index = 1 end
parent.parent.current_index.caption = _index parent.parent.current_index.caption = _index
parent.parent.title.title.caption = 'Viewing Poll: '.._index parent.parent.title.title.caption = 'Viewing Poll: '.._index
draw_poll(parent.parent.poll_area) draw_poll(parent.parent.poll_area)
@@ -202,7 +189,7 @@ Gui.popup.add{
frame.style.right_padding = 5 frame.style.right_padding = 5
frame.style.bottom_padding = 5 frame.style.bottom_padding = 5
local uuid = data.uuid local uuid = data.uuid
local poll = _polls().active[uuid] local poll = global.active[uuid]
if not poll then return end if not poll then return end
local flow = frame.add{ local flow = frame.add{
type='flow', type='flow',
@@ -240,7 +227,7 @@ Gui.popup.add{
local btn = next:draw(title) local btn = next:draw(title)
btn.style.width = 20 btn.style.width = 20
btn.style.height = 20 btn.style.height = 20
if Role.get_highest(frame.player_index):allowed('create-poll') then if Role and Role.get_highest(frame.player_index):allowed('create-poll') or player.admin then
local btn = create_poll:draw(title) local btn = create_poll:draw(title)
btn.style.width = 20 btn.style.width = 20
btn.style.height = 20 btn.style.height = 20
@@ -253,8 +240,12 @@ Gui.popup.add{
draw_poll(flow) draw_poll(flow)
end, end,
can_open=function(player) can_open=function(player)
if #_polls().old > 0 then return true if #global.old > 0 then return true
elseif Role.allowed(player,'create-poll') then return true elseif Role and Role.allowed(player,'create-poll') or player.admin then return true
else return {'polls.no-poll'} end else return {'polls.no-poll'} end
end end
} }
-- Event Handlers Define
-- Module Return
return ThisModule

View File

@@ -0,0 +1,19 @@
{
"name": "polls",
"version": "4.0.0",
"type": "Submodule",
"description": "Adds a poll gui into the game for quick polls (default 90 seconds)",
"location": "<blank>",
"keywords": [
"Polls",
"Poll",
"Question",
"Gui"
],
"dependencies": {
"ExpGamingCore.Gui": "^4.0.0",
"ExpGamingCore.Server": "^4.0.0",
"ExpGamingCore.Role": "?^4.0.0"
},
"collection": "ExpGamingPlayer_4.0.0"
}

View File

@@ -99,6 +99,25 @@
"FactorioStdLib.Game": "^0.8.0" "FactorioStdLib.Game": "^0.8.0"
}, },
"collection": "ExpGamingPlayer_4.0.0" "collection": "ExpGamingPlayer_4.0.0"
},
"polls": {
"name": "polls",
"version": "4.0.0",
"type": "Submodule",
"description": "Adds a poll gui into the game for quick polls (default 90 seconds)",
"location": "<blank>",
"keywords": [
"Polls",
"Poll",
"Question",
"Gui"
],
"dependencies": {
"ExpGamingCore.Gui": "^4.0.0",
"ExpGamingCore.Server": "^4.0.0",
"ExpGamingCore.Role": "?^4.0.0"
},
"collection": "ExpGamingPlayer_4.0.0"
} }
}, },
"dependencies": {} "dependencies": {}