-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshop.gd
143 lines (126 loc) · 3.87 KB
/
shop.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
extends Control
var ShopCard = preload("res://ui/shop_card.tscn")
var shopCard3D = preload("res://shop_card_3d.tscn")
var treasureCard3D = preload("res://ui/treasure_card_3d.tscn")
var Inventory = preload("res://inventory.tscn")
var cards
var bought
var in_inventory = false
func _ready():
# var merged_shop_theme = Theme.new()
# merged_shop_theme.merge_with(Game.original_theme)
# merged_shop_theme.merge_with($Shop.theme)
# $Shop.theme = merged_shop_theme
cards = []
$AnimationPlayer.play("RESET")
$Shop/TreasureView/AnimationPlayer.play("RESET")
Game.connect("accept_treasure", self, "on_accept_treasure")
$Shop.material.set_shader_param("time_offset", OS.get_ticks_msec() / 1000.0)
for child in $"%Cards".get_children():
$"%Cards".remove_child(child)
child.queue_free()
if Deck.pending_treasure_card == null:
if Game.skip_to_inventory:
Game.skip_to_inventory = false
go_to_inventory()
else:
$AnimationPlayer.play("fade_in")
yield(get_tree().create_timer(0.1), "timeout")
deal_shop_cards()
$Shop/Container.visible = true
else:
$Shop/TreasureView/AnimationPlayer.play("new_treasure")
var new_3d_card = treasureCard3D.instance()
new_3d_card.become(Deck.pending_treasure_card)
$"%ShopCamera".add_child(new_3d_card)
var on_accept_treasure_dead = false
func on_accept_treasure():
if on_accept_treasure_dead:
return
on_accept_treasure_dead = true
$DigSound.play()
$Shop/TreasureView/AnimationPlayer.play("fade_out")
yield($Shop/TreasureView/AnimationPlayer, "animation_finished")
$AnimationPlayer.play("fade_in")
yield(get_tree().create_timer(0.1), "timeout")
deal_shop_cards()
func on_bought(c):
$PurchaseSound.play()
bought[c.get_index()] = true
func deal_shop_cards():
# Deal some cards
cards = []
bought = [false, false, false]
cards.push_back(ShopDeck.deal())
cards.push_back(ShopDeck.deal())
cards.push_back(ShopDeck.deal())
for card in cards:
var new_card = ShopCard.instance()
new_card.card = card
$"%Cards".add_child(new_card)
new_card.connect("bought", self, "on_bought", [new_card])
if card == null:
continue
var new_3d_card = shopCard3D.instance()
new_3d_card.visible = false
new_3d_card.follow_node = new_card.get_node("%3DAnchor")
new_3d_card.become(card)
$"%ShopCamera".add_child(new_3d_card)
new_3d_card.global_rotation = Vector3.ZERO
new_3d_card.global_translation = Vector3.ZERO
func get_shop_cam():
return $"%ShopCamera"
func undeal_shop_cards():
for i in range(bought.size()):
if !bought[i]:
var card = cards[i]
if !card:
continue
ShopDeck.return_card(card)
var _on_SkipButton_pressed_dead = false
func _on_SkipButton_pressed():
if _on_SkipButton_pressed_dead:
return
_on_SkipButton_pressed_dead = true
# Game.level += 1
# Game.emit_signal("reset")
$DigSound.play()
undeal_shop_cards()
$AnimationPlayer.play("fade_out")
yield($AnimationPlayer, "animation_finished")
# get_tree().change_scene("res://inventory.tscn")
go_to_inventory()
func go_to_inventory():
in_inventory = true
for child in $Shop.get_children():
$Shop.remove_child(child)
for child in $"%ShopCamera".get_children():
$"%ShopCamera".remove_child(child)
var inventory = Inventory.instance()
inventory.controller = self
$Shop.add_child(inventory)
$AnimationPlayer.play("fade_in")
inventory.fade_in()
func _process(delta):
if in_inventory:
return
if $"%RerollButton" != null:
$"%RerollButton".disabled = Game.money < 2
var rerolling = false
func _on_RerollButton_pressed():
if rerolling:
return
rerolling = true
$"%RerollButton".release_focus()
Game.money -= 2
$PurchaseSound.play()
$AnimationPlayer.play("reroll_out")
yield($AnimationPlayer, "animation_finished")
undeal_shop_cards()
for child in $"%Cards".get_children():
$"%Cards".remove_child(child)
for child in $"%ShopCamera".get_children():
$"%ShopCamera".remove_child(child)
deal_shop_cards()
$AnimationPlayer.play("reroll_in")
rerolling = false