hanafuda/HanafudaCard.gd

64 lines
1.5 KiB
GDScript3
Raw Normal View History

2021-11-21 20:44:08 +01:00
tool
extends Node2D
2021-12-06 23:10:39 +01:00
class_name HanafudaCard
2021-11-16 23:22:54 +01:00
2021-11-21 20:44:08 +01:00
export var revealed: bool = true setget reveal
2021-12-06 23:10:39 +01:00
export(Enums.Month) var month: int
export(Enums.Type) var type: int
2021-11-21 20:44:08 +01:00
2021-11-21 23:29:05 +01:00
onready var _is_ready := true
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:
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-06 23:44:23 +01:00
func init_card(month_: int, type_: int) -> HanafudaCard:
2021-12-06 23:10:39 +01:00
month = month_
type = type_
2021-12-06 23:44:23 +01:00
return self
2021-12-06 23:10:39 +01:00
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:
2021-11-21 20:44:08 +01:00
revealed = new_reveal
2021-11-21 23:29:05 +01:00
if not _is_ready:
yield(self, "ready")
2021-11-21 20:44:08 +01:00
if revealed:
print("Reveal card")
$Frontside.show()
$Backside.hide()
else:
print("Conceal card")
$Frontside.hide()
$Backside.show()