-
Notifications
You must be signed in to change notification settings - Fork 8
/
blockflow.gd
135 lines (108 loc) ยท 4.49 KB
/
blockflow.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
## Blockflow plugin-wide constants.
# Modifying values here requires a plugin reload after save.
const PluginConstants = preload("res://addons/blockflow/core/constants.gd")
## Blockflow debugger constants messages
const Debugger = preload("res://addons/blockflow/debugger/debugger_messages.gd")
## Blockflow util scripts. Utility functions that didn't have place here.
const Utils = preload("res://addons/blockflow/core/utils.gd")
## Blockflow CommandRecord class. Used to manage registered commands in editor.
const CommandRecord = preload("res://addons/blockflow/core/command_record.gd")
# Made to ensure that classes are loaded before class_name populates editor
## [Collection] class.
const CollectionClass = preload("res://addons/blockflow/collection.gd")
## [CommandCollection] class.
const CommandCollectionClass = preload("res://addons/blockflow/command_collection.gd")
## [Command] class.
const CommandClass = preload("res://addons/blockflow/commands/command.gd")
## [CommandProcessor] class.
const CommandProcessorClass = preload("res://addons/blockflow/processors/command_processor.gd")
static func get_default_command_scripts() -> Array:
var commands := []
for command_path in PluginConstants.DEFAULT_COMMAND_PATHS:
if not ResourceLoader.exists(command_path, "Script"):
push_warning("!ResourceLoader.exists(%s) == true, continuing"%command_path)
continue
var command_script:Script = load(command_path) as Script
if not command_script:
push_warning("CommandList: Resource at '%s' is not an Script."%command_path)
continue
commands.append(command_script)
return commands
# TODO: Custom commands made by the user that are not a script/resource file
# and will live under a special folder.
## Commands defined in
## ProjectSettings [constant PROJECT_SETTING_CUSTOM_COMMANDS]
static func get_custom_commands() -> Array:
var commands := []
for command_path in ProjectSettings.get_setting(PluginConstants.PROJECT_SETTING_CUSTOM_COMMANDS, []):
if not ResourceLoader.exists(command_path):
push_warning("!ResourceLoader.exists(%s) == true, continuing"%command_path)
continue
# We can't guess the type, so let's load it as generic
# and let the caller handle it.
var command:Resource = ResourceLoader.load(command_path)
if not command:
# HOW?
push_warning("CommandList: Resource at '%s' is not valid."%command_path)
continue
commands.append(command)
return commands
static func get_plugin() -> Node:
if not Engine.has_meta(PluginConstants.PLUGIN_NAME):
return null
return Engine.get_meta(PluginConstants.PLUGIN_NAME)
static func get_editor_interface() -> EditorInterface:
return null
enum Toast {
SEVERITY_INFO,
SEVERITY_WARNING,
SEVERITY_ERROR
}
class CollectionData:
var main_collection:CollectionClass
var command_list:Array[CommandClass]
var bookmarks:Dictionary
static func generate_tree(collection:CollectionClass) -> CollectionData:
# if collection.is_updating_data: return
collection.is_updating_data = true
var data := CollectionData.new()
var command_pt:CommandClass
if collection.is_empty():
return data
var command_list:Array[CommandClass] = []
var owner:CollectionClass
command_pt = collection.collection[0]
for command in collection.collection:
_recursive_add(command, command_list)
var position:int = 0
var bookmarks := {}
for command_position in command_list.size():
command_pt = command_list[command_position]
command_pt.position = command_position
command_pt.weak_collection = weakref(collection as CommandCollectionClass)
if not command_pt.bookmark.is_empty():
bookmarks[command_pt.bookmark] = command_pt
data.command_list = command_list
data.bookmarks = bookmarks
data.main_collection = collection
if collection is CommandCollectionClass:
command_list.make_read_only()
collection._bookmarks = bookmarks
collection._command_list = command_list
# collection.set("data", data)
collection.is_updating_data = false
return data
static func _recursive_add(command, to) -> void:
to.append(command)
for subcommand in command:
_recursive_add(subcommand, to)
static func move_to_collection(command, to_collection, to_position=0) -> void:
var owner_collection = command.get_command_owner()
owner_collection.erase(command)
to_collection.insert(command, to_position)
# var idx = to_position if to_position > -1 else to_collection.collection.size()
# to_collection.collection.insert(idx, command)
# owner_collection.emit_changed()
# to_collection.emit_changed()
# owner_collection._notify_changed()
# to_collection._notify_changed()