From cca3326acd866e21de42f61b34bd77530b8bc492 Mon Sep 17 00:00:00 2001 From: Tony Bark Date: Thu, 18 Jan 2024 16:37:33 -0500 Subject: [PATCH] Moved flipping through frames to one function - Finally, moved a lot of redundant animation into a single function - Both forward and back buttons can now cycle through frames indefinitely - Renamed _game_save() to save_all() - Disabled outfits button in release builds --- godot.png | Bin 3305 -> 0 bytes godot.png.import | 34 -------------- src/scenes/game.tscn | 12 +++-- src/scripts/config.gd | 17 +++---- src/scripts/game.gd | 57 ++++++++++++++--------- src/sprites/ui/disable_button_style.tres | 14 ++++++ 6 files changed, 64 insertions(+), 70 deletions(-) delete mode 100644 godot.png delete mode 100644 godot.png.import create mode 100644 src/sprites/ui/disable_button_style.tres diff --git a/godot.png b/godot.png deleted file mode 100644 index c98fbb601c83c81ec8c22b1dba7d1d57c62b323c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3305 zcmVNc=P)Px>qe(&U$es`gSqKCHF-lq>v1vga#%UF>TTrLR zW%{UNJKZi|Pj@Rc9GyPBD1CamMMf6SL~V^ag9~Vzut^L^0!Tv0LK0FTdnJ`x->EF(MZIP5kY*1-@^egP~7mH>({qi7{6 zQF;bN-XMq~+RzA8lI9AtJuz@PY*+{SP-Gbd@mZ(r*eE&`XO5!C>w#-pcmS28K^qzY zfTGCjor*I@ltgKb03nh#Fh$KpDL=o}gj-g4v6{}ZR1*mvXv?|gEA&Yr#r;Zw*d zUabIx8iHf+WoIO_c11Ba&!34XihSMF&C#YFDjU0)mmbXz3ex!D&t9UYp>;&R%(O(_ z*z^;&A84SWzKiQpqsdQ+Vs?rFS(f?R;c8xg_ft;Roec_~1KsVww}wzq5D}*5x6k|& zf~2A3@L4|ix|Q=L>rnmKE;B3UB=OMQxAK$Ce;LvDp?hwn-{Rn}Uo~U4IXTs4V%MQY zCWULcZFU0R%gbU;_Ef(A#76r1%|YWis0t`9$R{cyjFnsV(POrI)SGQi-l{mu{e?5R zepcp?AQ54D3g_mswd@RL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2z`1RHny;F<^CEwk+}d^k^Ph zl);*XQ|ayL;rZWh=fA(G2#AJz1&r&as9I8S@9m3Owftrb5n*)pTluK^9LHOFIo{G2 zG}l$9R*{<+L2hCsOJ~Lt6Q-rRub*8X{*4{)e}>%=_&DxOFeq1LRia4Yyj*Tyynw>F zxkKf(MiaG0*L|V-^Zhtvg-(-|F0&1rU8bqab*n5TT8~C860O$|6Rt%P1=1(EjIQZ% z;Y^PU2VC*~^2!sG?mbBPS0~0yd-+086)+rHjhfk6>CB$t`o%;=kdYF9NwiKkwbIpN z;_FlOuHQHHSZ&@fUuSI-S*t`DjsiIB z{=1M@JKVC$a8z{2;xCPfRb{~T>uo#5rL4L+z9n`rSUt3Tt nAZ`TZm+q1gPVN84&*%Ra7her>#-hHS00000NkvXXu0mjf|6N@O diff --git a/godot.png.import b/godot.png.import deleted file mode 100644 index ca63310..0000000 --- a/godot.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="CompressedTexture2D" -uid="uid://d1hpnolu3m1ho" -path="res://.godot/imported/godot.png-5e0da45ed3d6786d5794553e04f58a8c.ctex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://godot.png" -dest_files=["res://.godot/imported/godot.png-5e0da45ed3d6786d5794553e04f58a8c.ctex"] - -[params] - -compress/mode=0 -compress/high_quality=false -compress/lossy_quality=0.7 -compress/hdr_compression=1 -compress/normal_map=0 -compress/channel_pack=0 -mipmaps/generate=false -mipmaps/limit=-1 -roughness/mode=0 -roughness/src_normal="" -process/fix_alpha_border=true -process/premult_alpha=false -process/normal_map_invert_y=false -process/hdr_as_srgb=false -process/hdr_clamp_exposure=false -process/size_limit=0 -detect_3d/compress_to=1 diff --git a/src/scenes/game.tscn b/src/scenes/game.tscn index 3401c9b..6baf51d 100644 --- a/src/scenes/game.tscn +++ b/src/scenes/game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=15 format=3 uid="uid://cvr2aries2lhr"] +[gd_scene load_steps=16 format=3 uid="uid://cvr2aries2lhr"] [ext_resource type="Script" path="res://src/scripts/game.gd" id="1_qt3fe"] [ext_resource type="Texture2D" uid="uid://33g80p0qnfw4" path="res://src/sprites/world/background.svg" id="1_uee2i"] @@ -12,6 +12,7 @@ [ext_resource type="SystemFont" uid="uid://dfre5a3mywuhy" path="res://src/sprites/ui/comic_sans.tres" id="12_0f8fj"] [ext_resource type="Script" path="res://addons/fontawesome/FontAwesome.gd" id="12_o3hu5"] [ext_resource type="Texture2D" uid="uid://clakkue2mohs4" path="res://src/sprites/ui/greenBtn.png" id="14_yk2bu"] +[ext_resource type="StyleBox" uid="uid://cdlprci8cx4tb" path="res://src/sprites/ui/disable_button_style.tres" id="15_0xxs0"] [ext_resource type="Texture2D" uid="uid://cd8mirubbhn10" path="res://src/sprites/ui/redBtn.png" id="15_g5gd1"] [ext_resource type="Texture2D" uid="uid://wr3ns0ywb75q" path="res://src/sprites/logo.png" id="16_y58oj"] @@ -160,8 +161,9 @@ theme_override_fonts/font = ExtResource("12_0f8fj") theme_override_styles/normal = ExtResource("11_a038t") theme_override_styles/hover = ExtResource("11_a038t") theme_override_styles/pressed = ExtResource("11_a038t") -theme_override_styles/disabled = ExtResource("11_a038t") +theme_override_styles/disabled = ExtResource("15_0xxs0") theme_override_styles/focus = ExtResource("11_a038t") +disabled = true text = "Outfits" metadata/_edit_use_anchors_ = true @@ -172,7 +174,7 @@ theme_override_fonts/font = ExtResource("12_0f8fj") theme_override_styles/normal = ExtResource("11_a038t") theme_override_styles/hover = ExtResource("11_a038t") theme_override_styles/pressed = ExtResource("11_a038t") -theme_override_styles/disabled = ExtResource("11_a038t") +theme_override_styles/disabled = ExtResource("15_0xxs0") theme_override_styles/focus = ExtResource("11_a038t") text = "Seperate" metadata/_edit_use_anchors_ = true @@ -197,7 +199,7 @@ theme_override_fonts/font = ExtResource("12_0f8fj") theme_override_styles/normal = ExtResource("11_a038t") theme_override_styles/hover = ExtResource("11_a038t") theme_override_styles/pressed = ExtResource("11_a038t") -theme_override_styles/disabled = ExtResource("11_a038t") +theme_override_styles/disabled = ExtResource("15_0xxs0") theme_override_styles/focus = ExtResource("11_a038t") text = "Save" @@ -207,7 +209,7 @@ theme_override_fonts/font = ExtResource("12_0f8fj") theme_override_styles/normal = ExtResource("11_a038t") theme_override_styles/hover = ExtResource("11_a038t") theme_override_styles/pressed = ExtResource("11_a038t") -theme_override_styles/disabled = ExtResource("11_a038t") +theme_override_styles/disabled = ExtResource("15_0xxs0") theme_override_styles/focus = ExtResource("11_a038t") text = "Exit" diff --git a/src/scripts/config.gd b/src/scripts/config.gd index 9e29ca0..777beeb 100644 --- a/src/scripts/config.gd +++ b/src/scripts/config.gd @@ -25,19 +25,20 @@ func save_config(config_file = "user://config.cfg"): 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) + var display_scale = DisplayServer.screen_get_scale(); + match display_scale: + 2: + config.set_value("window", "width", default_width * display_scale + 1) + config.set_value("window", "height", default_height * display_scale + 1) + 1, _: + 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): config.save(config_file) -func save_game(tops = 0, bottoms = 0, full_body = 0, save_file = "user://save.cfg", overwrite = false, ): +func save_game(tops = 0, bottoms = 0, full_body = 0, save_file = "user://save.cfg", overwrite = false): # Create new ConfigFile object. var config = ConfigFile.new() diff --git a/src/scripts/game.gd b/src/scripts/game.gd index ad4c175..dd99a21 100644 --- a/src/scripts/game.gd +++ b/src/scripts/game.gd @@ -8,14 +8,23 @@ extends Node @onready var bottoms_fwd = $Canvas/UI/DressUpCtrls/BottomsFwdBtn @onready var full_body = $FullBody -var is_seperate = true -var is_full_body = false +# Only here for debugging purposes +@onready var outfits_btn = $Canvas/UI/SettingsCtrls/FullbodyBtn + +var is_seperate: bool = true +var is_full_body: bool = false +var current_frame: int +var sprite_frames: SpriteFrames var config_file = Config.config_file() var save_file = Config.save_file() func _ready(): + # Keep outfits button enabled in debug builds + if OS.is_debug_build(): + outfits_btn.disabled = false + # If config files don't exist, create them if !FileAccess.file_exists(config_file): Config.save_config(config_file) @@ -40,47 +49,49 @@ func _ready(): # Set window size DisplayServer.window_set_size(Vector2i(window_width, window_height)) - -func game_save(): +func save_all(): Config.save_game(tops.frame, bottoms.frame, full_body.frame, save_file, true) + +func next_frame(animation: AnimatedSprite2D, sprite_frames: SpriteFrames, animation_name, rewind = false): + var max_frames = sprite_frames.get_frame_count(animation_name) - 1 + current_frame = animation.frame + + if !rewind: + animation.frame = current_frame + 1 + if current_frame == max_frames: + animation.frame = 0 + else: + animation.frame = current_frame + -1 + if current_frame == 0: + animation.frame = max_frames + func _process(delta): if Input.is_action_just_pressed("exit"): - game_save() + save_all() get_tree().quit() func _on_save_btn_pressed(): - game_save() + save_all() func _on_tops_fwd_btn_pressed(): - var current_frame - - if is_seperate: - current_frame = tops.frame - tops.frame = current_frame + 1; + next_frame(tops, tops.sprite_frames, "tops") if is_full_body: - current_frame = full_body.frame - full_body.frame = current_frame + 1; + next_frame(full_body, full_body.sprite_frames, "fullbody") func _on_tops_bck_btn_pressed(): - var current_frame - if is_seperate: - current_frame = tops.frame - tops.frame = current_frame + -1; + next_frame(tops, tops.sprite_frames, "tops", true) if is_full_body: - current_frame = full_body.frame - full_body.frame = current_frame + -1; + next_frame(full_body, full_body.sprite_frames, "fullbody", true) func _on_bottoms_bck_btn_pressed(): - var current_frame = bottoms.frame - bottoms.frame = current_frame + -1; + next_frame(bottoms, bottoms.sprite_frames, "bottoms", true) func _on_bottoms_fwd_btn_pressed(): - var current_frame = bottoms.frame - bottoms.frame = current_frame + 1; + next_frame(bottoms, bottoms.sprite_frames, "bottoms") func _on_fullbody_btn_pressed(): is_seperate = false diff --git a/src/sprites/ui/disable_button_style.tres b/src/sprites/ui/disable_button_style.tres new file mode 100644 index 0000000..f9dbc2d --- /dev/null +++ b/src/sprites/ui/disable_button_style.tres @@ -0,0 +1,14 @@ +[gd_resource type="StyleBoxFlat" format=3 uid="uid://cdlprci8cx4tb"] + +[resource] +bg_color = Color(0.490196, 0.490196, 0.490196, 1) +border_width_left = 3 +border_width_top = 3 +border_width_right = 3 +border_width_bottom = 3 +border_color = Color(0.247059, 0.247059, 0.247059, 1) +border_blend = true +corner_radius_top_left = 5 +corner_radius_top_right = 5 +corner_radius_bottom_right = 5 +corner_radius_bottom_left = 5