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",
"command": "git init",
"arg_number": 0,
"description": "Initialize the time machine!"
},
{
"id": "checkout",
"command": "git checkout",
"arg_number": 1,
"command": "git checkout [commit, ref]",
"description": "Drag this card to a commit or to a branch to travel to it!"
},
{
"id": "commit-auto",
"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."
},
{
"id": "merge",
"command": "git merge",
"arg_number": 1,
"command": "git merge [commit]",
"description": "Merge the specified timeline into yours. If necessary, will create a merge commit."
},
{
"id": "rebase",
"command": "git rebase",
"arg_number": 1,
"command": "git rebase [commit]",
"description": "Put the events in your current timeline on top of the specified one."
},
{
"id": "pull",
"command": "git pull",
"arg_number": 0,
"description": "Get timelines from a colleague."
},
{
"id": "push",
"command": "git push",
"arg_number": 0,
"description": "Give timelines to a colleague."
},
{
"id": "rebase-interactive",
"command": "git rebase -i",
"arg_number": 1,
"command": "git rebase -i [commit]",
"description": "Make changes to the events in your current timeline, back to the commit you drag this to."
},
{
"id": "reset-hard",
"command": "git reset --hard",
"arg_number": 1,
"command": "git reset --hard [commit]",
"description": "Move the branch you're on to the specified commit."
},
{
"id": "cherry-pick",
"command": "git cherry-pick",
"arg_number": 1,
"command": "git cherry-pick [commit]",
"description": "Repeat the specified action on top of your current timeline."
},
{
"id": "bisect-start",
"command": "git bisect start",
"arg_number": 0,
"description": "Start looking for the commit where things got bad."
},
{
"id": "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!"
},
{
"id": "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!"
}
]

View file

@ -4,7 +4,6 @@ var hovered = false
var dragged = false
var drag_offset
export var arg_number = 0
export var id = "" setget set_id
export var command = "" setget set_command
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:
dragged = true
game.dragged_object = self
_turn_on_highlights()
$PickupSound.play()
drag_offset = get_viewport().get_mouse_position() - global_position
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:
dragged = false
game.dragged_object = null
_turn_off_highlights()
modulate.a = 1
if get_viewport().get_mouse_position().y < get_viewport().size.y/3*2:
if arg_number == 0 :
try_play($Label.text)
else:
move_back()
# if arg_number == 0 :
# try_play($Label.text)
# else:
# move_back()
pass
else:
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():
hovered = true
z_index = 1
@ -92,23 +108,20 @@ func move_back():
rotation_degrees = _home_rotation
$ReturnSound.play()
func buuurn():
move_back()
func dropped_on(other):
var full_command = ""
match arg_number:
1:
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"):
argument = Array(other.id.split("/")).pop_back()
full_command = $Label.text + " " + argument
try_play(full_command)
# match arg_number:
# 1:
# 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"):
# argument = Array(other.id.split("/")).pop_back()
# full_command = $Label.text + " " + argument
# try_play(full_command)
# 2:
# if _first_argument:
# full_command = $Label.text + " " + _first_argument + " " + other.id
# $"../Terminal".send_command(full_command)
# buuurn()
# move_back()
# else:
# _first_argument = other.id
@ -121,7 +134,7 @@ func try_play(full_command):
var particles = preload("res://scenes/card_particles.tscn").instance()
particles.position = position
get_parent().add_child(particles)
buuurn()
move_back()
game.energy -= energy
else:
move_back()

View file

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

View file

@ -1,6 +1,7 @@
extends Node2D
var hovered = false
var highlighted = false setget _set_highlighted
func _ready():
pass
@ -16,3 +17,14 @@ func _input(event):
if event.button_index == BUTTON_LEFT and !event.pressed and hovered:
if game.dragged_object:
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://nodes/blob.svg" type="Texture" id=2]
[sub_resource type="CircleShape2D" id=1]
radius = 23.5871
[node name="DropArea" type="Node2D"]
[node name="DropArea" type="Node2D" groups=[
"drop_areas",
]]
position = Vector2( -0.197731, 0.0673599 )
script = ExtResource( 1 )
@ -14,5 +16,14 @@ script = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
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_exited" from="Area2D" to="." method="_mouse_exited"]