Browse Source

Migrating Game Settings into resource

pull/11/head
Ryan Reed 1 month ago
parent
commit
12dbc451b2
11 changed files with 42 additions and 5 deletions
  1. +19
    -0
      autoloads/game_settings_manager.gd
  2. +6
    -0
      resources/game_settings/game_options_settings_resource.gd
  3. +1
    -0
      resources/game_settings/game_options_settings_resource.gd.uid
  4. +9
    -0
      resources/game_settings/game_options_settings_resource.tres
  5. +2
    -0
      resources/game_settings/game_settings_resource.gd
  6. +0
    -0
      resources/game_settings/graphics_settings_resource.gd
  7. +0
    -0
      resources/game_settings/graphics_settings_resource.gd.uid
  8. +1
    -1
      resources/game_settings/graphics_settings_resource.tres
  9. +1
    -1
      scenes/blocks/block.gd
  10. +2
    -2
      scenes/ui/menus/settings_menu.gd
  11. +1
    -1
      scenes/ui/waila.gd

+ 19
- 0
autoloads/game_settings_manager.gd View File

@ -1,6 +1,11 @@
extends Node extends Node
#region Game Options Signals
signal game_options_block_highlight_changed(block_highlight_enabled: bool)
signal game_options_waila_changed(waila_enabled: bool)
#endregion
#region Graphics Settings Signals #region Graphics Settings Signals
signal apply_graphics_settings signal apply_graphics_settings
signal graphics_resolution_changed(resolution: Vector2i) signal graphics_resolution_changed(resolution: Vector2i)
@ -9,6 +14,7 @@ signal graphics_vsync_changed(vsync_enabled: bool)
signal graphics_fov_changed(fov: int) signal graphics_fov_changed(fov: int)
#endregion #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] ## 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] ## Default Paths:[br]
## * Windows: %APPDATA%\Godot\app_userdata\[project_name][br] ## * Windows: %APPDATA%\Godot\app_userdata\[project_name][br]
@ -22,6 +28,9 @@ var settings: GameSettingsResource = GameSettingsResource.new()
func _init() -> void: func _init() -> void:
game_options_block_highlight_changed.connect(_on_game_options_block_highlight_changed)
game_options_waila_changed.connect(_on_game_options_waila_changed)
graphics_fov_changed.connect(_on_graphics_fov_changed) graphics_fov_changed.connect(_on_graphics_fov_changed)
graphics_fullscreen_changed.connect(_on_graphics_fullscreen_changed) graphics_fullscreen_changed.connect(_on_graphics_fullscreen_changed)
graphics_resolution_changed.connect(_on_graphics_resolution_changed) graphics_resolution_changed.connect(_on_graphics_resolution_changed)
@ -29,6 +38,16 @@ func _init() -> void:
apply_graphics_settings.connect(_on_apply_graphics_settings) apply_graphics_settings.connect(_on_apply_graphics_settings)
#region Game Option Settings
func _on_game_options_block_highlight_changed(highlight_enabled: bool) -> void:
settings.game_options.enable_block_highlight = highlight_enabled
save_settings()
func _on_game_options_waila_changed(waila_enabled: bool) -> void:
settings.game_options.enable_waila = waila_enabled
save_settings()
#endregion
#region Graphics Settings #region Graphics Settings
func _on_apply_graphics_settings() -> void: func _on_apply_graphics_settings() -> void:
if settings.graphics.fullscreen: if settings.graphics.fullscreen:


+ 6
- 0
resources/game_settings/game_options_settings_resource.gd View File

@ -0,0 +1,6 @@
class_name GameOptionsSettingsResource
extends Resource
@export var enable_waila: bool = true ## Enable `What Am I Looking At` UI
@export var enable_block_highlight: bool = true

+ 1
- 0
resources/game_settings/game_options_settings_resource.gd.uid View File

@ -0,0 +1 @@
uid://7yv740somgqf

+ 9
- 0
resources/game_settings/game_options_settings_resource.tres View File

@ -0,0 +1,9 @@
[gd_resource type="Resource" script_class="GameOptionsSettingsResource" load_steps=2 format=3 uid="uid://cnpou521v2v8p"]
[ext_resource type="Script" uid="uid://7yv740somgqf" path="res://resources/game_settings/game_options_settings_resource.gd" id="1_wnf6r"]
[resource]
script = ExtResource("1_wnf6r")
enable_waila = true
enable_block_highlight = true
metadata/_custom_type_script = "uid://7yv740somgqf"

+ 2
- 0
resources/game_settings/game_settings_resource.gd View File

@ -5,4 +5,6 @@ extends Resource
@export var game_version: String = ProjectSettings.get_setting("application/config/version") @export var game_version: String = ProjectSettings.get_setting("application/config/version")
@export var game_options: GameOptionsSettingsResource = GameOptionsSettingsResource.new()
@export var graphics: GraphicsSettingsResource = GraphicsSettingsResource.new() @export var graphics: GraphicsSettingsResource = GraphicsSettingsResource.new()

resources/game_settings/graphics_settings.gd → resources/game_settings/graphics_settings_resource.gd View File


resources/game_settings/graphics_settings.gd.uid → resources/game_settings/graphics_settings_resource.gd.uid View File


resources/game_settings/graphics_settings.tres → resources/game_settings/graphics_settings_resource.tres View File

@ -1,6 +1,6 @@
[gd_resource type="Resource" script_class="GraphicsSettingsResource" load_steps=2 format=3 uid="uid://b07gyfa776057"] [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"]
[ext_resource type="Script" uid="uid://mfghfem8im6o" path="res://resources/game_settings/graphics_settings_resource.gd" id="1_3m2to"]
[resource] [resource]
script = ExtResource("1_3m2to") script = ExtResource("1_3m2to")

+ 1
- 1
scenes/blocks/block.gd View File

@ -22,7 +22,7 @@ func get_id() -> String:
return id return id
func hook() -> void: func hook() -> void:
if not Globals.enable_block_highlight: return
if not GameSettingsManager.settings.game_options.enable_block_highlight: return
highlight_mesh.visible = true highlight_mesh.visible = true


+ 2
- 2
scenes/ui/menus/settings_menu.gd View File

@ -12,10 +12,10 @@ extends Panel
#region Game Settings #region Game Settings
func _on_block_highlighting_toggled(toggled_on: bool) -> void: func _on_block_highlighting_toggled(toggled_on: bool) -> void:
Globals.enable_block_highlight = toggled_on
GameSettingsManager.game_options_block_highlight_changed.emit(toggled_on)
func _on_enable_waila_toggled(toggled_on: bool) -> void: func _on_enable_waila_toggled(toggled_on: bool) -> void:
Globals.enable_waila = toggled_on
GameSettingsManager.game_options_waila_changed.emit(toggled_on)
#endregion #endregion
#region Graphics Settings #region Graphics Settings


+ 1
- 1
scenes/ui/waila.gd View File

@ -29,7 +29,7 @@ func get_target() -> Block:
return _target return _target
func hook_target(id: String) -> void: func hook_target(id: String) -> void:
if not Globals.enable_waila: return
if not GameSettingsManager.settings.game_options.enable_waila: return
if not id: return if not id: return
var item: ItemResource = DBItems.data[id] var item: ItemResource = DBItems.data[id]


Loading…
Cancel
Save