mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-01-20 03:54:47 +00:00
63 lines
2.6 KiB
GDScript
63 lines
2.6 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/>.
|
|
## Manage environment settings and terrain maps within a scene.
|
|
extends Node
|
|
|
|
## The default [Environment] used by the current scene in case the [Terrain3D]
|
|
## node does not have a [WorldEnvironment] as one of its children.
|
|
var environment := Environment.new()
|
|
|
|
## Random number generator instance
|
|
var _rng := RandomNumberGenerator.new()
|
|
|
|
var _maps_resource : ArrayPackedSceneResource = preload("res://maps/maps.tres")
|
|
var maps : Array[PackedScene] = _maps_resource.get_items()
|
|
|
|
## Reference to the current terrain map in the scene
|
|
var current_map : Terrain3D = null:
|
|
set(new_map):
|
|
if current_map != null:
|
|
current_map.queue_free()
|
|
current_map = new_map
|
|
# forward user environment settings to current scene environment
|
|
var world : World3D = get_viewport().find_world_3d()
|
|
if world.environment:
|
|
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
|
|
|