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