Files
MaidEngine/nodes/fog_renderer.gd
2026-04-07 07:56:48 -04:00

44 lines
1.0 KiB
GDScript

class_name FogRenderer
extends Node2D
## Renders a fog/cave texture over every tile inside the map's bounding rect
## that is not part of any room. Future: drive visibility from map state.
const TILE_SIZE := 100.0
const FOG_RECT := Rect2(53, 53, 100, 100)
@export var atlas_texture: Texture2D
func draw_fog_for_layout(map_layout: MapLayout) -> void:
_clear()
if not map_layout or not atlas_texture:
return
for y in map_layout.size.y:
for x in map_layout.size.x:
var tile := Vector2i(x, y)
if map_layout.is_tile_valid(tile):
continue
_create_fog_sprite(Vector2(tile) * TILE_SIZE)
func _clear() -> void:
for child in get_children():
child.queue_free()
func _create_fog_sprite(pos: Vector2) -> void:
var atlas := AtlasTexture.new()
atlas.atlas = atlas_texture
atlas.region = FOG_RECT
var sprite := Sprite2D.new()
sprite.texture = atlas
sprite.centered = false
sprite.position = pos
sprite.scale = Vector2(
TILE_SIZE / FOG_RECT.size.x,
TILE_SIZE / FOG_RECT.size.y,
)
add_child(sprite)