1
Fork 0
mirror of https://github.com/Steffo99/nanogolf.git synced 2024-11-27 18:44:18 +00:00
algodist-steffo-nanogolf/scenes/phase_tracker.gd
2024-03-16 05:55:02 +01:00

34 lines
876 B
GDScript

extends Node
class_name PhaseTracker
## Phases of play of the game.
enum Phase {
## The game is currently gathering players in a lobby.
LOBBY,
## The game is currently running.
PLAYING,
## The game has ended.
ENDED,
}
## The phase the game is currently in.
var phase: Phase = Phase.LOBBY
## Change the current game phase everywhere.
@rpc("authority", "call_local", "reliable")
func rpc_set_phase(value: Phase):
var old: Phase = phase
if old != value:
Log.peer(self, "Changing phase to: %s" % value)
phase = value
phase_changed.emit(old, value)
## Ask the server which phase the game is currently in.
@rpc("any_peer", "call_local", "reliable")
func rpc_query_phase():
if multiplayer.is_server():
rpc_set_phase.rpc(phase)
## Emitted when the phase changes on the local scene because of [method rpc_set_phase].
signal phase_changed(old: Phase, new: Phase)