-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
323 lines (257 loc) · 12.9 KB
/
settings.py
File metadata and controls
323 lines (257 loc) · 12.9 KB
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
import json
from typing import List
from tools import BaseData
class Alias(BaseData):
def __init__(self, key: str = "", value: str = "", ID: str = ""):
super().__init__(ID)
self.key = key
self.value = value
def to_json_data(self) -> dict:
json_data = super().to_json_data()
json_data['Key'] = self.key
json_data['Value'] = self.value
return json_data
@classmethod
def from_json_data(cls, json_data: dict) -> 'Alias':
return cls(json_data["Key"], json_data["Value"], json_data['ID'])
class BaseTag(BaseData):
def __init__(self, name: str = "", ID: str = ""):
super().__init__(ID)
self.name = name
def to_json_data(self) -> dict:
json_data = super().to_json_data()
json_data['Name'] = self.name
return json_data
@classmethod
def from_json_data(cls, json_data: dict) -> 'BaseTag':
class_type = json_data["$type"]
result = None
if class_type == "HBP.Core.Data.BoolTag, Assembly-CSharp" or class_type == "HBP.Data.BoolTag, Assembly-CSharp":
result = BoolTag.from_json_data(json_data)
elif class_type == "HBP.Core.Data.EmptyTag, Assembly-CSharp" or class_type == "HBP.Data.EmptyTag, Assembly-CSharp":
result = EmptyTag.from_json_data(json_data)
elif class_type == "HBP.Core.Data.EnumTag, Assembly-CSharp" or class_type == "HBP.Data.EnumTag, Assembly-CSharp":
result = EnumTag.from_json_data(json_data)
elif class_type == "HBP.Core.Data.FloatTag, Assembly-CSharp" or class_type == "HBP.Data.FloatTag, Assembly-CSharp":
result = FloatTag.from_json_data(json_data)
elif class_type == "HBP.Core.Data.IntTag, Assembly-CSharp" or class_type == "HBP.Data.IntTag, Assembly-CSharp":
result = IntTag.from_json_data(json_data)
elif class_type == "HBP.Core.Data.StringTag, Assembly-CSharp" or class_type == "HBP.Data.StringTag, Assembly-CSharp":
result = StringTag.from_json_data(json_data)
return result
class BoolTag(BaseTag):
def __init__(self, name: str = "", ID: str = ""):
super().__init__(name, ID)
def to_json_data(self) -> dict:
json_data = dict()
json_data["$type"] = "HBP.Core.Data.BoolTag, Assembly-CSharp"
json_data.update(super().to_json_data())
return json_data
@classmethod
def from_json_data(cls, json_data: dict) -> 'BoolTag':
return cls(json_data["Name"], json_data["ID"])
class EmptyTag(BaseTag):
def __init__(self, name: str = "", ID: str = ""):
super().__init__(name, ID)
def to_json_data(self) -> dict:
json_data = dict()
json_data["$type"] = "HBP.Core.Data.EmptyTag, Assembly-CSharp"
json_data.update(super().to_json_data())
return json_data
@classmethod
def from_json_data(cls, json_data: dict) -> 'EmptyTag':
return cls(json_data["Name"], json_data["ID"])
class StringTag(BaseTag):
def __init__(self, name: str = "", ID: str = ""):
super().__init__(name, ID)
def to_json_data(self) -> dict:
json_data = dict()
json_data["$type"] = "HBP.Core.Data.StringTag, Assembly-CSharp"
json_data.update(super().to_json_data())
return json_data
@classmethod
def from_json_data(cls, json_data: dict) -> 'StringTag':
return cls(json_data["Name"], json_data["ID"])
class EnumTag(BaseTag):
def __init__(self, name: str = "", values: List[str] = None, ID: str = ""):
super().__init__(name, ID)
self.values = values
def to_json_data(self) -> dict:
json_data = dict()
json_data["$type"] = "HBP.Core.Data.EnumTag, Assembly-CSharp"
json_data.update(super().to_json_data())
json_data['Values'] = self.values
return json_data
@classmethod
def from_json_data(cls, json_data: dict) -> 'EnumTag':
return cls(json_data["Name"], json_data["Values"], json_data["ID"])
class FloatTag(BaseTag):
def __init__(self, name: str = "", clamped: bool = False, min_value: float = 0.0, max_value: float = 0.0, ID: str = ""):
super().__init__(name, ID)
self.clamped = clamped
self.min_value = min_value
self.max_value = max_value
def to_json_data(self) -> dict:
json_data = dict()
json_data["$type"] = "HBP.Core.Data.FloatTag, Assembly-CSharp"
json_data.update(super().to_json_data())
json_data['Clamped'] = self.clamped
json_data['Min'] = self.min_value
json_data['Max'] = self.max_value
return json_data
@classmethod
def from_json_data(cls, json_data: dict) -> 'FloatTag':
return cls(json_data['Name'], json_data['Clamped'], json_data['Min'], json_data['Max'], json_data['ID'])
class IntTag(BaseTag):
def __init__(self, name: str = "", clamped: bool = False, min_value: int = 0, max_value: int = 0, ID: str = ""):
super().__init__(name, ID)
self.clamped = clamped
self.min_value = min_value
self.max_value = max_value
def to_json_data(self) -> dict:
json_data = dict()
json_data["$type"] = "HBP.Core.Data.IntTag, Assembly-CSharp"
json_data.update(super().to_json_data())
json_data['Clamped'] = self.clamped
json_data['Min'] = self.min_value
json_data['Max'] = self.max_value
return json_data
@classmethod
def from_json_data(cls, json_data: dict) -> 'IntTag':
return cls(json_data['Name'],
json_data['Clamped'],
json_data['Min'],
json_data['Max'],
json_data['ID'])
class BaseTagValue(BaseData):
def __init__(self, tag: BaseTag = None, value=None, ID: str = ""):
super().__init__(ID)
self.tag = tag
self.value = value
def to_json_data(self):
json_data = super().to_json_data()
json_data['Tag'] = self.tag.ID
json_data['Value'] = self.value
return json_data
@classmethod
def from_json_data(cls, json_data: dict, tags: List[BaseTag] = None) -> 'BaseTagValue':
class_type = json_data["$type"]
result = None
if class_type == "HBP.Core.Data.BoolTagValue, Assembly-CSharp" or class_type == "HBP.Data.BoolTagValue, Assembly-CSharp":
result = BoolTagValue.from_json_data(json_data, tags)
elif class_type == "HBP.Core.Data.EmptyTagValue, Assembly-CSharp" or class_type == "HBP.Data.EmptyTagValue, Assembly-CSharp":
result = EmptyTagValue.from_json_data(json_data, tags)
elif class_type == "HBP.Core.Data.EnumTagValue, Assembly-CSharp" or class_type == "HBP.Data.EnumTagValue, Assembly-CSharp":
result = EnumTagValue.from_json_data(json_data, tags)
elif class_type == "HBP.Core.Data.FloatTagValue, Assembly-CSharp" or class_type == "HBP.Data.FloatTagValue, Assembly-CSharp":
result = FloatTagValue.from_json_data(json_data, tags)
elif class_type == "HBP.Core.Data.IntTagValue, Assembly-CSharp" or class_type == "HBP.Data.IntTagValue, Assembly-CSharp":
result = IntTagValue.from_json_data(json_data, tags)
elif class_type == "HBP.Core.Data.StringTagValue, Assembly-CSharp" or class_type == "HBP.Data.StringTagValue, Assembly-CSharp":
result = StringTagValue.from_json_data(json_data, tags)
return result
class BoolTagValue(BaseTagValue):
def __init__(self, tag: BoolTag = None, value: bool = False, ID: str = ""):
super().__init__(tag, value, ID)
def to_json_data(self):
json_data = dict()
json_data["$type"] = "HBP.Core.Data.BoolTagValue, Assembly-CSharp"
json_data.update(super().to_json_data())
return json_data
@classmethod
def from_json_data(cls, json_data: dict, tags: List[BaseTag] = None) -> 'BoolTagValue':
return cls(next(tag for tag in tags if tag.ID == json_data['Tag']), json_data['Value'], json_data['ID'])
class EmptyTagValue(BaseTagValue):
def __init__(self, tag: EmptyTag = None, ID: str = ""):
super().__init__(tag, None, ID)
def to_json_data(self):
json_data = dict()
json_data["$type"] = "HBP.Core.Data.EmptyTagValue, Assembly-CSharp"
json_data.update(super().to_json_data())
return json_data
@classmethod
def from_json_data(cls, json_data: dict, tags: List[BaseTag] = None) -> 'EmptyTagValue':
return cls(next(tag for tag in tags if tag.ID == json_data['Tag']), json_data['ID'])
class EnumTagValue(BaseTagValue):
def __init__(self, tag: EnumTag = None, value: int = 0, ID: str = ""):
super().__init__(tag, value, ID)
def to_json_data(self):
json_data = dict()
json_data["$type"] = "HBP.Core.Data.EnumTagValue, Assembly-CSharp"
json_data.update(super().to_json_data())
return json_data
@classmethod
def from_json_data(cls, json_data: dict, tags: List[BaseTag] = None) -> 'EnumTagValue':
return cls(next(tag for tag in tags if tag.ID == json_data['Tag']), json_data['Value'], json_data['ID'])
class FloatTagValue(BaseTagValue):
def __init__(self, tag: FloatTag = None, value: float = 0.0, ID: str = ""):
super().__init__(tag, value, ID)
def to_json_data(self):
json_data = dict()
json_data["$type"] = "HBP.Core.Data.FloatTagValue, Assembly-CSharp"
json_data.update(super().to_json_data())
return json_data
@classmethod
def from_json_data(cls, json_data: dict, tags: List[BaseTag] = None) -> 'FloatTagValue':
return cls(next(tag for tag in tags if tag.ID == json_data['Tag']), json_data['Value'], json_data['ID'])
class IntTagValue(BaseTagValue):
def __init__(self, tag: IntTag = None, value: int = 0, ID: str = ""):
super().__init__(tag, value, ID)
def to_json_data(self):
json_data = dict()
json_data["$type"] = "HBP.Core.Data.IntTagValue, Assembly-CSharp"
json_data.update(super().to_json_data())
return json_data
@classmethod
def from_json_data(cls, json_data: dict, tags: List[BaseTag] = None) -> 'IntTagValue':
return cls(next(tag for tag in tags if tag.ID == json_data['Tag']), json_data['Value'], json_data['ID'])
class StringTagValue(BaseTagValue):
def __init__(self, tag: StringTag = None, value: str = 0, ID: str = ""):
super().__init__(tag, value, ID)
def to_json_data(self):
json_data = dict()
json_data["$type"] = "HBP.Core.Data.StringTagValue, Assembly-CSharp"
json_data.update(super().to_json_data())
return json_data
@classmethod
def from_json_data(cls, json_data: dict, tags: List[BaseTag] = None) -> 'StringTagValue':
return cls(next(tag for tag in tags if tag.ID == json_data['Tag']), json_data['Value'], json_data['ID'])
class ProjectPreferences(BaseData):
def __init__(self, name: str = "", patient_database: str = "", localizer_database: str = "",
aliases: List[Alias] = None, general_tags: List[BaseTag] = None,
patients_tags: List[BaseTag] = None, sites_tags: List[BaseTag] = None, ID: str = ""):
super().__init__(ID)
self.name = name
self.patient_database = patient_database
self.localizer_database = localizer_database
self.aliases = aliases if aliases is not None else []
self.general_tags = general_tags if general_tags is not None else []
self.patients_tags = patients_tags if patients_tags is not None else []
self.sites_tags = sites_tags if sites_tags is not None else []
def to_json_data(self) -> dict:
json_data = super().to_json_data()
json_data['Name'] = self.name
json_data['PatientDatabase'] = self.patient_database
json_data['LocalizerDatabase'] = self.localizer_database
json_data['Aliases'] = [alias.to_json_data() for alias in self.aliases]
json_data['GeneralTags'] = [tag.to_json_data() for tag in self.general_tags]
json_data['PatientsTags'] = [tag.to_json_data() for tag in self.patients_tags]
json_data['SitesTags'] = [tag.to_json_data() for tag in self.sites_tags]
return json_data
def to_json_file(self, json_file):
with open(json_file, "w") as f:
json.dump(self.to_json_data(), f, indent=2)
@classmethod
def from_json_file(cls, json_file) -> 'ProjectPreferences':
with open(json_file, "r") as f:
return cls.from_json_data(json.load(f))
@classmethod
def from_json_data(cls, json_data) -> 'ProjectPreferences':
return cls(json_data["Name"],
json_data["PatientDatabase"],
json_data["LocalizerDatabase"],
[Alias.from_json_data(alias) for alias in json_data["Aliases"]],
[BaseTag.from_json_data(tag) for tag in json_data["GeneralTags"]],
[BaseTag.from_json_data(tag) for tag in json_data["PatientsTags"]],
[BaseTag.from_json_data(tag) for tag in json_data["SitesTags"]],
json_data["ID"])