diff --git a/HanafudaCard.gd b/HanafudaCard.gd index 770031e..63a721d 100644 --- a/HanafudaCard.gd +++ b/HanafudaCard.gd @@ -68,3 +68,36 @@ func _set_card_month(new_month: int) -> void: func _set_card_type(new_type: int) -> void: value.type = new_type + +func set_size(new_size: Vector2) -> void: + if not _is_ready: + yield(self, "ready") + + var texture_size = $Frontside.texture.get_size() + var scale = new_size / texture_size + self.scale = scale + +func set_min_dimension(dim: int) -> void: + if not _is_ready: + yield(self, "ready") + + var texture_size = $Frontside.texture.get_size() + var scale = Vector2(dim, dim) / texture_size + var max_scale = max(scale.x, scale.y) + self.scale = Vector2(max_scale, max_scale) + +func set_max_dimension(dim: int) -> void: + if not _is_ready: + yield(self, "ready") + + var texture_size = $Frontside.texture.get_size() + var scale = Vector2(dim, dim) / texture_size + var min_scale = min(scale.x, scale.y) + self.scale = Vector2(min_scale, min_scale) + +func get_size() -> Vector2: + if not _is_ready: + yield(self, "ready") + + var texture_size = $Frontside.texture.get_size() + return texture_size * self.scale diff --git a/HanafudaCard.tscn b/HanafudaCard.tscn index 023fa44..3e0c020 100644 --- a/HanafudaCard.tscn +++ b/HanafudaCard.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=5 format=2] [ext_resource path="res://HanafudaCard.gd" type="Script" id=1] -[ext_resource path="res://assets/png/Hanafuda_July_Kasu_1.png" type="Texture" id=2] +[ext_resource path="res://assets/png/Hanafuda_January_Hikari.png" type="Texture" id=2] [ext_resource path="res://assets/png/Hanafuda_border.png" type="Texture" id=3] [ext_resource path="res://assets/japanese_pattern_01.png" type="Texture" id=4] diff --git a/Main.gd b/Main.gd index 9f8deec..631b8c4 100644 --- a/Main.gd +++ b/Main.gd @@ -10,19 +10,30 @@ func _ready(): func oya(): tween.start() + var deck_position = Vector2(10, 10) + var card_reveal_duration = 0.5 + var card_dim = 150 + var card_1 = HanafudaCard.instance().init_card($Deck.draw_card()) + card_1.set_min_dimension(card_dim) add_child(card_1) -# card_1.show() + + var card_size = card_1.get_size() + var padding = 20 + var delta_x = (card_size.x + padding) / 2 tween.interpolate_property(card_1, "position", - Vector2(0, 0), Vector2(100, 100), 3, + deck_position, Vector2(get_viewport().size.x / 2 - delta_x, get_viewport().size.y / 2), + card_reveal_duration, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT) -# var card_2 = $Deck.card($Deck.draw_card()) -# card_2.show() -# tween.interpolate_property(card_2, "position", -# Vector2(0, 0), Vector2(-100, 100), 0.4, -# Tween.TRANS_LINEAR, Tween.EASE_IN_OUT) + var card_2 = HanafudaCard.instance().init_card($Deck.draw_card()) + card_2.set_min_dimension(card_dim) + add_child(card_2) + tween.interpolate_property(card_2, "position", + deck_position, Vector2(get_viewport().size.x / 2 + delta_x, get_viewport().size.y / 2), + card_reveal_duration, + Tween.TRANS_LINEAR, Tween.EASE_IN_OUT) yield(tween, "tween_all_completed")