add state stack
This commit is contained in:
parent
c6ec75e768
commit
916ea0fc49
6
Deck.gd
6
Deck.gd
|
@ -71,11 +71,15 @@ func _ready() -> void:
|
||||||
init_card_order()
|
init_card_order()
|
||||||
for c in cards:
|
for c in cards:
|
||||||
add_child(c)
|
add_child(c)
|
||||||
|
c.hide()
|
||||||
|
|
||||||
|
|
||||||
var card: HanafudaCard = cards[0]
|
var card: HanafudaCard = cards[0]
|
||||||
card.reveal(true)
|
card.show()
|
||||||
|
card.reveal(false)
|
||||||
|
|
||||||
func init_card_order() -> void:
|
func init_card_order() -> void:
|
||||||
card_order.resize(cards.size())
|
card_order.resize(cards.size())
|
||||||
for i in range(cards.size()):
|
for i in range(cards.size()):
|
||||||
card_order[i] = i
|
card_order[i] = i
|
||||||
|
card_order.shuffle()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[gd_scene load_steps=5 format=2]
|
[gd_scene load_steps=5 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://HanafudaCard.gd" type="Script" id=1]
|
[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/png/Hanafuda_border.png" type="Texture" id=3]
|
||||||
[ext_resource path="res://assets/japanese_pattern_01.png" type="Texture" id=4]
|
[ext_resource path="res://assets/japanese_pattern_01.png" type="Texture" id=4]
|
||||||
|
|
||||||
|
@ -11,10 +11,10 @@ month = 6
|
||||||
type = 3
|
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
|
||||||
|
|
36
Main.gd
36
Main.gd
|
@ -1,16 +1,34 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
|
||||||
# Declare member variables here. Examples:
|
var state_stack = []
|
||||||
# var a = 2
|
|
||||||
# var b = "text"
|
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready():
|
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.
|
state_stack.push_back(state.resume())
|
||||||
#func _process(delta):
|
|
||||||
# pass
|
func update_oya():
|
||||||
|
yield()
|
||||||
|
print("update oya")
|
||||||
|
yield()
|
||||||
|
|
||||||
|
func update_game():
|
||||||
|
print("update game")
|
||||||
|
|
Loading…
Reference in a new issue