mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-18 03:21:47 +02:00
Merge pull request #1198 from grilledham/landfill_remover_rank
Require auto trusted to use landfill remover.
This commit is contained in:
commit
1111e2e1a0
@ -3,15 +3,22 @@
|
||||
-- Use the decon planner within range of the landfill to remove it
|
||||
|
||||
local Event = require 'utils.event'
|
||||
local Rank = require 'features.rank_system'
|
||||
local Ranks = require 'resources.ranks'
|
||||
local table = require 'utils.table'
|
||||
local math = require 'utils.math'
|
||||
local config = global.config.landfill_remover
|
||||
|
||||
local Public = {}
|
||||
|
||||
local rank_too_low_message = {'landfill_remover.rank_too_low'}
|
||||
Public.rank_too_low_message =rank_too_low_message
|
||||
|
||||
local floor = math.floor
|
||||
local ceil = math.ceil
|
||||
local fast_remove = table.fast_remove
|
||||
|
||||
local collision_mask = {'floor-layer', 'object-layer'}
|
||||
local collision_mask = {'floor-layer', 'object-layer', 'resource-layer'}
|
||||
local whitelist = defines.deconstruction_item.tile_filter_mode.whitelist
|
||||
local entity_whitelist = defines.deconstruction_item.entity_filter_mode.whitelist
|
||||
|
||||
@ -153,6 +160,11 @@ Event.add(
|
||||
return
|
||||
end
|
||||
|
||||
if Rank.less_than(player.name, Ranks.auto_trusted) then
|
||||
player.print(rank_too_low_message)
|
||||
return
|
||||
end
|
||||
|
||||
local count_entities_filtered = surface.count_entities_filtered
|
||||
local tiles_to_add = {}
|
||||
local revert_tile = config.revert_tile or 'water-mud'
|
||||
@ -179,3 +191,5 @@ Event.add(
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
return Public
|
||||
|
@ -2,6 +2,9 @@ local Declare = require 'utils.test.declare'
|
||||
local EventFactory = require 'utils.test.event_factory'
|
||||
local Assert = require 'utils.test.assert'
|
||||
local Helper = require 'utils.test.helper'
|
||||
local Rank = require 'features.rank_system'
|
||||
local Ranks = require 'resources.ranks'
|
||||
local LandfillRemover = require 'features.landfill_remover'
|
||||
|
||||
local main_inventory = defines.inventory.character_main
|
||||
local config = global.config.landfill_remover
|
||||
@ -697,5 +700,46 @@ Declare.module(
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
Declare.test(
|
||||
'can not remove landfill when guest',
|
||||
function(context)
|
||||
-- Arrange
|
||||
local player = context.player
|
||||
local surface = player.surface
|
||||
local cursor = setup_player_with_valid_deconstruction_planner(player)
|
||||
local position = {2, 2}
|
||||
local area = {{2.1, 2.1}, {2.9, 2.9}}
|
||||
surface.set_tiles({{name = 'landfill', position = position}})
|
||||
|
||||
player.admin = false
|
||||
local old_rank = Rank.get_player_rank(player.name)
|
||||
Rank.set_player_rank(player.name, Ranks.guest)
|
||||
|
||||
context:add_teardown(function()
|
||||
player.admin = true
|
||||
Rank.set_player_rank(player.name, old_rank)
|
||||
end)
|
||||
|
||||
local messages = {}
|
||||
|
||||
Helper.modify_lua_object(context, player, 'print', function(text)
|
||||
messages[#messages+1] = text
|
||||
end)
|
||||
|
||||
Helper.modify_lua_object(context, game, 'get_player', function()
|
||||
return player
|
||||
end)
|
||||
|
||||
-- Act
|
||||
EventFactory.do_player_deconstruct_area(cursor, player, area)
|
||||
|
||||
-- Assert
|
||||
local tile = surface.get_tile(position[1], position[2])
|
||||
Assert.equal('landfill', tile.name)
|
||||
|
||||
Assert.array_contains(messages, LandfillRemover.rank_too_low_message)
|
||||
end
|
||||
)
|
||||
end
|
||||
)
|
||||
|
@ -186,3 +186,6 @@ empty_corpse=[color=red][Corpse][/color]Your corpse was empty and has been remov
|
||||
|
||||
[dump_offline_inventories]
|
||||
inventory_location=[color=blue][Corpse][/color] __1__ has been offline __2__ minutes. Their inventory is now available at [gps=__3__,__4__,__5__]
|
||||
|
||||
[landfill_remover]
|
||||
rank_too_low=You must be auto trusted or above to use the deconstruction planner on landfill.
|
||||
|
@ -48,6 +48,16 @@ function Public.table_equal(a, b)
|
||||
end
|
||||
end
|
||||
|
||||
function Public.array_contains(array, item)
|
||||
for _, v in pairs(array) do
|
||||
if v == item then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
error('array does not contain ' .. _G.dump(item), 2)
|
||||
end
|
||||
|
||||
function Public.is_true(condition, optional_message)
|
||||
if not condition then
|
||||
error(optional_message or 'condition was not true', 2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user