2020-11-17 17:07:16 +01:00
|
|
|
class_name Item
|
2020-11-17 16:27:16 +01:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
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"
|
2020-11-17 17:07:16 +01:00
|
|
|
export var editable = true
|
2020-11-18 18:06:46 +01:00
|
|
|
|
|
|
|
var attributes
|
|
|
|
|
2020-11-17 18:31:19 +01:00
|
|
|
var held
|
|
|
|
var GRID_SIZE = 60
|
|
|
|
var file_browser
|
2020-11-17 16:27:16 +01:00
|
|
|
|
|
|
|
onready var label_node = $Label
|
|
|
|
onready var status_icon = $Status
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
_set_label(label)
|
|
|
|
_set_status(status)
|
2020-11-18 18:06:46 +01:00
|
|
|
|
|
|
|
read_from_file()
|
|
|
|
# if not editable:
|
|
|
|
# type = "nothing"
|
2020-11-17 16:27:16 +01:00
|
|
|
#$PopupMenu.add_item("Delete file", 0)
|
|
|
|
|
2020-11-18 18:06:46 +01:00
|
|
|
func read_from_file():
|
|
|
|
print(file_browser)
|
|
|
|
attributes = helpers.parse(file_browser.shell.run("cat '%s'" % label))
|
|
|
|
position.x = int(attributes["x"])
|
|
|
|
position.y = int(attributes["y"])
|
|
|
|
|
|
|
|
func write_to_file():
|
|
|
|
attributes["x"] = str(position.x)
|
|
|
|
attributes["y"] = str(position.y)
|
|
|
|
|
|
|
|
var content = ""
|
|
|
|
for key in attributes:
|
|
|
|
content += "%s = %s\n" % [key, attributes[key]]
|
|
|
|
file_browser.shell.run("echo \"%s\" > %s" % [content, label])
|
|
|
|
|
2020-11-17 16:27:16 +01:00
|
|
|
func _set_label(new_label):
|
|
|
|
label = new_label
|
|
|
|
if label_node:
|
|
|
|
label_node.text = helpers.abbreviate(new_label, 30)
|
|
|
|
|
|
|
|
#func _gui_input(event):
|
|
|
|
# if event is InputEventMouseButton and event.is_pressed() and event.button_index == BUTTON_LEFT:
|
|
|
|
# emit_signal("clicked", self)
|
|
|
|
# if event is InputEventMouseButton and event.is_pressed() and event.button_index == BUTTON_RIGHT and status != IconStatus.REMOVED:
|
|
|
|
# $PopupMenu.set_position(get_global_mouse_position())
|
|
|
|
# $PopupMenu.popup()
|
|
|
|
|
|
|
|
func _set_status(new_status):
|
|
|
|
if status_icon:
|
|
|
|
match new_status:
|
|
|
|
IconStatus.NEW:
|
|
|
|
status_icon.texture = preload("res://images/new.svg")
|
|
|
|
status_icon.modulate = Color("33BB33")
|
|
|
|
IconStatus.REMOVED:
|
|
|
|
status_icon.texture = preload("res://images/removed.svg")
|
|
|
|
status_icon.modulate = Color("D10F0F")
|
|
|
|
IconStatus.CONFLICT:
|
|
|
|
status_icon.texture = preload("res://images/conflict.svg")
|
|
|
|
status_icon.modulate = Color("DE5E09")
|
|
|
|
IconStatus.EDIT:
|
|
|
|
status_icon.texture = preload("res://images/modified.svg")
|
|
|
|
status_icon.modulate = Color("344DED")
|
|
|
|
IconStatus.UNTRACKED:
|
|
|
|
status_icon.texture = preload("res://images/untracked.svg")
|
|
|
|
status_icon.modulate = Color("9209B8")
|
|
|
|
IconStatus.NONE:
|
|
|
|
status_icon.texture = null
|
|
|
|
|
|
|
|
status = new_status
|
2020-11-17 18:31:19 +01:00
|
|
|
|
2020-11-18 18:06:46 +01:00
|
|
|
func move(diff):
|
|
|
|
position += diff
|
|
|
|
write_to_file()
|
2020-11-17 18:31:19 +01:00
|
|
|
if held:
|
2020-11-18 18:06:46 +01:00
|
|
|
held.move(diff)
|