2020-03-18 18:20:55 +03:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
var id setget id_set
|
2020-03-18 18:28:48 +03:00
|
|
|
var content setget content_set
|
2020-03-18 18:20:55 +03:00
|
|
|
var type setget type_set
|
2020-09-21 21:28:43 +03:00
|
|
|
var repository: Control
|
2020-03-18 18:20:55 +03:00
|
|
|
|
2020-10-22 15:56:10 +03:00
|
|
|
onready var content_label = $Content/ContentLabel
|
2020-10-23 17:52:03 +03:00
|
|
|
onready var file_browser = $OnTop/FileBrowser
|
2020-10-22 15:56:10 +03:00
|
|
|
|
2020-03-18 22:03:17 +03:00
|
|
|
var children = {} setget children_set
|
2020-09-01 22:25:24 +03:00
|
|
|
var id_always_visible = false
|
2020-09-04 16:10:04 +03:00
|
|
|
var held = false
|
2020-09-21 19:53:36 +03:00
|
|
|
var hovered = false
|
2020-10-27 14:02:20 +03:00
|
|
|
var start_pos = null
|
2020-03-18 18:20:55 +03:00
|
|
|
|
2020-10-26 21:15:47 +03:00
|
|
|
var arrow = preload("res://scenes/arrow.tscn")
|
2020-10-27 14:58:38 +03:00
|
|
|
var time_arrow = preload("res://scenes/time_arrow.tscn")
|
2020-03-18 18:20:55 +03:00
|
|
|
|
|
|
|
func _ready():
|
2020-10-22 15:56:10 +03:00
|
|
|
content_set(content)
|
2020-10-23 17:52:03 +03:00
|
|
|
type_set(type)
|
2020-10-27 13:38:04 +03:00
|
|
|
if not repository.simplified_view:
|
|
|
|
$Pop.pitch_scale = rand_range(0.8, 1.2)
|
|
|
|
$Pop.play()
|
2020-03-18 18:20:55 +03:00
|
|
|
|
2020-09-08 21:26:14 +03:00
|
|
|
func _process(_delta):
|
2020-09-04 16:10:04 +03:00
|
|
|
if held:
|
2020-09-21 19:33:34 +03:00
|
|
|
if not Input.is_action_pressed("click"):
|
|
|
|
held = false
|
|
|
|
else:
|
|
|
|
global_position = get_global_mouse_position()
|
2020-09-14 17:03:01 +03:00
|
|
|
|
|
|
|
if visible:
|
|
|
|
apply_forces()
|
|
|
|
|
|
|
|
func apply_forces():
|
2020-10-27 18:10:02 +03:00
|
|
|
var offset = Vector2(-80, 0)
|
2020-09-14 17:03:01 +03:00
|
|
|
|
2020-08-24 17:48:30 +03:00
|
|
|
for c in children.keys():
|
2020-10-27 18:10:02 +03:00
|
|
|
if type == "ref" or type == "head":
|
|
|
|
offset = Vector2(0, 80)
|
2020-09-15 19:41:06 +03:00
|
|
|
if repository.objects.has(c):
|
|
|
|
var other = repository.objects[c]
|
2020-09-14 17:03:01 +03:00
|
|
|
if other.visible:
|
|
|
|
var d = other.position.distance_to(position+offset)
|
|
|
|
var dir = (other.position - (position+offset)).normalized()
|
2020-10-27 18:10:02 +03:00
|
|
|
var f = (d*0.12)
|
2020-09-14 17:03:01 +03:00
|
|
|
position += dir*f
|
|
|
|
other.position -= dir*f
|
2020-08-24 17:48:30 +03:00
|
|
|
|
2020-03-18 18:20:55 +03:00
|
|
|
func id_set(new_id):
|
2020-08-24 17:48:30 +03:00
|
|
|
id = new_id
|
|
|
|
$ID.text = id
|
|
|
|
|
2020-03-18 18:28:48 +03:00
|
|
|
func content_set(new_content):
|
2020-08-24 17:48:30 +03:00
|
|
|
content = new_content
|
2020-10-22 15:56:10 +03:00
|
|
|
if content_label:
|
|
|
|
content_label.text = content
|
2020-03-18 18:20:55 +03:00
|
|
|
|
|
|
|
func type_set(new_type):
|
2020-08-24 17:48:30 +03:00
|
|
|
type = new_type
|
2020-10-23 17:52:03 +03:00
|
|
|
if type == "commit" and file_browser:
|
|
|
|
file_browser.commit = self
|
|
|
|
file_browser.title = "Commit"
|
2020-08-24 17:48:30 +03:00
|
|
|
if type != "ref":
|
|
|
|
$ID.text = $ID.text.substr(0,8)
|
|
|
|
match new_type:
|
|
|
|
"blob":
|
2020-09-21 20:59:36 +03:00
|
|
|
$Sprite.texture = preload("res://nodes/blob.svg")
|
2020-08-24 17:48:30 +03:00
|
|
|
"tree":
|
2020-09-21 20:59:36 +03:00
|
|
|
$Sprite.texture = preload("res://nodes/tree.svg")
|
2020-08-24 17:48:30 +03:00
|
|
|
"commit":
|
2020-09-21 20:59:36 +03:00
|
|
|
$Sprite.texture = preload("res://nodes/commit.svg")
|
2020-08-24 17:48:30 +03:00
|
|
|
"tag":
|
2020-09-21 20:59:36 +03:00
|
|
|
$Sprite.texture = preload("res://nodes/blob.svg")
|
2020-08-24 17:48:30 +03:00
|
|
|
"ref":
|
2020-09-21 20:59:36 +03:00
|
|
|
$Sprite.texture = preload("res://nodes/ref.svg")
|
2020-09-01 22:25:24 +03:00
|
|
|
id_always_visible = true
|
2020-08-24 17:48:30 +03:00
|
|
|
"head":
|
2020-10-27 15:11:15 +03:00
|
|
|
$Sprite.texture = preload("res://nodes/head.svg")
|
|
|
|
id_always_visible = false
|
2020-09-01 22:25:24 +03:00
|
|
|
if id_always_visible:
|
|
|
|
$ID.show()
|
2020-03-18 18:20:55 +03:00
|
|
|
|
|
|
|
func children_set(new_children):
|
2020-08-24 17:48:30 +03:00
|
|
|
for c in $Arrows.get_children():
|
|
|
|
if not new_children.has(c.target):
|
|
|
|
c.queue_free()
|
|
|
|
for c in new_children:
|
|
|
|
if not children.has(c):
|
|
|
|
var a = arrow.instance()
|
2020-10-27 14:58:38 +03:00
|
|
|
if type == "commit":
|
|
|
|
a = time_arrow.instance()
|
2020-09-22 21:25:45 +03:00
|
|
|
a.source = id
|
2020-08-24 17:48:30 +03:00
|
|
|
a.target = c
|
2020-09-01 18:24:21 +03:00
|
|
|
a.repository = repository
|
2020-08-24 17:48:30 +03:00
|
|
|
$Arrows.add_child(a)
|
|
|
|
children = new_children
|
2020-03-18 18:28:48 +03:00
|
|
|
|
|
|
|
func _on_hover():
|
2020-09-21 19:53:36 +03:00
|
|
|
hovered = true
|
2020-09-21 20:28:39 +03:00
|
|
|
if not id_always_visible:
|
2020-10-22 15:56:10 +03:00
|
|
|
content_label.visible = true
|
2020-10-27 13:40:44 +03:00
|
|
|
#$ID.visible = true
|
2020-08-24 17:48:30 +03:00
|
|
|
|
2020-03-18 18:28:48 +03:00
|
|
|
func _on_unhover():
|
2020-09-21 19:53:36 +03:00
|
|
|
hovered = false
|
2020-09-01 22:25:24 +03:00
|
|
|
if not id_always_visible:
|
2020-10-22 15:56:10 +03:00
|
|
|
content_label.visible = false
|
2020-09-01 22:25:24 +03:00
|
|
|
$ID.visible = false
|
2020-09-21 19:53:36 +03:00
|
|
|
|
|
|
|
func _input(event):
|
|
|
|
if hovered:
|
|
|
|
if event.is_action_pressed("click"):
|
2020-10-27 14:02:20 +03:00
|
|
|
start_pos = get_viewport().get_mouse_position()
|
2020-09-21 19:53:36 +03:00
|
|
|
held = true
|
2020-09-21 21:28:43 +03:00
|
|
|
elif event.is_action_pressed("right_click"):
|
2020-09-27 22:50:14 +03:00
|
|
|
var input = get_tree().get_current_scene().find_node("Input")
|
2020-09-21 21:28:43 +03:00
|
|
|
input.text += id
|
|
|
|
input.caret_position = input.text.length()
|
2020-09-21 19:53:36 +03:00
|
|
|
if event.is_action_released("click"):
|
|
|
|
held = false
|
2020-10-27 14:02:20 +03:00
|
|
|
if type == "commit":
|
|
|
|
if start_pos:
|
|
|
|
var dist = get_viewport().get_mouse_position() - start_pos
|
|
|
|
print(dist.length())
|
|
|
|
if dist.length() < 3:
|
2020-10-27 14:15:45 +03:00
|
|
|
var state = file_browser.visible
|
|
|
|
repository.close_all_file_browsers()
|
|
|
|
file_browser.visible = not state
|
2020-10-27 14:02:20 +03:00
|
|
|
|
|
|
|
start_pos = null
|