Test regular door occupancy resolution

This commit is contained in:
Your Name 2026-08-12 00:30:41 -04:00
parent 17140fe39f
commit 23fe9d1c58

View file

@ -261,6 +261,40 @@ test("circuit resolution passes doorway occupancy to a wired door", function()
assertFalse(wiredDoor.canClose, "resolver omitted player doorway obstruction") assertFalse(wiredDoor.canClose, "resolver omitted player doorway obstruction")
end) end)
test("room switch resolution keeps a regular door open around an occupant", function()
local oldLove, oldLoadSprite = love, loadSprite
love = {audio = {newSource = function()
return {stop = function() end, play = function() end}
end}}
loadSprite = function()
return {getWidth = function() return 16 end, getHeight = function() return 16 end}
end
require "room"
local door = Door:new(2, 2, "red")
local player, block = {x = 2, y = 2}, {x = 1, y = 1}
function player:occupiesCell(cell) return self.x == cell.x and self.y == cell.y end
function block:occupiesCell(cell) return self.x == cell.x and self.y == cell.y end
function block:canPassOver() return false end
local room = setmetatable({
player = {blue = player}, doors = {door},
collideables = {red = {door}, green = {block}, blue = {}},
}, {__index = Room})
room.switchCheck = function() return {red = true} end
room:resolveSwitchesAndDoors()
assertFalse(door.locked, "switch did not open regular door")
room.switchCheck = function() return {red = false} end
room:resolveSwitchesAndDoors()
assertFalse(door.locked, "regular door shut through player during room resolution")
room.player.blue.x, room.player.blue.y = 1, 1
room.collideables.green[1].x, room.collideables.green[1].y = 2, 2
room:resolveSwitchesAndDoors()
assertFalse(door.locked, "regular door shut through collidable during room resolution")
room.collideables.green[1].x, room.collideables.green[1].y = 1, 1
room:resolveSwitchesAndDoors()
assertTrue(door.locked, "regular door did not close once clear")
love, loadSprite = oldLove, oldLoadSprite
end)
test("selecting a parked colour changes to its room", function() test("selecting a parked colour changes to its room", function()
local function player() local function player()
local entity = {switched = false} local entity = {switched = false}