fix(client): address PR review — invalidation, constants, tests

Review feedback from Hoshe + Tyre on PR #8:

- Extract shared TILE_SIZE to Constants class_name (Tyre #5, Hoshe #7)
- Fix tile invalidation: detect tile/visibility count changes instead
  of one-shot dirty flag, supports chunk loading (Tyre #3, #4)
- Fog dirty tracking: only re-render when visible_positions changes
- Add bounds warning for unknown tile types (Hoshe #1)
- Add player-not-found warning in GameState (Hoshe #5)
- Use Image.fill_rect() instead of pixel loops (Tyre #10)
- Document _player_pos as reserved for fog decay #113 (Tyre #6)
- Add TODO(#130) for D-033 relationship colors (Hoshe #3, Tyre #8)
- Add class_name to EntityRenderer, FogRenderer, TileRenderer
- 20 new rendering tests (D-030 Layer 1): entity lifecycle, fog
  registration, tile type mapping, snapshot completeness, constants
- 65 total tests passing, 0 failures

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-12 00:15:42 +01:00
co-authored by Claude Opus 4.6
parent 1443f9dc9e
commit aa3a3fea7d
8 changed files with 267 additions and 39 deletions
+10 -11
View File
@@ -1,3 +1,4 @@
class_name TileRenderer
extends TileMapLayer
# Tile renderer — draws map tiles from ObserverSnapshot tile data
@@ -9,7 +10,7 @@ extends TileMapLayer
# (2,0) = door — brown
# (3,0) = object — teal
const TILE_SIZE: int = 32
const TILE_SIZE: int = Constants.TILE_SIZE
enum TileType { FLOOR = 0, WALL = 1, DOOR = 2, OBJECT = 3 }
@@ -71,6 +72,8 @@ func update_tiles(tiles: Array) -> void:
var tile_type_str: String = tile_data.type
if not TILE_TYPE_MAP.has(tile_type_str):
push_warning("TileRenderer: unknown tile type '%s' at (%d, %d)" % [
tile_type_str, tile_data.x, tile_data.y])
continue
var atlas_x: int = TILE_TYPE_MAP[tile_type_str]
@@ -79,17 +82,13 @@ func update_tiles(tiles: Array) -> void:
# Fill a tile region with a solid color
func _fill_tile(img: Image, tile_index: int, color: Color) -> void:
var x_offset := tile_index * TILE_SIZE
for x in range(TILE_SIZE):
for y in range(TILE_SIZE):
img.set_pixel(x_offset + x, y, color)
var rect := Rect2i(tile_index * TILE_SIZE, 0, TILE_SIZE, TILE_SIZE)
img.fill_rect(rect, color)
# Fill a tile region with a color and a 1px border
func _fill_tile_with_border(img: Image, tile_index: int, fill: Color, border: Color) -> void:
var x_offset := tile_index * TILE_SIZE
for x in range(TILE_SIZE):
for y in range(TILE_SIZE):
if x == 0 or y == 0 or x == TILE_SIZE - 1 or y == TILE_SIZE - 1:
img.set_pixel(x_offset + x, y, border)
else:
img.set_pixel(x_offset + x, y, fill)
# Border (full tile)
img.fill_rect(Rect2i(x_offset, 0, TILE_SIZE, TILE_SIZE), border)
# Fill (inset by 1px)
img.fill_rect(Rect2i(x_offset + 1, 1, TILE_SIZE - 2, TILE_SIZE - 2), fill)