open-fpsz/systems/maps_manager.gd
2024-04-27 14:52:11 -04:00

56 lines
2.2 KiB
GDScript

# This file is part of open-fpsz.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
extends Node
var environment := Environment.new()
var flagstand : Marker3D = null
var _rng := RandomNumberGenerator.new()
var current_map : Terrain3D = null:
set(new_map):
if current_map != null:
current_map.queue_free()
current_map = new_map
flagstand = new_map.get_node("FlagStand")
var world : World3D = get_viewport().find_world_3d()
if world.environment:
# forward user environment settings
world.environment.sdfgi_enabled = MapsManager.environment.sdfgi_enabled
world.environment.glow_enabled = MapsManager.environment.glow_enabled
world.environment.ssao_enabled = MapsManager.environment.ssao_enabled
world.environment.ssr_enabled = MapsManager.environment.ssr_enabled
world.environment.ssr_max_steps = MapsManager.environment.ssr_max_steps
world.environment.ssil_enabled = MapsManager.environment.ssil_enabled
world.environment.volumetric_fog_enabled = MapsManager.environment.volumetric_fog_enabled
func get_player_spawn() -> Node3D:
if current_map == null:
push_error("MapsManager.current_map is null")
return null
if not current_map.has_node("PlayerSpawns"):
push_warning("PlayerSpawns node not found in MapsManager.current_map")
return null
var player_spawns : Node = current_map.get_node("PlayerSpawns")
var spawn_count : int = player_spawns.get_child_count()
if spawn_count == 0:
push_error("PlayerSpawns has no children (%s)" % current_map.name)
return null
var spawn_index : int = _rng.randi_range(0, spawn_count - 1)
var random_spawn : Marker3D = player_spawns.get_child(spawn_index)
return random_spawn