From 916ea0fc4901f19a6e4d2aeb749e2576c6f4ce6c Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Sun, 12 Dec 2021 23:21:03 +0100 Subject: [PATCH] add state stack --- Deck.gd | 6 +++++- HanafudaCard.tscn | 4 ++-- Main.gd | 36 +++++++++++++++++++++++++++--------- Main.tscn | 1 + 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/Deck.gd b/Deck.gd index 71a5786..be124e2 100644 --- a/Deck.gd +++ b/Deck.gd @@ -71,11 +71,15 @@ func _ready() -> void: init_card_order() for c in cards: add_child(c) + c.hide() + var card: HanafudaCard = cards[0] - card.reveal(true) + card.show() + card.reveal(false) func init_card_order() -> void: card_order.resize(cards.size()) for i in range(cards.size()): card_order[i] = i + card_order.shuffle() diff --git a/HanafudaCard.tscn b/HanafudaCard.tscn index de2d77d..18b8fa3 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_April_Kasu_1.png" type="Texture" id=2] +[ext_resource path="res://assets/png/Hanafuda_July_Kasu_1.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] @@ -11,10 +11,10 @@ month = 6 type = 3 [node name="Frontside" type="Sprite" parent="."] -visible = false texture = ExtResource( 2 ) [node name="Backside" type="Node2D" parent="."] +visible = false [node name="TextureRect" type="TextureRect" parent="Backside"] margin_left = -110.0 diff --git a/Main.gd b/Main.gd index 1eccaec..fae3ad7 100644 --- a/Main.gd +++ b/Main.gd @@ -1,16 +1,34 @@ extends Node -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" +var state_stack = [] - -# Called when the node enters the scene tree for the first time. func _ready(): - pass # Replace with function body. + state_stack.push_back(funcref(self, "update_game")) + state_stack.push_back(funcref(self, "update_oya")) + +func _process(delta): + if state_stack.empty(): + return + var state = state_stack.pop_back() + if state == null: + return + + if state is FuncRef: + state_stack.push_back(state.call_func()) + return + + if not (state is GDScriptFunctionState and state.is_valid()): + printerr("Invalid state") + return -# Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass + state_stack.push_back(state.resume()) + +func update_oya(): + yield() + print("update oya") + yield() + +func update_game(): + print("update game") diff --git a/Main.tscn b/Main.tscn index 7e07080..9687049 100644 --- a/Main.tscn +++ b/Main.tscn @@ -21,4 +21,5 @@ position = Vector2( 205, 447 ) month = 2 [node name="Deck" type="Node2D" parent="."] +position = Vector2( 293, 412 ) script = ExtResource( 3 )