1
Fork 0
mirror of https://github.com/Steffo99/nanogolf.git synced 2024-11-22 08:04:21 +00:00
algodist-steffo-nanogolf/scenes/level_manager.gd

43 lines
1.1 KiB
GDScript3
Raw Normal View History

2024-03-12 16:31:26 +00:00
extends Node
class_name LevelManager
## The blank [GolfLevel] to initialize on clients.
const base_scene: PackedScene = preload("res://scenes/golf_level.tscn")
## The [LevelPlaylist] to use to load [GolfLevel]s from.
@export var playlist: LevelPlaylist = null
## The [PlayerNodeDirectory] to use to determine which players to spawn on clients.
@export var player_dir: PlayerNodeDirectory = null
## The currently instantiated [GolfLevel].
var level: GolfLevel = null
## Create the empty [GolfLevel] object everywhere.
@rpc("authority", "call_local", "reliable")
func rpc_next_level():
# Destroy the current level
if level != null:
level.queue_free()
level = null
# Create the new level
level = base_scene.instantiate()
level.player_dir = player_dir
2024-03-15 18:57:15 +00:00
level.level_completed.connect(_on_level_completed)
# Determine the next level
if multiplayer.is_server():
var target = playlist.advance().instantiate()
level.target = target
# Add the level to the tree
2024-03-15 18:57:15 +00:00
add_child(level, true)
# Start the replication
if multiplayer.is_server():
level.build()
2024-03-15 18:57:15 +00:00
func _on_level_completed() -> void:
if multiplayer.is_server():
rpc_next_level.rpc()