refactor ControlledUnit
This commit is contained in:
parent
bdf05d5479
commit
58a231d02a
@ -2,13 +2,13 @@ extends Unit
|
||||
class_name ControlledUnit
|
||||
|
||||
signal moving_started
|
||||
signal moving_ended
|
||||
signal moving_finished
|
||||
|
||||
var _anthill: Anthill
|
||||
|
||||
var _hovered_rect: bool = false
|
||||
var _selected: bool = false
|
||||
var _is_relocating: bool = false
|
||||
var _is_moving: bool = false
|
||||
var _ground_plane: Plane = Plane(Vector3.UP, 0)
|
||||
|
||||
@onready var selection_indicator: VisualInstance3D = $SelectionIndicator
|
||||
@ -38,9 +38,9 @@ func _process(delta: float) -> void:
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
super._physics_process(delta)
|
||||
if _is_relocating and nav_agent.is_navigation_finished():
|
||||
_is_relocating = false
|
||||
moving_ended.emit()
|
||||
if _is_moving and nav_agent.is_navigation_finished():
|
||||
_is_moving = false
|
||||
moving_finished.emit()
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
@ -55,8 +55,12 @@ func _input(event: InputEvent) -> void:
|
||||
if HoveringManager.hovered_node is Interactable:
|
||||
_interact(HoveringManager.hovered_node as Interactable)
|
||||
else:
|
||||
var click_pos := _click_raycast(button_event.position)
|
||||
if click_pos == null:
|
||||
return
|
||||
|
||||
navigate(click_pos, true)
|
||||
moving_started.emit()
|
||||
_set_target_click(button_event.position)
|
||||
|
||||
|
||||
func initialize(from: Anthill, pos: Vector3) -> ControlledUnit:
|
||||
@ -73,8 +77,8 @@ func set_selected(on: bool) -> void:
|
||||
_selected = on
|
||||
|
||||
|
||||
func navigate(to: Vector3, relocating: bool = false) -> void:
|
||||
_is_relocating = relocating
|
||||
func navigate(to: Vector3, moving: bool = false) -> void:
|
||||
_is_moving = moving
|
||||
nav_agent.set_target_position(to)
|
||||
|
||||
|
||||
@ -82,14 +86,6 @@ func _interact(with: Interactable) -> void:
|
||||
print(self, " interacting with ", with)
|
||||
|
||||
|
||||
func _set_target_click(mouse_pos: Vector2) -> void:
|
||||
var click_pos := _click_raycast(mouse_pos)
|
||||
if click_pos == null:
|
||||
return
|
||||
|
||||
navigate(click_pos, true)
|
||||
|
||||
|
||||
func _click_raycast(mouse_pos: Vector2) -> Vector3:
|
||||
var from := StaticNodesManager.main_camera.global_position
|
||||
var to := StaticNodesManager.main_camera.project_ray_normal(mouse_pos)
|
||||
|
||||
@ -23,7 +23,7 @@ func _ready() -> void:
|
||||
assert(gathering != null, "gathering missing!")
|
||||
super._ready()
|
||||
moving_started.connect(_on_moving_started)
|
||||
moving_ended.connect(_on_moving_ended)
|
||||
moving_finished.connect(_on_moving_ended)
|
||||
nav_agent.navigation_finished.connect(gathering.on_nav_agent_navigation_finished)
|
||||
var item_bones: Array[int] = []
|
||||
for i in MAX_CARRY:
|
||||
@ -34,7 +34,7 @@ func _ready() -> void:
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
super._process(delta)
|
||||
if _is_relocating:
|
||||
if _is_moving:
|
||||
state = State.MOVING
|
||||
|
||||
_handle_wandering(delta)
|
||||
|
||||
@ -22,7 +22,7 @@ func _ready() -> void:
|
||||
assert(gathering != null, "gathering missing!")
|
||||
super._ready()
|
||||
moving_started.connect(_on_moving_started)
|
||||
moving_ended.connect(_on_moving_ended)
|
||||
moving_finished.connect(_on_moving_ended)
|
||||
nav_agent.navigation_finished.connect(gathering.on_nav_agent_navigation_finished)
|
||||
var item_bones: Array[int] = []
|
||||
for i in gathering.DEFAULT_MAX_CARRYING:
|
||||
@ -33,7 +33,7 @@ func _ready() -> void:
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
super._process(delta)
|
||||
if _is_relocating:
|
||||
if _is_moving:
|
||||
state = State.MOVING
|
||||
|
||||
_handle_wandering(delta)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user