Room system added
This commit is contained in:
@@ -2,6 +2,7 @@ class_name CombatMap
|
||||
extends Node2D
|
||||
|
||||
@export var tile_set: DLTileset
|
||||
@export var map_layout: MapLayout
|
||||
@onready var tile_map: TileMapLayer = %TerrainLayer
|
||||
@onready var highlight_map: GridOverlay = %OverlayLayer
|
||||
|
||||
@@ -18,6 +19,8 @@ func _ready() -> void:
|
||||
for entry in _pending_units:
|
||||
_apply_deploy(entry.unit, entry.coords)
|
||||
_pending_units.clear()
|
||||
if map_layout:
|
||||
apply_layout(map_layout)
|
||||
|
||||
|
||||
func snap_to_grid(pos: Vector2) -> Vector2:
|
||||
@@ -79,3 +82,52 @@ func remove_unit(unit: Unit) -> void:
|
||||
|
||||
func target_tile(coords: Vector2i) -> void:
|
||||
highlight_map.target_tile(coords)
|
||||
|
||||
|
||||
func apply_layout(layout: MapLayout) -> void:
|
||||
map_layout = layout
|
||||
map_layout.initialize()
|
||||
load_from_layout()
|
||||
draw_room_walls()
|
||||
|
||||
|
||||
func is_tile_passable(from: Vector2i, to: Vector2i) -> bool:
|
||||
if map_layout:
|
||||
return map_layout.is_passable(from, to)
|
||||
# Fallback: no room system, use legacy wall check
|
||||
return not is_wall(to)
|
||||
|
||||
|
||||
func is_tile_valid(coords: Vector2i) -> bool:
|
||||
if map_layout:
|
||||
return map_layout.is_tile_valid(coords)
|
||||
# Fallback: no room system, any non-wall tile is valid
|
||||
return not is_wall(coords)
|
||||
|
||||
|
||||
func draw_room_walls() -> void:
|
||||
if not map_layout:
|
||||
return
|
||||
var walls := map_layout.get_walls()
|
||||
for wall in walls:
|
||||
var from_world := coords_to_world(wall[0]) + Vector2(TILE_SIZE / 2, TILE_SIZE / 2)
|
||||
var to_world := coords_to_world(wall[1]) + Vector2(TILE_SIZE / 2, TILE_SIZE / 2)
|
||||
var midpoint := (from_world + to_world) / 2
|
||||
var diff := to_world - from_world
|
||||
var wall_dir := Vector2(-diff.y, diff.x).normalized()
|
||||
var half_len := TILE_SIZE / 2
|
||||
|
||||
var line := Line2D.new()
|
||||
line.add_point(midpoint - wall_dir * half_len)
|
||||
line.add_point(midpoint + wall_dir * half_len)
|
||||
line.width = 4.0
|
||||
line.default_color = Color(0.6, 0.5, 0.4)
|
||||
add_child(line)
|
||||
|
||||
|
||||
func load_from_layout() -> void:
|
||||
if not map_layout:
|
||||
return
|
||||
for room in map_layout.rooms:
|
||||
for tile in room.tiles:
|
||||
draw_floor(tile)
|
||||
|
||||
@@ -118,7 +118,8 @@ func _physics_process(delta: float) -> void:
|
||||
|
||||
var next_pos := _selected_unit.position + dir * dl_map.TILE_SIZE
|
||||
var grid_coords := dl_map.world_to_coords(next_pos)
|
||||
if dl_map.is_wall(grid_coords):
|
||||
var current_coords := dl_map.world_to_coords(_selected_unit.position)
|
||||
if not dl_map.is_tile_passable(current_coords, grid_coords):
|
||||
_goal_pos = _selected_unit.position
|
||||
return
|
||||
|
||||
@@ -139,7 +140,7 @@ func _handle_left_click(screen_pos: Vector2) -> void:
|
||||
elif _selected_unit:
|
||||
var snapped_pos := dl_map.snap_to_grid(world_pos)
|
||||
var grid_coords := dl_map.world_to_coords(world_pos)
|
||||
if dl_map.is_wall(grid_coords):
|
||||
if not dl_map.is_tile_valid(grid_coords):
|
||||
return
|
||||
_goal_pos = snapped_pos
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
@@ -7,6 +7,31 @@ class_name StrategyPhase extends Node2D
|
||||
@onready var camera: CameraController = $Camera2D
|
||||
|
||||
func _ready() -> void:
|
||||
# -- Test room layout (remove once map editor exists) --
|
||||
var room_a := Room.new()
|
||||
room_a.id = 0
|
||||
room_a.tiles = [
|
||||
Vector2i(0, 0), Vector2i(1, 0), Vector2i(2, 0),
|
||||
Vector2i(0, 1), Vector2i(1, 1), Vector2i(2, 1),
|
||||
Vector2i(0, 2), Vector2i(1, 2), Vector2i(2, 2),
|
||||
]
|
||||
|
||||
var room_b := Room.new()
|
||||
room_b.id = 1
|
||||
room_b.tiles = [
|
||||
Vector2i(3, 0), Vector2i(4, 0), Vector2i(5, 0),
|
||||
Vector2i(3, 1), Vector2i(4, 1), Vector2i(5, 1),
|
||||
Vector2i(3, 2), Vector2i(4, 2), Vector2i(5, 2),
|
||||
]
|
||||
|
||||
var layout := MapLayout.new()
|
||||
layout.rooms = [room_a, room_b]
|
||||
# Opening between (2,1) in room_a and (3,1) in room_b
|
||||
layout.openings = [Vector2i(2, 1), Vector2i(3, 1)]
|
||||
|
||||
combat_map.apply_layout(layout)
|
||||
# -- End test room layout --
|
||||
|
||||
player_controller.combat_requested.connect(_on_combat_requested)
|
||||
player_controller.mouse_grid_changed.connect(_on_mouse_grid_changed)
|
||||
player_controller.camera_drag.connect(camera.apply_drag)
|
||||
|
||||
Reference in New Issue
Block a user