Fix 2-player placement zone and game.over null crash
BoardShapeGenerator: 2-player rectangle now assigns one row per seat (row 0 for seat 0, top row for seat 1), restoring the original 1v1 behaviour. 3-4 player lobbies keep the two-row zones for extra placement room. Game.gd game.over: server sends playerOutcomes:null for 2-player games. d.get(key, default) returns null when the key exists with value null, so 'null as Array' crashed. Use 'is Array' guard to safely fall back to an empty array when the field is absent or null. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -584,7 +584,8 @@ func _on_server_push(type: String, payload: Variant) -> void:
|
|||||||
var wc : String = str(d.get("winCondition", ""))
|
var wc : String = str(d.get("winCondition", ""))
|
||||||
var wd : int = int(d.get("winnerRankDelta", 0))
|
var wd : int = int(d.get("winnerRankDelta", 0))
|
||||||
var ld : int = int(d.get("loserRankDelta", 0))
|
var ld : int = int(d.get("loserRankDelta", 0))
|
||||||
var outcomes : Array = d.get("playerOutcomes", []) as Array
|
var _raw_outcomes = d.get("playerOutcomes")
|
||||||
|
var outcomes : Array = _raw_outcomes as Array if _raw_outcomes is Array else []
|
||||||
session_id = "" # Clear so _on_auth_reconnect doesn't resend game.ready for an ended game
|
session_id = "" # Clear so _on_auth_reconnect doesn't resend game.ready for an ended game
|
||||||
state = {} # Clear stale state so a new GameScreen calls send_ready() on the next match
|
state = {} # Clear stale state so a new GameScreen calls send_ready() on the next match
|
||||||
game_over.emit(winner, wc, wd, ld, outcomes)
|
game_over.emit(winner, wc, wd, ld, outcomes)
|
||||||
|
|||||||
@@ -43,14 +43,24 @@ public static class BoardShapeGenerator
|
|||||||
|
|
||||||
var zones = new Dictionary<int, HashSet<Coord>>();
|
var zones = new Dictionary<int, HashSet<Coord>>();
|
||||||
|
|
||||||
// Seat 0 = bottom 2 rows
|
// 2-player: one placement row each (preserves original 1v1 behavior).
|
||||||
zones[0] = CoordsInRows(0, 1, w);
|
// 3-4 player: two rows/cols per seat to give more placement room.
|
||||||
if (playerCount >= 2)
|
if (playerCount <= 2)
|
||||||
zones[1] = CoordsInRows(h - 2, h - 1, w);
|
{
|
||||||
if (playerCount >= 3)
|
zones[0] = CoordsInRows(0, 0, w);
|
||||||
zones[2] = CoordsInCols(0, 1, h);
|
if (playerCount >= 2)
|
||||||
if (playerCount >= 4)
|
zones[1] = CoordsInRows(h - 1, h - 1, w);
|
||||||
zones[3] = CoordsInCols(w - 2, w - 1, h);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
zones[0] = CoordsInRows(0, 1, w);
|
||||||
|
if (playerCount >= 2)
|
||||||
|
zones[1] = CoordsInRows(h - 2, h - 1, w);
|
||||||
|
if (playerCount >= 3)
|
||||||
|
zones[2] = CoordsInCols(0, 1, h);
|
||||||
|
if (playerCount >= 4)
|
||||||
|
zones[3] = CoordsInCols(w - 2, w - 1, h);
|
||||||
|
}
|
||||||
|
|
||||||
// Return a new Board with the zones attached (Board is a reference type with mutable Tiles
|
// Return a new Board with the zones attached (Board is a reference type with mutable Tiles
|
||||||
// so we create a wrapper that shares the same Tiles dictionary).
|
// so we create a wrapper that shares the same Tiles dictionary).
|
||||||
|
|||||||
Reference in New Issue
Block a user