From a4a7c62e79172527a97ae9a07954a47e85112a73 Mon Sep 17 00:00:00 2001 From: Tony Bark Date: Tue, 16 Jan 2024 18:25:16 -0500 Subject: [PATCH] Resize default window size times 3 on Retina displays --- scenes/character.tscn | 6 +++--- scripts/config.gd | 17 +++++++++++++---- scripts/game.gd | 14 ++++++++++---- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/scenes/character.tscn b/scenes/character.tscn index a2a12e0..18c56b5 100644 --- a/scenes/character.tscn +++ b/scenes/character.tscn @@ -123,7 +123,7 @@ script = ExtResource("1_k1mtq") position = Vector2(-33.7592, 99.4079) scale = Vector2(0.927713, 1) sprite_frames = SubResource("1") -frame_progress = 0.472335 +frame_progress = 0.0205252 [node name="Body" type="Sprite2D" parent="."] position = Vector2(12, 81) @@ -132,9 +132,9 @@ texture = ExtResource("5_i8wm6") [node name="Eyes" type="AnimatedSprite2D" parent="."] position = Vector2(28.6857, -15.7785) sprite_frames = SubResource("2") -frame_progress = 0.389606 +frame_progress = 0.937796 [node name="Mouth" type="AnimatedSprite2D" parent="."] position = Vector2(49.1195, -14.3155) sprite_frames = SubResource("3") -frame_progress = 0.509661 +frame_progress = 0.0578512 diff --git a/scripts/config.gd b/scripts/config.gd index 35a1f65..9e29ca0 100644 --- a/scripts/config.gd +++ b/scripts/config.gd @@ -19,10 +19,19 @@ func save_file(save_file = "user://save.cfg"): func save_config(config_file = "user://config.cfg"): # Create new ConfigFile object. var config = ConfigFile.new() - - # Store some values. - config.set_value("window", "height", 1024) - config.set_value("window", "width", 768) + + var window_size = "display/window/size/"; + var default_width = ProjectSettings.get_setting(window_size + "viewport_width") + var default_height = ProjectSettings.get_setting(window_size + "viewport_height") + + # If Retina display, set a higher resolution + var screen_scale = DisplayServer.screen_get_scale(); + if screen_scale == 2: + config.set_value("window", "width", default_width * 3) + config.set_value("window", "height", default_height * 3) + else: + config.set_value("window", "width", default_width) + config.set_value("window", "height", default_height) # Save it to a file (overwrite if already exists) if !FileAccess.file_exists(config_file): diff --git a/scripts/game.gd b/scripts/game.gd index 7964138..ad4c175 100644 --- a/scripts/game.gd +++ b/scripts/game.gd @@ -15,26 +15,32 @@ var config_file = Config.config_file() var save_file = Config.save_file() func _ready(): - + + # If config files don't exist, create them if !FileAccess.file_exists(config_file): Config.save_config(config_file) if !FileAccess.file_exists(save_file): Config.save_game(save_file) - + + # Load last saved game if FileAccess.file_exists(save_file): var clothes_section = "clothes" tops.frame = Config.load_config(clothes_section, "tops", save_file) bottoms.frame = Config.load_config(clothes_section, "bottoms", save_file) full_body.frame = Config.load_config(clothes_section, "full_body", save_file) + # Load window size if FileAccess.file_exists(config_file): var window_section = "window" var window_height = Config.load_config(window_section, "height", config_file) var window_width = Config.load_config(window_section, "width", config_file) + var viewport = get_viewport(); - if window_height && window_width != null: - DisplayServer.window_set_size(Vector2i(window_height, window_width)) + # Set window size + DisplayServer.window_set_size(Vector2i(window_width, window_height)) + + func game_save(): Config.save_game(tops.frame, bottoms.frame, full_body.frame, save_file, true)