1
Fork 0
mirror of https://github.com/Steffo99/nanogolf.git synced 2024-11-21 15:44:21 +00:00
This commit is contained in:
Steffo 2024-03-16 05:55:02 +01:00
parent 76f304613c
commit 923a5e17c9
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
6 changed files with 32 additions and 12 deletions

View file

@ -24,12 +24,12 @@ func _on_playernode_name_changed(old: String, new: String, playernode: PlayerNod
instance.from_score(playernode)
instance.name = "PlayerScoreLabel__%s" % new
func _on_playernode_color_changed(old: Color, new: Color, playernode: PlayerNode) -> void:
func _on_playernode_color_changed(_old: Color, _new: Color, playernode: PlayerNode) -> void:
var instance = get_node_or_null("PlayerScoreLabel__%s" % playernode.player_name)
if instance != null:
instance.from_score(playernode)
func _on_playernode_possessed(old: int, new: int, playernode: PlayerNode) -> void:
func _on_playernode_possessed(_old: int, _new: int, playernode: PlayerNode) -> void:
var instance = get_node_or_null("PlayerScoreLabel__%s" % playernode.player_name)
if instance != null:
instance.from_score(playernode)
@ -41,9 +41,14 @@ func _on_playernode_score_reported(strokes: int, playernode: PlayerNode) -> void
scores_container.add_child(score_instance)
scores_panel.show()
func _on_playernode_scores_changed(old: Array, new: Array, playernode: PlayerNode) -> void:
func _on_playernode_scores_changed(_old: Array, _new: Array, _playernode: PlayerNode) -> void:
pass
func _on_local_player_spawned(ball: GolfBall, _level: GolfLevel) -> void:
ball.putt_controller.putt.connect(_on_putt.bind(ball))
func _on_putt(_putt_vector: Vector2, ball: GolfBall) -> void:
strokes_label.text = "%d" % ball.strokes
func _on_strokes_changed(strokes: int) -> void:

View file

@ -134,6 +134,7 @@ func check_has_entered_hole() -> bool:
func rpc_sync_enter_hole():
in_hole = true
visible = false
if not multiplayer.is_server():
hole_sound.play()
entered_hole.emit(strokes)

View file

@ -5,6 +5,8 @@ class_name GolfLevel
## Emitted when it's time to change to the next level.
signal level_completed
## Emitted when the [GolfBall] for the local player has been spawned.
signal local_player_spawned(ball: GolfBall)
@export_category("Level Data")
@ -143,8 +145,9 @@ func build_balls() -> void:
func rpc_build_ball(player_name: String):
Log.peer(self, "Building tee ball for: %s" % player_name)
var playernode: PlayerNode = player_dir.get_playernode(player_name)
tee.spawn(playernode)
var ball = tee.spawn(playernode)
if playernode.is_multiplayer_authority():
local_player_spawned.emit(ball)
## Replicate the [field hole] of the [field target] to the remote [field hole].
func build_hole() -> void:

View file

@ -12,6 +12,9 @@ class_name LevelManager
@export var player_dir: PlayerNodeDirectory = null
## Emitted when the [GolfBall] for the local player was spawned in a level.
signal local_player_spawned(ball: GolfBall, level: GolfLevel)
## Emitted when the current level is about to be destroyed.
signal level_destroying(level: GolfLevel)
@ -62,6 +65,7 @@ func rpc_next_level():
# Configure the new level
Log.peer(self, "Configuring level variables...")
level.player_dir = player_dir
level.local_player_spawned.connect(_on_local_player_spawned)
level.level_completed.connect(_on_level_completed)
if multiplayer.is_server():
Log.peer(self, "Instantiating the target level scene...")
@ -82,3 +86,8 @@ func _on_level_completed() -> void:
level_completed.emit(level)
if is_multiplayer_authority():
rpc_next_level.rpc()
func _on_local_player_spawned(ball: GolfBall) -> void:
Log.peer(self, "Local player spawned: %s" % ball)
local_player_spawned.emit(ball, level)

View file

@ -69,9 +69,11 @@ func init_client_game(player_name: String, player_color: Color, server_address:
client_game_instance.init_signals()
client_game_instance.local_player_name = player_name
client_game_instance.local_player_color = player_color
client_game_instance.phase_tracker.phase_changed.connect(_on_phase_changed)
smp.set_multiplayer_peer(peer)
func deinit_client_game() -> void:
client_game_instance.phase_tracker.phase_changed.disconnect(_on_phase_changed)
client_game_instance.multiplayer.multiplayer_peer = null
scene_tree.set_multiplayer(multiplayer, ^"/root/Main/Client")
client_game_instance.queue_free()
@ -90,7 +92,6 @@ func init_lobby_menu() -> void:
client_game_instance.player_dir.playernode_name_changed.connect(lobby_menu_instance.players_list._on_playernode_name_changed)
client_game_instance.player_dir.playernode_color_changed.connect(lobby_menu_instance.players_list._on_playernode_color_changed)
client_game_instance.player_dir.playernode_possessed.connect(lobby_menu_instance.players_list._on_playernode_possessed)
client_game_instance.phase_tracker.phase_changed.connect(_on_phase_changed)
interface_instance.add_child(lobby_menu_instance)
func deinit_lobby_menu() -> void:
@ -103,13 +104,13 @@ func deinit_lobby_menu() -> void:
client_game_instance.player_dir.playernode_name_changed.disconnect(lobby_menu_instance.players_list._on_playernode_name_changed)
client_game_instance.player_dir.playernode_color_changed.disconnect(lobby_menu_instance.players_list._on_playernode_color_changed)
client_game_instance.player_dir.playernode_possessed.disconnect(lobby_menu_instance.players_list._on_playernode_possessed)
client_game_instance.phase_tracker.phase_changed.disconnect(_on_phase_changed)
lobby_menu_instance.queue_free()
lobby_menu_instance = null
func init_game_hud() -> void:
game_hud_instance = game_hud_scene.instantiate()
client_game_instance.level_manager.level_completed.connect(game_hud_instance._on_level_completed)
client_game_instance.level_manager.local_player_spawned.connect(game_hud_instance._on_local_player_spawned)
client_game_instance.player_dir.playernode_name_changed.connect(game_hud_instance._on_playernode_name_changed)
client_game_instance.player_dir.playernode_color_changed.connect(game_hud_instance._on_playernode_color_changed)
client_game_instance.player_dir.playernode_possessed.connect(game_hud_instance._on_playernode_possessed)
@ -119,6 +120,7 @@ func init_game_hud() -> void:
func deinit_game_hud() -> void:
client_game_instance.level_manager.level_completed.disconnect(game_hud_instance._on_level_completed)
client_game_instance.level_manager.local_player_spawned.disconnect(game_hud_instance._on_local_player_spawned)
client_game_instance.player_dir.playernode_name_changed.disconnect(game_hud_instance._on_playernode_name_changed)
client_game_instance.player_dir.playernode_color_changed.disconnect(game_hud_instance._on_playernode_color_changed)
client_game_instance.player_dir.playernode_possessed.disconnect(game_hud_instance._on_playernode_possessed)

View file

@ -18,9 +18,9 @@ var phase: Phase = Phase.LOBBY
## Change the current game phase everywhere.
@rpc("authority", "call_local", "reliable")
func rpc_set_phase(value: Phase):
Log.peer(self, "Changing phase to: %s" % value)
if phase != value:
var old: Phase = phase
if old != value:
Log.peer(self, "Changing phase to: %s" % value)
phase = value
phase_changed.emit(old, value)