feat: render exploration fog states

This commit is contained in:
goose
2026-10-01 07:04:22 -04:00
parent 84d6d653ad
commit 6e8456ca42
5 changed files with 93 additions and 6 deletions
+5
View File
@@ -17,6 +17,7 @@ var enemy_views: Dictionary[StringName, ActorView] = {}
func _ready() -> void:
game_state = _create_initial_state()
map_renderer.set_map(game_state.map)
_sync_map_renderer_visibility()
player_view.set_actor(game_state.player)
_sync_enemy_views()
hud.refresh(game_state)
@@ -47,6 +48,7 @@ func get_game_state() -> GameState:
func _process_action(direction: Vector2i) -> Array[TurnResult]:
var results := game_state.try_player_action(direction)
_sync_map_renderer_visibility()
player_view.refresh()
_sync_enemy_views()
hud.refresh(game_state, results)
@@ -68,6 +70,9 @@ func _create_initial_state() -> GameState:
var goblin := ActorStateType.new(&"goblin", Vector2i(4, 2), 6, 2)
return GameStateType.new(map, player, {&"goblin": goblin})
func _sync_map_renderer_visibility() -> void:
map_renderer.set_visibility(game_state.visible_cells, game_state.explored_cells)
func _sync_enemy_views() -> void:
for enemy_id in enemy_views.keys():
if not game_state.enemies.has(enemy_id):
+30 -1
View File
@@ -2,6 +2,7 @@ class_name MapRenderer
extends Node2D
const TILE_SIZE := Vector2i(32, 32)
const EXPLORED_DIM_COLOR := Color(0.35, 0.35, 0.35, 1.0)
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
const TEXTURES := {
GridMapStateType.CellKind.FLOOR: preload("res://assets/dcss/floor.png"),
@@ -12,15 +13,43 @@ const TEXTURES := {
}
var map: GridMapState
var _visible_cells: Dictionary[Vector2i, bool] = {}
var _explored_cells: Dictionary[Vector2i, bool] = {}
func set_map(new_map: GridMapState) -> void:
map = new_map
queue_redraw()
func set_visibility(visible_cells: Dictionary[Vector2i, bool], explored_cells: Dictionary[Vector2i, bool]) -> void:
_visible_cells = visible_cells.duplicate()
_explored_cells = explored_cells.duplicate()
queue_redraw()
func get_cell_visibility_state(cell: Vector2i) -> StringName:
if _visible_cells.has(cell):
return &"visible"
if _explored_cells.has(cell):
return &"explored"
return &"unknown"
func get_cell_render_color(cell: Vector2i) -> Color:
match get_cell_visibility_state(cell):
&"visible":
return Color.WHITE
&"explored":
return EXPLORED_DIM_COLOR
_:
return Color.BLACK
func _draw() -> void:
if map == null:
return
for y in range(map.size.y):
for x in range(map.size.x):
var cell := Vector2i(x, y)
draw_texture(TEXTURES[map.get_cell(cell)], Vector2(cell * TILE_SIZE))
var tile_rect := Rect2(Vector2(cell * TILE_SIZE), Vector2(TILE_SIZE))
var color := get_cell_render_color(cell)
if color == Color.BLACK:
draw_rect(tile_rect, Color.BLACK)
else:
draw_texture_rect(TEXTURES[map.get_cell(cell)], tile_rect, false, color)