mirror of
https://github.com/Steffo99/nanogolf.git
synced 2024-11-24 17:14:19 +00:00
35 lines
878 B
GDScript3
35 lines
878 B
GDScript3
|
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)
|