-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.gd
203 lines (183 loc) · 6.34 KB
/
global.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
extends Node
var saverReloader = preload("res://specialFunction/SAVER_RELOADER_PlaceholderHack.gd").new()
var structures = preload("res://specialFunction/structrures.gd").new()
var LibraryElementStructure = {
'uniwu/item/variable/New_variable':{
'Library' : '',
'Type':'Element',#Inheritable,errorhandler
'Title' : 'ADD VARIABLE',
'Description' : 'test description',
'Doc':'Doc Example',
'Icon':'',
'GroupPath':'',
'Dependencies':[],
'Inherit':[],
'Iniciator':[],
'AntiIniciator':[],
'Parent':false,
'Morphs':{#loop-able, keys are not fixed
#Placeholder key but Base maybe found in most elements
'Base' :{#fixed keys
'Feature' : '',
'Code' : '',
'Properties':{#loop-able keys are not fixed
#Placeholder key
'Enter Variable Name':{#fixed keys
'VariableName':'n',
'Type':'n',
'Display':'Options',
'DisplayType':'n',
'subtype':['s','t'],
'DefaultValue':'',
'InputOutput':'Input'
},
'Static':{#fixed keys
'VariableName':'n',
'Type':'n',
'Display':'Options',
'DisplayType':'n',
'subtype':['s','t'],
'DefaultValue':'',
'InputOutput':'Output'
}
}
}
}
},
}
signal LibraryElementStructure_Constructed
var current_project_filePath = ''
var current_project = {} : set = current_Project_set
signal current_Project_changed
var GlobalVariables = {}
var FlowVariables = []
var highlighted_element = null : set =highlighted_element_set
signal highlighted_element_changed
var selected_flow = 'main' : set = selected_flow_changed
func _ready():
create_dir()
create_newProject()
#get_LibraryElementStructure()
func create_newProject():
current_project = {
'Version' : '0.0.1.Dev',
'FileState' : 'Flow',#Library,Flow,App -->'App' filestate is reserved for deployed clients
'LibrariesVersion' :{#loop-able keys are not fixed
'built-in': '0.0.1.Alfa',
},
'Globals':{#loop-able keys are not fixed
'Globalsid':{
'Type':'',
'Value':''
}
},
'Flows': {#loop-able, keys are not fixed
'main' : {},
},
'ElementStructures':{}, # if FileState is Flow flowElementslist only include used elements
'ElementUpdatePatterns':{#loop-able keys are not fixed
#Intended for libraries to be able to be updated atleast in minorEditor releases
#TOBE DEFINED
}
}
func create_Update_flow(flowname,changes):
if current_project.Flows.has(flowname) and typeof(changes) == TYPE_DICTIONARY:
current_project.Flows[flowname] = changes
emit_signal("current_Project_changed")
return OK
return FAILED
func add_NewFlow(flowname):
current_project.Flows[flowname] ={}
selected_flow = flowname
emit_signal("current_Project_changed")
return OK
func rename_flow(flowname,_changes):
if current_project.Flows.has(flowname):
#FORCE_SAVE
current_project.Flows[_changes] = current_project.Flows[flowname]
current_project.Flows.erase(flowname)
emit_signal("current_Project_changed")
return OK
return FAILED
func delete_flow(flowname):
if current_project.Flows.has(flowname):
current_project.Flows.erase(flowname)
emit_signal("current_Project_changed")
return OK
return FAILED
func run_current_flow(_params):
pass
func save_current_benchpress():
pass
func current_Project_set(newvalue):
current_project = newvalue
emit_signal("current_Project_changed")
func highlighted_element_set(newvalue):
highlighted_element = newvalue
emit_signal("highlighted_element_changed")
func selected_flow_changed(newvalue):
selected_flow = newvalue
emit_signal("current_Project_changed")
func get_LibraryElementStructure():
var contents = dir_contents('user://Library').files
LibraryElementStructure.clear()
for file_name in contents:
if file_name.get_extension() != 'benchpress': continue
#get data .benchpress files that are type library store it in BenchPressfile
var BenchPressfile =saverReloader._load('user://Library/'+file_name)
if BenchPressfile['FileState'] != 'Library':continue
for SourceLibraryName in BenchPressfile['ElementStructures']:
var uniqueSourceLibraryName = SourceLibraryName.get_slice("/", 0)+'/'+SourceLibraryName.get_slice("/", 0)+'/'+SourceLibraryName.get_slice("/", 1)+'/'+SourceLibraryName.get_slice("/", 2)
var makeunique = 0
while LibraryElementStructure.has(uniqueSourceLibraryName):
makeunique += 1
uniqueSourceLibraryName =(SourceLibraryName.get_slice("/", 0)+str(makeunique))+'/'+SourceLibraryName.get_slice("/", 0)+'/'+SourceLibraryName.get_slice("/", 1)+'/'+SourceLibraryName.get_slice("/", 2)
LibraryElementStructure[uniqueSourceLibraryName] = BenchPressfile['ElementStructures'][SourceLibraryName]
emit_signal("LibraryElementStructure_Constructed")
func dir_contents(path):
var contents = {
'directories':[],
'files':[],
}
var directory = DirAccess.open(path)
if directory == OK:
directory.list_dir_begin()
var file_name = directory.get_next()
while file_name != "":
if directory.current_is_dir():
contents['directories'].append(file_name)
else:
contents['files'].append(file_name)
file_name = directory.get_next()
return contents
func create_dir(dirAndFiles = structures.custom_user_folders):
for dir in dirAndFiles:
var directory = DirAccess.open("user://")
if directory == null:
printerr(error_string(DirAccess.get_open_error()))
return
if ! directory.dir_exists(dir):
directory.make_dir_recursive(dir)
for copyfile in dirAndFiles[dir]:
if ! directory.file_exists(dir +'/'+copyfile) and directory.file_exists(dirAndFiles[dir][copyfile]):
directory.copy(dirAndFiles[dir][copyfile],dir+'/'+copyfile)
if FileAccess.get_sha256(dir +'/'+copyfile) != FileAccess.get_sha256(dirAndFiles[dir][copyfile]):
directory.copy(dirAndFiles[dir][copyfile],dir+'/'+copyfile)
func unique_name(names:PackedStringArray,newName:String):
if ! names.has(newName): return newName
#remove any numerals ends on newName
var newName_CharacterIndex =range(len(newName))
newName_CharacterIndex.reverse()
var arrayNumbers = PackedStringArray(range(10))
var countnumbers = 0
for chr in newName_CharacterIndex:
if ! arrayNumbers.has(newName[chr]): break
countnumbers += 1
#create a unique name
var uniqueName = newName.substr(0,len(newName)-countnumbers)
if uniqueName != '' and ! names.has(uniqueName): return uniqueName
var makeunique = 0
while names.has(newName):
makeunique += 1
newName = uniqueName + str(makeunique)
return newName