Prevent doors closing through occupants
This commit is contained in:
parent
bf09a8844a
commit
9731202739
5 changed files with 108 additions and 6 deletions
|
|
@ -192,6 +192,66 @@ test("an orphaned stub at a door does not block a valid switch run", function()
|
|||
assertTrue(wiredDoor.powered)
|
||||
end)
|
||||
|
||||
test("real wired and regular doors stay open while any player or collidable blocks the doorway", function()
|
||||
local oldLoadSprite = loadSprite
|
||||
loadSprite = function()
|
||||
return {getWidth = function() return 16 end, getHeight = function() return 16 end}
|
||||
end
|
||||
require "color"
|
||||
require "wired_door"
|
||||
|
||||
local function occupant(x, y)
|
||||
local entity = {x = x, y = y}
|
||||
function entity:occupiesCell(cell) return self.x == cell.x and self.y == cell.y end
|
||||
function entity:canPassOver() return false end
|
||||
return entity
|
||||
end
|
||||
|
||||
local wired = WiredDoor:new(2, 2, "blue", "circuit_a")
|
||||
local ordinary = Door:new(4, 2, "red")
|
||||
local room = {
|
||||
player = {green = occupant(2, 2)},
|
||||
collideables = {
|
||||
red = {ordinary}, green = {occupant(4, 2)}, blue = {wired},
|
||||
},
|
||||
}
|
||||
local world = setmetatable({}, {__index = World})
|
||||
|
||||
wired:setPowered(true)
|
||||
assertFalse(wired.locked, "wired door did not open")
|
||||
assertFalse(world:doorCanClose(room, wired), "green player did not block blue wired door")
|
||||
wired:setPowered(false, world:doorCanClose(room, wired))
|
||||
assertFalse(wired.locked, "wired door shut on player")
|
||||
|
||||
ordinary:setColors({red = true})
|
||||
assertFalse(ordinary.locked, "regular door did not open")
|
||||
assertFalse(world:doorCanClose(room, ordinary), "green collidable did not block red regular door")
|
||||
ordinary:setColors({red = false}, world:doorCanClose(room, ordinary))
|
||||
assertFalse(ordinary.locked, "regular door shut on collidable")
|
||||
|
||||
room.player.green.x, room.player.green.y = 1, 1
|
||||
room.collideables.green[1].x, room.collideables.green[1].y = 1, 1
|
||||
wired:setPowered(false, world:doorCanClose(room, wired))
|
||||
ordinary:setColors({red = false}, world:doorCanClose(room, ordinary))
|
||||
assertTrue(wired.locked, "wired door did not close once clear")
|
||||
assertTrue(ordinary.locked, "regular door did not close once clear")
|
||||
loadSprite = oldLoadSprite
|
||||
end)
|
||||
|
||||
test("circuit resolution passes doorway occupancy to a wired door", function()
|
||||
local world, roomA, _, wiredDoor = makeWorld()
|
||||
local player = {x = 1, y = 1}
|
||||
function player:occupiesCell(cell) return self.x == cell.x and self.y == cell.y end
|
||||
roomA.player.green = player
|
||||
function wiredDoor:setPowered(powered, canClose)
|
||||
self.powered, self.canClose = powered, canClose
|
||||
end
|
||||
|
||||
world:resolveCircuits()
|
||||
assertFalse(wiredDoor.powered, "unpressed switch unexpectedly powered door")
|
||||
assertFalse(wiredDoor.canClose, "resolver omitted player doorway obstruction")
|
||||
end)
|
||||
|
||||
test("selecting a parked colour changes to its room", function()
|
||||
local function player()
|
||||
local entity = {switched = false}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue