Automatically draw new cards

This commit is contained in:
bleeptrack 2020-10-13 17:29:24 +02:00
parent 92c6dce691
commit 0d5c78d2a4
2 changed files with 27 additions and 12 deletions

18
card.gd
View file

@ -30,10 +30,16 @@ func _unhandled_input(event):
dragged = false dragged = false
game.dragged_object = null game.dragged_object = null
modulate.a = 1 modulate.a = 1
move_back()
if arg_number == 0 and get_viewport().get_mouse_position().y < get_viewport().size.y/2 :
$"../Terminal".send_command($Label.text) if get_viewport().get_mouse_position().y < get_viewport().size.y/2:
if arg_number == 0 :
$"../Terminal".send_command($Label.text)
buuurn()
else:
move_back()
else:
_home_position = get_viewport().get_mouse_position() + drag_offset
func _mouse_entered(): func _mouse_entered():
hovered = true hovered = true
@ -48,6 +54,10 @@ func set_command(new_command):
func move_back(): func move_back():
position = _home_position position = _home_position
func buuurn():
queue_free()
$"..".draw_rand_card()
func dropped_on(other): func dropped_on(other):
#print("I have been dropped on "+str(other.id)) #print("I have been dropped on "+str(other.id))
var full_command = "" var full_command = ""
@ -55,10 +65,12 @@ func dropped_on(other):
1: 1:
full_command = $Label.text + " " + other.id full_command = $Label.text + " " + other.id
$"../Terminal".send_command(full_command) $"../Terminal".send_command(full_command)
buuurn()
2: 2:
if _first_argument: if _first_argument:
full_command = $Label.text + " " + _first_argument + " " + other.id full_command = $Label.text + " " + _first_argument + " " + other.id
$"../Terminal".send_command(full_command) $"../Terminal".send_command(full_command)
buuurn()
else: else:
_first_argument = other.id _first_argument = other.id

View file

@ -24,14 +24,17 @@ func _ready():
$Terminal.repository = $Repository $Terminal.repository = $Repository
var pos_x = 100 for i in range(4):
for card in cards: draw_rand_card()
var new_card = preload("res://card.tscn").instance()
new_card.command = card.command
new_card.arg_number = card.arg_number
new_card.position = Vector2(pos_x, get_viewport().size.y*3/4)
pos_x += 250
add_child(new_card)
func _update_repo(): func _update_repo():
$Repository.update_everything() $Repository.update_everything()
func draw_rand_card():
var new_card = preload("res://card.tscn").instance()
var card = cards[randi() % cards.size()]
new_card.command = card.command
new_card.arg_number = card.arg_number
new_card.position = Vector2(rand_range(200, get_viewport().size.x - 200), get_viewport().size.y*3/4 + rand_range(-200,200))
add_child(new_card)