From 0f8c97dca5372e2083c19a8e3ceb4ab65aca1555 Mon Sep 17 00:00:00 2001 From: Terry Hearst Date: Wed, 6 Mar 2024 18:25:32 -0500 Subject: [PATCH] Add link to share score once completed --- src/main.gd | 37 ++++++++++++++++++++-- src/main.tscn | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 120 insertions(+), 3 deletions(-) diff --git a/src/main.gd b/src/main.gd index 2511d46..2cdb57a 100644 --- a/src/main.gd +++ b/src/main.gd @@ -17,6 +17,7 @@ var keyboard_buttons := {} var target_word: String var current_guess: int var ended: bool +var won: bool var input_guess: String @onready var title: Label = %Title @@ -26,8 +27,10 @@ var input_guess: String @onready var keyboard_vbox: VBoxContainer = %KeyboardVBox @onready var guess_button: Button = %GuessButton @onready var backspace_button: Button = %ButtonBksp +@onready var share_button: Button = %ShareButton @onready var info_text_animation: AnimationPlayer = %InfoTextAnimation +@onready var copied_text_animation: AnimationPlayer = %CopiedTextAnimation @onready var error_text_color_default := info_text.label_settings.font_color @@ -57,6 +60,7 @@ func _ready() -> void: target_word = Global.generate_word(letter_count, random_seed) current_guess = 0 ended = false + won = false for i in range(0, 26): var letter := char("A".unicode_at(0) + i) @@ -65,6 +69,8 @@ func _ready() -> void: var error := keyboard_button.connect("pressed", Callable(self, "type_letter").bind(letter)) assert(not error) + share_button.hide() + func type_letter(letter: String) -> void: if ended or input_guess.length() >= letter_count: @@ -161,13 +167,12 @@ func guess_entered() -> void: current_guess += 1 - var won := false - if input_guess == target_word: ended = true won = true elif current_guess >= guess_count: ended = true + won = false input_guess = "" @@ -180,6 +185,7 @@ func guess_entered() -> void: show_info("Congrats! You won!", Color(0.4, 0.9, 0.6)) else: show_info("Game Over. The word was %s" % target_word, error_text_color_default) + share_button.show() func show_error(text: String): @@ -210,3 +216,30 @@ func _on_MenuButton_pressed() -> void: func _on_ButtonBksp_pressed() -> void: backspace() + + +func _on_share_button_pressed() -> void: + var text := title.text + if won: + text += " %d/%d\n\n" % [current_guess, guess_count] + elif ended: + text += " X/%d\n\n" % [guess_count] + else: + # Can probably bail early but I might as allow it + text += " ?/%d\n\n" % [guess_count] + + for i in range(current_guess): + for j in range(letter_count): + var letter_instance := letters[i][j] as ColorRect + if letter_instance.color.is_equal_approx(color_correct): + text += "🟩" + elif letter_instance.color.is_equal_approx(color_misplaced): + text += "🟨" + else: + text += "⬛" + text += "\n" + + text += "\nhttps://thearst3rd.com/games/gordle" + DisplayServer.clipboard_set(text) + copied_text_animation.stop() + copied_text_animation.play("Copied") diff --git a/src/main.tscn b/src/main.tscn index d97b64e..9b747d7 100644 --- a/src/main.tscn +++ b/src/main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=3 uid="uid://busmmqyj42lv5"] +[gd_scene load_steps=14 format=3 uid="uid://busmmqyj42lv5"] [ext_resource type="FontFile" uid="uid://b7jasa607pvfx" path="res://fonts/Louis George Cafe Bold.ttf" id="1"] [ext_resource type="Script" path="res://src/main.gd" id="2"] @@ -97,6 +97,63 @@ cache/0/36/0/scale = 1.0 cache/0/36/0/kerning_overrides/16/0 = Vector2(0, 0) cache/0/36/0/kerning_overrides/36/0 = Vector2(0, 0) +[sub_resource type="FontFile" id="FontFile_6m14o"] +fallbacks = Array[Font]([ExtResource("1")]) +subpixel_positioning = 0 +msdf_pixel_range = 14 +msdf_size = 128 +cache/0/16/0/ascent = 0.0 +cache/0/16/0/descent = 0.0 +cache/0/16/0/underline_position = 0.0 +cache/0/16/0/underline_thickness = 0.0 +cache/0/16/0/scale = 1.0 +cache/0/16/0/kerning_overrides/16/0 = Vector2(0, 0) +cache/0/16/0/kerning_overrides/24/0 = Vector2(0, 0) +cache/0/24/0/ascent = 0.0 +cache/0/24/0/descent = 0.0 +cache/0/24/0/underline_position = 0.0 +cache/0/24/0/underline_thickness = 0.0 +cache/0/24/0/scale = 1.0 +cache/0/24/0/kerning_overrides/16/0 = Vector2(0, 0) +cache/0/24/0/kerning_overrides/24/0 = Vector2(0, 0) + +[sub_resource type="LabelSettings" id="LabelSettings_vxdpn"] +font_size = 24 +font_color = Color(0.968627, 1, 0, 1) + +[sub_resource type="Animation" id="Animation_xl3cv"] +resource_name = "Copied" +length = 4.0 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("CopiedText:modulate") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 0.3, 3, 4), +"transitions": PackedFloat32Array(1, 1, 1, 1), +"update": 0, +"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 1), Color(1, 1, 1, 1), Color(1, 1, 1, 0)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("CopiedText:position") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0, 0.3, 4), +"transitions": PackedFloat32Array(1, 1, 1), +"update": 0, +"values": [Vector2(126, 31), Vector2(126, 51), Vector2(126, 51)] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_sgitb"] +_data = { +"Copied": SubResource("Animation_xl3cv") +} + [node name="Main" type="Control"] layout_mode = 3 anchors_preset = 15 @@ -344,6 +401,32 @@ focus_mode = 0 theme_override_fonts/font = SubResource("5") text = "Guess" +[node name="ShareButton" type="Button" parent="C/V/KeyboardVBox/GuessButton"] +unique_name_in_owner = true +offset_left = 180.0 +offset_right = 283.0 +offset_bottom = 49.0 +focus_mode = 0 +text = "Share" + +[node name="CopiedText" type="Label" parent="C/V/KeyboardVBox/GuessButton"] +modulate = Color(1, 1, 1, 0) +offset_left = 126.0 +offset_top = 31.0 +offset_right = 347.0 +offset_bottom = 59.0 +theme_override_colors/font_color = Color(1, 0.309804, 0.309804, 1) +theme_override_fonts/font = SubResource("FontFile_6m14o") +text = "Copied to clipboard!" +label_settings = SubResource("LabelSettings_vxdpn") +horizontal_alignment = 1 + +[node name="CopiedTextAnimation" type="AnimationPlayer" parent="C/V/KeyboardVBox/GuessButton"] +unique_name_in_owner = true +libraries = { +"": SubResource("AnimationLibrary_sgitb") +} + [node name="MenuButton" type="Button" parent="."] layout_mode = 1 anchors_preset = 1 @@ -359,4 +442,5 @@ text = "Menu" [connection signal="pressed" from="C/V/KeyboardVBox/HRow3/ButtonBksp" to="." method="_on_ButtonBksp_pressed"] [connection signal="pressed" from="C/V/KeyboardVBox/GuessButton" to="." method="_on_GuessButton_pressed"] +[connection signal="pressed" from="C/V/KeyboardVBox/GuessButton/ShareButton" to="." method="_on_share_button_pressed"] [connection signal="pressed" from="MenuButton" to="." method="_on_MenuButton_pressed"]