1
Fork 0
mirror of https://github.com/Steffo99/nanogolf.git synced 2024-11-28 02:54:19 +00:00
algodist-steffo-nanogolf/scenes/phase_tracker.gd

35 lines
876 B
GDScript3
Raw Normal View History

2024-03-12 14:45:08 +00:00
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):
2024-03-16 04:55:02 +00:00
var old: Phase = phase
if old != value:
Log.peer(self, "Changing phase to: %s" % value)
2024-03-12 14:45:08 +00:00
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)