2024-03-12 16:31:26 +00:00
|
|
|
extends Node
|
|
|
|
class_name LevelManager
|
|
|
|
|
2024-03-14 04:17:00 +00:00
|
|
|
## 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)
|
2024-03-14 04:17:00 +00:00
|
|
|
# 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)
|
2024-03-14 04:17:00 +00:00
|
|
|
# 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()
|