hanafuda/HanafudaCard.gd

63 lines
1.5 KiB
GDScript

tool
extends Node2D
class_name HanafudaCard
export var revealed: bool = true setget reveal
export(Enums.Month) var month: int
export(Enums.Type) var type: int
onready var _is_ready := true
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var texture_path := card_texture()
$Frontside.texture = load(texture_path)
reveal(revealed)
func init_card(month_: int, type_: int) -> void:
month = month_
type = type_
func card_texture() -> String:
var m := ""
match month:
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 := ""
match type:
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:
revealed = new_reveal
if not _is_ready:
yield(self, "ready")
if revealed:
print("Reveal card")
$Frontside.show()
$Backside.hide()
else:
print("Conceal card")
$Frontside.hide()
$Backside.show()