27 lines
865 B
GDScript
27 lines
865 B
GDScript
class_name MapRenderer
|
|
extends Node2D
|
|
|
|
const TILE_SIZE := Vector2i(32, 32)
|
|
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"),
|
|
}
|
|
|
|
var map: GridMapState
|
|
|
|
func set_map(new_map: GridMapState) -> void:
|
|
map = new_map
|
|
queue_redraw()
|
|
|
|
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))
|