From 4e9a94c56f6aea4b361b86a6e226128d4bda8fb6 Mon Sep 17 00:00:00 2001 From: cutekibry Date: Sat, 10 Feb 2024 14:40:33 +0800 Subject: [PATCH 1/9] =?UTF-8?q?refactor(card):=20=E5=B0=86=20Highlight=20b?= =?UTF-8?q?order=20=E7=8B=AC=E7=AB=8B=E5=87=BA=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将原先 card_highlighted.png 替换为仅包含高亮而不包含卡背颜色的素材 card_highlight_border.png, 同时新建 Sprite2D 场景 HighlightSprite 用于显示高亮 --- objects/card/card.gd | 9 ++--- objects/card/card.tscn | 25 ++++++------- objects/card/card_highlight_border.png | Bin 0 -> 183 bytes objects/card/card_highlight_border.png.import | 34 ++++++++++++++++++ objects/card/card_highlighted.png | Bin 187 -> 0 bytes 5 files changed, 49 insertions(+), 19 deletions(-) create mode 100644 objects/card/card_highlight_border.png create mode 100644 objects/card/card_highlight_border.png.import delete mode 100644 objects/card/card_highlighted.png diff --git a/objects/card/card.gd b/objects/card/card.gd index 72b76c1..4e6bcb9 100644 --- a/objects/card/card.gd +++ b/objects/card/card.gd @@ -25,6 +25,7 @@ var is_shaking := false func _ready(): origin_global_position = global_position last_global_position = global_position + $HighlightSprite.visible = false func _on_mouse_release(): #prints(entered_area.name, is_card_entered, entered_area.occupied) @@ -135,22 +136,22 @@ func shake(is_letter_red: bool, amount: float, duration: float) -> void: if is_letter_red: $Word.set_color(ImageLib.PALETTE["red"]) else: - $CardBackSprite.animation = "default" + $HighlightSprite.visible = false + func _on_mouse_entered(): - $CardBackSprite.animation = "highlighted" + $HighlightSprite.visible = true Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND) func _on_mouse_exited(): - $CardBackSprite.animation = "default" + $HighlightSprite.visible = false Input.set_default_cursor_shape(Input.CURSOR_ARROW) func set_color(value: Color) -> void: $Word.set_color(value) - func set_victory(v: bool): if v: $CollisionShape2D.set_deferred("disabled", true) diff --git a/objects/card/card.tscn b/objects/card/card.tscn index 531bdc5..8f54e54 100644 --- a/objects/card/card.tscn +++ b/objects/card/card.tscn @@ -5,11 +5,9 @@ [ext_resource type="Texture2D" uid="uid://cfbqh1k0etr6g" path="res://objects/card/card1.png" id="3_o4f0v"] [ext_resource type="Texture2D" uid="uid://c8qjbksyn1bqt" path="res://objects/card/card2.png" id="4_c30j1"] [ext_resource type="Texture2D" uid="uid://bevrfq1hhyqwe" path="res://objects/card/card3.png" id="5_w81n3"] -[ext_resource type="Texture2D" uid="uid://cmcc5xrpkrd0f" path="res://objects/card/card_highlighted.png" id="6_po2i6"] +[ext_resource type="Texture2D" uid="uid://pmapbo480in1" path="res://objects/card/card_highlight_border.png" id="7_kix4t"] [ext_resource type="AudioStream" uid="uid://cj4v8ehypq3sk" path="res://objects/card/put_down.wav" id="7_u4ylf"] -[sub_resource type="RectangleShape2D" id="RectangleShape2D_gu6l6"] - [sub_resource type="SpriteFrames" id="SpriteFrames_fo0r0"] animations = [{ "frames": [{ @@ -25,16 +23,10 @@ animations = [{ "loop": true, "name": &"default", "speed": 5.0 -}, { -"frames": [{ -"duration": 1.0, -"texture": ExtResource("6_po2i6") -}], -"loop": true, -"name": &"highlighted", -"speed": 5.0 }] +[sub_resource type="RectangleShape2D" id="RectangleShape2D_gu6l6"] + [node name="Card" type="Area2D"] z_index = 50 script = ExtResource("1_0bviv") @@ -45,14 +37,17 @@ frame_progress = 0.111549 text_id = 1 color = Color(0, 0, 0, 1) -[node name="CollisionShape2D" type="CollisionShape2D" parent="."] -z_index = 15 -shape = SubResource("RectangleShape2D_gu6l6") - [node name="CardBackSprite" type="AnimatedSprite2D" parent="."] sprite_frames = SubResource("SpriteFrames_fo0r0") autoplay = "default" +[node name="HighlightSprite" type="Sprite2D" parent="."] +texture = ExtResource("7_kix4t") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +z_index = 15 +shape = SubResource("RectangleShape2D_gu6l6") + [node name="SFXPutDown" type="AudioStreamPlayer" parent="."] stream = ExtResource("7_u4ylf") volume_db = 13.117 diff --git a/objects/card/card_highlight_border.png b/objects/card/card_highlight_border.png new file mode 100644 index 0000000000000000000000000000000000000000..2f7f1952c44107cca096b4b9fb76f614b8b5c714 GIT binary patch literal 183 zcmeAS@N?(olHy`uVBq!ia0vp^G9b*s1|*Ak?@s|zjKx9jP7LeL$-D$|3O!vMLp(a) zUOULuV8FwC!R^og_;u<_(?SHJt330h7w22+8g%Wpe*c$~;m)<#05;{rKhokSpS`nM zao%BrM{c6WI*(mrw0X+3JMQ@A=W!YV3mh7mSoby0Rn7WxJig2C>-qDWr(Y|Rd$FQ3 gE!fp!+3r{J@1$*v&c*~(04-@lUpr0wzrw;tOG&9pjFZ9Sz1E4Q#Khl) zZ4J4xyIyejILYxatT Date: Sat, 10 Feb 2024 14:44:47 +0800 Subject: [PATCH 2/9] =?UTF-8?q?feat(expr=5Fvalidator.gd):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20VAR=20=E5=92=8C=20CONST?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将原先 enum 里的 VAL 分化为 VAR 和 CONST,并将 BRAC_L 和 BRAC_R 中的下划线删去 --- scripts/expr_validator.gd | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/scripts/expr_validator.gd b/scripts/expr_validator.gd index 5db6550..bdf841a 100644 --- a/scripts/expr_validator.gd +++ b/scripts/expr_validator.gd @@ -48,7 +48,7 @@ const IS_PAIR_VALID := [ [1, 1, 1, 1, 0, 0] ] -enum {OP, COMP, BRAC_L, BRAC_R, VAR, CONST} +enum {OP, COMP, BRACL, BRACR, VAR, CONST} static func get_char_type(ch: String) -> int: @@ -57,16 +57,40 @@ static func get_char_type(ch: String) -> int: elif ch == "<" or ch == "=" or ch == ">": return COMP elif ch == "(": - return BRAC_L + return BRACL elif ch == ")": - return BRAC_R + return BRACR elif ch == "0" or ch == "1": return CONST - else: + elif is_alpha(ch): return VAR + else: + push_error("get_char_type(%s) is undefined" % ch) + return -1 + +static func get_char_type_enum_name(value: int) -> String: + if value == OP: + return "OP" + elif value == COMP: + return "COMP" + elif value == BRACL: + return "BRACL" + elif value == BRACR: + return "BRACR" + elif value == VAR: + return "VAR" + elif value == CONST: + return "CONST" + else: + push_error("get_char_type_enum_name(%d) is undefined" % value) + return "ERR" +static func get_char_type_as_str(ch: String) -> String: + return get_char_type_enum_name(get_char_type(ch)) + + static func has_implict_prod(string: String) -> bool: - return get_char_type(string[0]) in [BRAC_R, VAR, CONST] and get_char_type(string[1]) in [BRAC_L, VAR, CONST] + return get_char_type(string[0]) in [BRACR, VAR, CONST] and get_char_type(string[1]) in [BRACL, VAR, CONST] static func get_priority(ch: String) -> int: if ch == "*": @@ -175,9 +199,9 @@ static func calculate_value(expr: String, var_values: Dictionary) -> bool: ## ## 合法返回 [],否则返回不合法的下标。 static func check_valid(expr: String) -> Array: - if get_char_type(expr[0]) != BRAC_L and get_char_type(expr[0]) not in [VAR, CONST]: + if get_char_type(expr[0]) != BRACL and get_char_type(expr[0]) not in [VAR, CONST]: return [0] - if get_char_type(expr[len(expr) - 1]) != BRAC_R and get_char_type(expr[len(expr) - 1]) not in [VAR, CONST]: + if get_char_type(expr[len(expr) - 1]) != BRACR and get_char_type(expr[len(expr) - 1]) not in [VAR, CONST]: return [len(expr) - 1] for i in range(len(expr) - 1): if not IS_PAIR_VALID[get_char_type(expr[i])][get_char_type(expr[i + 1])]: From 826cd41f307361a0666ce55d5c320e1c4a6904f7 Mon Sep 17 00:00:00 2001 From: cutekibry Date: Sat, 10 Feb 2024 15:22:58 +0800 Subject: [PATCH 3/9] =?UTF-8?q?feat(image=5Flib.gd):=20=E6=96=B0=E9=85=8D?= =?UTF-8?q?=E8=89=B2=E5=8F=8A=20update=5Fanimation=20=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit update_animation 可以用于加载特定编号的素材,并将某个颜色替换为另一个颜色(即 word.gd 中的 void update_animation()) --- scripts/image_lib.gd | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/scripts/image_lib.gd b/scripts/image_lib.gd index b0366c3..dc9224e 100644 --- a/scripts/image_lib.gd +++ b/scripts/image_lib.gd @@ -7,6 +7,10 @@ const PALETTE = { "orange": Color("#ffb463"), "card-op": Color("#ffb463"), + "skyblue": Color("#c2fdff"), + "card-bracl": Color("#c2fdff"), + "card-bracr": Color("#c2fdff"), + "lightblue": Color("#8eacf3"), "card-var": Color("#8eacf3"), @@ -19,7 +23,7 @@ const PALETTE = { "default": Color.BLACK, } -static func change_color(image: Texture, old_color: Color, new_color: Color) -> Texture: +static func change_color(image: Texture2D, old_color: Color, new_color: Color) -> Texture2D: var new_texture = image.get_image() for x in range(new_texture.get_width()): for y in range(new_texture.get_height()): @@ -27,3 +31,20 @@ static func change_color(image: Texture, old_color: Color, new_color: Color) -> if color == old_color: new_texture.set_pixel(x, y, new_color) return ImageTexture.create_from_image(new_texture) + +static func update_animation( + sprite: AnimatedSprite2D, + start: int, + n: int, + step: int, + path_pattern: String, + old_color: Color, + new_color: Color +) -> void: + var animation_id = "%d_%d_%d_%s" % [start, n, step, new_color.to_html()] + if not sprite.sprite_frames.has_animation(animation_id): + sprite.sprite_frames.add_animation(animation_id) + for i in range(n): + var image = load(path_pattern % (i * step + start)) + sprite.sprite_frames.add_frame(animation_id, ImageLib.change_color(image, old_color, new_color)) + sprite.play(animation_id) From 7c203a4738fc7139998a342b9cc118c9f5946893 Mon Sep 17 00:00:00 2001 From: cutekibry Date: Sat, 10 Feb 2024 15:25:42 +0800 Subject: [PATCH 4/9] =?UTF-8?q?refactor(word):=20=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E4=B8=BA=20image=5Flib=20=E4=B8=AD=E7=9A=84=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=8A=A8=E7=94=BB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- objects/word/word.gd | 18 +----------------- objects/word/word.tscn | 18 +----------------- 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/objects/word/word.gd b/objects/word/word.gd index 321d3ba..74ba764 100644 --- a/objects/word/word.gd +++ b/objects/word/word.gd @@ -30,12 +30,7 @@ func set_text_id(value: int) -> void: update_animation() func update_animation() -> void: - var animation_id = str(text_id) + color.to_html() - if not sprite_frames.has_animation(animation_id): - sprite_frames.add_animation(animation_id) - for i in range(3): - sprite_frames.add_frame(animation_id, load_image(i * STEP + text_id + 1, color)) - animation = animation_id + ImageLib.update_animation(self, text_id + 1, 3, STEP, "res://objects/word/sprites/sprite%d.png", Color.BLACK, color) @@ -53,11 +48,6 @@ func get_word() -> String: func _ready(): update_animation() - - - -func _process(_delta): - update_animation() func set_color(value: Color) -> void: color = value @@ -72,9 +62,3 @@ func set_victory(v: bool) -> void: set_color(ImageLib.PALETTE["golden"]) else: set_color(ImageLib.PALETTE["default"]) - -func load_image(h: int, new_color: Color): - var image := load("res://objects/word/sprites/sprite" + str(h) + ".png") - if new_color != Color.BLACK: - return ImageLib.change_color(image, Color.BLACK, new_color) - return image diff --git a/objects/word/word.tscn b/objects/word/word.tscn index 9fa61db..3678ecc 100644 --- a/objects/word/word.tscn +++ b/objects/word/word.tscn @@ -1,35 +1,19 @@ -[gd_scene load_steps=6 format=3 uid="uid://cvx7wowcbfo0r"] +[gd_scene load_steps=4 format=3 uid="uid://cvx7wowcbfo0r"] [ext_resource type="Texture2D" uid="uid://cyyu6tsje4x72" path="res://objects/word/sprites/sprite3.png" id="1_ariam"] [ext_resource type="Script" path="res://objects/word/word.gd" id="1_lkxlh"] -[ext_resource type="Texture2D" uid="uid://bqtqgiv5etyny" path="res://objects/word/sprites/sprite28.png" id="2_l4ops"] -[ext_resource type="Texture2D" uid="uid://dua7hylyf4ws6" path="res://objects/word/sprites/sprite53.png" id="3_2kshj"] [sub_resource type="SpriteFrames" id="SpriteFrames_3n85j"] animations = [{ "frames": [{ "duration": 1.0, "texture": ExtResource("1_ariam") -}, { -"duration": 1.0, -"texture": ExtResource("2_l4ops") -}, { -"duration": 1.0, -"texture": ExtResource("3_2kshj") }], "loop": true, "name": &"default", -"speed": 3.0 -}, { -"frames": [], -"loop": true, -"name": &"new_animation", "speed": 5.0 }] [node name="Word" type="AnimatedSprite2D"] sprite_frames = SubResource("SpriteFrames_3n85j") -autoplay = "default" script = ExtResource("1_lkxlh") -text_id = null -color = null From b95ca390f3de614acaaefa2e9150193f50d63fe5 Mon Sep 17 00:00:00 2001 From: cutekibry Date: Sat, 10 Feb 2024 15:26:55 +0800 Subject: [PATCH 5/9] =?UTF-8?q?feat(card):=20=E6=B7=BB=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E4=BF=AE=E6=94=B9=E5=8D=A1=E8=83=8C=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- objects/card/card.gd | 15 +++++++++++++-- objects/card/card.tscn | 4 ---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/objects/card/card.gd b/objects/card/card.gd index 4e6bcb9..5e5e148 100644 --- a/objects/card/card.gd +++ b/objects/card/card.gd @@ -13,6 +13,8 @@ var is_card_entered = 0 var entered_area: Block var last_occupied_area: Block +var cardback_color : Color + var is_card_base_entered = 0 var entered_card_base_global_position: Vector2 @@ -117,8 +119,17 @@ func on_card_base_exited() -> void: is_card_base_entered -= 1 #print(is_card_entered) -func set_word(e: String) -> void: - $Word.set_word(e) +func set_word(value: String) -> void: + $Word.set_word(value) + var card_type := "card-%s" % ExprValidator.get_char_type_as_str(get_word()).to_lower() + if ImageLib.PALETTE.has(card_type): + ImageLib.update_animation( + $CardBackSprite, 1, 3, 1, "res://objects/card/card%d.png", + ImageLib.PALETTE["lightblue"], ImageLib.PALETTE[card_type] + ) + print($CardBackSprite.animation) + print($CardBackSprite.sprite_frames.animations) + func get_word() -> String: return $Word.get_word() diff --git a/objects/card/card.tscn b/objects/card/card.tscn index 8f54e54..02533d7 100644 --- a/objects/card/card.tscn +++ b/objects/card/card.tscn @@ -33,13 +33,9 @@ script = ExtResource("1_0bviv") [node name="Word" parent="." instance=ExtResource("1_ns36n")] z_index = 1 -frame_progress = 0.111549 -text_id = 1 -color = Color(0, 0, 0, 1) [node name="CardBackSprite" type="AnimatedSprite2D" parent="."] sprite_frames = SubResource("SpriteFrames_fo0r0") -autoplay = "default" [node name="HighlightSprite" type="Sprite2D" parent="."] texture = ExtResource("7_kix4t") From 41fde44eef1c05691f18da1c15576e5917ff1a83 Mon Sep 17 00:00:00 2001 From: cutekibry Date: Sat, 10 Feb 2024 15:28:26 +0800 Subject: [PATCH 6/9] =?UTF-8?q?fix(card.gd):=20=E5=88=A0=E5=8E=BB=E6=9C=AA?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84=20cardback=5Fcolor=20=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 如果以后要使用再写。 --- objects/card/card.gd | 2 -- 1 file changed, 2 deletions(-) diff --git a/objects/card/card.gd b/objects/card/card.gd index 5e5e148..c039f8e 100644 --- a/objects/card/card.gd +++ b/objects/card/card.gd @@ -13,8 +13,6 @@ var is_card_entered = 0 var entered_area: Block var last_occupied_area: Block -var cardback_color : Color - var is_card_base_entered = 0 var entered_card_base_global_position: Vector2 From c7c84707febc8c0dd868e20752ed472dad217667 Mon Sep 17 00:00:00 2001 From: cutekibry Date: Sat, 10 Feb 2024 15:46:13 +0800 Subject: [PATCH 7/9] =?UTF-8?q?fix(card.gd):=20=E4=BF=AE=E6=AD=A3=E9=9C=87?= =?UTF-8?q?=E5=8A=A8=E6=97=B6=E9=AB=98=E4=BA=AE=E8=BE=B9=E6=A1=86=E4=B8=8D?= =?UTF-8?q?=E5=8A=A8=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- objects/card/card.gd | 1 + 1 file changed, 1 insertion(+) diff --git a/objects/card/card.gd b/objects/card/card.gd index c039f8e..9f050b7 100644 --- a/objects/card/card.gd +++ b/objects/card/card.gd @@ -98,6 +98,7 @@ func _process(_delta: float) -> void: var progress = $ShakeTimer.time_left / $ShakeTimer.wait_time * 2 * PI offset = int(sin(progress) * shake_amount) $CardBackSprite.position.x = offset + $HighlightSprite.position.x = offset $Word.position.x = offset func on_card_entered(area: Block) -> void: From 99e5b496918ebfec139a2e0b0613d3d6408f4065 Mon Sep 17 00:00:00 2001 From: cutekibry Date: Sat, 10 Feb 2024 15:46:46 +0800 Subject: [PATCH 8/9] =?UTF-8?q?refactor(card=5Fbase):=20=E5=88=86=E7=A6=BB?= =?UTF-8?q?=E9=AB=98=E4=BA=AE=E5=92=8C=E4=B8=8D=E5=8F=AF=E7=94=A8=E7=9A=84?= =?UTF-8?q?=20sprite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 将 card_base_highlighted.png 修改为仅包含高亮不包含背景色的 card_base_highlight_border.png * 将原先的 AnimatedSprite2D 场景分离为 DisabledSprite、HighlightSprite 和 CardBaseSprite --- objects/card_base/card_base.tscn | 25 +++++++++--------- .../card_base/card_base_highlight_border.png | Bin 0 -> 230 bytes ... => card_base_highlight_border.png.import} | 8 +++--- objects/card_base/card_base_highlighted.png | Bin 296 -> 0 bytes 4 files changed, 16 insertions(+), 17 deletions(-) create mode 100644 objects/card_base/card_base_highlight_border.png rename objects/card_base/{card_base_highlighted.png.import => card_base_highlight_border.png.import} (63%) delete mode 100644 objects/card_base/card_base_highlighted.png diff --git a/objects/card_base/card_base.tscn b/objects/card_base/card_base.tscn index 1bdbd1b..e02c82e 100644 --- a/objects/card_base/card_base.tscn +++ b/objects/card_base/card_base.tscn @@ -5,7 +5,7 @@ [ext_resource type="FontFile" uid="uid://1000owdyvwfg" path="res://fonts/unifont-15.1.04.otf" id="3_0qykx"] [ext_resource type="Texture2D" uid="uid://b5d2rfms7vyfi" path="res://objects/card_base/card_base1.png" id="3_h7i1h"] [ext_resource type="Texture2D" uid="uid://bkjbrw1ppac5q" path="res://objects/card_base/card_base_disabled.png" id="4_0unxr"] -[ext_resource type="Texture2D" uid="uid://cs7vfmsrhpomj" path="res://objects/card_base/card_base_highlighted.png" id="5_tkdj2"] +[ext_resource type="Texture2D" uid="uid://bkuwo3g8pyuyi" path="res://objects/card_base/card_base_highlight_border.png" id="5_r41oe"] [ext_resource type="AudioStream" uid="uid://0sefo32v1jne" path="res://objects/card_base/pick_up.wav" id="7_0c7kt"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_2cmwb"] @@ -28,14 +28,6 @@ animations = [{ "loop": true, "name": &"disabled", "speed": 5.0 -}, { -"frames": [{ -"duration": 1.0, -"texture": ExtResource("5_tkdj2") -}], -"loop": true, -"name": &"highlighted", -"speed": 5.0 }] [node name="CardBase" type="Area2D"] @@ -45,10 +37,20 @@ script = ExtResource("1_k5qn1") shape = SubResource("RectangleShape2D_2cmwb") debug_color = Color(0.65098, 0.431373, 0.756863, 0.419608) +[node name="CardBaseSprite" type="AnimatedSprite2D" parent="."] +sprite_frames = SubResource("SpriteFrames_bhb3x") + [node name="Word" parent="." instance=ExtResource("2_jvsp3")] -z_index = 1 frame_progress = 0.953211 +[node name="HighlightSprite" type="Sprite2D" parent="."] +visible = false +texture = ExtResource("5_r41oe") + +[node name="DisabledSprite" type="Sprite2D" parent="."] +visible = false +texture = ExtResource("4_0unxr") + [node name="Label" type="Label" parent="."] offset_left = -13.0 offset_top = 17.0 @@ -59,9 +61,6 @@ text = "0" horizontal_alignment = 1 vertical_alignment = 1 -[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] -sprite_frames = SubResource("SpriteFrames_bhb3x") - [node name="Cards" type="Node" parent="."] [node name="FadeTimer" type="Timer" parent="."] diff --git a/objects/card_base/card_base_highlight_border.png b/objects/card_base/card_base_highlight_border.png new file mode 100644 index 0000000000000000000000000000000000000000..19ad568e3664d94166295e04b43a5226525c6231 GIT binary patch literal 230 zcmVPx#ph-kQR9J=Wm$4GSAP7UX|NqbF)H{u!cnV#}s6rmJ1C)~LRaXxH;EGYLQ!n-M z7QkSr0EveTv8rYzOTOWt4LSwb0eZBc+YnODu4whb0c7SScElS(@=!lbqyXSo5Yx{Z ztps5u2rEHY3BpPcR)VlZ5U;`63=%OAnLt`abVZ$6H3+XxeLm)y)uTH@vD*Po%a$o= g#QM2ao##US0yXYbG{X&;Z2$lO07*qoM6N<$g7Z9B@c;k- literal 0 HcmV?d00001 diff --git a/objects/card_base/card_base_highlighted.png.import b/objects/card_base/card_base_highlight_border.png.import similarity index 63% rename from objects/card_base/card_base_highlighted.png.import rename to objects/card_base/card_base_highlight_border.png.import index 5c5565a..5de750e 100644 --- a/objects/card_base/card_base_highlighted.png.import +++ b/objects/card_base/card_base_highlight_border.png.import @@ -2,16 +2,16 @@ importer="texture" type="CompressedTexture2D" -uid="uid://cs7vfmsrhpomj" -path="res://.godot/imported/card_base_highlighted.png-50d4af98046c8a87d73d61ca6664f89e.ctex" +uid="uid://bkuwo3g8pyuyi" +path="res://.godot/imported/card_base_highlight_border.png-02641e6f6e23a694917134adadde948a.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://objects/card_base/card_base_highlighted.png" -dest_files=["res://.godot/imported/card_base_highlighted.png-50d4af98046c8a87d73d61ca6664f89e.ctex"] +source_file="res://objects/card_base/card_base_highlight_border.png" +dest_files=["res://.godot/imported/card_base_highlight_border.png-02641e6f6e23a694917134adadde948a.ctex"] [params] diff --git a/objects/card_base/card_base_highlighted.png b/objects/card_base/card_base_highlighted.png deleted file mode 100644 index 6213968765537dcf0591673a3d507e4fefa444b3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 296 zcmV+@0oVSCP)Px#;z>k7R9J=WmoW~)FbqZQijmuJ6ok~FJ2T=O6?1onN)<=pHtc3fWt_Nal^7WO zrYcG6mmgJf0Gv-Sw}6PKN+HC>TIysifvBJ&lpK^2x5ulf_~p3I%0vTPqEujuP@}z6 zTO##MzUfAru%c^w=-NK2nM}kYjlkh_o`pE-(R>pkqMwTJRQ@6n02hgI5s8aPTtwm` z5*LvqMPy4?ljk(#MRF~_CF;>wq$1O}kJtHmCl@0khCVXLl(vrAaqya}FIck2EQP1B uC}JhV1%d>?io0)0rWQPiO@E2yh5QZIJ6S|><|Tgs0000J( From f049ab1df2b20b96bc81028cb9cbf37895247c1c Mon Sep 17 00:00:00 2001 From: cutekibry Date: Sat, 10 Feb 2024 16:13:00 +0800 Subject: [PATCH 9/9] =?UTF-8?q?feat(card=5Fbase.gd):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=94=B9=E5=8F=98=E5=8D=A1=E8=83=8C=E9=A2=9C=E8=89=B2=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- objects/card_base/card_base.gd | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/objects/card_base/card_base.gd b/objects/card_base/card_base.gd index f137c1b..5cf3b4e 100644 --- a/objects/card_base/card_base.gd +++ b/objects/card_base/card_base.gd @@ -11,6 +11,9 @@ signal card_put var fade_flag := false var mouse_on := false +enum { DEFAULT, HIGHLIGHT, DISABLED} +var available_stat := DEFAULT + var card_count = 0 var new_card_node: Card @@ -25,11 +28,11 @@ func set_card_count(value): card_count = value if card_count > 0: if mouse_on: - $AnimatedSprite2D.animation = "highlighted" + available_stat = HIGHLIGHT else: - $AnimatedSprite2D.animation = "default" + available_stat = DEFAULT else: - $AnimatedSprite2D.animation = "disabled" + available_stat = DISABLED update_card_count_label() @@ -74,6 +77,11 @@ func _input_event(_viewport: Object, event: InputEvent, _shape_idx: int) -> void func set_word(e: String) -> void: $Word.set_word(e) + var card_type := "card-%s" % ExprValidator.get_char_type_as_str(e).to_lower() + if ImageLib.PALETTE.has(card_type): + ImageLib.update_animation($CardBaseSprite, 1, 1, 1, "res://objects/card_base/card_base%d.png", + ImageLib.PALETTE["lightblue"], ImageLib.PALETTE[card_type]) + func get_word() -> String: return $Word.get_word() @@ -98,18 +106,23 @@ func _process(_delta) -> void: if fade_flag: var offset = $FadeTimer.time_left / $FadeTimer.wait_time offset = (1 - pow(offset, 1.5)) * FADE_MOVE_AMOUNT - $AnimatedSprite2D.position.y = offset + $CardBaseSprite.position.y = offset + $HighlightSprite.position.y = offset + $DisabledSprite.position.y = offset $Word.position.y = offset + + $HighlightSprite.visible = (available_stat == HIGHLIGHT) + $DisabledSprite.visible = (available_stat == DISABLED) func _on_mouse_entered(): mouse_on = true - if $AnimatedSprite2D.animation == "default": - $AnimatedSprite2D.animation = "highlighted" + if available_stat == DEFAULT: + available_stat = HIGHLIGHT Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND) func _on_mouse_exited(): mouse_on = false - if $AnimatedSprite2D.animation == "highlighted": - $AnimatedSprite2D.animation = "default" + if available_stat == HIGHLIGHT: + available_stat = DEFAULT Input.set_default_cursor_shape(Input.CURSOR_ARROW)