oh-my-git/node.gd

70 lines
1.4 KiB
GDScript3
Raw Normal View History

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-01 18:24:21 +03:00
var repository: Node2D
2020-03-18 18:20:55 +03:00
2020-03-18 22:03:17 +03:00
var children = {} setget children_set
2020-03-18 18:20:55 +03:00
var arrow = preload("res://arrow.tscn")
func _ready():
pass
2020-03-18 18:20:55 +03:00
func _process(delta):
for c in children.keys():
if get_node("..").objects.has(c):
var other = get_node("..").objects[c]
var d = other.position.distance_to(position)
var dir = (other.position - position).normalized()
var f = (d*0.05)
position += dir*f
other.position -= dir*f
2020-03-18 18:20:55 +03:00
func id_set(new_id):
id = new_id
$ID.text = id
2020-03-18 18:28:48 +03:00
func content_set(new_content):
content = new_content
$Content.text = content
2020-03-18 18:20:55 +03:00
func type_set(new_type):
type = new_type
if type != "ref":
$ID.text = $ID.text.substr(0,8)
match new_type:
"blob":
$Rect.color = Color.gray
"tree":
$Rect.color = Color.darkgreen
"commit":
$Rect.color = Color.orange
"tag":
$Rect.color = Color.blue
"ref":
$Rect.color = Color("#6680ff")
"head":
$Rect.color = Color.red
2020-03-18 18:20:55 +03:00
func children_set(new_children):
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()
a.label = new_children[c]
a.target = c
2020-09-01 18:24:21 +03:00
a.repository = repository
$Arrows.add_child(a)
children = new_children
2020-03-18 18:28:48 +03:00
func _on_hover():
$Content.visible = true
2020-03-18 18:28:48 +03:00
func _on_unhover():
$Content.visible = false
2020-03-18 18:28:48 +03:00