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

@ -440,8 +440,24 @@ function Room:switchPlayerColorLocal(color)
local targetPlayer = self.player[color]
if not targetPlayer then return false end
local canSwitch = not self:onlyColorIsActive(color)
if canSwitch then
local activeColors = self:getActiveColors()
local canJoin = not self:colorIsActive(color) and #activeColors > 0
if canJoin then
local target = targetPlayer:getGridPos()
for _, activeColor in ipairs(activeColors) do
local activePlayer = self.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 not self:onlyColorIsActive(color)
if canJoin then
self:setActiveColor(color, true)
elseif canSwitch then
for _, c in ipairs(self:getPossibleColors()) do
self:setActiveColor(c, c == color)
end