sunder/autoloads/settings.gd
2026-02-18 18:33:17 -05:00

72 lines
2.8 KiB
GDScript

# This file is part of sunder.
#
# This program is free software:you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
## Wrapper around ConfigFile to manage game settings file.
extends Node
# @TODO: use res:// settings to load defaults when needed instead of hardcoding here
const settings_path:String = "res://config/settings.cfg"
const user_settings_path:String = "user://settings.cfg"
var _config_file:ConfigFile = ConfigFile.new()
func _ready() -> void:
# make sure we load most recent core settings
reset()
# merge core settings with user-defined settings
var err:Error = _config_file.load(user_settings_path)
if err == ERR_FILE_CANT_OPEN:
push_warning("settings not found, using defaults")
# save state
save()
func get_value(section:String, key:String, default:Variant = null) -> Variant:
return _config_file.get_value(section, key, default)
func set_value(section:String, key:String, value:Variant) -> void:
return _config_file.set_value(section, key, value)
func reset() -> void:
_config_file.clear()
# video settings
_config_file.set_value("ui", "scale", 2)
_config_file.set_value("video", "quality", 1.)
_config_file.set_value("video", "filter", 0)
_config_file.set_value("video", "fsr_sharpness", 0)
_config_file.set_value("video", "window_mode", 2)
_config_file.set_value("video", "vsync", 0)
_config_file.set_value("video", "taa", 0)
_config_file.set_value("video", "msaa", 0)
_config_file.set_value("video", "fxaa", 0)
_config_file.set_value("video", "fov", 90)
# controls settings
_config_file.set_value("controls", "mouse_sensitivity", .6)
_config_file.set_value("controls", "inverted_y_axis", false)
# quality settings
_config_file.set_value("quality", "shadow_size", 3)
_config_file.set_value("quality", "shadow_filter", 2)
_config_file.set_value("quality", "mesh_lod", 2)
# environment settings
_config_file.set_value("environment", "sdfgi", 0)
_config_file.set_value("environment", "glow", 0)
_config_file.set_value("environment", "ssao", 0)
_config_file.set_value("environment", "ssr", 0)
_config_file.set_value("environment", "ssil", 0)
_config_file.set_value("environment", "volumetric_fog", 0)
# server settings
_config_file.set_value("server", "host", "localhost")
_config_file.set_value("server", "port", 9000)
func save() -> void:
_config_file.save(user_settings_path)