Skip to content

Commit 60fb4ee

Browse files
committed
Move default resolution logic to Resolution
Add Resolution.set_resolution_from for generic values
1 parent 8c47f82 commit 60fb4ee

2 files changed

Lines changed: 26 additions & 15 deletions

File tree

game/src/Autoload/Resolution.gd

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ signal resolution_added(value : Vector2i)
44

55
const error_resolution : Vector2i = Vector2i(-1,-1)
66

7+
var default_resolution : Vector2i = error_resolution
8+
79
@export
810
var minimum_resolution : Vector2i = Vector2i(1,1)
911

@@ -31,6 +33,14 @@ func _ready() -> void:
3133
assert(minimum_resolution.x > 0 and minimum_resolution.y > 0, "Minimum resolution must be positive!")
3234
for resolution_value : Vector2i in _starting_resolutions:
3335
add_resolution(resolution_value)
36+
37+
default_resolution = Vector2i(
38+
ProjectSettings.get_setting("display/window/size/viewport_width"),
39+
ProjectSettings.get_setting("display/window/size/viewport_height")
40+
)
41+
if default_resolution > minimum_resolution:
42+
add_resolution(default_resolution)
43+
3444
assert(not _resolutions.is_empty(), "No valid starting resolutions!")
3545

3646
_regex = RegEx.new()
@@ -91,6 +101,19 @@ func set_resolution(resolution : Vector2i) -> void:
91101
return
92102
push_error("Trying to set resolution before window exists!")
93103

104+
func set_resolution_from(load_value : Variant) -> Vector2i:
105+
var target_resolution := Resolution.error_resolution
106+
match typeof(load_value):
107+
TYPE_VECTOR2I:
108+
target_resolution = load_value
109+
return target_resolution
110+
TYPE_STRING, TYPE_STRING_NAME:
111+
target_resolution = Resolution.get_resolution_value_from_string(load_value)
112+
return target_resolution
113+
if Resolution.add_resolution(target_resolution):
114+
Resolution.set_resolution(target_resolution)
115+
return target_resolution
116+
94117
func get_current_window_mode() -> Window.Mode:
95118
var viewport := get_viewport()
96119
if viewport != null:

game/src/UI/GameMenu/OptionMenu/ResolutionSelector.gd

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,8 @@ func _update_resolution_options_text() -> void:
5858

5959
func _setup_button() -> void:
6060
Resolution.resolution_added.connect(func (_value : Vector2i) -> void: _sync_resolutions())
61-
if default_value.x <= 0:
62-
default_value.x = ProjectSettings.get_setting("display/window/size/viewport_width")
63-
if default_value.y <= 0:
64-
default_value.y = ProjectSettings.get_setting("display/window/size/viewport_height")
65-
if not Resolution.has_resolution(default_value):
66-
Resolution.add_resolution(default_value)
67-
else:
68-
_sync_resolutions()
61+
default_value = Resolution.default_resolution
62+
_sync_resolutions()
6963

7064
func _get_value_for_file(select_value : int):
7165
if _valid_index(select_value):
@@ -76,16 +70,10 @@ func _get_value_for_file(select_value : int):
7670
# REQUIREMENTS:
7771
# * SS-25
7872
func _set_value_from_file(load_value : Variant) -> void:
79-
var target_resolution := Resolution.error_resolution
80-
match typeof(load_value):
81-
TYPE_VECTOR2I: target_resolution = load_value
82-
TYPE_STRING, TYPE_STRING_NAME: target_resolution = Resolution.get_resolution_value_from_string(load_value)
73+
var target_resolution := Resolution.set_resolution_from(load_value)
8374
if target_resolution != Resolution.error_resolution:
8475
selected = _find_resolution_index_by_value(target_resolution)
8576
if selected != -1: return
86-
if Resolution.add_resolution(target_resolution):
87-
Resolution.set_resolution(target_resolution)
88-
return
8977
push_error("Setting value '%s' invalid for setting [%s] %s" % [load_value, section_name, setting_name])
9078
selected = default_selected
9179

0 commit comments

Comments
 (0)