refactor BunchSpawner
This commit is contained in:
parent
d207ac4fdc
commit
deaed96117
@ -19,19 +19,22 @@ func _ready() -> void:
|
||||
0,
|
||||
randf_range(-gizmo_extents, gizmo_extents),
|
||||
)
|
||||
|
||||
var scene: PackedScene
|
||||
var holder: Node
|
||||
match what:
|
||||
WhatToSpawn.APHID:
|
||||
_spawn(
|
||||
aphid,
|
||||
global_position + pos_offset,
|
||||
StaticNodesManager.aphids_holder
|
||||
)
|
||||
scene = aphid
|
||||
holder = StaticNodesManager.aphids_holder
|
||||
WhatToSpawn.HONEYDEW:
|
||||
_spawn(
|
||||
honeydew,
|
||||
global_position + pos_offset,
|
||||
StaticNodesManager.honeydew_holder
|
||||
)
|
||||
scene = honeydew
|
||||
holder = StaticNodesManager.honeydew_holder
|
||||
|
||||
_spawn(
|
||||
scene,
|
||||
global_position + pos_offset,
|
||||
holder,
|
||||
)
|
||||
|
||||
|
||||
func _spawn(scene: PackedScene, where: Vector3, holder: Node) -> void:
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
extends Camera3D
|
||||
class_name MainCamera
|
||||
|
||||
enum CameraState {
|
||||
enum State {
|
||||
FREE,
|
||||
HEADING_TO,
|
||||
}
|
||||
@ -48,7 +48,7 @@ var heading_from_position: Vector3 = Vector3.ZERO
|
||||
var heading_from_zoom: float = 0
|
||||
var heading_progress: float = 0
|
||||
|
||||
var state: CameraState = CameraState.FREE
|
||||
var state: State = State.FREE
|
||||
|
||||
var window_out_of_focus: bool = false
|
||||
|
||||
@ -120,7 +120,7 @@ func head_to(to: Vector3, zoom: float = ZOOM_VALUE_DEFAULT) -> void:
|
||||
heading_progress = 0
|
||||
heading_from_zoom = zoom_value
|
||||
heading_to_zoom = zoom
|
||||
state = CameraState.HEADING_TO
|
||||
state = State.HEADING_TO
|
||||
|
||||
|
||||
func _handle_advance_anim_step() -> void:
|
||||
@ -161,7 +161,7 @@ func _handle_dof() -> void:
|
||||
func _handle_movement(delta: float) -> void:
|
||||
if (
|
||||
window_out_of_focus
|
||||
or state != CameraState.FREE
|
||||
or state != State.FREE
|
||||
or CursorManager.disable_confinement
|
||||
or SelectionManager.selecting
|
||||
):
|
||||
@ -208,12 +208,12 @@ func _handle_movement(delta: float) -> void:
|
||||
|
||||
|
||||
func _handle_heading_to(delta: float) -> void:
|
||||
if state != CameraState.HEADING_TO:
|
||||
if state != State.HEADING_TO:
|
||||
return
|
||||
|
||||
if heading_progress >= 1:
|
||||
target_position = heading_to_position
|
||||
state = CameraState.FREE
|
||||
state = State.FREE
|
||||
|
||||
heading_progress += HEADING_SPEED * delta
|
||||
var eased_progress := ease(heading_progress, -3)
|
||||
|
||||
@ -23,6 +23,7 @@ func _ready() -> void:
|
||||
assert(buy_gatherer_button != null, "buy_gatherer_button missing!")
|
||||
assert(gatherer_price_counter != null, "gatherer_price_counter missing!")
|
||||
assert(gatherer_info != null, "gatherer_info missing!")
|
||||
assert(counter != null, "counter missing!")
|
||||
super._ready()
|
||||
buy_nitwit_button.pressed.connect(_on_buy_nitwit_button_pressed)
|
||||
nitwit_info.visible = false
|
||||
|
||||
@ -17,7 +17,7 @@ var rect_size: float = RECT_SIZE
|
||||
|
||||
func _ready() -> void:
|
||||
assert(atlas != null, "atlas missing!")
|
||||
count_per_row = floor(size.x / (rect_size + GAP))
|
||||
count_per_row = floori(size.x / (rect_size + GAP))
|
||||
|
||||
|
||||
func initialize(
|
||||
@ -34,7 +34,7 @@ func initialize(
|
||||
|
||||
for i in (ceil(init_max_count / SPRITES_PER_RECT) as int):
|
||||
var col: int = i % count_per_row
|
||||
var row: int = floor(i / count_per_row)
|
||||
var row: int = floori(i / count_per_row)
|
||||
var rect := _create_rect(col, row)
|
||||
rects.append(rect)
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
extends FollowingUI
|
||||
class_name UnitInfo
|
||||
|
||||
enum InfoState {
|
||||
enum State {
|
||||
NONE,
|
||||
ANT_IDLE,
|
||||
ANT_MOVING,
|
||||
@ -16,7 +16,7 @@ enum InfoState {
|
||||
const ANIMATION_SPEED: float = 0.25
|
||||
|
||||
var unit: Unit
|
||||
var state: InfoState = InfoState.NONE
|
||||
var state: State = State.NONE
|
||||
var anim_time: float = 0
|
||||
|
||||
@onready var texture_rect: TextureRect = $TextureRect
|
||||
@ -53,44 +53,44 @@ func close() -> void:
|
||||
|
||||
|
||||
func _handle_pictogram() -> void:
|
||||
texture_rect.visible = state != InfoState.NONE
|
||||
texture_rect.visible = state != State.NONE
|
||||
atlas.region.position.y = (state - 1) * atlas.region.size.y
|
||||
atlas.region.position.x = floor(
|
||||
atlas.region.position.x = floorf(
|
||||
wrapf(anim_time / ANIMATION_SPEED, 0, 4)
|
||||
) * atlas.region.size.x
|
||||
|
||||
func _get_state() -> void:
|
||||
if unit is Aphid:
|
||||
match (unit as Aphid).state:
|
||||
Aphid.AphidState.WANDERING:
|
||||
state = InfoState.APHID_IDLE
|
||||
Aphid.State.WANDERING:
|
||||
state = State.APHID_IDLE
|
||||
|
||||
if unit is AntNitwit:
|
||||
match (unit as AntNitwit).state:
|
||||
AntNitwit.AntNitwitState.WANDERING:
|
||||
state = InfoState.ANT_IDLE
|
||||
AntNitwit.AntNitwitState.MOVING:
|
||||
state = InfoState.ANT_MOVING
|
||||
AntNitwit.AntNitwitState.GATHERING:
|
||||
AntNitwit.State.WANDERING:
|
||||
state = State.ANT_IDLE
|
||||
AntNitwit.State.MOVING:
|
||||
state = State.ANT_MOVING
|
||||
AntNitwit.State.GATHERING:
|
||||
_get_gathering_state((unit as AntNitwit).gathering.state)
|
||||
|
||||
if unit is AntGatherer:
|
||||
match (unit as AntGatherer).state:
|
||||
AntGatherer.AntGathererState.WANDERING:
|
||||
state = InfoState.ANT_IDLE
|
||||
AntGatherer.AntGathererState.MOVING:
|
||||
state = InfoState.ANT_MOVING
|
||||
AntGatherer.AntGathererState.GATHERING:
|
||||
AntGatherer.State.WANDERING:
|
||||
state = State.ANT_IDLE
|
||||
AntGatherer.State.MOVING:
|
||||
state = State.ANT_MOVING
|
||||
AntGatherer.State.GATHERING:
|
||||
_get_gathering_state((unit as AntGatherer).gathering.state)
|
||||
|
||||
|
||||
func _get_gathering_state(gather_state: Gathering.GatherState) -> void:
|
||||
func _get_gathering_state(gather_state: Gathering.State) -> void:
|
||||
match gather_state:
|
||||
Gathering.GatherState.PICKING_UP:
|
||||
state = InfoState.ANT_PICKING_UP
|
||||
Gathering.GatherState.DEPOSITING:
|
||||
state = InfoState.ANT_DEPOSITING
|
||||
Gathering.GatherState.AWAITING:
|
||||
state = InfoState.ANT_AWAITING
|
||||
Gathering.GatherState.STOP:
|
||||
state = InfoState.NONE
|
||||
Gathering.State.PICKING_UP:
|
||||
state = State.ANT_PICKING_UP
|
||||
Gathering.State.DEPOSITING:
|
||||
state = State.ANT_DEPOSITING
|
||||
Gathering.State.AWAITING:
|
||||
state = State.ANT_AWAITING
|
||||
Gathering.State.STOP:
|
||||
state = State.NONE
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
extends ControlledUnit
|
||||
class_name AntGatherer
|
||||
|
||||
enum AntGathererState {
|
||||
enum State {
|
||||
WANDERING,
|
||||
MOVING,
|
||||
GATHERING,
|
||||
@ -10,7 +10,7 @@ enum AntGathererState {
|
||||
const ITEM_BONE_NAME = "Gatherer_item_"
|
||||
const MAX_CARRY: int = 8
|
||||
|
||||
var state: AntGathererState = AntGathererState.WANDERING
|
||||
var state: State = State.WANDERING
|
||||
|
||||
@onready var gathering: Gathering = $Gathering
|
||||
@onready var skeleton: Skeleton3D = $AntModel/Armature/Skeleton3D
|
||||
@ -37,7 +37,7 @@ func _ready() -> void:
|
||||
func _process(delta: float) -> void:
|
||||
super._process(delta)
|
||||
if is_relocating:
|
||||
state = AntGathererState.MOVING
|
||||
state = State.MOVING
|
||||
|
||||
_handle_wandering(delta)
|
||||
_handle_gathering()
|
||||
@ -45,12 +45,12 @@ func _process(delta: float) -> void:
|
||||
|
||||
func _interact(with: Interactable) -> void:
|
||||
if with is Honeydew:
|
||||
state = AntGathererState.GATHERING
|
||||
state = State.GATHERING
|
||||
gathering.start_gathering(with as Honeydew)
|
||||
|
||||
|
||||
func _handle_wandering(delta: float) -> void:
|
||||
if state != AntGathererState.WANDERING:
|
||||
if state != State.WANDERING:
|
||||
return
|
||||
|
||||
_wander(delta)
|
||||
@ -61,17 +61,17 @@ func _handle_gathering() -> void:
|
||||
|
||||
|
||||
func _on_moving_ended() -> void:
|
||||
state = AntGathererState.WANDERING
|
||||
state = State.WANDERING
|
||||
|
||||
|
||||
func _on_moving_started() -> void:
|
||||
if state == AntGathererState.GATHERING:
|
||||
if state == State.GATHERING:
|
||||
gathering.stop_gathering()
|
||||
state = AntGathererState.MOVING
|
||||
state = State.MOVING
|
||||
|
||||
|
||||
func _on_gathering_navigate_to(pos: Vector3) -> void:
|
||||
if state != AntGathererState.GATHERING:
|
||||
if state != State.GATHERING:
|
||||
return
|
||||
|
||||
navigate(pos)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
extends ControlledUnit
|
||||
class_name AntNitwit
|
||||
|
||||
enum AntNitwitState {
|
||||
enum State {
|
||||
WANDERING,
|
||||
MOVING,
|
||||
GATHERING,
|
||||
@ -9,7 +9,7 @@ enum AntNitwitState {
|
||||
|
||||
const ITEM_BONE_NAME = "Nitwit_item_"
|
||||
|
||||
var state: AntNitwitState = AntNitwitState.WANDERING
|
||||
var state: State = State.WANDERING
|
||||
|
||||
@onready var gathering: Gathering = $Gathering
|
||||
@onready var skeleton: Skeleton3D = $AntModel/Armature/Skeleton3D
|
||||
@ -36,7 +36,7 @@ func _ready() -> void:
|
||||
func _process(delta: float) -> void:
|
||||
super._process(delta)
|
||||
if is_relocating:
|
||||
state = AntNitwitState.MOVING
|
||||
state = State.MOVING
|
||||
|
||||
_handle_wandering(delta)
|
||||
_handle_gathering()
|
||||
@ -44,12 +44,12 @@ func _process(delta: float) -> void:
|
||||
|
||||
func _interact(with: Interactable) -> void:
|
||||
if with is Honeydew:
|
||||
state = AntNitwitState.GATHERING
|
||||
state = State.GATHERING
|
||||
gathering.start_gathering(with as Honeydew)
|
||||
|
||||
|
||||
func _handle_wandering(delta: float) -> void:
|
||||
if state != AntNitwitState.WANDERING:
|
||||
if state != State.WANDERING:
|
||||
return
|
||||
|
||||
_wander(delta)
|
||||
@ -60,18 +60,18 @@ func _handle_gathering() -> void:
|
||||
|
||||
|
||||
func _on_moving_ended() -> void:
|
||||
state = AntNitwitState.WANDERING
|
||||
state = State.WANDERING
|
||||
|
||||
|
||||
func _on_moving_started() -> void:
|
||||
if state == AntNitwitState.GATHERING:
|
||||
if state == State.GATHERING:
|
||||
gathering.stop_gathering()
|
||||
state = AntNitwitState.MOVING
|
||||
state = State.MOVING
|
||||
|
||||
|
||||
func _on_gathering_navigate_to(pos: Vector3) -> void:
|
||||
print('_on_gathering_navigate_to')
|
||||
if state != AntNitwitState.GATHERING:
|
||||
if state != State.GATHERING:
|
||||
return
|
||||
print('_on_gathering_navigate_to 2')
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
extends Unit
|
||||
class_name Aphid
|
||||
|
||||
enum AphidState {
|
||||
enum State {
|
||||
WANDERING,
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ const HONEYDEW_INTERVAL_MAX: float = 60
|
||||
const HONEYDEW_SPAWN_SPREAD: float = 0.5
|
||||
const HONEYDEWS_MAX: int = 5
|
||||
|
||||
var state: AphidState = AphidState.WANDERING
|
||||
var state: State = State.WANDERING
|
||||
var honeydew_spawn_timer: float = 0
|
||||
var spawned_honeydews: Dictionary = {}
|
||||
|
||||
@ -37,7 +37,7 @@ func erase_honeydew(item: Honeydew) -> void:
|
||||
|
||||
|
||||
func _handle_wandering(delta: float) -> void:
|
||||
if state != AphidState.WANDERING:
|
||||
if state != State.WANDERING:
|
||||
return
|
||||
|
||||
_wander(delta)
|
||||
@ -50,8 +50,7 @@ func _handle_honeydew_spawn(delta: float) -> void:
|
||||
if honeydew_spawn_timer >= 0:
|
||||
honeydew_spawn_timer -= delta
|
||||
return
|
||||
|
||||
audio_player.play_sound(SoundManager.pop())
|
||||
|
||||
var new_honeydew := honeydew_scene.instantiate() as Honeydew
|
||||
new_honeydew.set_aphid(self)
|
||||
|
||||
|
||||
@ -9,14 +9,14 @@ const DEFAULT_PICKUP_INTERVAL = 0.5
|
||||
const DROP_SPREAD: float = 0.1
|
||||
const ANTHILL_DEPOSIT_RADIUS: float = 0.5
|
||||
|
||||
enum GatherState {
|
||||
enum State {
|
||||
AWAITING,
|
||||
PICKING_UP,
|
||||
DEPOSITING,
|
||||
STOP,
|
||||
}
|
||||
|
||||
var state: GatherState = GatherState.STOP
|
||||
var state: State = State.STOP
|
||||
|
||||
var nearby_items: Dictionary = {}
|
||||
var carrying_items: Array[Honeydew] = []
|
||||
@ -94,7 +94,7 @@ func handle_gathering(showing_info: bool) -> void:
|
||||
collision_shape.global_rotation = Vector3.ZERO
|
||||
|
||||
radius_indicator.visible = (
|
||||
(state != GatherState.STOP and showing_info)
|
||||
(state != State.STOP and showing_info)
|
||||
or showing_after_set
|
||||
)
|
||||
|
||||
@ -102,40 +102,40 @@ func handle_gathering(showing_info: bool) -> void:
|
||||
func start_gathering(item: Honeydew) -> void:
|
||||
gathering_center = item.global_position
|
||||
showing_after_set = true
|
||||
state = GatherState.AWAITING
|
||||
state = State.AWAITING
|
||||
_go_pick_up(item)
|
||||
|
||||
|
||||
func stop_gathering() -> void:
|
||||
state = GatherState.STOP
|
||||
state = State.STOP
|
||||
target = null
|
||||
|
||||
|
||||
func on_nav_agent_navigation_finished() -> void:
|
||||
if state == GatherState.PICKING_UP:
|
||||
if state == State.PICKING_UP:
|
||||
_pick_up()
|
||||
|
||||
if (
|
||||
state == GatherState.DEPOSITING
|
||||
state == State.DEPOSITING
|
||||
and global_position.distance_to(anthill.global_position) < 1
|
||||
):
|
||||
_deposit()
|
||||
|
||||
|
||||
func _go_pick_up(item: Honeydew) -> void:
|
||||
state = GatherState.AWAITING
|
||||
state = State.AWAITING
|
||||
if anthill.space_left() <= 0:
|
||||
return
|
||||
if carrying_items.size() >= max_carrying:
|
||||
_go_deposit()
|
||||
return
|
||||
target = item
|
||||
state = GatherState.PICKING_UP
|
||||
state = State.PICKING_UP
|
||||
navigate_to.emit(item.global_position)
|
||||
|
||||
|
||||
func _go_deposit() -> void:
|
||||
state = GatherState.DEPOSITING
|
||||
state = State.DEPOSITING
|
||||
var dir := anthill.global_position.direction_to(global_position)
|
||||
navigate_to.emit(
|
||||
anthill.global_position
|
||||
@ -151,7 +151,7 @@ func _get_nth_pile_pos(n: int) -> Vector3:
|
||||
func _pick_up() -> void:
|
||||
var nearest := _find_nearest(nearby_items.values())
|
||||
if target == null or target.carried:
|
||||
state = GatherState.AWAITING
|
||||
state = State.AWAITING
|
||||
if nearest != null:
|
||||
_go_pick_up(nearest)
|
||||
elif carrying_items.size() > 0:
|
||||
@ -177,11 +177,11 @@ func _pick_up() -> void:
|
||||
func _deposit() -> void:
|
||||
await get_tree().create_timer(0.5).timeout
|
||||
while carrying_items.size() > 0:
|
||||
if state != GatherState.DEPOSITING:
|
||||
if state != State.DEPOSITING:
|
||||
return
|
||||
|
||||
if anthill.space_left() <= 0:
|
||||
state = GatherState.AWAITING
|
||||
state = State.AWAITING
|
||||
await _drop_everything()
|
||||
return
|
||||
|
||||
@ -200,7 +200,7 @@ func _deposit() -> void:
|
||||
_go_pick_up(nearest)
|
||||
return
|
||||
|
||||
state = GatherState.AWAITING
|
||||
state = State.AWAITING
|
||||
navigate_to.emit(gathering_center)
|
||||
|
||||
|
||||
@ -247,7 +247,7 @@ func _on_body_entered(item: Node3D) -> void:
|
||||
return
|
||||
|
||||
nearby_items[item_id] = item as Honeydew
|
||||
if state == GatherState.AWAITING and anthill.space_left() > 0:
|
||||
if state == State.AWAITING and anthill.space_left() > 0:
|
||||
_go_pick_up(item as Honeydew)
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user