add card Deck

This commit is contained in:
Fabien Freling 2021-12-06 23:10:39 +01:00
parent e135c75787
commit 5007d7aa2a
7 changed files with 189 additions and 39 deletions

70
Deck.gd Normal file
View file

@ -0,0 +1,70 @@
extends Node
var HanafudaCard = preload("res://HanafudaCard.tscn")
onready var cards = [
HanafudaCard.instance().init_card(Enums.Month.JANUARY, Enums.Type.LIGHT),
HanafudaCard.instance().init_card(Enums.Month.JANUARY, Enums.Type.RIBBON),
HanafudaCard.instance().init_card(Enums.Month.JANUARY, Enums.Type.SCRAP_1),
HanafudaCard.instance().init_card(Enums.Month.JANUARY, Enums.Type.SCRAP_2),
HanafudaCard.instance().init_card(Enums.Month.FEBRUARY, Enums.Type.ANIMAL),
HanafudaCard.instance().init_card(Enums.Month.FEBRUARY, Enums.Type.RIBBON),
HanafudaCard.instance().init_card(Enums.Month.FEBRUARY, Enums.Type.SCRAP_1),
HanafudaCard.instance().init_card(Enums.Month.FEBRUARY, Enums.Type.SCRAP_2),
HanafudaCard.instance().init_card(Enums.Month.MARCH, Enums.Type.LIGHT),
HanafudaCard.instance().init_card(Enums.Month.MARCH, Enums.Type.RIBBON),
HanafudaCard.instance().init_card(Enums.Month.MARCH, Enums.Type.SCRAP_1),
HanafudaCard.instance().init_card(Enums.Month.MARCH, Enums.Type.SCRAP_2),
HanafudaCard.instance().init_card(Enums.Month.APRIL, Enums.Type.ANIMAL),
HanafudaCard.instance().init_card(Enums.Month.APRIL, Enums.Type.RIBBON),
HanafudaCard.instance().init_card(Enums.Month.APRIL, Enums.Type.SCRAP_1),
HanafudaCard.instance().init_card(Enums.Month.APRIL, Enums.Type.SCRAP_2),
HanafudaCard.instance().init_card(Enums.Month.MAY, Enums.Type.ANIMAL),
HanafudaCard.instance().init_card(Enums.Month.MAY, Enums.Type.RIBBON),
HanafudaCard.instance().init_card(Enums.Month.MAY, Enums.Type.SCRAP_1),
HanafudaCard.instance().init_card(Enums.Month.MAY, Enums.Type.SCRAP_2),
HanafudaCard.instance().init_card(Enums.Month.JUNE, Enums.Type.ANIMAL),
HanafudaCard.instance().init_card(Enums.Month.JUNE, Enums.Type.RIBBON),
HanafudaCard.instance().init_card(Enums.Month.JUNE, Enums.Type.SCRAP_1),
HanafudaCard.instance().init_card(Enums.Month.JUNE, Enums.Type.SCRAP_2),
HanafudaCard.instance().init_card(Enums.Month.JULY, Enums.Type.ANIMAL),
HanafudaCard.instance().init_card(Enums.Month.JULY, Enums.Type.RIBBON),
HanafudaCard.instance().init_card(Enums.Month.JULY, Enums.Type.SCRAP_1),
HanafudaCard.instance().init_card(Enums.Month.JULY, Enums.Type.SCRAP_2),
HanafudaCard.instance().init_card(Enums.Month.AUGUST, Enums.Type.LIGHT),
HanafudaCard.instance().init_card(Enums.Month.AUGUST, Enums.Type.ANIMAL),
HanafudaCard.instance().init_card(Enums.Month.AUGUST, Enums.Type.SCRAP_1),
HanafudaCard.instance().init_card(Enums.Month.AUGUST, Enums.Type.SCRAP_2),
HanafudaCard.instance().init_card(Enums.Month.SEPTEMBER, Enums.Type.ANIMAL),
HanafudaCard.instance().init_card(Enums.Month.SEPTEMBER, Enums.Type.RIBBON),
HanafudaCard.instance().init_card(Enums.Month.SEPTEMBER, Enums.Type.SCRAP_1),
HanafudaCard.instance().init_card(Enums.Month.SEPTEMBER, Enums.Type.SCRAP_2),
HanafudaCard.instance().init_card(Enums.Month.OCTOBER, Enums.Type.ANIMAL),
HanafudaCard.instance().init_card(Enums.Month.OCTOBER, Enums.Type.RIBBON),
HanafudaCard.instance().init_card(Enums.Month.OCTOBER, Enums.Type.SCRAP_1),
HanafudaCard.instance().init_card(Enums.Month.OCTOBER, Enums.Type.SCRAP_2),
HanafudaCard.instance().init_card(Enums.Month.NOVEMBER, Enums.Type.LIGHT),
HanafudaCard.instance().init_card(Enums.Month.NOVEMBER, Enums.Type.ANIMAL),
HanafudaCard.instance().init_card(Enums.Month.NOVEMBER, Enums.Type.RIBBON),
HanafudaCard.instance().init_card(Enums.Month.NOVEMBER, Enums.Type.SCRAP_1),
HanafudaCard.instance().init_card(Enums.Month.DECEMBER, Enums.Type.LIGHT),
HanafudaCard.instance().init_card(Enums.Month.DECEMBER, Enums.Type.SCRAP_1),
HanafudaCard.instance().init_card(Enums.Month.DECEMBER, Enums.Type.SCRAP_2),
HanafudaCard.instance().init_card(Enums.Month.DECEMBER, Enums.Type.SCRAP_3),
]
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
for c in cards:
add_child(c)

40
Enums.gd Normal file
View file

@ -0,0 +1,40 @@
extends Node
enum Month {
JANUARY,
FEBRUARY,
MARCH,
APRIL,
MAY,
JUNE,
JULY,
AUGUST,
SEPTEMBER,
OCTOBER,
NOVEMBER,
DECEMBER,
}
enum Flower {
PINE,
PLUM_BLOSSOM,
CHERRY_BLOSSOM,
WISTERIA,
IRIS,
PEONY,
BUSH_CLOVER,
GRASS,
CHRYSANTHEMUM,
MAPLE,
WILLOW,
PAULOWNIA,
}
enum Type {
LIGHT,
ANIMAL,
RIBBON,
SCRAP_1,
SCRAP_2,
SCRAP_3,
}

View file

@ -1,49 +1,52 @@
tool tool
extends Node2D extends Node2D
class_name HanafudaCard
enum Month {
JANUARY,
FEBRUARY,
MARCH,
APRIL,
MAY,
JUNE,
JULY,
AUGUST,
SEPTEMBER,
OCTOBER,
NOVEMBER,
DECEMBER,
}
enum Flower {
PINE,
PLUM_BLOSSOM,
CHERRY_BLOSSOM,
WISTERIA,
IRIS,
PEONY,
BUSH_CLOVER,
GRASS,
CHRYSANTHEMUM,
MAPLE,
WILLOW,
PAULOWNIA,
}
export var revealed: bool = true setget reveal export var revealed: bool = true setget reveal
export(Enums.Month) var month: int
export(Enums.Type) var type: int
onready var _is_ready := true onready var _is_ready := true
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready() -> void:
var texture_path := card_texture()
$Frontside.texture = load(texture_path)
reveal(revealed) reveal(revealed)
# Called every frame. 'delta' is the elapsed time since the previous frame. func init_card(month_: int, type_: int) -> void:
func _process(delta): month = month_
pass type = type_
func reveal(new_reveal: bool): 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 revealed = new_reveal
if not _is_ready: if not _is_ready:

View file

@ -7,13 +7,14 @@
[node name="HanafudaCard" type="Node2D"] [node name="HanafudaCard" type="Node2D"]
script = ExtResource( 1 ) script = ExtResource( 1 )
revealed = false month = 6
type = 3
[node name="Frontside" type="Sprite" parent="."] [node name="Frontside" type="Sprite" parent="."]
visible = false
texture = ExtResource( 2 ) texture = ExtResource( 2 )
[node name="Backside" type="Node2D" parent="."] [node name="Backside" type="Node2D" parent="."]
visible = false
[node name="TextureRect" type="TextureRect" parent="Backside"] [node name="TextureRect" type="TextureRect" parent="Backside"]
margin_left = -110.0 margin_left = -110.0

16
Main.gd Normal file
View file

@ -0,0 +1,16 @@
extends Node
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

View file

@ -1,8 +1,11 @@
[gd_scene load_steps=2 format=2] [gd_scene load_steps=4 format=2]
[ext_resource path="res://HanafudaCard.tscn" type="PackedScene" id=1] [ext_resource path="res://HanafudaCard.tscn" type="PackedScene" id=1]
[ext_resource path="res://Main.gd" type="Script" id=2]
[ext_resource path="res://Deck.gd" type="Script" id=3]
[node name="Node" type="Node"] [node name="Node" type="Node"]
script = ExtResource( 2 )
[node name="Background" type="ColorRect" parent="."] [node name="Background" type="ColorRect" parent="."]
anchor_right = 1.0 anchor_right = 1.0
@ -14,4 +17,7 @@ __meta__ = {
[node name="HanafudaCard" parent="." instance=ExtResource( 1 )] [node name="HanafudaCard" parent="." instance=ExtResource( 1 )]
position = Vector2( 205, 447 ) position = Vector2( 205, 447 )
revealed = true month = 2
[node name="Deck" type="Node" parent="."]
script = ExtResource( 3 )

View file

@ -8,12 +8,26 @@
config_version=4 config_version=4
_global_script_classes=[ {
"base": "Node2D",
"class": "HanafudaCard",
"language": "GDScript",
"path": "res://HanafudaCard.gd"
} ]
_global_script_class_icons={
"HanafudaCard": ""
}
[application] [application]
config/name="Hanafuda" config/name="Hanafuda"
run/main_scene="res://Main.tscn" run/main_scene="res://Main.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
[autoload]
Enums="*res://Enums.gd"
[display] [display]
window/size/width=600 window/size/width=600