| @ -0,0 +1,82 @@ | |||
| extends Node | |||
| #region Graphics Settings Signals | |||
| signal apply_graphics_settings | |||
| signal graphics_resolution_changed(resolution: Vector2i) | |||
| signal graphics_fullscreen_changed(fullscreen_enabled: bool) | |||
| signal graphics_vsync_changed(vsync_enabled: bool) | |||
| signal graphics_fov_changed(fov: int) | |||
| #endregion | |||
| ## See documentation to where this path is: https://docs.godotengine.org/en/stable/tutorials/io/data_paths.html#accessing-persistent-user-data-user[br][br] | |||
| ## Default Paths:[br] | |||
| ## * Windows: %APPDATA%\Godot\app_userdata\[project_name][br] | |||
| ## * macOS: ~/Library/Application Support/Godot/app_userdata/[project_name][br] | |||
| ## * Linux: ~/.local/share/godot/app_userdata/[project_name][br] | |||
| var save_data_path: String = "user://game_data/" | |||
| var settings_file_name: String = "game_settings.tres" | |||
| var settings_file_path: String = save_data_path + settings_file_name | |||
| var settings: GameSettingsResource = GameSettingsResource.new() | |||
| func _init() -> void: | |||
| graphics_fov_changed.connect(_on_graphics_fov_changed) | |||
| graphics_fullscreen_changed.connect(_on_graphics_fullscreen_changed) | |||
| graphics_resolution_changed.connect(_on_graphics_resolution_changed) | |||
| graphics_vsync_changed.connect(_on_graphics_vsync_changed) | |||
| apply_graphics_settings.connect(_on_apply_graphics_settings) | |||
| #region Graphics Settings | |||
| func _on_apply_graphics_settings() -> void: | |||
| if settings.graphics.fullscreen: | |||
| DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) | |||
| else: | |||
| DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) | |||
| get_window().size = settings.graphics.resolution | |||
| if settings.graphics.vsync: | |||
| DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED) | |||
| else: | |||
| DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_DISABLED) | |||
| save_settings() | |||
| func _on_graphics_fov_changed(fov: int) -> void: | |||
| settings.graphics.fov = fov | |||
| func _on_graphics_fullscreen_changed(fullscreen_enabled: bool) -> void: | |||
| settings.graphics.fullscreen = fullscreen_enabled | |||
| func _on_graphics_resolution_changed(resolution: Vector2i) -> void: | |||
| settings.graphics.resolution = resolution | |||
| func _on_graphics_vsync_changed(vsync_enabled: bool) -> void: | |||
| settings.graphics.vsync = vsync_enabled | |||
| #endregion | |||
| #region Saving and Loading Settings | |||
| func load_settings(apply_after_load: bool = true) -> void: | |||
| if !FileAccess.file_exists(settings_file_path): | |||
| printerr("Failed to load game settings. File does not exist: ", settings_file_path) | |||
| return | |||
| settings = ResourceLoader.load(settings_file_path) | |||
| if settings == null: | |||
| printerr("Failed to load game settings. Unknown format? ", settings_file_path) | |||
| return | |||
| if apply_after_load: | |||
| apply_graphics_settings.emit() | |||
| func save_settings() -> void: | |||
| if !DirAccess.dir_exists_absolute(save_data_path): | |||
| DirAccess.make_dir_absolute(save_data_path) | |||
| var result: int = ResourceSaver.save(settings, settings_file_path) | |||
| if result != OK: | |||
| printerr("Failed to save game settings: ", result) | |||
| #endregion | |||
| @ -0,0 +1 @@ | |||
| uid://dxe2y12f412lp | |||
| @ -1,51 +1,9 @@ | |||
| extends Node | |||
| signal graphics_settings_changed(resolution: Vector2, fullscreen: bool, vsync: bool) | |||
| signal graphics_fov_changed(fov: int) | |||
| const BLOCK_PREFAB: PackedScene = preload("res://scenes/blocks/block.tscn") | |||
| const DROPPED_BLOCK_PREFAB: PackedScene = preload("res://scenes/blocks/dropped_block.tscn") | |||
| # TODO: Move the following into the GameSettingsManager | |||
| var enable_waila: bool = true ## Enable `What Am I Looking At` UI | |||
| var enable_block_highlight: bool = true | |||
| # TODO: Replace the following with a Resource | |||
| var graphics_settings: Dictionary[String, Variant] = { | |||
| "resolution": Vector2i.ZERO, | |||
| "fov": 75, | |||
| "fullscreen": false, | |||
| "vsync": false, | |||
| } | |||
| func _init() -> void: | |||
| graphics_settings_changed.connect(_on_graphics_settings_changed) | |||
| graphics_fov_changed.connect(_on_graphics_fov_changed) | |||
| func apply_graphics_settings() -> void: | |||
| if graphics_settings.fullscreen: | |||
| DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) | |||
| else: | |||
| DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) | |||
| get_window().size = graphics_settings.resolution | |||
| if graphics_settings.vsync: | |||
| DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED) | |||
| else: | |||
| DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_DISABLED) | |||
| func _on_graphics_fov_changed(fov: int) -> void: | |||
| graphics_settings.fov = fov | |||
| func _on_graphics_settings_changed(resolution: Vector2i, fullscreen: bool, vsync: bool) -> void: | |||
| graphics_settings.resolution = resolution | |||
| graphics_settings.fullscreen = fullscreen | |||
| graphics_settings.vsync = vsync | |||
| apply_graphics_settings() | |||
| @ -0,0 +1,8 @@ | |||
| ## The resource for saving game settings. | |||
| ## This should be not be saved with saves (for game syncing reasons) | |||
| class_name GameSettingsResource | |||
| extends Resource | |||
| @export var game_version: String = ProjectSettings.get_setting("application/config/version") | |||
| @export var graphics: GraphicsSettingsResource = GraphicsSettingsResource.new() | |||
| @ -0,0 +1 @@ | |||
| uid://cffw77d120p56 | |||
| @ -0,0 +1,9 @@ | |||
| [gd_resource type="Resource" script_class="GameSettingsResource" load_steps=2 format=3 uid="uid://b3kkeyyos7a7"] | |||
| [ext_resource type="Script" uid="uid://cffw77d120p56" path="res://resources/game_settings/game_settings_resource.gd" id="1_fe7s4"] | |||
| [resource] | |||
| script = ExtResource("1_fe7s4") | |||
| game_version = null | |||
| graphics = [] | |||
| metadata/_custom_type_script = "uid://cffw77d120p56" | |||
| @ -0,0 +1,9 @@ | |||
| ## The resource for saving game settings. | |||
| ## This should be not be saved with saves (for game syncing reasons) | |||
| class_name GraphicsSettingsResource | |||
| extends Resource | |||
| @export var resolution: Vector2i = Vector2i(1280, 720) | |||
| @export var fullscreen: bool = false | |||
| @export var vsync: bool = false | |||
| @export var fov: int = 75 | |||
| @ -0,0 +1 @@ | |||
| uid://mfghfem8im6o | |||
| @ -0,0 +1,11 @@ | |||
| [gd_resource type="Resource" script_class="GraphicsSettingsResource" load_steps=2 format=3 uid="uid://b07gyfa776057"] | |||
| [ext_resource type="Script" uid="uid://mfghfem8im6o" path="res://resources/game_settings/graphics_settings.gd" id="1_3m2to"] | |||
| [resource] | |||
| script = ExtResource("1_3m2to") | |||
| resolution = Vector2i(1280, 720) | |||
| fullscreen = false | |||
| vsync = false | |||
| fov = 75 | |||
| metadata/_custom_type_script = "uid://mfghfem8im6o" | |||