1
Fork 0
mirror of https://github.com/Steffo99/nanogolf.git synced 2024-11-21 23:54:21 +00:00
algodist-steffo-nanogolf/scenes/phase_tracker.gd
2024-03-12 15:45:08 +01:00

34 lines
878 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):
Log.peer(self, "Changing phase to: %s" % value)
if phase != value:
var old: Phase = phase
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)