Refactored unit

This commit is contained in:
gamer147
2026-04-08 18:44:58 -04:00
parent c192d48bc4
commit b807e9897d
16 changed files with 239 additions and 154 deletions

View File

@@ -8,6 +8,7 @@ extends Node2D
@onready var wall_renderer: WallRenderer = %WallRenderer
@onready var fog_renderer: FogRenderer = %FogRenderer
const DEPLOYED_UNIT_SCENE = preload("res://prefabs/deployed_unit.tscn")
const TILE_SIZE := 100.0
const SOURCE_ID: int = 0
@@ -19,7 +20,7 @@ func _ready() -> void:
if _pending_layout:
_apply_layout(_pending_layout)
for entry in _pending_units:
_apply_deploy(entry.unit, entry.coords)
_apply_deploy(entry.deployed, entry.coords)
_pending_units.clear()
if map_layout:
apply_layout(map_layout)
@@ -51,10 +52,12 @@ func load_map(layout: String) -> void:
func deploy_unit(unit: Unit, coords: Vector2i) -> void:
var deployed: DeployedUnit = DEPLOYED_UNIT_SCENE.instantiate()
deployed.unit = unit
if is_node_ready():
_apply_deploy(unit, coords)
_apply_deploy(deployed, coords)
else:
_pending_units.append({unit = unit, coords = coords})
_pending_units.append({deployed = deployed, coords = coords})
func _apply_layout(layout: String) -> void:
@@ -69,14 +72,14 @@ func _apply_layout(layout: String) -> void:
draw_floor(coords)
func _apply_deploy(unit: Unit, coords: Vector2i) -> void:
unit.position = coords_to_world(coords)
add_child(unit)
func _apply_deploy(deployed: DeployedUnit, coords: Vector2i) -> void:
deployed.position = coords_to_world(coords)
add_child(deployed)
func remove_unit(unit: Unit) -> void:
if unit.get_parent() == self:
remove_child(unit)
func remove_unit(deployed: DeployedUnit) -> void:
if deployed.get_parent() == self:
remove_child(deployed)
func target_tile(coords: Vector2i) -> void: