Join co-located player colors

This commit is contained in:
Your Name 2026-08-12 00:30:13 -04:00
parent e200ddcaad
commit cb1b5006b9
3 changed files with 71 additions and 4 deletions

View file

@ -731,8 +731,23 @@ function World:switchPlayerColor(room, color)
return true
end
local activeColors = room:getActiveColors()
local canSwitch = #activeColors ~= 1 or activeColors[1] ~= color
if canSwitch then
local canJoin = not room:colorIsActive(color) and #activeColors > 0
if canJoin then
local target = player:getGridPos()
for _, activeColor in ipairs(activeColors) do
local activePlayer = room.player[activeColor]
local activePos = activePlayer and activePlayer:getGridPos()
if not activePos or activePos.x ~= target.x or activePos.y ~= target.y then
canJoin = false
break
end
end
end
local canSwitch = canJoin or #activeColors ~= 1 or activeColors[1] ~= color
if canJoin then
room:setActiveColor(color, true)
elseif canSwitch then
for _, possibleColor in ipairs(room:getPossibleColors()) do
room:setActiveColor(possibleColor, possibleColor == color)
end