Support sparse (non-rectangular) boards and N-player camera
Sparse board fixes: - _bfs_path: skip neighbour tiles not present in _tile_bodies (e.g. Cross arm corners), preventing movement through void gaps on non-rectangular boards - _valid_move_tiles: same tile-existence guard before adding candidates - _attack_range_tiles: same guard for ranged-reach highlights Camera improvements: - Auto-scale _cam_distance from board size (max_dim × 1.5, clamped 12–30) so RadialStar, HexRing and other large boards are fully visible on load - Camera orientation now uses board.startingZones centroid to derive yaw for any seat index, enabling correct "look from behind" for seats 2–5 in Cross, Triangular, RadialStar, and HexRing layouts; falls back to P1/P2 logic when zones are absent (legacy 1v1 games) - Pan limits scale with board size (board_half_extent clamped 6–20) instead of hardcoded ±6 world units, allowing full pan across large boards 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:
@@ -809,8 +809,9 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
var fwd := Vector3(_camera_rig.global_basis.z.x, 0,
|
||||
_camera_rig.global_basis.z.z).normalized()
|
||||
_cam_pivot += right + fwd * -delta.y * ps
|
||||
_cam_pivot.x = clampf(_cam_pivot.x, -6.0, 6.0)
|
||||
_cam_pivot.z = clampf(_cam_pivot.z, -6.0, 6.0)
|
||||
var pan_lim := clampf(max(Game.board_width(), Game.board_height()) * TILE_SPACING * 0.5, 6.0, 20.0)
|
||||
_cam_pivot.x = clampf(_cam_pivot.x, -pan_lim, pan_lim)
|
||||
_cam_pivot.z = clampf(_cam_pivot.z, -pan_lim, pan_lim)
|
||||
_apply_camera()
|
||||
|
||||
elif event is InputEventScreenTouch:
|
||||
@@ -847,8 +848,9 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
var fwd := Vector3(_camera_rig.global_basis.z.x, 0,
|
||||
_camera_rig.global_basis.z.z).normalized()
|
||||
_cam_pivot += right + fwd * cdelta.y * ps
|
||||
_cam_pivot.x = clampf(_cam_pivot.x, -6.0, 6.0)
|
||||
_cam_pivot.z = clampf(_cam_pivot.z, -6.0, 6.0)
|
||||
var pan_lim2 := clampf(max(Game.board_width(), Game.board_height()) * TILE_SPACING * 0.5, 6.0, 20.0)
|
||||
_cam_pivot.x = clampf(_cam_pivot.x, -pan_lim2, pan_lim2)
|
||||
_cam_pivot.z = clampf(_cam_pivot.z, -pan_lim2, pan_lim2)
|
||||
_apply_camera()
|
||||
|
||||
|
||||
@@ -1851,6 +1853,8 @@ func _bfs_path(from: Vector2i, to: Vector2i, blocked: Dictionary) -> Array[Vecto
|
||||
var nxt := cur + d
|
||||
if nxt.x < 0 or nxt.x >= bw or nxt.y < 0 or nxt.y >= bh:
|
||||
continue
|
||||
if not _tile_bodies.has("%d,%d" % [nxt.x, nxt.y]):
|
||||
continue
|
||||
if visited.has(nxt):
|
||||
continue
|
||||
if blocked.has(nxt) and nxt != to:
|
||||
@@ -2200,6 +2204,7 @@ func _valid_move_tiles(unit: Dictionary) -> Array:
|
||||
if mp <= 0: return results
|
||||
for tx in range(bw):
|
||||
for ty in range(bh):
|
||||
if not _tile_bodies.has("%d,%d" % [tx, ty]): continue
|
||||
var dist : int = abs(tx - ux) + abs(ty - uy)
|
||||
if dist == 0 or dist > mp: continue
|
||||
if Game.get_tile(tx, ty).get("occupantId"): continue
|
||||
@@ -2266,6 +2271,7 @@ func _attack_range_tiles(unit: Dictionary) -> Array:
|
||||
var bh : int = Game.board_height()
|
||||
for tx in range(bw):
|
||||
for ty in range(bh):
|
||||
if not _tile_bodies.has("%d,%d" % [tx, ty]): continue
|
||||
var dist : int = abs(tx - ux) + abs(ty - uy)
|
||||
if dist >= min_r and dist <= max_r:
|
||||
results.append(Vector2i(tx, ty))
|
||||
@@ -3535,19 +3541,41 @@ func _on_state_updated(state: Dictionary) -> void:
|
||||
_local_is_p1 = Auth.user_id.to_lower() == p1_id.to_lower()
|
||||
if not _camera_oriented and not p1_id.is_empty():
|
||||
_camera_oriented = true
|
||||
var bh := float(Game.board_height())
|
||||
# Shift cam_pivot toward the opponent's side (30 % of board half-length)
|
||||
# so the player's own row appears in the lower-middle of the screen,
|
||||
# above the hand panel — not hidden behind it.
|
||||
var pivot_offset := (bh - 1.0) * 0.3
|
||||
if _local_is_p1:
|
||||
# P1 row is at world -Z. Camera looks from -Z toward +Z → yaw=180°.
|
||||
# Shift pivot toward world -Z so P1's row is NOT at the very bottom.
|
||||
_cam_yaw = 180.0
|
||||
_cam_pivot = Vector3(0.0, 0.0, -pivot_offset)
|
||||
var bw := float(Game.board_width())
|
||||
var bh := float(Game.board_height())
|
||||
var max_dim := max(bw, bh)
|
||||
# Auto-scale camera distance: larger boards need more distance to see the whole layout.
|
||||
_cam_distance = clampf(max(max_dim, 10.0) * 1.5, 12.0, 30.0)
|
||||
# Pivot shifts the look-at point toward the local player so their row stays
|
||||
# near the bottom-center of the screen above the hand panel.
|
||||
var pivot_len := clampf(max_dim * 0.2, 1.0, 5.0)
|
||||
|
||||
# Use the local player's starting zone to derive camera yaw for N-player boards.
|
||||
var board_d : Dictionary = Game.get_board()
|
||||
var sz_raw : Dictionary = board_d.get("startingZones", {}) as Dictionary
|
||||
var my_seat : int = int(Game.get_my_player().get("seatIndex", 0))
|
||||
var zone : Array = (sz_raw.get(str(my_seat), []) as Array) if not sz_raw.is_empty() else []
|
||||
|
||||
if not zone.is_empty():
|
||||
# Compute world-space centroid of this player's starting tiles.
|
||||
var cx := 0.0; var cz_v := 0.0
|
||||
for coord: Dictionary in zone:
|
||||
cx += float(coord.get("x", 0)) * TILE_SPACING - (bw - 1.0) * TILE_SPACING * 0.5
|
||||
cz_v += float(coord.get("y", 0)) * TILE_SPACING - (bh - 1.0) * TILE_SPACING * 0.5
|
||||
cx /= zone.size()
|
||||
cz_v /= zone.size()
|
||||
# Yaw places the camera behind the player's zone, looking toward the center.
|
||||
_cam_yaw = rad_to_deg(atan2(cx, cz_v))
|
||||
var len2d := sqrt(cx * cx + cz_v * cz_v)
|
||||
if len2d > 0.001:
|
||||
_cam_pivot = Vector3(cx / len2d * pivot_len, 0.0, cz_v / len2d * pivot_len)
|
||||
else:
|
||||
# P2 row is at world +Z (default yaw=0°).
|
||||
_cam_pivot = Vector3(0.0, 0.0, pivot_offset)
|
||||
# Legacy / no-zone fallback: P1 row at -Z, P2 at +Z.
|
||||
if _local_is_p1:
|
||||
_cam_yaw = 180.0
|
||||
_cam_pivot = Vector3(0.0, 0.0, -pivot_len)
|
||||
else:
|
||||
_cam_pivot = Vector3(0.0, 0.0, pivot_len)
|
||||
_apply_camera()
|
||||
|
||||
var board : Dictionary = state.get("board", {})
|
||||
|
||||
Reference in New Issue
Block a user