extends Node2D ## Phase 1 world view. 80×80 TileMap with 6 layers, placeholder tiles. ## ## Real ElvGames art lands in Phase 5+ (wood walls custom-authored on ## FG_Houses, stone walls autotiled from FG_Fortress per the 2026-05-10 ## audit lock). Phase 1 is just "render an 80² map" and exists to prove ## the layer pipeline + camera UX + speed loop end-to-end. ## ## TileMap layer indices follow docs/architecture.md: ## 0 Terrain · 1 Floor · 2 Wall · 3 Designation · 4 Roof · 5 Fog const MAP_SIZE_TILES: Vector2i = Vector2i(80, 80) const TILE_SIZE_PX: int = 16 # Atlas coords inside the placeholder tileset (one source, source_id = 0). # Real assets in Phase 5 will use multiple atlas sources. const TILE_GRASS: Vector2i = Vector2i(0, 0) const TILE_DIRT: Vector2i = Vector2i(1, 0) const TILE_STONE: Vector2i = Vector2i(2, 0) const TILE_STONE_DARK: Vector2i = Vector2i(3, 0) const PLACEHOLDER_SOURCE_ID: int = 0 @onready var terrain_layer: TileMapLayer = $Terrain @onready var floor_layer: TileMapLayer = $Floor @onready var wall_layer: TileMapLayer = $Wall @onready var designation_layer: TileMapLayer = $Designation @onready var roof_layer: TileMapLayer = $Roof @onready var fog_layer: TileMapLayer = $Fog func _ready() -> void: Audit.log("world", "Phase 1 — building %d×%d world view." % [MAP_SIZE_TILES.x, MAP_SIZE_TILES.y]) var tileset := _build_placeholder_tileset() for layer in [terrain_layer, floor_layer, wall_layer, designation_layer, roof_layer, fog_layer]: layer.tile_set = tileset _paint_terrain() _paint_sample_walls() _apply_camera_bounds() func world_bounds_px() -> Rect2: return Rect2(Vector2.ZERO, Vector2(MAP_SIZE_TILES * TILE_SIZE_PX)) func _build_placeholder_tileset() -> TileSet: # Four 16×16 placeholder tiles laid out as a 4×1 atlas. No PNG dependency # — atlas built at runtime from a programmatic Image. Real ElvGames art # replaces this when wood/stone wall variants are imported in Phase 5. var ts := TileSet.new() ts.tile_size = Vector2i(TILE_SIZE_PX, TILE_SIZE_PX) var atlas_w := TILE_SIZE_PX * 4 var img := Image.create(atlas_w, TILE_SIZE_PX, false, Image.FORMAT_RGBA8) var palette: Array[Color] = [ Color(0.45, 0.65, 0.30), # grass Color(0.55, 0.45, 0.30), # dirt Color(0.60, 0.60, 0.55), # stone Color(0.30, 0.30, 0.32), # stone dark ] for i in palette.size(): var base: Color = palette[i] var border: Color = base.darkened(0.15) for px in TILE_SIZE_PX: for py in TILE_SIZE_PX: var on_border := ( px == 0 or px == TILE_SIZE_PX - 1 or py == 0 or py == TILE_SIZE_PX - 1 ) img.set_pixel(i * TILE_SIZE_PX + px, py, border if on_border else base) var tex := ImageTexture.create_from_image(img) var src := TileSetAtlasSource.new() src.texture = tex src.texture_region_size = Vector2i(TILE_SIZE_PX, TILE_SIZE_PX) for i in palette.size(): src.create_tile(Vector2i(i, 0)) ts.add_source(src, PLACEHOLDER_SOURCE_ID) return ts func _paint_terrain() -> void: # Solid grass for now. Phase 4+ introduces ore veins, trees-as-entities, # water, etc. — this fill is a baseline. for x in MAP_SIZE_TILES.x: for y in MAP_SIZE_TILES.y: terrain_layer.set_cell(Vector2i(x, y), PLACEHOLDER_SOURCE_ID, TILE_GRASS) func _paint_sample_walls() -> void: # An 8×8 stone ring near the map centre as a visual landmark. Proves the # wall layer renders on top of terrain and gives the camera something to # pan toward in the demo. Phase 5 deletes this and stands up real player- # built walls. var origin := Vector2i(36, 36) var size: int = 8 for i in size: wall_layer.set_cell(origin + Vector2i(i, 0), PLACEHOLDER_SOURCE_ID, TILE_STONE) wall_layer.set_cell(origin + Vector2i(i, size - 1), PLACEHOLDER_SOURCE_ID, TILE_STONE) wall_layer.set_cell(origin + Vector2i(0, i), PLACEHOLDER_SOURCE_ID, TILE_STONE_DARK) wall_layer.set_cell(origin + Vector2i(size - 1, i), PLACEHOLDER_SOURCE_ID, TILE_STONE_DARK) func _apply_camera_bounds() -> void: var cam := get_node_or_null("CameraRig") if cam == null: Audit.log("world", "no CameraRig child yet — bounds set later when camera lands.") return if not cam.has_method("set_world_bounds"): Audit.log("world", "CameraRig present but missing set_world_bounds() — skipping.") return cam.set_world_bounds(world_bounds_px())