Refactor Part II
This commit is contained in:
parent
cd20f952ce
commit
3f99f1b8dd
56 changed files with 193 additions and 168 deletions
|
|
@ -1,14 +1,14 @@
|
|||
extends Node
|
||||
|
||||
@export var starting_pistol: StringName
|
||||
@export var starting_knife: StringName
|
||||
@export var weapon_spawner: MultiplayerSpawner
|
||||
@export var starting_pistol: PackedScene
|
||||
@export var starting_knife: PackedScene
|
||||
@export var weapon_system: WeaponSystem
|
||||
|
||||
func _ready() -> void:
|
||||
deferred_ready.call_deferred()
|
||||
|
||||
func deferred_ready() -> void:
|
||||
if is_multiplayer_authority():
|
||||
weapon_spawner.spawn({"scene_file_path": starting_pistol})
|
||||
weapon_spawner.spawn({"scene_file_path": starting_knife})
|
||||
weapon_system.add(starting_pistol.instantiate(),"secondary")
|
||||
weapon_system.add(starting_knife.instantiate(),"knife")
|
||||
queue_free()
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ class_name WeaponSubStateMachine
|
|||
remaining_ammo = 0
|
||||
else:
|
||||
remaining_ammo = value
|
||||
ammo_updated.emit()
|
||||
|
||||
@export var speed_modifier: float = 1.0
|
||||
@export var can_be_previous: bool = true
|
||||
|
|
@ -52,6 +53,16 @@ func _ready() -> void:
|
|||
child.machine = self
|
||||
child.transition.connect(on_transition_required)
|
||||
child.return_to_previous.connect(request_return.emit)
|
||||
|
||||
var parent = get_parent()
|
||||
if parent is WeaponSystem:
|
||||
system = parent
|
||||
animation_player = system.animation_player
|
||||
player_camera = system.camera
|
||||
player = system.player
|
||||
request_return.connect(system.return_to_previous)
|
||||
ammo_depleted.connect(system.check_for_empty)
|
||||
ammo_updated.connect(system.on_ammo_updated)
|
||||
|
||||
func enter() -> void:
|
||||
super()
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ signal slots_updated(slots: Dictionary[StringName,WeaponSubStateMachine])
|
|||
signal ammo_updated(ammo: int, remaining_ammo: int)
|
||||
|
||||
func _ready() -> void:
|
||||
$WeaponSpawner.spawn_function = pick_up_weapon
|
||||
player_input.drop.connect(drop_current)
|
||||
player_input.fire_begin.connect(use_begin)
|
||||
player_input.fire_end.connect(use_end)
|
||||
|
|
@ -43,33 +42,32 @@ func get_speed_modifier() -> float:
|
|||
func can_add(slot: StringName) -> bool:
|
||||
return slots.has(slot) and slots[slot] == null
|
||||
|
||||
@rpc("call_local","reliable")
|
||||
func add(state: WeaponSubStateMachine, slot: StringName,ignore_parent: bool = false) -> void:
|
||||
func add(state: WeaponSubStateMachine, slot: StringName) -> void:
|
||||
if not multiplayer.is_server():
|
||||
return
|
||||
if can_add(slot) == false:
|
||||
return
|
||||
|
||||
if ignore_parent == false:
|
||||
if state.get_parent() == null:
|
||||
add_child(state, true)
|
||||
if state.get_parent() != self:
|
||||
state.get_parent().remove_child(state)
|
||||
add_child(state,true)
|
||||
state.ready.emit()
|
||||
add_child(state, true)
|
||||
|
||||
slots[slot] = state
|
||||
state.system = self
|
||||
state.animation_player = animation_player
|
||||
state.player_camera = camera
|
||||
state.player = player
|
||||
state.request_return.connect(return_to_previous)
|
||||
state.ammo_depleted.connect(check_for_empty)
|
||||
state.ammo_updated.connect(on_ammo_updated)
|
||||
slots_updated.emit(slots)
|
||||
|
||||
if current_state == null:
|
||||
current_state = state
|
||||
ammo_updated.emit(current_state.ammo,current_state.remaining_ammo)
|
||||
state.enter.call_deferred()
|
||||
|
||||
|
||||
func process_spawned_weapon(weapon_node: Node):
|
||||
var weapon = weapon_node as WeaponSubStateMachine
|
||||
|
||||
slots[weapon.slot] = weapon
|
||||
slots_updated.emit(slots)
|
||||
|
||||
if current_state == null:
|
||||
current_state = weapon
|
||||
ammo_updated.emit(current_state.ammo,current_state.remaining_ammo)
|
||||
|
||||
func get_empty_ability_slot() -> StringName:
|
||||
if slots["ability_first"] == null:
|
||||
|
|
@ -133,32 +131,6 @@ func drop_slot(slot: StringName):
|
|||
return
|
||||
drop(slots[slot])
|
||||
|
||||
# Spawn function
|
||||
# Data should be a dictionary with these keys:
|
||||
# ammo
|
||||
# remaining_ammo
|
||||
# scene_file_path
|
||||
func pick_up_weapon(data: Variant) -> Node:
|
||||
if data.has("scene_file_path") == false:
|
||||
return Node.new()
|
||||
if data.has_all(["ammo","remaining_ammo"]):
|
||||
var scene: WeaponSubStateMachine = load(data["scene_file_path"]).instantiate()
|
||||
scene.ammo = data["ammo"]
|
||||
scene.remaining_ammo = data["remaining_ammo"]
|
||||
scene.slot = data["slot"]
|
||||
scene.set_multiplayer_authority(get_multiplayer_authority())
|
||||
|
||||
add(scene,scene.slot,true)
|
||||
|
||||
return scene
|
||||
else:
|
||||
var scene: WeaponSubStateMachine = load(data["scene_file_path"]).instantiate()
|
||||
scene.set_multiplayer_authority(get_multiplayer_authority())
|
||||
|
||||
add(scene,scene.slot,true)
|
||||
|
||||
return scene
|
||||
|
||||
func check_for_empty() -> void:
|
||||
if is_multiplayer_authority() == false:
|
||||
return
|
||||
|
|
@ -167,7 +139,8 @@ func check_for_empty() -> void:
|
|||
child.queue_free()
|
||||
|
||||
func on_ammo_updated() -> void:
|
||||
ammo_updated.emit(current_state.ammo,current_state.remaining_ammo)
|
||||
if current_state != null:
|
||||
ammo_updated.emit(current_state.ammo,current_state.remaining_ammo)
|
||||
|
||||
func disable() -> void:
|
||||
disabled = true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue