mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-24 16:20:08 +01:00
Dynamic Card Generation
This commit is contained in:
parent
36759f2909
commit
92c6dce691
3 changed files with 65 additions and 6 deletions
41
card.gd
41
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
18
cardgame.gd
18
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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue