2024-09-02 13:26:07 +02:00
|
|
|
@tool
|
2021-12-06 23:10:39 +01:00
|
|
|
class_name HanafudaCard
|
2021-12-14 21:53:45 +01:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
const CardValue = preload("res://CardValue.gd")
|
2021-11-16 23:22:54 +01:00
|
|
|
|
2024-09-02 13:26:07 +02:00
|
|
|
@export var revealed: bool = true: set = reveal
|
|
|
|
@export var month: int: set = _set_card_month
|
|
|
|
@export var type: int: set = _set_card_type
|
2021-11-21 20:44:08 +01:00
|
|
|
|
2022-01-24 23:23:19 +01:00
|
|
|
var value: CardValue = CardValue.new(Enums.Month.JANUARY, Enums.Type.LIGHT)
|
|
|
|
|
2024-09-02 13:26:07 +02:00
|
|
|
@onready var _is_ready := true
|
2021-11-21 23:29:05 +01:00
|
|
|
|
2021-11-16 23:22:54 +01:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
2021-12-06 23:10:39 +01:00
|
|
|
func _ready() -> void:
|
2021-12-14 21:53:45 +01:00
|
|
|
|
2021-12-06 23:10:39 +01:00
|
|
|
var texture_path := card_texture()
|
|
|
|
$Frontside.texture = load(texture_path)
|
2021-11-21 20:44:08 +01:00
|
|
|
reveal(revealed)
|
2021-11-16 23:22:54 +01:00
|
|
|
|
2021-12-14 21:53:45 +01:00
|
|
|
func init_card(value_: CardValue) -> HanafudaCard:
|
|
|
|
value = value_
|
2021-12-06 23:44:23 +01:00
|
|
|
return self
|
2021-12-06 23:10:39 +01:00
|
|
|
|
|
|
|
func card_texture() -> String:
|
|
|
|
var m := ""
|
2021-12-14 21:53:45 +01:00
|
|
|
match value.month:
|
2021-12-06 23:10:39 +01:00
|
|
|
Enums.Month.JANUARY: m = "January"
|
|
|
|
Enums.Month.FEBRUARY: m = "February"
|
|
|
|
Enums.Month.MARCH: m = "March"
|
|
|
|
Enums.Month.APRIL: m = "April"
|
|
|
|
Enums.Month.MAY: m = "May"
|
|
|
|
Enums.Month.JUNE: m = "June"
|
|
|
|
Enums.Month.JULY: m = "July"
|
|
|
|
Enums.Month.AUGUST: m = "August"
|
|
|
|
Enums.Month.SEPTEMBER: m = "September"
|
|
|
|
Enums.Month.OCTOBER: m = "October"
|
|
|
|
Enums.Month.NOVEMBER: m = "November"
|
|
|
|
Enums.Month.DECEMBER: m = "December"
|
|
|
|
|
|
|
|
var t := ""
|
2021-12-14 21:53:45 +01:00
|
|
|
match value.type:
|
2021-12-06 23:10:39 +01:00
|
|
|
Enums.Type.LIGHT: t = "Hikari"
|
|
|
|
Enums.Type.ANIMAL: t = "Tane"
|
|
|
|
Enums.Type.RIBBON: t = "Tanzaku"
|
|
|
|
Enums.Type.SCRAP_1: t = "Kasu_1"
|
|
|
|
Enums.Type.SCRAP_2: t = "Kasu_2"
|
|
|
|
Enums.Type.SCRAP_3: t = "Kasu_3"
|
|
|
|
|
|
|
|
var texture_path := "res://assets/png/Hanafuda_{month}_{type}.png".format({"month": m, "type": t})
|
|
|
|
return texture_path
|
|
|
|
|
|
|
|
func reveal(new_reveal: bool) -> void:
|
2021-11-21 20:44:08 +01:00
|
|
|
revealed = new_reveal
|
2021-11-21 23:29:05 +01:00
|
|
|
|
|
|
|
if not _is_ready:
|
2024-09-02 13:26:07 +02:00
|
|
|
await self.ready
|
2021-11-21 23:29:05 +01:00
|
|
|
|
2021-11-21 20:44:08 +01:00
|
|
|
if revealed:
|
|
|
|
$Frontside.show()
|
|
|
|
$Backside.hide()
|
|
|
|
else:
|
|
|
|
$Frontside.hide()
|
|
|
|
$Backside.show()
|
2021-12-14 21:53:45 +01:00
|
|
|
|
|
|
|
func _set_card_month(new_month: int) -> void:
|
|
|
|
value.month = new_month
|
|
|
|
|
|
|
|
func _set_card_type(new_type: int) -> void:
|
|
|
|
value.type = new_type
|
2022-01-23 23:56:54 +01:00
|
|
|
|
|
|
|
func set_size(new_size: Vector2) -> void:
|
|
|
|
if not _is_ready:
|
2024-09-02 13:26:07 +02:00
|
|
|
await self.ready
|
2022-01-23 23:56:54 +01:00
|
|
|
|
|
|
|
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:
|
2024-09-02 13:26:07 +02:00
|
|
|
await self.ready
|
2022-01-23 23:56:54 +01:00
|
|
|
|
|
|
|
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:
|
2024-09-02 13:26:07 +02:00
|
|
|
await self.ready
|
2022-01-23 23:56:54 +01:00
|
|
|
|
|
|
|
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:
|
2024-09-02 13:26:07 +02:00
|
|
|
await self.ready
|
2022-01-23 23:56:54 +01:00
|
|
|
|
|
|
|
var texture_size = $Frontside.texture.get_size()
|
|
|
|
return texture_size * self.scale
|