From 92c6dce691d9ca12d6ee0275df87b652315a822f Mon Sep 17 00:00:00 2001 From: bleeptrack Date: Tue, 13 Oct 2020 17:08:37 +0200 Subject: [PATCH] Dynamic Card Generation --- card.gd | 41 +++++++++++++++++++++++++++++++++++------ cardgame.gd | 18 ++++++++++++++++++ cardgame.tscn | 12 ++++++++++++ 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/card.gd b/card.gd index 04e805b..556c0e6 100644 --- a/card.gd +++ b/card.gd @@ -3,9 +3,15 @@ extends Node2D var hovered = false var dragged = false var drag_offset +export var arg_number = 0 +export var command = "" setget set_command +var _first_argument = null +var _home_position = null + func _ready(): set_process_unhandled_input(true) + _home_position = position func _process(delta): if dragged: @@ -20,21 +26,44 @@ func _unhandled_input(event): drag_offset = get_viewport().get_mouse_position() - global_position get_tree().set_input_as_handled() 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 game.dragged_object = null 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(): hovered = true func _mouse_exited(): hovered = false + +func set_command(new_command): + command = new_command + $Label.text = self.command + +func move_back(): + position = _home_position func dropped_on(other): #print("I have been dropped on "+str(other.id)) - print("Running " + $Label.text + " " + other.id) - var command = $Label.text + " " + other.id - $"../Terminal".send_command(command) - queue_free() + var full_command = "" + match arg_number: + 1: + 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 + + + + + + diff --git a/cardgame.gd b/cardgame.gd index 8e48ade..8237c0f 100644 --- a/cardgame.gd +++ b/cardgame.gd @@ -1,5 +1,14 @@ 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(): var path = game.tmp_prefix_inside+"/repos/sandbox/" @@ -14,6 +23,15 @@ func _ready(): $Repository.path = path $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(): $Repository.update_everything() diff --git a/cardgame.tscn b/cardgame.tscn index 69589b9..a1fcc59 100644 --- a/cardgame.tscn +++ b/cardgame.tscn @@ -16,13 +16,25 @@ margin_bottom = 592.0 [node name="DropArea" parent="." instance=ExtResource( 2 )] [node name="Card2" parent="." instance=ExtResource( 1 )] +visible = false 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 )] +visible = false position = Vector2( 1348, 830.017 ) +command = "git add ." [node name="Card" parent="." instance=ExtResource( 1 )] +visible = false position = Vector2( 558.857, 824.539 ) +arg_number = 1 +command = "git checkout" [node name="Terminal" parent="." instance=ExtResource( 5 )] margin_left = 1488.0