2020-10-14 14:48:38 +02:00
|
|
|
extends Control
|
2020-10-13 14:16:36 +02:00
|
|
|
|
2020-10-27 11:55:47 +01:00
|
|
|
var card_store = {}
|
|
|
|
var cards
|
2020-10-27 15:48:23 +01:00
|
|
|
var card_radius = 1500
|
2020-10-13 17:08:37 +02:00
|
|
|
|
2020-10-13 14:16:36 +02:00
|
|
|
func _ready():
|
2020-10-27 11:55:47 +01:00
|
|
|
load_card_store()
|
2020-10-27 12:16:33 +01:00
|
|
|
#redraw_all_cards()
|
2020-10-13 18:58:30 +02:00
|
|
|
arrange_cards()
|
2020-10-15 16:41:42 +02:00
|
|
|
pass
|
2020-10-13 14:16:36 +02:00
|
|
|
|
2020-10-26 19:56:52 +01:00
|
|
|
func _process(_delta):
|
2020-10-15 15:53:23 +02:00
|
|
|
if $Energy:
|
|
|
|
$Energy.text = str(game.energy)
|
2020-10-27 11:55:47 +01:00
|
|
|
|
|
|
|
func load_card_store():
|
|
|
|
var cards_json = JSON.parse(helpers.read_file("res://resources/cards.json")).result
|
|
|
|
for card in cards_json:
|
|
|
|
card_store[card["id"]] = card
|
2020-10-13 17:29:24 +02:00
|
|
|
|
|
|
|
func draw_rand_card():
|
2020-10-15 15:53:23 +02:00
|
|
|
var deck = []
|
|
|
|
|
|
|
|
for card in cards:
|
|
|
|
deck.push_back(card)
|
|
|
|
|
|
|
|
# We want a lot of commit and checkout cards!
|
2020-10-26 19:56:52 +01:00
|
|
|
for _i in range(5):
|
2020-10-15 15:53:23 +02:00
|
|
|
deck.push_back(cards[0])
|
|
|
|
deck.push_back(cards[1])
|
|
|
|
|
|
|
|
var card = deck[randi() % deck.size()]
|
2020-10-15 16:11:02 +02:00
|
|
|
draw_card(card)
|
|
|
|
|
|
|
|
func draw_card(card):
|
2020-10-26 19:15:47 +01:00
|
|
|
var new_card = preload("res://scenes/card.tscn").instance()
|
2020-10-15 16:11:02 +02:00
|
|
|
|
2020-10-27 13:14:07 +01:00
|
|
|
new_card.id = card["id"]
|
2020-10-27 11:55:47 +01:00
|
|
|
new_card.command = card["command"]
|
|
|
|
new_card.description = card["description"]
|
2020-10-15 16:11:02 +02:00
|
|
|
new_card.energy = 0 #card.energy
|
2020-10-14 14:48:38 +02:00
|
|
|
new_card.position = Vector2(rect_size.x, rect_size.y*2)
|
2020-10-13 17:29:24 +02:00
|
|
|
add_child(new_card)
|
2020-10-13 18:58:30 +02:00
|
|
|
arrange_cards()
|
2020-10-13 17:29:24 +02:00
|
|
|
|
2020-10-27 12:16:33 +01:00
|
|
|
func draw(ids):
|
|
|
|
for card in get_tree().get_nodes_in_group("cards"):
|
|
|
|
card.queue_free()
|
|
|
|
|
|
|
|
for id in ids:
|
|
|
|
draw_card(card_store[id])
|
|
|
|
|
|
|
|
arrange_cards()
|
|
|
|
|
2020-10-13 18:58:30 +02:00
|
|
|
func arrange_cards():
|
2020-10-14 00:04:47 +02:00
|
|
|
var t = Timer.new()
|
|
|
|
t.wait_time = 0.05
|
|
|
|
add_child(t)
|
|
|
|
t.start()
|
|
|
|
yield(t, "timeout")
|
|
|
|
|
2020-10-13 18:58:30 +02:00
|
|
|
var amount_cards = get_tree().get_nodes_in_group("cards").size()
|
2020-10-27 19:44:17 +01:00
|
|
|
var total_angle = min(35, 45.0/7*amount_cards)
|
2020-10-13 18:58:30 +02:00
|
|
|
var angle_between_cards = 0
|
|
|
|
if amount_cards > 1:
|
|
|
|
angle_between_cards = total_angle / (amount_cards-1)
|
2020-10-29 15:58:26 +01:00
|
|
|
else:
|
|
|
|
total_angle = 0
|
2020-10-14 00:04:47 +02:00
|
|
|
|
2020-10-13 18:58:30 +02:00
|
|
|
var current_angle = -total_angle/2
|
|
|
|
for card in get_tree().get_nodes_in_group("cards"):
|
2020-10-27 15:48:23 +01:00
|
|
|
var target_position = Vector2(rect_size.x/2, rect_size.y + card_radius)
|
2020-10-14 00:04:47 +02:00
|
|
|
var target_rotation = current_angle
|
2020-10-27 15:48:23 +01:00
|
|
|
var translation_vec = Vector2(0,-card_radius).rotated(current_angle/180.0*PI)
|
2020-10-14 00:04:47 +02:00
|
|
|
target_position += translation_vec
|
2020-10-13 18:58:30 +02:00
|
|
|
current_angle += angle_between_cards
|
2020-10-14 00:04:47 +02:00
|
|
|
card._home_position = target_position
|
2020-10-15 15:02:43 +02:00
|
|
|
card._home_rotation = target_rotation
|
2020-10-14 00:04:47 +02:00
|
|
|
|
|
|
|
var tween = Tween.new()
|
|
|
|
tween.interpolate_property(card, "position", card.position, target_position, 0.5, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
|
|
|
|
tween.interpolate_property(card, "rotation_degrees", card.rotation_degrees, target_rotation, 0.5, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
|
|
|
|
add_child(tween)
|
|
|
|
tween.start()
|
2020-10-13 18:58:30 +02:00
|
|
|
|
2020-10-13 18:13:42 +02:00
|
|
|
func redraw_all_cards():
|
2020-10-15 15:53:23 +02:00
|
|
|
game.energy = 5
|
2020-10-15 16:11:02 +02:00
|
|
|
|
2020-10-13 18:13:42 +02:00
|
|
|
for card in get_tree().get_nodes_in_group("cards"):
|
|
|
|
card.queue_free()
|
2020-10-26 18:56:35 +01:00
|
|
|
|
2020-10-27 11:55:47 +01:00
|
|
|
for card in card_store:
|
|
|
|
draw_card(card_store[card])
|
2020-10-27 12:16:33 +01:00
|
|
|
|
|
|
|
arrange_cards()
|
2020-10-15 16:41:42 +02:00
|
|
|
|
|
|
|
func add_card(command):
|
|
|
|
draw_card({"command": command, "description": "", "arg_number": 0, "energy": 0})
|