Join co-located player colors
This commit is contained in:
parent
e200ddcaad
commit
cb1b5006b9
3 changed files with 71 additions and 4 deletions
|
|
@ -291,6 +291,42 @@ test("selecting a parked colour changes to its room", function()
|
|||
currentRoom, setEditorRoomName = oldCurrentRoom, oldSetEditorRoomName
|
||||
end)
|
||||
|
||||
test("co-located colours join the active player selection", function()
|
||||
local function player(x, y)
|
||||
local entity = {x = x, y = y, switched = false}
|
||||
function entity:getGridPos() return {x = self.x, y = self.y} end
|
||||
function entity:playSwitchSound(success) self.switched = success end
|
||||
return entity
|
||||
end
|
||||
local room = {
|
||||
name = "a",
|
||||
player = {red = player(3, 4), green = player(3, 4), blue = player(6, 4)},
|
||||
activeColors = {red = true, green = false, blue = false},
|
||||
colorsPlayerHas = {"red", "green", "blue"},
|
||||
}
|
||||
function room:getPossibleColors() return self.colorsPlayerHas end
|
||||
function room:getActiveColors()
|
||||
local colors = {}
|
||||
for _, color in ipairs(self.colorsPlayerHas) do
|
||||
if self.activeColors[color] then table.insert(colors, color) end
|
||||
end
|
||||
return colors
|
||||
end
|
||||
function room:colorIsActive(color) return self.activeColors[color] end
|
||||
function room:setActiveColor(color, value) self.activeColors[color] = value end
|
||||
local world = setmetatable({
|
||||
levels = {a = room}, roomByName = {a = {name = "a", x = 1, y = 1}},
|
||||
}, {__index = World})
|
||||
world.flushRuntime = function() end
|
||||
|
||||
assertTrue(world:switchPlayerColor(room, "green"))
|
||||
assertTrue(room.activeColors.red and room.activeColors.green,
|
||||
"co-located red and green did not become active together")
|
||||
assertTrue(world:switchPlayerColor(room, "blue"))
|
||||
assertTrue(room.activeColors.blue and not room.activeColors.red and not room.activeColors.green,
|
||||
"separated blue player should still select by itself")
|
||||
end)
|
||||
|
||||
test("one run cannot terminate at two different switches", function()
|
||||
local second = switch("red", 1, 2)
|
||||
local world, _, roomB = makeWorld(second)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue