Dynamic Card Generation

This commit is contained in:
bleeptrack 2020-10-13 17:08:37 +02:00
parent 36759f2909
commit 92c6dce691
3 changed files with 65 additions and 6 deletions

39
card.gd
View file

@ -3,9 +3,15 @@ extends Node2D
var hovered = false var hovered = false
var dragged = false var dragged = false
var drag_offset var drag_offset
export var arg_number = 0
export var command = "" setget set_command
var _first_argument = null
var _home_position = null
func _ready(): func _ready():
set_process_unhandled_input(true) set_process_unhandled_input(true)
_home_position = position
func _process(delta): func _process(delta):
if dragged: if dragged:
@ -20,11 +26,14 @@ func _unhandled_input(event):
drag_offset = get_viewport().get_mouse_position() - global_position drag_offset = get_viewport().get_mouse_position() - global_position
get_tree().set_input_as_handled() get_tree().set_input_as_handled()
modulate.a = 0.5 modulate.a = 0.5
elif event.button_index == BUTTON_LEFT and !event.pressed: elif event.button_index == BUTTON_LEFT and !event.pressed and dragged:
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)
func _mouse_entered(): func _mouse_entered():
hovered = true hovered = true
@ -32,9 +41,29 @@ func _mouse_entered():
func _mouse_exited(): func _mouse_exited():
hovered = false hovered = false
func set_command(new_command):
command = new_command
$Label.text = self.command
func move_back():
position = _home_position
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))
print("Running " + $Label.text + " " + other.id) var full_command = ""
var command = $Label.text + " " + other.id match arg_number:
$"../Terminal".send_command(command) 1:
queue_free() full_command = $Label.text + " " + other.id
$"../Terminal".send_command(full_command)
2:
if _first_argument:
full_command = $Label.text + " " + _first_argument + " " + other.id
$"../Terminal".send_command(full_command)
else:
_first_argument = other.id

View file

@ -1,5 +1,14 @@
extends Node2D extends Node2D
var cards = [
{"command": 'git add .', "arg_number": 0},
{"command": 'git checkout', "arg_number": 1},
{"command": 'touch "file$RANDOM"', "arg_number": 0},
{"command": 'git commit --allow-empty -m "$RANDOM"', "arg_number": 0},
{"command": 'git checkout -b "$RANDOM"', "arg_number": 0},
{"command": 'git merge', "arg_number": 1}
]
func _ready(): func _ready():
var path = game.tmp_prefix_inside+"/repos/sandbox/" var path = game.tmp_prefix_inside+"/repos/sandbox/"
@ -15,5 +24,14 @@ func _ready():
$Terminal.repository = $Repository $Terminal.repository = $Repository
var pos_x = 100
for card in cards:
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()

View file

@ -16,13 +16,25 @@ margin_bottom = 592.0
[node name="DropArea" parent="." instance=ExtResource( 2 )] [node name="DropArea" parent="." instance=ExtResource( 2 )]
[node name="Card2" parent="." instance=ExtResource( 1 )] [node name="Card2" parent="." instance=ExtResource( 1 )]
visible = false
position = Vector2( 948.833, 814.382 ) position = Vector2( 948.833, 814.382 )
command = "git commit --allow-empty -m \"$RANDOM\""
[node name="Card4" parent="." instance=ExtResource( 1 )]
visible = false
position = Vector2( 1651.83, 834.382 )
command = "touch \"file$RANDOM\""
[node name="Card3" parent="." instance=ExtResource( 1 )] [node name="Card3" parent="." instance=ExtResource( 1 )]
visible = false
position = Vector2( 1348, 830.017 ) position = Vector2( 1348, 830.017 )
command = "git add ."
[node name="Card" parent="." instance=ExtResource( 1 )] [node name="Card" parent="." instance=ExtResource( 1 )]
visible = false
position = Vector2( 558.857, 824.539 ) position = Vector2( 558.857, 824.539 )
arg_number = 1
command = "git checkout"
[node name="Terminal" parent="." instance=ExtResource( 5 )] [node name="Terminal" parent="." instance=ExtResource( 5 )]
margin_left = 1488.0 margin_left = 1488.0