mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Eddit To ExpGamingCore.Gui and Added ExpGamingPlayer.Polls
This commit is contained in:
@@ -12,7 +12,7 @@ commands.add_command('jail', 'Jails a player', {
|
||||
local player = args.player
|
||||
local reason = args.reason
|
||||
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)
|
||||
end)
|
||||
|
||||
@@ -23,6 +23,6 @@ commands.add_command('unjail', 'Returns a player\'s old rank', {
|
||||
['player']={true,'player'}
|
||||
}, function(event,args)
|
||||
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)
|
||||
end)
|
||||
@@ -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 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}
|
||||
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 max_time_to_live = 2^32 - 1
|
||||
local sq_range = range^2
|
||||
|
||||
@@ -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,
|
||||
['string']=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,
|
||||
['number']=function(value,event) return 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{'commands.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-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,
|
||||
['player']=function(value,event) return Game.get_player(player) or commands.error{'commands.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-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-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,
|
||||
['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{'ExpGamingCore_Command.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{'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{'ExpGamingCore_Command.error-number-range'} 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{'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{'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{'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-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)
|
||||
if not success then error(err)
|
||||
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))
|
||||
if game.player then game.player.play_sound{path='utility/cannot_build'} end
|
||||
return
|
||||
end
|
||||
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))
|
||||
if game.player then game.player.play_sound{path='utility/cannot_build'} end
|
||||
return
|
||||
@@ -190,7 +190,7 @@ local function run_custom_command(command)
|
||||
-- gets the args for the command
|
||||
local args, err = commands.validate_args(command)
|
||||
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)
|
||||
if game.player then game.player.play_sound{path='utility/deconstruct_big'} end
|
||||
return
|
||||
@@ -198,7 +198,7 @@ local function run_custom_command(command)
|
||||
-- runs the command
|
||||
local success, err = pcall(data.callback,command,args)
|
||||
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)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[commands]
|
||||
[ExpGamingCore_Command]
|
||||
unauthorized=401 - Unbefugt: Zugang verweigert. Du hast keinen Zugriff auf diese Befehle!
|
||||
invalid-inputs=ungültige Eingabe, /__1__ __2__
|
||||
invalid-range=ungültige Reichweite, Min: __1__, Max: __2__
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[commands]
|
||||
[ExpGamingCore_Command]
|
||||
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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[commands]
|
||||
[ExpGamingCore_Command]
|
||||
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
|
||||
invalid-inputs=Invalid Input, /__1__ __2__
|
||||
invalid-range=Invalid Range, Min: __1__, Max: __2__
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[commands]
|
||||
[ExpGamingCore_Command]
|
||||
unauthorized=401 - Onbevoegd: toegang wordt geweigerd vanwege ongeldige inloggegevens
|
||||
invalid-inputs=Onjuiste invoer, /__1__ __2__
|
||||
invalid-range=Onjuiste radius, Min: __1__, Max: __2__
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[commands]
|
||||
[ExpGamingCore_Command]
|
||||
unauthorized=401 - Otillåten: Tillgång nekas på grund av otillräcklig säkerhetsprövning.
|
||||
invalid-inputs=Igiltig inmatning, /__1__ __2__
|
||||
invalid-range=Invalid räckvid, Min: __1__, Max: __2__
|
||||
|
||||
@@ -177,4 +177,5 @@ script.on_event('on_init',function(event)
|
||||
end)
|
||||
|
||||
-- Module Return
|
||||
-- calling will attempt to define a new group
|
||||
return setmetatable(Group,{__call=function(tbl,...) tbl.define(...) end})
|
||||
@@ -1,4 +1,4 @@
|
||||
[gui]
|
||||
[ExpGamingCore_Gui]
|
||||
unauthorized=401 - Unbefugt: Du hast keinen Zugriff auf diese Befehle!
|
||||
cant-open=Du kannst dieses Menü nicht öffnen, Grund: __1__
|
||||
cant-open-no-reason=Du kannst dieses Menü gerade nicht öffnen.
|
||||
@@ -1,4 +1,4 @@
|
||||
[gui]
|
||||
[ExpGamingCore_Gui]
|
||||
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
|
||||
cant-open=You can't open this panel right now, reason: __1__
|
||||
cant-open-no-reason=You can't open this panel right now
|
||||
@@ -1,4 +1,4 @@
|
||||
[gui]
|
||||
[ExpGamingCore_Gui]
|
||||
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
|
||||
cant-open=You can not open this panel right now, reason: __1__
|
||||
cant-open-no-reason=You can not open this panel right now
|
||||
@@ -1,4 +1,4 @@
|
||||
[gui]
|
||||
[ExpGamingCore_Gui]
|
||||
unauthorized=401 - Onbevoegd: toegang wordt geweigerd vanwege ongeldige inloggegevens
|
||||
cant-open=Je kan dit momenteel niet openen. Reden: __1__
|
||||
cant-open-no-reason=Je kan dit momenteel niet openen.
|
||||
@@ -1,4 +1,4 @@
|
||||
[gui]
|
||||
[ExpGamingCore_Gui]
|
||||
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-no-reason=Du kan inte öppna den här panelen just nu
|
||||
@@ -13,17 +13,18 @@ local mod_gui = require("mod-gui")
|
||||
local Gui = Gui -- this is to force gui to remain in the ENV
|
||||
|
||||
local center = {}
|
||||
center._center = {}
|
||||
center._prototype = {}
|
||||
|
||||
--- Adds a new obj to the center gui
|
||||
-- @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)
|
||||
-- @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)
|
||||
if not is_type(obj,'table') then return end
|
||||
if not is_type(obj.name,'string') then return end
|
||||
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 = {}
|
||||
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
|
||||
-- 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 _center = Gui.data.center[event.element.name]
|
||||
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
|
||||
-- not recomented for direct use see Gui.center.open
|
||||
function center._center:draw(frame)
|
||||
function center._prototype:draw(frame)
|
||||
Gui.bar(frame,510)
|
||||
local tab_bar = frame.add{
|
||||
type='frame',
|
||||
@@ -161,7 +162,7 @@ function center._center:draw(frame)
|
||||
local first_tab = nil
|
||||
for name,button in pairs(self.tabs) do
|
||||
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
|
||||
self._tabs[self.name..'_'..first_tab](tab_scroll_flow)
|
||||
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 function callback this is called when button is pressed with function(root_frame)
|
||||
-- @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)
|
||||
self._tabs[self.name..'_'..name] = callback
|
||||
self.tabs[name] = Gui.inputs.add{
|
||||
@@ -210,4 +211,5 @@ center._events = {[defines.events.on_gui_closed]=function(event)
|
||||
end}
|
||||
|
||||
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})
|
||||
@@ -13,7 +13,7 @@ local mod_gui = require("mod-gui")
|
||||
local Gui = Gui -- this is to force gui to remain in the ENV
|
||||
|
||||
local inputs = {}
|
||||
inputs._input = {}
|
||||
inputs._prototype = {}
|
||||
-- these are just so you can have short cuts to this
|
||||
inputs.events = {
|
||||
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
|
||||
-- @tparam function callback the function you want to run on the event
|
||||
-- @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 inputs.events[event] then event = inputs.events[event] end
|
||||
if event == 'error' then self._error = callback return self end
|
||||
@@ -42,7 +42,7 @@ end
|
||||
-- @usage button:draw(frame)
|
||||
-- @param root the element you want to add the input to
|
||||
-- @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)
|
||||
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)
|
||||
@@ -89,8 +89,9 @@ end
|
||||
|
||||
--- 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 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
|
||||
-- @treturn table the custom input object
|
||||
-- @treturn table the custom input object, calling the returned calue will draw the button
|
||||
function inputs.add(obj)
|
||||
if not is_type(obj,'table') 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.data = {}
|
||||
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)
|
||||
return obj
|
||||
end
|
||||
@@ -378,7 +379,7 @@ function inputs.add_drop_down(name,items,index,callback)
|
||||
return drop_down
|
||||
end
|
||||
|
||||
-- second return is join event and third is rank change event
|
||||
return inputs
|
||||
-- calling will attempt to add a new input
|
||||
return setmetatable(inputs,{__call=function(self,...) self.add(...) end})
|
||||
|
||||
-- to see examples look at GuiParts/test.lua
|
||||
|
||||
@@ -15,7 +15,7 @@ local mod_gui = require("mod-gui")
|
||||
local Gui = Gui -- this is to force gui to remain in the ENV
|
||||
|
||||
local left = {}
|
||||
left._left = {}
|
||||
left._prototype = {}
|
||||
|
||||
-- used for debugging
|
||||
function left.override_open(state)
|
||||
@@ -23,13 +23,14 @@ function left.override_open(state)
|
||||
end
|
||||
--- 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 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
|
||||
-- @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)
|
||||
if not is_type(obj,'table') then return end
|
||||
if not is_type(obj.name,'string') then return end
|
||||
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.toolbar.add(obj.name,obj.caption,obj.tooltip,obj.toggle)
|
||||
return obj
|
||||
@@ -122,7 +123,7 @@ function left.close(left_name)
|
||||
end
|
||||
|
||||
-- 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 _left = Gui.data.left[event.element.name]
|
||||
local left_flow = mod_gui.get_frame_flow(player)
|
||||
@@ -139,7 +140,7 @@ function left._left.open(event)
|
||||
end
|
||||
|
||||
-- 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 _left = Gui.data.left[event.element.name]
|
||||
local left_flow = mod_gui.get_frame_flow(player)
|
||||
@@ -167,8 +168,8 @@ function left._left.toggle(event)
|
||||
else
|
||||
left.style.visible = false
|
||||
end
|
||||
if open == false then player_return({'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
|
||||
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({'ExpGamingCore_Gui.cant-open',open},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} end
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
return left
|
||||
-- calling will attempt to add a new gui
|
||||
return setmetatable(left,{__call=function(self,...) self.add(...) end})
|
||||
@@ -12,10 +12,10 @@ local mod_gui = require("mod-gui")
|
||||
local Gui = Gui -- this is to force gui to remain in the ENV
|
||||
|
||||
local popup = {}
|
||||
popup._popup = {}
|
||||
popup._prototype = {}
|
||||
|
||||
function popup.load()
|
||||
popup._popup.close = Gui.inputs.add{
|
||||
popup._prototype.close = Gui.inputs.add{
|
||||
type='button',
|
||||
name='popup-close',
|
||||
caption='utility/set_bar_slot',
|
||||
@@ -28,13 +28,14 @@ end
|
||||
|
||||
--- Used to add a popup gui style
|
||||
-- @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)
|
||||
-- @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)
|
||||
if not is_type(obj,'table') then return end
|
||||
if not is_type(obj.name,'string') then return end
|
||||
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
|
||||
Gui.data('popup',name,obj)
|
||||
obj.name = name
|
||||
@@ -73,7 +74,7 @@ function popup.open(style,data,players)
|
||||
direction='vertical',
|
||||
style='image_frame'
|
||||
}
|
||||
_popup.close:draw(_frame)
|
||||
_popup.close(_frame)
|
||||
if is_type(_popup.draw,'function') then
|
||||
local success, err = pcall(_popup.draw,frame,data)
|
||||
if not success then error(err) end
|
||||
@@ -97,7 +98,7 @@ function popup.open(style,data,players)
|
||||
direction='vertical',
|
||||
style='image_frame'
|
||||
}
|
||||
thread.data.popup.close:draw(_frame)
|
||||
thread.data.popup.close(_frame)
|
||||
if is_type(thread.data.popup.draw,'function') then
|
||||
local success, err = pcall(thread.data.popup.draw,frame,thread.data.data)
|
||||
if not success then error(err) end
|
||||
@@ -106,11 +107,12 @@ function popup.open(style,data,players)
|
||||
end
|
||||
end
|
||||
|
||||
function popup._popup:add_left(obj)
|
||||
function popup._prototype:add_left(obj)
|
||||
obj.name = obj.name or self.name
|
||||
self.left = Gui.left.add(obj)
|
||||
end
|
||||
|
||||
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})
|
||||
@@ -20,7 +20,7 @@ local toolbar = {}
|
||||
-- @tparam string caption can be a sprite path or text to show
|
||||
-- @tparam string tooltip the help to show for the button
|
||||
-- @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)
|
||||
verbose('Created Toolbar Button: '..name)
|
||||
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
|
||||
if is_type(Role,'table') then
|
||||
if Role.allowed(player,name) then
|
||||
button:draw(toolbar_frame)
|
||||
button(toolbar_frame)
|
||||
end
|
||||
else button:draw(toolbar_frame) end
|
||||
else button(toolbar_frame) end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -53,4 +53,5 @@ end
|
||||
|
||||
toolbar.on_role_change = 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})
|
||||
@@ -18,7 +18,7 @@ local Role = {
|
||||
order={},
|
||||
flags={},
|
||||
actions={},
|
||||
meta={times={},groups={}},
|
||||
meta={times={},groups={},count=0},
|
||||
roles=setmetatable({},{
|
||||
__index=table.autokey,
|
||||
__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].lowest < index then self.meta.groups[role.group.name].lowest = index end
|
||||
if previous then setmetatable(previous.allow,{__index=role.allow}) end
|
||||
self.meta.count = self.meta.count+1
|
||||
role.index = index
|
||||
previous = role
|
||||
end
|
||||
@@ -487,4 +488,5 @@ script.on_event(defines.events.on_tick,function(event)
|
||||
end)
|
||||
|
||||
-- Module Return
|
||||
-- calling will attempt to define a new role
|
||||
return setmetatable(Role,{__call=function(tbl,...) tbl.define(...) end})
|
||||
@@ -4,7 +4,7 @@ commands.add_validation('player-rank',function(value,event)
|
||||
local player,err = commands.validate['player'](value)
|
||||
return err and commands.error(err)
|
||||
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)
|
||||
|
||||
commands.add_validation('player-rank-online',function(value,event)
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
[Server]
|
||||
[ExpGamingCore_Server]
|
||||
interface-description=Runs the given input from the script
|
||||
@@ -23,7 +23,7 @@ Server.add_module_to_interface('Server','ExpGamingCore.Server')
|
||||
--- Runs the given input from the script
|
||||
-- @command interface
|
||||
-- @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'}
|
||||
}, function(event,args)
|
||||
local callback = args.code
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
--- A full ranking system for factorio.
|
||||
-- @module ExpGamingPlayer.playerInfo
|
||||
-- @module ExpGamingPlayer.afkKick@4.0.0
|
||||
-- @author Cooldude2606
|
||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||
|
||||
local Game = require('FactorioStdLib.Game')
|
||||
local Gui = require('ExpGamingCore.Gui')
|
||||
local Role -- hanndled on load
|
||||
local Sync -- hanndled on load
|
||||
local Game = require('FactorioStdLib.Game@^0.8.0')
|
||||
local Gui = require('ExpGamingCore.Gui@^4.0.0')
|
||||
local Role -- ExpGamingCore.Role@^4.0.0
|
||||
local Sync -- ExpGamingCore.Sync@^4.0.0
|
||||
|
||||
function get_allowed_afk_time(player)
|
||||
local function get_allowed_afk_time(player)
|
||||
local role
|
||||
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 base = role.index or false
|
||||
if not base then return false end
|
||||
return (10/base)*count
|
||||
return (Role.meta.count/base)*count
|
||||
end
|
||||
|
||||
script.on_event(defines.events.on_tick,function(event)
|
||||
@@ -28,11 +28,11 @@ script.on_event(defines.events.on_tick,function(event)
|
||||
end
|
||||
end)
|
||||
|
||||
return {
|
||||
return setmetatable({
|
||||
get_allowed_afk_time=get_allowed_afk_time,
|
||||
on_init=function(self)
|
||||
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end
|
||||
if loaded_modules['ExpGamingCore.Sync'] then Sync = require('ExpGamingCore.Sync') end
|
||||
if loaded_modules['ExpGamingCore.Server'] then require(module_path..'/src/server',Sync) end
|
||||
if loaded_modules['ExpGamingCore.Role@^4.0.0'] then Role = require('ExpGamingCore.Role@^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.Server@^4.0.0'] then require(module_path..'/src/server',Sync,self) end
|
||||
end
|
||||
}
|
||||
},{__call=function(self,...) self.get_allowed_afk_time(...) end})
|
||||
@@ -1,4 +1,5 @@
|
||||
local Sync = Sync
|
||||
local get_allowed_afk_time = self
|
||||
local Server = require('ExpGamingCore.Server@^4.0.0')
|
||||
Event[defines.events.on_tick] = nil
|
||||
script.on_init(function(event)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
--- Desction <get from json>
|
||||
-- @module ThisModule@X.Y.Z
|
||||
-- @author <get from json>
|
||||
-- @license <get from json>
|
||||
--- Adds an inventory search that is proformed on a random player every 15 seconds
|
||||
-- @module ExpGamingPlayer.inventorySearch@4.0.0
|
||||
-- @author Cooldude2606
|
||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||
-- @alais ThisModule
|
||||
|
||||
-- Module Require
|
||||
@@ -54,9 +54,9 @@ local ThisModule = {
|
||||
|
||||
-- Function Define
|
||||
local function take_action(player,item_name,category)
|
||||
if category == 'low_items' then player_return({'inventory-search.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 == 'high_items' then player_return({'inventory-search.high',item_name},defines.textcolor.crit,player) Admin.temp_ban(player,'<server>','Found A Banned Item')
|
||||
if category == 'low_items' then player_return({'ExpGamingPlayer_inventorySearch.low',item_name},defines.textcolor.med,player)
|
||||
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({'ExpGamingPlayer_inventorySearch.high',item_name},defines.textcolor.crit,player) Admin.temp_ban(player,'<server>','Found A Banned Item')
|
||||
else return end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
--- A full ranking system for factorio.
|
||||
-- @module ExpGamingPlayer.playerInfo
|
||||
--- Used to give so common info on a player as a lua table or a frame.
|
||||
-- @module ExpGamingPlayer.playerInfo@4.0.0
|
||||
-- @author Cooldude2606
|
||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||
|
||||
local Game = require('FactorioStdLib.Game')
|
||||
local Gui = require('ExpGamingCore.Gui')
|
||||
local Role -- hanndled on load
|
||||
local Group -- hanndled on load
|
||||
local Game = require('FactorioStdLib.Game@^0.8.0')
|
||||
local Gui = require('ExpGamingCore.Gui@^4.0.0')
|
||||
local Role -- ExpGamingCore.Role@^4.0.0
|
||||
local Group -- ExpGamingCore.Group@^4.0.0
|
||||
|
||||
local function get_player_info(player,frame,add_cam)
|
||||
local player = Game.get_player(player)
|
||||
@@ -30,15 +30,15 @@ local function get_player_info(player,frame,add_cam)
|
||||
frame.style.width = 200
|
||||
if Role then frame.style.height = 275
|
||||
else frame.style.height = 260 end
|
||||
frame.add{type='label',caption={'player-info.name',_player.index,_player.name},style='caption_label'}
|
||||
local _online = {'player-info.no'}; if _player.online then _online = {'player-info.yes'} end
|
||||
frame.add{type='label',caption={'player-info.online',_online,tick_to_display_format(_player.online_time)}}
|
||||
local _admin = {'player-info.no'}; if _player.admin then _admin = {'player-info.yes'} end
|
||||
frame.add{type='label',caption={'player-info.admin',_admin}}
|
||||
frame.add{type='label',caption={'ExpGamingPlayer_playerInfo.name',_player.index,_player.name},style='caption_label'}
|
||||
local _online = {'ExpGamingPlayer_playerInfo.no'}; if _player.online then _online = {'ExpGamingPlayer_playerInfo.yes'} end
|
||||
frame.add{type='label',caption={'ExpGamingPlayer_playerInfo.online',_online,tick_to_display_format(_player.online_time)}}
|
||||
local _admin = {'ExpGamingPlayer_playerInfo.no'}; if _player.admin then _admin = {'ExpGamingPlayer_playerInfo.yes'} end
|
||||
frame.add{type='label',caption={'ExpGamingPlayer_playerInfo.admin',_admin}}
|
||||
if Role then
|
||||
frame.add{type='label',caption={'player-info.group',_player.group}}
|
||||
frame.add{type='label',caption={'player-info.role',_player.highest_role}}
|
||||
frame.add{type='label',caption={'player-info.roles',table.concat(_player.roles,', ')}}
|
||||
frame.add{type='label',caption={'ExpGamingPlayer_playerInfo.group',_player.group}}
|
||||
frame.add{type='label',caption={'ExpGamingPlayer_playerInfo.role',_player.highest_role}}
|
||||
frame.add{type='label',caption={'ExpGamingPlayer_playerInfo.roles',table.concat(_player.roles,', ')}}
|
||||
end
|
||||
if add_cam then
|
||||
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({
|
||||
get_player_info=get_player_info,
|
||||
on_init=function(self)
|
||||
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end
|
||||
if loaded_modules['ExpGamingCore.Group'] then Group = require('ExpGamingCore.Group') end
|
||||
if loaded_modules['ExpGamingCore.Role@^4.0.0'] then Role = require('ExpGamingCore.Role@^4.0.0') end
|
||||
if loaded_modules['ExpGamingCore.Group@^4.0.0'] then Group = require('ExpGamingCore.Group@^4.0.0') end
|
||||
end
|
||||
},{
|
||||
__call=function(self,...) self.get_player_info(...) end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
--- A full ranking system for factorio.
|
||||
-- @module ExpGamingPlayer.playerList
|
||||
-- @module ExpGamingPlayer.playerList@4.0.0
|
||||
-- @author Cooldude2606
|
||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||
|
||||
|
||||
@@ -1,24 +1,34 @@
|
||||
--[[
|
||||
Explosive Gaming
|
||||
--- Adds a poll gui into the game for quick polls (default 90 seconds)
|
||||
-- @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.
|
||||
Contact a member of management on our discord to seek permission to use our code.
|
||||
Any changes that you may make to the code are yours but that does not make the script yours.
|
||||
Discord: https://discord.gg/r6dC2uK
|
||||
]]
|
||||
--Please Only Edit Below This Line-----------------------------------------------------------
|
||||
-- Module Require
|
||||
local Server = require('ExpGamingCore.Server@^4.0.0')
|
||||
local Gui = require('ExpGamingCore.Gui@^4.0.0')
|
||||
local Role -- ExpGamingCore.Server@^4.0.0
|
||||
|
||||
-- Local Varibles
|
||||
local poll_time_out = 90 -- In seconds
|
||||
|
||||
local function _polls(reset)
|
||||
global.addons = not reset and global.addons or {}
|
||||
global.addons.polls = not reset and global.addons.polls or {active={},old={}}
|
||||
return global.addons.polls
|
||||
end
|
||||
-- Module Define
|
||||
local module_verbose = false
|
||||
local ThisModule = {
|
||||
on_init=function()
|
||||
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 poll = _polls().active[uuid]
|
||||
local poll = global.active[uuid]
|
||||
if not poll then return end
|
||||
local highest = {nil,-1}
|
||||
local _votes = {}
|
||||
@@ -32,15 +42,15 @@ function _poll_end(self)
|
||||
poll.votes = _votes
|
||||
poll.answers = nil
|
||||
poll.voted = nil
|
||||
table.insert(_polls().old,poll)
|
||||
_polls().active[uuid] = nil
|
||||
table.insert(global.old,poll)
|
||||
global.active[uuid] = nil
|
||||
game.print({'polls.end',poll.question},defines.textcolor.info)
|
||||
game.print({'polls.winner',highest[1]},defines.textcolor.info)
|
||||
end
|
||||
|
||||
local function _poll_data(question,answers)
|
||||
local poll = {
|
||||
uuid=Server.new_uuid(),
|
||||
uuid=Server.uuid(),
|
||||
question=question,
|
||||
answers=answers or {'None'},
|
||||
votes={},
|
||||
@@ -51,37 +61,14 @@ 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
|
||||
_polls().active[poll.uuid]=poll
|
||||
global.active[poll.uuid]=poll
|
||||
return poll.uuid
|
||||
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 opptions = {'Please Select An Opption'}
|
||||
local uuid = root_frame.name
|
||||
local poll = _polls().active[uuid]
|
||||
local poll = global.active[uuid]
|
||||
if not poll then return {'Invalid Poll'} end
|
||||
for _,answer in pairs(poll.answers) do
|
||||
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 uuid = element.parent.name
|
||||
local poll = _polls().active[uuid]
|
||||
local poll = global.active[uuid]
|
||||
if not poll then return end
|
||||
if poll.voted[player.index] and poll.voted[player.index] > 1 then
|
||||
local old_vote = poll.voted[player.index]
|
||||
@@ -112,7 +99,7 @@ local prev = Gui.inputs.add{
|
||||
local parent = event.element.parent
|
||||
local index = parent.parent.current_index.caption
|
||||
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.title.title.caption = 'Viewing Poll: '.._index
|
||||
draw_poll(parent.parent.poll_area)
|
||||
@@ -126,7 +113,7 @@ local next = Gui.inputs.add{
|
||||
local parent = event.element.parent
|
||||
local index = parent.parent.current_index.caption
|
||||
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.title.title.caption = 'Viewing Poll: '.._index
|
||||
draw_poll(parent.parent.poll_area)
|
||||
@@ -202,7 +189,7 @@ Gui.popup.add{
|
||||
frame.style.right_padding = 5
|
||||
frame.style.bottom_padding = 5
|
||||
local uuid = data.uuid
|
||||
local poll = _polls().active[uuid]
|
||||
local poll = global.active[uuid]
|
||||
if not poll then return end
|
||||
local flow = frame.add{
|
||||
type='flow',
|
||||
@@ -240,7 +227,7 @@ Gui.popup.add{
|
||||
local btn = next:draw(title)
|
||||
btn.style.width = 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)
|
||||
btn.style.width = 20
|
||||
btn.style.height = 20
|
||||
@@ -253,8 +240,12 @@ Gui.popup.add{
|
||||
draw_poll(flow)
|
||||
end,
|
||||
can_open=function(player)
|
||||
if #_polls().old > 0 then return true
|
||||
elseif Role.allowed(player,'create-poll') then return true
|
||||
if #global.old > 0 then return true
|
||||
elseif Role and Role.allowed(player,'create-poll') or player.admin then return true
|
||||
else return {'polls.no-poll'} end
|
||||
end
|
||||
}
|
||||
-- Event Handlers Define
|
||||
|
||||
-- Module Return
|
||||
return ThisModule
|
||||
19
modules/ExpGamingPlayer/polls/softmod.json
Normal file
19
modules/ExpGamingPlayer/polls/softmod.json
Normal 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"
|
||||
}
|
||||
@@ -99,6 +99,25 @@
|
||||
"FactorioStdLib.Game": "^0.8.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": {}
|
||||
|
||||
Reference in New Issue
Block a user