40 lines
942 B
GDScript
40 lines
942 B
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
|
|
## Fog tile region in aux_terrain.BMP
|
|
const FOG_RECT := Rect2(53, 53, 100, 100)
|
|
|
|
@export var atlas_texture: Texture2D
|
|
|
|
var _fog_tiles: PackedVector2Array = []
|
|
|
|
|
|
func draw_fog_for_layout(map_layout: MapLayout) -> void:
|
|
_fog_tiles.clear()
|
|
if not map_layout or not atlas_texture:
|
|
queue_redraw()
|
|
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
|
|
_fog_tiles.append(Vector2(tile) * TILE_SIZE)
|
|
queue_redraw()
|
|
|
|
|
|
func _draw() -> void:
|
|
if not atlas_texture:
|
|
return
|
|
var dest_size := Vector2(TILE_SIZE, TILE_SIZE)
|
|
for pos in _fog_tiles:
|
|
draw_texture_rect_region(
|
|
atlas_texture,
|
|
Rect2(pos, dest_size),
|
|
FOG_RECT,
|
|
)
|