add state stack

main
Fabien Freling 2021-12-12 23:21:03 +01:00
parent c6ec75e768
commit 916ea0fc49
4 changed files with 35 additions and 12 deletions

View File

@ -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()

View File

@ -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

36
Main.gd
View File

@ -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")

View File

@ -21,4 +21,5 @@ position = Vector2( 205, 447 )
month = 2
[node name="Deck" type="Node2D" parent="."]
position = Vector2( 293, 412 )
script = ExtResource( 3 )