From 38faac548580375634b8ff024b0fb3b7be7e8486 Mon Sep 17 00:00:00 2001 From: blinry Date: Sat, 7 Nov 2020 13:59:47 +0100 Subject: [PATCH] Make drop areas react to collision with "cursor" scene This is a preparation to allow drop areas on GUI elements. --- resources/cards.json | 5 +++++ scenes/card.gd | 11 ++++++++--- scenes/cursor.gd | 4 ++++ scenes/drop_area.gd | 4 ++-- scenes/drop_area.tscn | 9 ++++++--- scenes/file_browser.gd | 10 ++++++++-- scenes/file_browser_item.gd | 1 + scenes/file_browser_item.tscn | 1 + scenes/level.gd | 2 +- scenes/main.tscn | 18 +++++++++++++++++- 10 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 scenes/cursor.gd diff --git a/resources/cards.json b/resources/cards.json index 8eb90c2..fae1d75 100644 --- a/resources/cards.json +++ b/resources/cards.json @@ -63,5 +63,10 @@ "id": "bisect-bad", "command": "git bisect bad", "description": "State that the current commit is bad! When you're automatically transferred, keep playing the `good` and `bad` cards!" + }, + { + "id": "add", + "command": "git add [file]", + "description": "" } ] diff --git a/scenes/card.gd b/scenes/card.gd index d71e08e..26706bd 100644 --- a/scenes/card.gd +++ b/scenes/card.gd @@ -106,9 +106,14 @@ func move_back(): func dropped_on(other): if "[" in command: - var argument = other.id - if (command.begins_with("git checkout") or command.begins_with("git rebase")) and other.id.begins_with("refs/heads"): - argument = Array(other.id.split("/")).pop_back() + var argument + if other.type == "file": + argument = other.label + else: + argument = other.id + + if (command.begins_with("git checkout") or command.begins_with("git rebase")) and argument.begins_with("refs/heads"): + argument = Array(argument.split("/")).pop_back() var arg_regex = RegEx.new() arg_regex.compile("\\[(.*)\\]") diff --git a/scenes/cursor.gd b/scenes/cursor.gd new file mode 100644 index 0000000..7f7f641 --- /dev/null +++ b/scenes/cursor.gd @@ -0,0 +1,4 @@ +extends Node2D + +func _process(delta): + global_position = get_global_mouse_position() diff --git a/scenes/drop_area.gd b/scenes/drop_area.gd index a2cbc84..e90df3a 100644 --- a/scenes/drop_area.gd +++ b/scenes/drop_area.gd @@ -6,10 +6,10 @@ var highlighted = false setget _set_highlighted func _ready(): _set_highlighted(false) -func _mouse_entered(): +func _mouse_entered(_area): hovered = true -func _mouse_exited(): +func _mouse_exited(_area): hovered = false func _input(event): diff --git a/scenes/drop_area.tscn b/scenes/drop_area.tscn index 7d941fb..7b81dee 100644 --- a/scenes/drop_area.tscn +++ b/scenes/drop_area.tscn @@ -10,10 +10,13 @@ radius = 23.5871 "drop_areas", ]] position = Vector2( -0.197731, 0.0673599 ) -z_index = -2 +z_index = 2 script = ExtResource( 1 ) [node name="Area2D" type="Area2D" parent="."] +input_pickable = false +collision_layer = 0 +collision_mask = 524288 [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] shape = SubResource( 1 ) @@ -25,5 +28,5 @@ modulate = Color( 0.847059, 0.788235, 0.996078, 0.533333 ) position = Vector2( 0.177797, -0.65835 ) scale = Vector2( 1.23678, 1.23678 ) texture = ExtResource( 2 ) -[connection signal="mouse_entered" from="Area2D" to="." method="_mouse_entered"] -[connection signal="mouse_exited" from="Area2D" to="." method="_mouse_exited"] +[connection signal="area_entered" from="Area2D" to="." method="_mouse_entered"] +[connection signal="area_exited" from="Area2D" to="." method="_mouse_exited"] diff --git a/scenes/file_browser.gd b/scenes/file_browser.gd index 2b3f5b0..75aa247 100644 --- a/scenes/file_browser.gd +++ b/scenes/file_browser.gd @@ -46,12 +46,12 @@ func update(): # The last entry is an empty string, remove it. files.pop_back() files.sort_custom(self, "very_best_sort") - visible = false + var is_visible = false for file_path in files: file_path = file_path.substr(2) if file_path.substr(0, 5) == ".git/": continue - visible = true + is_visible = true var item = preload("res://scenes/file_browser_item.tscn").instance() item.label = file_path item.connect("clicked", self, "item_clicked") @@ -59,6 +59,8 @@ func update(): item.status = get_file_status(file_path, shell, 1) grid.add_child(item) + visible = is_visible + FileBrowserMode.COMMIT: if commit: var files = Array(commit.repository.shell.run("git ls-tree --name-only -r %s" % commit.id).split("\n")) @@ -70,6 +72,7 @@ func update(): item.connect("clicked", self, "item_clicked") grid.add_child(item) FileBrowserMode.INDEX: + var is_visible = false if repository and repository.there_is_a_git(): var files = Array(repository.shell.run("git ls-files -s | cut -f2 | uniq").split("\n")) # The last entry is an empty string, remove it. @@ -80,6 +83,9 @@ func update(): item.connect("clicked", self, "item_clicked") item.status = get_file_status(file_path, repository.shell, 0) grid.add_child(item) + if item.status != item.IconStatus.NONE: + is_visible = true + visible = is_visible func get_file_status(file_path, shell, idx): var file_status = shell.run("git status -s '%s'" % file_path) diff --git a/scenes/file_browser_item.gd b/scenes/file_browser_item.gd index aeb2fc8..4a2bea6 100644 --- a/scenes/file_browser_item.gd +++ b/scenes/file_browser_item.gd @@ -6,6 +6,7 @@ signal clicked(what) enum IconStatus {NONE, NEW, REMOVED, CONFLICT, EDIT, UNTRACKED} export(IconStatus) var status setget _set_status export var label: String setget _set_label +var type = "file" onready var label_node = $VBoxContainer/Label onready var status_icon = $VBoxContainer/Control/TextureRect/StatusIcon diff --git a/scenes/file_browser_item.tscn b/scenes/file_browser_item.tscn index 4a61ba1..9272cad 100644 --- a/scenes/file_browser_item.tscn +++ b/scenes/file_browser_item.tscn @@ -10,6 +10,7 @@ anchor_bottom = 0.126 margin_right = 0.319992 margin_bottom = -0.0800018 rect_min_size = Vector2( 175, 150 ) +mouse_filter = 1 script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": false diff --git a/scenes/level.gd b/scenes/level.gd index 07eb91e..0a74800 100644 --- a/scenes/level.gd +++ b/scenes/level.gd @@ -21,7 +21,7 @@ func load(path): title = config.get("title", slug) description = config.get("description", "(no description)") congrats = config.get("congrats", "Good job, you solved the level!\n\nFeel free to try a few more things or click 'Next level'.") - cards = Array(config.get("cards", "checkout commit-auto merge rebase rebase-interactive reset-hard cherry-pick").split(" ")) + cards = Array(config.get("cards", "checkout commit-auto merge rebase rebase-interactive reset-hard cherry-pick add").split(" ")) var keys = config.keys() var repo_setups = [] diff --git a/scenes/main.tscn b/scenes/main.tscn index e4f36bd..a771d29 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=2] +[gd_scene load_steps=12 format=2] [ext_resource path="res://scenes/terminal.tscn" type="PackedScene" id=1] [ext_resource path="res://scenes/main.gd" type="Script" id=2] @@ -8,6 +8,7 @@ [ext_resource path="res://styles/theme.tres" type="Theme" id=6] [ext_resource path="res://fonts/big.tres" type="DynamicFont" id=7] [ext_resource path="res://sounds/success.wav" type="AudioStream" id=8] +[ext_resource path="res://scenes/cursor.gd" type="Script" id=9] [sub_resource type="StyleBoxFlat" id=1] content_margin_left = 10.0 @@ -20,6 +21,9 @@ corner_radius_top_right = 3 corner_radius_bottom_right = 3 corner_radius_bottom_left = 3 +[sub_resource type="CircleShape2D" id=2] +radius = 1.0 + [node name="Main" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 @@ -235,6 +239,18 @@ size_flags_vertical = 3 [node name="SuccessSound" type="AudioStreamPlayer" parent="."] stream = ExtResource( 8 ) volume_db = -10.0 + +[node name="Cursor" type="Node2D" parent="."] +position = Vector2( 68.6342, 59.1206 ) +script = ExtResource( 9 ) + +[node name="Area2D" type="Area2D" parent="Cursor"] +input_pickable = false +collision_layer = 524288 +collision_mask = 0 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Cursor/Area2D"] +shape = SubResource( 2 ) [connection signal="button_down" from="Rows/Columns/RightSide/LevelInfo/Menu/ChapterSelect" to="." method="repopulate_chapters"] [connection signal="button_down" from="Rows/Columns/RightSide/LevelInfo/Menu/LevelSelect" to="." method="repopulate_levels"] [connection signal="pressed" from="Rows/Columns/RightSide/LevelInfo/Menu/ReloadButton" to="." method="reload_level"]