Minnor fixes around the place

This commit is contained in:
Cooldude2606
2018-10-13 00:10:17 +01:00
parent 7cb517e4aa
commit 43df8e6a56
9 changed files with 57 additions and 24 deletions

View File

@@ -57,17 +57,49 @@ 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{'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,
['string-len']=function(value,event,max)
local rtn = tostring(value) and tostring(value):len() <= max and tostring(value) or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-string-len'} end return rtn end,
['number']=function(value,event)
local rtn = tonumber(value) or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-number'} end return rtn end,
['number-int']=function(value,event)
local rtn = tonumber(value) and math.floor(tonumber(value)) or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-number'} end return rtn end,
['number-range']=function(value,event,min,max)
local rtn = tonumber(value) and tonumber(value) > min and tonumber(value) <= max and tonumber(value) or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-number-range'} end return rtn end,
['number-range-int']=function(value,event,min,max)
local rtn = tonumber(value) and math.floor(tonumber(value)) > min and math.floor(tonumber(value)) <= max and math.floor(tonumber(value)) or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-number-range'} end return rtn end,
['player']=function(value,event)
local rtn = Game.get_player(value) or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-player',value} end return rtn end,
['player-online']=function(value,event)
local player,err = commands.validate['player'](value)
if err then return commands.error(err) end
local rtn = player.conected and player or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-player-online'} end return rtn end,
['player-alive']=function(value,event)
local player,err = commands.validate['player-online'](value)
if err then return commands.error(err) end
local rtn = player.character and player.character.health > 0 and player or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-player-alive'} end return rtn end,
['player-rank']=function(value,event)
local player,err = commands.validate['player'](value)
if err then return commands.error(err) end
local rtn = player.admin and Game.get_player(event).admin and player or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-player-rank'} end return rtn 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,
}
--- Adds a function to the validation list
-- @tparam string name the name of the validation
@@ -190,7 +222,8 @@ 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({'ExpGamingCore_Command.'..err,command.name,commands.format_inputs(data)},defines.textcolor.high)
if is_type(err,'table') then table.insert(err,command.name) table.insert(err,commands.format_inputs(data))
player_return(err,defines.textcolor.high) else player_return({'ExpGamingCore_Command.invalid-inputs',command.name,commands.format_inputs(data)},defines.textcolor.high) end
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

View File

@@ -147,7 +147,7 @@ function left._prototype:close(player)
left_flow[self.name].style.visible = false
local count = 0
for _,child in pairs(left_flow.children) do if child.style.visible then count = count+1 end if count > 1 then break end end
if count == 1 then left_flow['gui-left-hide'].style.visible = false end
if count == 1 and left_flow['gui-left-hide'] then left_flow['gui-left-hide'].style.visible = false end
end
--- When the gui is first made or is updated this function is called, used by the script
@@ -203,7 +203,7 @@ function left._prototype:toggle(player)
left.style.visible = false
local count = 0
for _,child in pairs(left_flow.children) do if child.style.visible then count = count+1 end if count > 1 then break end end
if count == 1 then left_flow['gui-left-hide'].style.visible = false end
if count == 1 and left_flow['gui-left-hide'] then left_flow['gui-left-hide'].style.visible = false end
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

View File

@@ -483,7 +483,6 @@ end)
script.on_event(defines.events.on_player_joined_game,function(event)
local player = Game.get_player(event)
log(serpent.line(event))
local highest = Role.get_highest(player) or Role.meta.default
Group.assign(player,highest.group)
player.tag=highest.tag

View File

@@ -2,9 +2,9 @@ local Role = self
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{'ExpGamingCore_Command.error-player-rank'}
if err then return commands.error(err) end
local rtn = Role.get_highest(player).index > Role.get_highest(event).index and player or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-player-rank'} end return rtn
end)
commands.add_validation('player-rank-online',function(value,event)

View File

@@ -12,7 +12,7 @@ local Game = require('FactorioStdLib.Game@^0.8.0')
local module_verbose = false
local ThisModule = {
on_init=function()
if loaded_modules['ExpGamingCore.Sync^4.0.0'] then require(module_path..'/src/sync',{Gui=Gui}) end
if loaded_modules['ExpGamingCore.Sync@^4.0.0'] then require(module_path..'/src/sync') end
end
}

View File

@@ -1,5 +1,5 @@
local Sync = require('ExpGamingCore.Sync@^4.0.0')
local Gui = Gui
local Gui = require('ExpGamingCore.Gui@^4.0.0')
Sync.add_to_gui(Gui.inputs.add_button('readme-sync-guildlines','View Guildlines','View the guildlines in the readme',function(player,element)
Gui.center.open_tab(player,'readme','guildlines')

View File

@@ -38,7 +38,7 @@ local function get_player_info(player,frame,add_cam)
if Role then
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,', ')}}
frame.add{type='label',caption={'ExpGamingPlayer-playerInfo.roles',table.concat(_player.roles,', ')}}.style.single_line = false
end
if add_cam then
Gui.cam_link{entity=player.character,frame=frame,width=200,height=150,zoom=0.5,respawn_open=true}

View File

@@ -29,3 +29,4 @@ effect-reload-map=Reload Minimap
effect-kill-biters=Kill Biters
effect-crc=Force CRC Check
effect-reset-force=Reset Force
effect-clear-pollution=Clear Pollution

View File

@@ -78,11 +78,11 @@ script.on_event({defines.events.on_built_entity,on_robot_built_entity}, function
local surface = entity.surface
if entites[entity.name] then
local box = entity.prototype.collision_box
local size = math.abs(box.left_top.x-box.right_bottom.x)*math.abs(box.left_top.y-box.right_bottom.y)
local size = math.ceil(box.right_bottom.x)*math.ceil(box.right_bottom.y)
for x = box.left_top.x,box.right_bottom.x do for y = box.left_top.y,box.right_bottom.y do
local pos = {x=x,y=y}
local pos = {x=entity.position.x+x,y=entity.position.y+y}
local tile = surface.get_tile(pos).name
if paths[tile] and math.random() < paths[tile][1]*size/(-10) then
if paths[tile] and math.random() < paths[tile][1]*size/(-2) then
ThisModule.down_grade(surface,pos)
end
end end