Specify valid targets in cards' command, highlight them when dragged

This commit is contained in:
blinry 2020-11-03 12:39:40 +01:00
parent fe0262cc30
commit 977a085940
5 changed files with 62 additions and 40 deletions

View file

@ -2,79 +2,66 @@
{ {
"id": "init", "id": "init",
"command": "git init", "command": "git init",
"arg_number": 0,
"description": "Initialize the time machine!" "description": "Initialize the time machine!"
}, },
{ {
"id": "checkout", "id": "checkout",
"command": "git checkout", "command": "git checkout [commit, ref]",
"arg_number": 1,
"description": "Drag this card to a commit or to a branch to travel to it!" "description": "Drag this card to a commit or to a branch to travel to it!"
}, },
{ {
"id": "commit-auto", "id": "commit-auto",
"command": "git add .; git commit", "command": "git add .; git commit",
"arg_number": 0,
"description": "Make a new commit containing your current environment!\nDrag this card anywhere. You'll be asked to enter a short description of what you changed." "description": "Make a new commit containing your current environment!\nDrag this card anywhere. You'll be asked to enter a short description of what you changed."
}, },
{ {
"id": "merge", "id": "merge",
"command": "git merge", "command": "git merge [commit]",
"arg_number": 1,
"description": "Merge the specified timeline into yours. If necessary, will create a merge commit." "description": "Merge the specified timeline into yours. If necessary, will create a merge commit."
}, },
{ {
"id": "rebase", "id": "rebase",
"command": "git rebase", "command": "git rebase [commit]",
"arg_number": 1,
"description": "Put the events in your current timeline on top of the specified one." "description": "Put the events in your current timeline on top of the specified one."
}, },
{ {
"id": "pull", "id": "pull",
"command": "git pull", "command": "git pull",
"arg_number": 0,
"description": "Get timelines from a colleague." "description": "Get timelines from a colleague."
}, },
{ {
"id": "push", "id": "push",
"command": "git push", "command": "git push",
"arg_number": 0,
"description": "Give timelines to a colleague." "description": "Give timelines to a colleague."
}, },
{ {
"id": "rebase-interactive", "id": "rebase-interactive",
"command": "git rebase -i", "command": "git rebase -i [commit]",
"arg_number": 1,
"description": "Make changes to the events in your current timeline, back to the commit you drag this to." "description": "Make changes to the events in your current timeline, back to the commit you drag this to."
}, },
{ {
"id": "reset-hard", "id": "reset-hard",
"command": "git reset --hard", "command": "git reset --hard [commit]",
"arg_number": 1,
"description": "Move the branch you're on to the specified commit." "description": "Move the branch you're on to the specified commit."
}, },
{ {
"id": "cherry-pick", "id": "cherry-pick",
"command": "git cherry-pick", "command": "git cherry-pick [commit]",
"arg_number": 1,
"description": "Repeat the specified action on top of your current timeline." "description": "Repeat the specified action on top of your current timeline."
}, },
{ {
"id": "bisect-start", "id": "bisect-start",
"command": "git bisect start", "command": "git bisect start",
"arg_number": 0,
"description": "Start looking for the commit where things got bad." "description": "Start looking for the commit where things got bad."
}, },
{ {
"id": "bisect-good", "id": "bisect-good",
"command": "git bisect good", "command": "git bisect good",
"arg_number": 0,
"description": "State that the current commit is good! When you're automatically transferred, keep playing the `good` and `bad` cards!" "description": "State that the current commit is good! When you're automatically transferred, keep playing the `good` and `bad` cards!"
}, },
{ {
"id": "bisect-bad", "id": "bisect-bad",
"command": "git bisect bad", "command": "git bisect bad",
"arg_number": 0,
"description": "State that the current commit is bad! When you're automatically transferred, keep playing the `good` and `bad` cards!" "description": "State that the current commit is bad! When you're automatically transferred, keep playing the `good` and `bad` cards!"
} }
] ]

View file

@ -4,7 +4,6 @@ var hovered = false
var dragged = false var dragged = false
var drag_offset var drag_offset
export var arg_number = 0
export var id = "" setget set_id export var id = "" setget set_id
export var command = "" setget set_command export var command = "" setget set_command
export var description = "" setget set_description export var description = "" setget set_description
@ -43,6 +42,7 @@ func _unhandled_input(event):
if event.button_index == BUTTON_LEFT and event.pressed and hovered: if event.button_index == BUTTON_LEFT and event.pressed and hovered:
dragged = true dragged = true
game.dragged_object = self game.dragged_object = self
_turn_on_highlights()
$PickupSound.play() $PickupSound.play()
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()
@ -50,16 +50,32 @@ func _unhandled_input(event):
elif event.button_index == BUTTON_LEFT and !event.pressed and dragged: elif event.button_index == BUTTON_LEFT and !event.pressed and dragged:
dragged = false dragged = false
game.dragged_object = null game.dragged_object = null
_turn_off_highlights()
modulate.a = 1 modulate.a = 1
if get_viewport().get_mouse_position().y < get_viewport().size.y/3*2: if get_viewport().get_mouse_position().y < get_viewport().size.y/3*2:
if arg_number == 0 : # if arg_number == 0 :
try_play($Label.text) # try_play($Label.text)
else: # else:
move_back() # move_back()
pass
else: else:
move_back() move_back()
func _turn_on_highlights():
var arg_regex = RegEx.new()
arg_regex.compile("\\[(.*)\\]")
var m = arg_regex.search(command)
if m:
var types = Array(m.get_string(1).split(","))
for type in types:
for area in get_tree().get_nodes_in_group("drop_areas"):
area.highlight(type.strip_edges())
func _turn_off_highlights():
for area in get_tree().get_nodes_in_group("drop_areas"):
area.highlighted = false
func _mouse_entered(): func _mouse_entered():
hovered = true hovered = true
z_index = 1 z_index = 1
@ -91,24 +107,21 @@ func move_back():
position = _home_position position = _home_position
rotation_degrees = _home_rotation rotation_degrees = _home_rotation
$ReturnSound.play() $ReturnSound.play()
func buuurn():
move_back()
func dropped_on(other): func dropped_on(other):
var full_command = "" var full_command = ""
match arg_number: # match arg_number:
1: # 1:
var argument = other.id # var argument = other.id
if ($Label.text.begins_with("git checkout") or $Label.text.begins_with("git rebase")) and other.id.begins_with("refs/heads"): # if ($Label.text.begins_with("git checkout") or $Label.text.begins_with("git rebase")) and other.id.begins_with("refs/heads"):
argument = Array(other.id.split("/")).pop_back() # argument = Array(other.id.split("/")).pop_back()
full_command = $Label.text + " " + argument # full_command = $Label.text + " " + argument
try_play(full_command) # try_play(full_command)
# 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() # move_back()
# else: # else:
# _first_argument = other.id # _first_argument = other.id
@ -121,7 +134,7 @@ func try_play(full_command):
var particles = preload("res://scenes/card_particles.tscn").instance() var particles = preload("res://scenes/card_particles.tscn").instance()
particles.position = position particles.position = position
get_parent().add_child(particles) get_parent().add_child(particles)
buuurn() move_back()
game.energy -= energy game.energy -= energy
else: else:
move_back() move_back()

View file

@ -38,7 +38,6 @@ func draw_card(card):
new_card.id = card["id"] new_card.id = card["id"]
new_card.command = card["command"] new_card.command = card["command"]
new_card.arg_number = int(card["arg_number"])
new_card.description = card["description"] new_card.description = card["description"]
new_card.energy = 0 #card.energy new_card.energy = 0 #card.energy
new_card.position = Vector2(rect_size.x, rect_size.y*2) new_card.position = Vector2(rect_size.x, rect_size.y*2)

View file

@ -1,6 +1,7 @@
extends Node2D extends Node2D
var hovered = false var hovered = false
var highlighted = false setget _set_highlighted
func _ready(): func _ready():
pass pass
@ -16,3 +17,14 @@ func _input(event):
if event.button_index == BUTTON_LEFT and !event.pressed and hovered: if event.button_index == BUTTON_LEFT and !event.pressed and hovered:
if game.dragged_object: if game.dragged_object:
game.dragged_object.dropped_on($"..") game.dragged_object.dropped_on($"..")
func _set_highlighted(new_highlighted):
highlighted = new_highlighted
$Highlight.visible = highlighted
func highlight(type):
print("highlight:")
print(type)
print(get_parent().type)
if get_parent().type == type:
_set_highlighted(true)

View file

@ -1,12 +1,14 @@
[gd_scene load_steps=3 format=2] [gd_scene load_steps=4 format=2]
[ext_resource path="res://scenes/drop_area.gd" type="Script" id=1] [ext_resource path="res://scenes/drop_area.gd" type="Script" id=1]
[ext_resource path="res://nodes/blob.svg" type="Texture" id=2]
[sub_resource type="CircleShape2D" id=1] [sub_resource type="CircleShape2D" id=1]
radius = 23.5871 radius = 23.5871
[node name="DropArea" type="Node2D"] [node name="DropArea" type="Node2D" groups=[
"drop_areas",
]]
position = Vector2( -0.197731, 0.0673599 ) position = Vector2( -0.197731, 0.0673599 )
script = ExtResource( 1 ) script = ExtResource( 1 )
@ -14,5 +16,14 @@ script = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource( 1 ) shape = SubResource( 1 )
[node name="Highlight" type="Node2D" parent="."]
visible = false
[node name="Sprite" type="Sprite" parent="Highlight"]
modulate = Color( 0.65098, 0.560784, 0.890196, 0.533333 )
position = Vector2( -0.302719, 0.302704 )
scale = Vector2( 1.64865, 1.64865 )
texture = ExtResource( 2 )
[connection signal="mouse_entered" from="Area2D" to="." method="_mouse_entered"] [connection signal="mouse_entered" from="Area2D" to="." method="_mouse_entered"]
[connection signal="mouse_exited" from="Area2D" to="." method="_mouse_exited"] [connection signal="mouse_exited" from="Area2D" to="." method="_mouse_exited"]