aboutsummaryrefslogtreecommitdiff
path: root/game/src/Autoload
diff options
context:
space:
mode:
Diffstat (limited to 'game/src/Autoload')
-rw-r--r--game/src/Autoload/Events.gd3
-rw-r--r--game/src/Autoload/Events/Options.gd22
-rw-r--r--game/src/Autoload/Resolution.gd55
3 files changed, 63 insertions, 17 deletions
diff --git a/game/src/Autoload/Events.gd b/game/src/Autoload/Events.gd
new file mode 100644
index 0000000..f0f60b7
--- /dev/null
+++ b/game/src/Autoload/Events.gd
@@ -0,0 +1,3 @@
+extends Node
+
+var Options = preload("Events/Options.gd").new()
diff --git a/game/src/Autoload/Events/Options.gd b/game/src/Autoload/Events/Options.gd
new file mode 100644
index 0000000..0acaa63
--- /dev/null
+++ b/game/src/Autoload/Events/Options.gd
@@ -0,0 +1,22 @@
+extends RefCounted
+
+signal save_settings(save_file: ConfigFile)
+signal load_settings(load_file: ConfigFile)
+signal reset_settings()
+
+func load_settings_from_file() -> void:
+ load_settings.emit(_settings_file)
+
+func save_settings_from_file() -> void:
+ save_settings.emit(_settings_file)
+ _settings_file.save(_settings_file_path)
+
+func try_reset_settings() -> void:
+ reset_settings.emit()
+
+var _settings_file_path := ProjectSettings.get_setting("openvic2/settings/settings_file_path", "user://settings.cfg") as String
+var _settings_file := ConfigFile.new()
+
+func _init():
+ if FileAccess.file_exists(_settings_file_path):
+ _settings_file.load(_settings_file_path)
diff --git a/game/src/Autoload/Resolution.gd b/game/src/Autoload/Resolution.gd
index cde46f5..ac54c0d 100644
--- a/game/src/Autoload/Resolution.gd
+++ b/game/src/Autoload/Resolution.gd
@@ -1,28 +1,38 @@
extends Node
-const _resolutions := {
- &"3840x2160": Vector2i(3840,2160),
- &"2560x1440": Vector2i(2560,1080),
- &"1920x1080": Vector2i(1920,1080),
- &"1366x768": Vector2i(1366,768),
- &"1536x864": Vector2i(1536,864),
- &"1280x720": Vector2i(1280,720),
- &"1440x900": Vector2i(1440,900),
- &"1600x900": Vector2i(1600,900),
- &"1024x600": Vector2i(1024,600),
- &"800x600": Vector2i(800,600)
-}
+var _resolutions : Array[Dictionary]= [
+ { "name": &"", "value": Vector2i(3840,2160) },
+ { "name": &"", "value": Vector2i(2560,1080) },
+ { "name": &"", "value": Vector2i(1920,1080) },
+ { "name": &"", "value": Vector2i(1366,768) },
+ { "name": &"", "value": Vector2i(1536,864) },
+ { "name": &"", "value": Vector2i(1280,720) },
+ { "name": &"", "value": Vector2i(1440,900) },
+ { "name": &"", "value": Vector2i(1600,900) },
+ { "name": &"", "value": Vector2i(1024,600) },
+ { "name": &"", "value": Vector2i(800,600) }
+]
+
+func _ready():
+ for resolution in _resolutions:
+ resolution["tag"] = _get_name_of_resolution(resolution["name"], resolution["value"])
func has_resolution(resolution_name : StringName) -> bool:
return resolution_name in _resolutions
func get_resolution(resolution_name : StringName, default : Vector2i = Vector2i(1920, 1080)) -> Vector2i:
- return _resolutions.get(resolution_name, default)
+ var resolution := _get_resolution_by_name(resolution_name)
+ if resolution.x < 0 and resolution.y < 0:
+ return default
+ return resolution
-func get_resolution_name_list() -> Array:
- return _resolutions.keys()
+func get_resolution_name_list() -> Array[StringName]:
+ var result : Array[StringName] = []
+ for resolution in _resolutions:
+ result.append(resolution["tag"])
+ return result
-func get_current_resolution() -> Vector2:
+func get_current_resolution() -> Vector2i:
var window := get_viewport().get_window()
match window.mode:
Window.MODE_EXCLUSIVE_FULLSCREEN, Window.MODE_FULLSCREEN:
@@ -30,7 +40,7 @@ func get_current_resolution() -> Vector2:
_:
return window.size
-func set_resolution(resolution : Vector2) -> void:
+func set_resolution(resolution : Vector2i) -> void:
var window := get_viewport().get_window()
match window.mode:
Window.MODE_EXCLUSIVE_FULLSCREEN, Window.MODE_FULLSCREEN:
@@ -41,3 +51,14 @@ func set_resolution(resolution : Vector2) -> void:
func reset_resolution() -> void:
set_resolution(get_current_resolution())
+
+func _get_name_of_resolution(resolution_name : StringName, resolution_value : Vector2i) -> StringName:
+ if resolution_name != null and not resolution_name.is_empty():
+ return "%s (%sx%s)" % [resolution_name, resolution_value.x, resolution_value.y]
+ return "%sx%s" % [resolution_value.x, resolution_value.y]
+
+func _get_resolution_by_name(resolution_name : StringName) -> Vector2i:
+ for resolution in _resolutions:
+ if resolution["name"] == resolution_name or resolution["tag"] == resolution_name:
+ return resolution["value"]
+ return Vector2i(-1, -1)