Refactored unit
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user