mirror of
https://github.com/Steffo99/nanogolf.git
synced 2024-11-21 15:44:21 +00:00
yes
This commit is contained in:
parent
f2b4788903
commit
14fbad5261
6 changed files with 53 additions and 20 deletions
|
@ -233,22 +233,24 @@ func _ready() -> void:
|
||||||
|
|
||||||
func _on_everyone_entered_hole():
|
func _on_everyone_entered_hole():
|
||||||
Log.peer(self, "Everyone entered hole, starting end timer...")
|
Log.peer(self, "Everyone entered hole, starting end timer...")
|
||||||
complete_timer = complete_timer_scene.instantiate()
|
if is_multiplayer_authority():
|
||||||
complete_timer.timeout.connect(_on_complete_timer_timeout)
|
complete_timer = complete_timer_scene.instantiate()
|
||||||
add_child(complete_timer)
|
complete_timer.timeout.connect(_on_complete_timer_timeout)
|
||||||
|
add_child(complete_timer)
|
||||||
|
|
||||||
func _on_complete_timer_timeout():
|
func _on_complete_timer_timeout():
|
||||||
Log.peer(self, "End timer has timed out, emitting level_completed signal...")
|
Log.peer(self, "End timer has timed out, emitting level_completed signal...")
|
||||||
level_completed.emit()
|
|
||||||
complete_timer.queue_free()
|
complete_timer.queue_free()
|
||||||
|
player_dir.rpc_push_reported_scores.rpc()
|
||||||
|
level_completed.emit()
|
||||||
|
|
||||||
func _on_local_playernode_possessed(_old: int, new: int, playernode: PlayerNode):
|
func _on_local_playernode_possessed(_old: int, _new: int, playernode: PlayerNode):
|
||||||
if camera != null:
|
if camera != null:
|
||||||
var ctarget = tee.get_node(playernode.player_name)
|
var ctarget = tee.get_node(playernode.player_name)
|
||||||
camera.target = ctarget
|
camera.target = ctarget
|
||||||
|
|
||||||
|
|
||||||
## Emitted when it's time to change to the next level.
|
## Emitted on the server when it's time to change to the next level.
|
||||||
signal level_completed
|
signal level_completed
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ func spawn(playernode: PlayerNode, tposition: Vector2 = Vector2.ZERO, tstrokes:
|
||||||
obj.player_name = playernode.player_name
|
obj.player_name = playernode.player_name
|
||||||
obj.player_color = playernode.player_color
|
obj.player_color = playernode.player_color
|
||||||
obj.set_multiplayer_authority(playernode.get_multiplayer_authority())
|
obj.set_multiplayer_authority(playernode.get_multiplayer_authority())
|
||||||
|
obj.putt_controller.set_multiplayer_authority(playernode.get_multiplayer_authority())
|
||||||
obj.putt_controller.can_putt = not multiplayer.is_server() and playernode.is_multiplayer_authority()
|
obj.putt_controller.can_putt = not multiplayer.is_server() and playernode.is_multiplayer_authority()
|
||||||
if thole:
|
if thole:
|
||||||
obj.enter_hole()
|
obj.enter_hole()
|
||||||
|
@ -72,6 +73,7 @@ func _on_color_changed(old: Color, new: Color, obj: GolfBall) -> void:
|
||||||
func _on_possessed(old: int, new: int, obj: GolfBall) -> void:
|
func _on_possessed(old: int, new: int, obj: GolfBall) -> void:
|
||||||
Log.peer(self, "PlayerNode changed owner, updating it on GolfBall: %d → %d" % [old, new])
|
Log.peer(self, "PlayerNode changed owner, updating it on GolfBall: %d → %d" % [old, new])
|
||||||
obj.set_multiplayer_authority(new)
|
obj.set_multiplayer_authority(new)
|
||||||
|
obj.putt_controller.set_multiplayer_authority(new)
|
||||||
obj.putt_controller.can_putt = is_multiplayer_authority()
|
obj.putt_controller.can_putt = is_multiplayer_authority()
|
||||||
if new == 1:
|
if new == 1:
|
||||||
obj.hide()
|
obj.hide()
|
||||||
|
@ -88,6 +90,6 @@ func _on_cleanup(playernode: PlayerNode, on_name_changed: Callable, on_color_cha
|
||||||
|
|
||||||
func _on_entered_hole(strokes: int, playernode: PlayerNode) -> void:
|
func _on_entered_hole(strokes: int, playernode: PlayerNode) -> void:
|
||||||
if playernode.is_multiplayer_authority():
|
if playernode.is_multiplayer_authority():
|
||||||
playernode.report_score(strokes)
|
playernode.rpc_report_score.rpc(strokes)
|
||||||
if is_everyone_in_hole():
|
if is_everyone_in_hole():
|
||||||
everyone_entered_hole.emit()
|
everyone_entered_hole.emit()
|
||||||
|
|
|
@ -145,6 +145,8 @@ func next_level() -> void:
|
||||||
rpc_wipe_level.rpc()
|
rpc_wipe_level.rpc()
|
||||||
init_target()
|
init_target()
|
||||||
build_level()
|
build_level()
|
||||||
|
else:
|
||||||
|
rpc_destroy_level.rpc()
|
||||||
|
|
||||||
|
|
||||||
## Clear the current level on all clients and prepare to build a new one.
|
## Clear the current level on all clients and prepare to build a new one.
|
||||||
|
@ -154,9 +156,22 @@ func rpc_wipe_level():
|
||||||
destroy_level()
|
destroy_level()
|
||||||
initialize_level()
|
initialize_level()
|
||||||
|
|
||||||
|
## Clear the current level on all clients.
|
||||||
|
@rpc("authority", "call_local", "reliable")
|
||||||
|
func rpc_destroy_level():
|
||||||
|
if level != null:
|
||||||
|
destroy_level()
|
||||||
|
|
||||||
|
|
||||||
|
## Emit [signal level_completed] everywhere.
|
||||||
|
@rpc("authority", "call_local", "reliable")
|
||||||
|
func rpc_level_completed() -> void:
|
||||||
|
level_completed.emit(level)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _on_level_completed() -> void:
|
func _on_level_completed() -> void:
|
||||||
Log.peer(self, "Level completed!")
|
Log.peer(self, "Level completed!")
|
||||||
level_completed.emit(level)
|
rpc_level_completed.rpc()
|
||||||
if is_multiplayer_authority():
|
if is_multiplayer_authority():
|
||||||
next_level()
|
next_level()
|
||||||
|
|
|
@ -58,21 +58,18 @@ func rpc_query_color():
|
||||||
if is_multiplayer_authority():
|
if is_multiplayer_authority():
|
||||||
rpc_set_color.rpc(player_color)
|
rpc_set_color.rpc(player_color)
|
||||||
|
|
||||||
|
## The score reported for the current level.
|
||||||
|
##
|
||||||
|
## If the player hasn't completed the level, this should be -1.
|
||||||
|
var reported_score: int = -1
|
||||||
|
|
||||||
## Add a new score entry to the [field hole_scores].
|
|
||||||
func report_score(strokes: int) -> void:
|
|
||||||
assert(is_multiplayer_authority())
|
|
||||||
rpc_report_score.rpc(strokes)
|
|
||||||
var tscores = hole_scores.duplicate(true)
|
|
||||||
tscores.push_back(strokes)
|
|
||||||
rpc_set_scores.rpc(tscores)
|
|
||||||
|
|
||||||
## Emit [signal score_reported] everywhere.
|
## Update [field reported_score] and emit [signal score_reported] everywhere.
|
||||||
@rpc("authority", "call_local", "reliable")
|
@rpc("authority", "call_local", "reliable")
|
||||||
func rpc_report_score(strokes: int):
|
func rpc_report_score(strokes: int):
|
||||||
|
reported_score = strokes
|
||||||
score_reported.emit(strokes)
|
score_reported.emit(strokes)
|
||||||
|
|
||||||
|
|
||||||
## Change the [field hole_scores] everywhere.
|
## Change the [field hole_scores] everywhere.
|
||||||
@rpc("authority", "call_local", "reliable")
|
@rpc("authority", "call_local", "reliable")
|
||||||
func rpc_set_scores(value: Array):
|
func rpc_set_scores(value: Array):
|
||||||
|
|
|
@ -3,7 +3,7 @@ class_name PlayerNodeDirectory
|
||||||
|
|
||||||
|
|
||||||
## The scene to instantiate on creation of a new [PlayerNode].
|
## The scene to instantiate on creation of a new [PlayerNode].
|
||||||
@export var playernode_scene: PackedScene = preload("res://scenes/playernode.tscn")
|
const playernode_scene: PackedScene = preload("res://scenes/playernode.tscn")
|
||||||
|
|
||||||
|
|
||||||
## Find the subordinate [PlayerNode] with the given player_name, and return it if found, otherwise return null.
|
## Find the subordinate [PlayerNode] with the given player_name, and return it if found, otherwise return null.
|
||||||
|
@ -32,11 +32,28 @@ func rpc_possess_playernode(player_name: String, peer_id: int):
|
||||||
var sanitized_player_name = PlayerNode.sanitize_player_name(player_name)
|
var sanitized_player_name = PlayerNode.sanitize_player_name(player_name)
|
||||||
playernode.player_name = sanitized_player_name
|
playernode.player_name = sanitized_player_name
|
||||||
playernode.name = sanitized_player_name
|
playernode.name = sanitized_player_name
|
||||||
|
# Determine the number of holes that this player has skipped
|
||||||
|
var played_holes = 0
|
||||||
|
for othernode in get_children():
|
||||||
|
var othernode_played_holes = len(othernode.hole_scores)
|
||||||
|
if othernode_played_holes > played_holes:
|
||||||
|
played_holes = othernode_played_holes
|
||||||
|
# Fill the empty scores with -1
|
||||||
|
for _index in range(played_holes):
|
||||||
|
playernode.hole_scores.push_back(-1)
|
||||||
|
# Add the playernode to the SceneTree
|
||||||
add_child(playernode)
|
add_child(playernode)
|
||||||
# If the multiplayer authority does not match the requested one, make it match
|
# If the multiplayer authority does not match the requested one, make it match
|
||||||
playernode.possess(peer_id)
|
playernode.possess(peer_id)
|
||||||
|
|
||||||
|
|
||||||
|
## Push the [field reported_score] of all children to the [field hole_scores] array, and reset its value to -1.
|
||||||
|
@rpc("authority", "call_local", "reliable")
|
||||||
|
func rpc_push_reported_scores():
|
||||||
|
for playernode in get_children():
|
||||||
|
playernode.hole_scores.push_back(playernode.reported_score)
|
||||||
|
playernode.reported_score = -1
|
||||||
|
|
||||||
|
|
||||||
func _on_playernode_name_changed(old: String, new: String, playernode: PlayerNode) -> void:
|
func _on_playernode_name_changed(old: String, new: String, playernode: PlayerNode) -> void:
|
||||||
playernode_name_changed.emit(old, new, playernode)
|
playernode_name_changed.emit(old, new, playernode)
|
||||||
|
|
|
@ -104,9 +104,9 @@ func end_putt(end_position: Vector2):
|
||||||
can_putt = false
|
can_putt = false
|
||||||
var putt_vector = compute_putt(drag_start_point, end_position)
|
var putt_vector = compute_putt(drag_start_point, end_position)
|
||||||
putt.emit(putt_vector)
|
putt.emit(putt_vector)
|
||||||
play_putt_sound(putt_vector)
|
play_putt_sound.rpc(putt_vector)
|
||||||
|
|
||||||
|
|
||||||
|
@rpc("authority", "call_local", "reliable")
|
||||||
func play_putt_sound(putt_vector: Vector2):
|
func play_putt_sound(putt_vector: Vector2):
|
||||||
var putt_impulse: float = putt_vector.length()
|
var putt_impulse: float = putt_vector.length()
|
||||||
sound.volume_db = putt_volume.sample(putt_impulse / putt_max_impulse)
|
sound.volume_db = putt_volume.sample(putt_impulse / putt_max_impulse)
|
||||||
|
|
Loading…
Reference in a new issue