🔧 Settings, Maps and Environments management

This commit is contained in:
anyreso 2024-04-28 06:15:19 +00:00
parent 31e6c0910a
commit 5d896e1dd3
31 changed files with 1917 additions and 381 deletions

59
systems/maps_manager.gd Normal file
View file

@ -0,0 +1,59 @@
# 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()
## 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

View file

@ -1,37 +1,65 @@
class_name Settings extends Node
# 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 _config_file : ConfigFile = ConfigFile.new()
var fov : int = 90
var mouse_sensitivity : float = 0.6
var inverted_y_axis : bool = false
var fullscreen : bool = false
const SETTINGS_FILE_PATH : String = "user://settings.cfg"
var _file : ConfigFile = ConfigFile.new()
const path : String = "user://settings.cfg"
func _ready() -> void:
var error : Error = _config_file.load(SETTINGS_FILE_PATH)
# make sure we load most recent core settings
self.reset()
# merge core settings with user-defined settings
var err : Error = _file.load(self.path)
if err == ERR_FILE_CANT_OPEN:
push_warning("settings not found, using defaults")
# apply state
self.apply()
fov = _config_file.get_value("gameplay", "fov", fov)
mouse_sensitivity = _config_file.get_value("gameplay", "mouse_sensitivity", mouse_sensitivity)
inverted_y_axis = _config_file.get_value("gameplay", "inverted_y_axis", inverted_y_axis)
fullscreen = _config_file.get_value("graphics", "fullscreen", fullscreen)
_update_screen()
if error != OK:
print("Settings not found, using defaults")
save_to_file()
func get_value(section: String, key: String, default: Variant = null) -> Variant:
return _file.get_value(section, key, default)
func save_to_file() -> void:
_config_file.set_value("gameplay", "fov", fov)
_config_file.set_value("gameplay", "mouse_sensitivity", mouse_sensitivity)
_config_file.set_value("gameplay", "inverted_y_axis", inverted_y_axis)
_config_file.set_value("graphics", "fullscreen", fullscreen)
_update_screen()
_config_file.save(SETTINGS_FILE_PATH)
func set_value(section: String, key: String, value: Variant) -> void:
return _file.set_value(section, key, value)
func _update_screen() -> void:
if fullscreen:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
else:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
func reset() -> void:
_file.clear()
# video settings
_file.set_value("ui", "scale", 2)
_file.set_value("video", "quality", 1.125)
_file.set_value("video", "filter", 0)
_file.set_value("video", "fsr_sharpness", 0)
_file.set_value("video", "window_mode", 2)
_file.set_value("video", "vsync", 0)
_file.set_value("video", "taa", 0)
_file.set_value("video", "msaa", 0)
_file.set_value("video", "fxaa", 0)
_file.set_value("video", "fov", 90)
# controls settings
_file.set_value("controls", "mouse_sensitivity", .6)
_file.set_value("controls", "inverted_y_axis", false)
# quality settings
_file.set_value("quality", "shadow_size", 3)
_file.set_value("quality", "shadow_filter", 2)
_file.set_value("quality", "mesh_lod", 2)
# environment settings
_file.set_value("environment", "sdfgi", 0)
_file.set_value("environment", "glow", 0)
_file.set_value("environment", "ssao", 0)
_file.set_value("environment", "ssr", 0)
_file.set_value("environment", "ssil", 0)
_file.set_value("environment", "volumetric_fog", 0)
func apply() -> void:
_file.save(self.path)

20
systems/teams.gd Normal file
View file

@ -0,0 +1,20 @@
# 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/>.
class_name Team extends Object
var team_id : int
func _init(id : int) -> void:
team_id = id