mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-22 16:20:19 +01:00
100 lines
2.2 KiB
GDScript
100 lines
2.2 KiB
GDScript
extends Node2D
|
|
|
|
var id setget id_set
|
|
var content setget content_set
|
|
var type setget type_set
|
|
var repository: Container
|
|
|
|
var children = {} setget children_set
|
|
var id_always_visible = false
|
|
var held = false
|
|
|
|
var arrow = preload("res://arrow.tscn")
|
|
|
|
|
|
func _ready():
|
|
pass
|
|
|
|
func _process(_delta):
|
|
if held:
|
|
global_position = get_global_mouse_position()
|
|
|
|
if visible:
|
|
apply_forces()
|
|
|
|
func apply_forces():
|
|
var offset = Vector2(0, 80)
|
|
|
|
for c in children.keys():
|
|
if repository.objects.has(c):
|
|
var other = repository.objects[c]
|
|
if other.visible:
|
|
var d = other.position.distance_to(position+offset)
|
|
var dir = (other.position - (position+offset)).normalized()
|
|
var f = (d*0.03)
|
|
position += dir*f
|
|
other.position -= dir*f
|
|
|
|
func id_set(new_id):
|
|
id = new_id
|
|
$ID.text = id
|
|
|
|
func content_set(new_content):
|
|
content = new_content
|
|
$Content.text = content
|
|
|
|
func type_set(new_type):
|
|
type = new_type
|
|
if type != "ref":
|
|
$ID.text = $ID.text.substr(0,8)
|
|
#elif type == "ref":
|
|
#$ID.text = $ID.text.replace("refs/", "")
|
|
match new_type:
|
|
"blob":
|
|
$Rect.color = Color("#333333")
|
|
"tree":
|
|
$Rect.color = Color.darkgreen
|
|
"commit":
|
|
$Rect.color = Color.orange
|
|
"tag":
|
|
$Rect.color = Color.blue
|
|
"ref":
|
|
$Rect.color = Color("#6680ff")
|
|
id_always_visible = true
|
|
"head":
|
|
$Rect.color = Color.red
|
|
id_always_visible = true
|
|
if id_always_visible:
|
|
$ID.show()
|
|
|
|
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
|
|
a.repository = repository
|
|
$Arrows.add_child(a)
|
|
children = new_children
|
|
|
|
func _on_hover():
|
|
$Content.visible = true
|
|
$ID.visible = true
|
|
|
|
func _on_unhover():
|
|
if not id_always_visible:
|
|
$Content.visible = false
|
|
$ID.visible = false
|
|
|
|
func _input_event(_viewport, event, _shape_idx):
|
|
if event is InputEventMouseButton:
|
|
if event.button_index == BUTTON_LEFT:
|
|
held = event.pressed
|
|
if event.button_index == BUTTON_RIGHT:
|
|
if event.pressed:
|
|
var input = get_tree().get_current_scene().find_node("Terminal").find_node("Control").find_node("Input")
|
|
input.text += id
|
|
input.caret_position = input.text.length()
|