class_name MapRenderer extends Node2D const TILE_SIZE := Vector2i(32, 32) # Explored terrain remains recognizable through the original tile texture, but a # near-black blue overlay makes it decisively darker than the current FOV. const EXPLORED_DIM_COLOR := Color(0.08, 0.14, 0.28, 1.0) const EXPLORED_OVERLAY_COLOR := Color(0.015, 0.035, 0.09, 0.72) const UNKNOWN_COLOR := Color(0.005, 0.008, 0.02, 1.0) const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd") const TEXTURES := { GridMapStateType.CellKind.FLOOR: preload("res://assets/dcss/floor.png"), GridMapStateType.CellKind.WALL: preload("res://assets/dcss/wall.png"), GridMapStateType.CellKind.CLOSED_DOOR: preload("res://assets/dcss/closed_door.png"), GridMapStateType.CellKind.CHEST: preload("res://assets/dcss/chest.png"), GridMapStateType.CellKind.STAIRS: preload("res://assets/dcss/stairs.png"), # B6 has no distinct bed sprite yet; a bed remains visibly traversable. GridMapStateType.CellKind.BED: preload("res://assets/dcss/floor.png"), } var map: GridMapState var _visible_cells: Dictionary[Vector2i, bool] = {} var _explored_cells: Dictionary[Vector2i, bool] = {} var _traps: Dictionary[Vector2i, Dictionary] = {} var _shrines: Dictionary[Vector2i, Dictionary] = {} var _quest_boards: Dictionary[Vector2i, Dictionary] = {} var _ground_items: Dictionary[Vector2i, Array] = {} func get_cell_rect(cell: Vector2i) -> Rect2: return Rect2(Vector2(cell * TILE_SIZE), Vector2(TILE_SIZE)) 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 set_special_markers(traps: Dictionary[Vector2i, Dictionary], shrines: Dictionary[Vector2i, Dictionary], quest_boards: Dictionary[Vector2i, Dictionary]) -> void: _traps = traps.duplicate(true) _shrines = shrines.duplicate(true) _quest_boards = quest_boards.duplicate(true) queue_redraw() func set_ground_items(ground_items: Dictionary[Vector2i, Array]) -> void: _ground_items = ground_items.duplicate() queue_redraw() func get_ground_item_marker_cells() -> Dictionary[Vector2i, bool]: var cells: Dictionary[Vector2i, bool] = {} for cell in _ground_items: if _visible_cells.has(cell) and not _ground_items[cell].is_empty(): cells[cell] = true return cells 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 UNKNOWN_COLOR 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) var tile_rect := get_cell_rect(cell) var color := get_cell_render_color(cell) if color == UNKNOWN_COLOR: draw_rect(tile_rect, UNKNOWN_COLOR) elif color == EXPLORED_DIM_COLOR: draw_texture_rect(TEXTURES[map.get_cell(cell)], tile_rect, false) draw_rect(tile_rect, EXPLORED_OVERLAY_COLOR) else: draw_texture_rect(TEXTURES[map.get_cell(cell)], tile_rect, false, color) _draw_special_marker(cell, tile_rect) func _draw_special_marker(cell: Vector2i, tile_rect: Rect2) -> void: # Never expose special content through black fog or dim explored memory. if not _visible_cells.has(cell): return if _traps.has(cell): var trap: Dictionary = _traps[cell] if bool(trap.get("discovered", false)) and not bool(trap.get("disarmed", false)): draw_circle(tile_rect.get_center(), 5.0, Color(1.0, 0.35, 0.2, 0.95)) if _shrines.has(cell): draw_circle(tile_rect.get_center(), 5.0, Color(0.45, 0.85, 1.0, 0.95)) if _quest_boards.has(cell): draw_rect(Rect2(tile_rect.position + Vector2(10, 7), Vector2(12, 18)), Color(0.95, 0.78, 0.32, 0.95)) if _ground_items.has(cell) and not _ground_items[cell].is_empty(): # Gold diamond: visible only inside current FOV, matching all world markers. var center := tile_rect.get_center() var diamond := PackedVector2Array([ center + Vector2(0, -7), center + Vector2(7, 0), center + Vector2(0, 7), center + Vector2(-7, 0), ]) draw_colored_polygon(diamond, Color(1.0, 0.82, 0.22, 0.96))