-
Notifications
You must be signed in to change notification settings - Fork 12
/
vsk_map_validator.gd
388 lines (341 loc) · 14.3 KB
/
vsk_map_validator.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
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# Copyright (c) 2018-present. This file is part of V-Sekai https://v-sekai.org/.
# SaracenOne & K. S. Ernest (Fire) Lee & Lyuma & MMMaellon & Contributors
# vsk_map_validator.gd
# SPDX-License-Identifier: MIT
@tool
extends "res://addons/vsk_importer_exporter/vsk_validator.gd"
const map_validator_const = preload("res://addons/vsk_importer_exporter/vsk_map_validator.gd")
# FIXME: dictionary cannot be const????
var valid_node_whitelist = {
"AnimatedSprite3D": AnimatedSprite3D,
"AnimationPlayer": AnimationPlayer,
"AnimationTree": AnimationTree,
"Area3D": Area3D,
"AudioStreamPlayer": AudioStreamPlayer,
"AudioStreamPlayer3D": AudioStreamPlayer3D,
"BoneAttachment3D": BoneAttachment3D,
"Camera3D": Camera3D,
"CharacterBody3D": CharacterBody3D,
"CollisionObject3D": CollisionObject3D,
"CollisionShape3D": CollisionShape3D,
"ConeTwistJoint3D": ConeTwistJoint3D,
"CPUParticles3D": CPUParticles3D,
"DirectionalLight3D": DirectionalLight3D,
"GridMap": GridMap,
"GeometryInstance3D": GeometryInstance3D,
"Generic6DOFJoint3D": Generic6DOFJoint3D,
"GPUParticles3D": GPUParticles3D,
"HingeJoint3D": HingeJoint3D,
"Joint3D": Joint3D,
"Light3D": Light3D,
"LightmapGI": LightmapGI,
"Label3D": Label3D,
"MeshInstance3D": MeshInstance3D,
"MultiMeshInstance3D": MultiMeshInstance3D,
"NavigationAgent3D": NavigationAgent3D,
"NavigationRegion3D": NavigationRegion3D,
"Node": Node,
"Node3D": Node3D,
"OmniLight3D": OmniLight3D,
"Path3D": Path3D,
"PathFollow3D": PathFollow3D,
"PhysicsBody3D": PhysicsBody3D,
"PinJoint3D": PinJoint3D,
"Marker3D": Marker3D,
"Position3D": Marker3D,
"RayCast3D": RayCast3D,
"ReflectionProbe": ReflectionProbe,
"RigidBody3D": RigidBody3D,
"RemoteTransform3D": RemoteTransform3D,
"SliderJoint3D": SliderJoint3D,
"Skeleton3D": Skeleton3D,
"SpotLight3D": SpotLight3D,
"SpringArm3D": SpringArm3D,
"Sprite3D": Sprite3D,
"SpriteBase3D": SpriteBase3D,
"StaticBody3D": StaticBody3D,
"VehicleWheel3D": VehicleWheel3D,
"VisibleOnScreenEnabler3D": VisibleOnScreenEnabler3D,
"VisibleOnScreenNotifier3D": VisibleOnScreenNotifier3D,
"VisualInstance3D": VisualInstance3D,
"VoxelGI": VoxelGI,
"WorldEnvironment": WorldEnvironment,
"OccluderInstance3D": OccluderInstance3D,
"CSGCombiner3D": CSGCombiner3D,
"CSGMesh3D": CSGMesh3D,
"CSGBox3D": CSGBox3D,
"CSGCylinder3D": CSGCylinder3D,
"SubViewport": SubViewport,
}
var valid_canvas_node_whitelist = {
"Node": Node,
"HBoxContainer": HBoxContainer,
"VBoxContainer": VBoxContainer,
"Control": Control,
"Container": Container,
"AspectRatioContainer": AspectRatioContainer,
"TabContainer": TabContainer,
"Label": Label,
"RichTextLabel": RichTextLabel,
"BaseButton": BaseButton,
"Button": Button,
"CheckBox": CheckBox,
}
# FIXME: dictionary cannot be const????
var valid_resource_whitelist = {
"AnimatedTexture": AnimatedTexture,
"Animation": Animation,
"AnimationLibrary": AnimationLibrary,
"AnimationNodeAdd2": AnimationNodeAdd2,
"AnimationNodeAdd3": AnimationNodeAdd3,
"AnimationNodeAnimation": AnimationNodeAnimation,
"AnimationNodeBlend2": AnimationNodeBlend2,
"AnimationNodeBlend3": AnimationNodeBlend3,
"AnimationNodeBlendSpace1D": AnimationNodeBlendSpace1D,
"AnimationNodeBlendSpace2D": AnimationNodeBlendSpace2D,
"AnimationNodeBlendTree": AnimationNodeBlendTree,
"AnimationNodeOneShot": AnimationNodeOneShot,
"AnimationNodeOutput": AnimationNodeOutput,
"AnimationNodeStateMachine": AnimationNodeStateMachine,
"AnimationNodeStateMachineTransition": AnimationNodeStateMachineTransition,
"AnimationNodeTimeScale": AnimationNodeTimeScale,
"AnimationNodeTimeSeek": AnimationNodeTimeSeek,
"AnimationNodeTransition": AnimationNodeTransition,
"ArrayMesh": ArrayMesh,
"AtlasTexture": AtlasTexture,
"AudioStreamSample": AudioStreamWAV, # compatibility. delete me.
"AudioStreamWAV": AudioStreamWAV,
"AudioStreamOggVorbis": AudioStreamOggVorbis,
"BoxMesh": BoxMesh,
"BoxShape3D": BoxShape3D,
"CameraAttributesPhysical": CameraAttributesPhysical,
"CameraAttributesPractical": CameraAttributesPractical,
"CapsuleMesh": CapsuleMesh,
"CapsuleShape3D": CapsuleShape3D,
"ConcavePolygonShape3D": ConcavePolygonShape3D,
"ConvexPolygonShape3D": ConvexPolygonShape3D,
"Curve": Curve,
"Curve2D": Curve2D,
"Curve3D": Curve3D,
"CurveTexture": CurveTexture,
"CurveXYZTexture": CurveXYZTexture,
"CylinderMesh": CylinderMesh,
"CylinderShape3D": CylinderShape3D,
"Environment": Environment,
"GradientTexture1D": GradientTexture1D,
"GradientTexture2D": GradientTexture2D,
"HeightMapShape3D": HeightMapShape3D,
"ImageTexture": ImageTexture,
"LightmapGIData": LightmapGIData,
"Mesh": Mesh,
"MeshLibrary": MeshLibrary,
"MeshTexture": MeshTexture,
"NavigationMesh": NavigationMesh,
"NoiseTexture2D": NoiseTexture2D,
"ORMMaterial3D": ORMMaterial3D,
"PackedScene": PackedScene,
"PhysicalSkyMaterial": PhysicalSkyMaterial,
"PanoramaSkyMaterial": PanoramaSkyMaterial,
"ProceduralSkyMaterial": ProceduralSkyMaterial,
"PhysicsMaterial": PhysicsMaterial,
"PlaneMesh": PlaneMesh,
"PointMesh": PointMesh,
"PrimitiveMesh": PrimitiveMesh,
"PrismMesh": PrismMesh,
"Resource": Resource,
"Shader": Shader,
"ShaderMaterial": ShaderMaterial,
"Shape3D": Shape3D,
"Skin": Skin,
"Sky": Sky,
"StandardMaterial3D": StandardMaterial3D,
"StyleBoxEmpty": StyleBoxEmpty,
"SphereMesh": SphereMesh,
"SphereShape3D": SphereShape3D,
"CompressedTexture2D": CompressedTexture2D,
"PortableCompressedTexture2D": PortableCompressedTexture2D,
"Cubemap": Cubemap,
"CubemapArray": CubemapArray,
"Texture2D": Texture2D,
"Texture2DArray": Texture2DArray,
"Texture3D": Texture3D,
"TextureLayered": TextureLayered,
"Image": Image,
"ViewportTexture": ViewportTexture,
"VoxelGIData": VoxelGIData,
"WorldBoundaryShape3D": WorldBoundaryShape3D,
"Occluder3D": Occluder3D,
"QuadMesh": QuadMesh,
"World2D": World2D,
}
var valid_external_path_whitelist = {
"res://addons/entity_manager/entity.gd": true,
"res://addons/vsk_entities/vsk_interactable_prop.tscn": true,
"res://addons/network_manager/network_spawn.gd": true,
"res://addons/vsk_importer_exporter/vsk_uro_pipeline.gd": true,
"res://addons/vsk_importer_exporter/vsk_pipeline.gd": true,
"res://addons/vsk_map/vsk_map_definition.gd": true,
"res://addons/vsk_map/vsk_map_definition_runtime.gd": true,
"res://vsk_default/audio/sfx/basketball_drop.wav": true,
"res://vsk_default/import/beachball/Scene_-_Root.tres": true,
"res://vsk_default/import/basketball_reexport/Scene_-_Root.tres": true,
"res://addons/vsk_map/vsk_map_entity_instance_record.gd": true,
"res://addons/network_manager/network_identity.gd": true,
"res://addons/vsk_entities/extensions/test_entity_rpc_table.gd": true,
"res://addons/network_manager/network_logic.gd": true,
"res://addons/vsk_entities/extensions/test_entity_simulation_logic.gd": true,
"res://addons/entity_manager/transform_notification.gd": true,
"res://addons/entity_manager/hierarchy_component.gd": true,
"res://addons/vsk_entities/extensions/prop_simulation_logic.gd": true,
"res://addons/network_manager/network_hierarchy.gd": true,
"res://addons/network_manager/network_transform.gd": true,
"res://addons/network_manager/network_model.gd": true,
"res://addons/network_manager/network_physics.gd": true,
"res://addons/smoothing/smoothing.gd": true,
"res://vsk_default/environments/default_env.tres": true,
}
################
# Map Entities #
################
var entity_script: Script = load("res://addons/entity_manager/entity.gd")
const valid_entity_whitelist = ["res://addons/vsk_entities/vsk_interactable_prop.tscn"]
const valid_resource_script_whitelist = []
static func check_if_script_type_is_valid(p_script: Script, p_node_class: String) -> bool:
var network_spawn_const = load("res://addons/network_manager/network_spawn.gd")
var map_definition_runtime = load("res://addons/vsk_map/vsk_map_definition_runtime.gd")
var map_definition = load("res://addons/vsk_map/vsk_map_definition.gd")
var vsk_uro_pipeline = load("res://addons/vsk_importer_exporter/vsk_uro_pipeline.gd")
var entity_identity = load("res://addons/network_manager/network_identity.gd")
var entity_network_logic = load("res://addons/network_manager/network_logic.gd")
var entity_transform_notification = load("res://addons/entity_manager/transform_notification.gd")
var entity_entity = load("res://addons/entity_manager/entity.gd")
var hierarchy_component = load("res://addons/entity_manager/hierarchy_component.gd")
var network_hierarchy = load("res://addons/network_manager/network_hierarchy.gd")
var network_transform = load("res://addons/network_manager/network_transform.gd")
var network_model = load("res://addons/network_manager/network_model.gd")
var network_physics = load("res://addons/network_manager/network_physics.gd")
var smoothing = load("res://addons/smoothing/smoothing.gd")
var script_type_table = {
network_spawn_const: ["Position3D", "Marker3D", "Node3D"],
map_definition: ["Position3D", "Marker3D", "Node3D"],
map_definition_runtime: ["Position3D", "Marker3D", "Node3D"],
vsk_uro_pipeline: ["Node"],
entity_identity: ["Node"],
entity_network_logic: ["Node"],
entity_transform_notification: ["Node3D"],
entity_entity: ["Node3D"],
hierarchy_component: ["Node"],
network_hierarchy: ["Node"],
network_transform: ["Node"],
network_model: ["Node"],
network_physics: ["Node"],
smoothing: ["Node3D"],
}
if script_type_table.get(p_script) != null:
var valid_classes: Array = script_type_table.get(p_script)
for class_str in valid_classes:
if class_str == p_node_class:
return true
push_warning("Validator: Script failed check " + str(p_script) + "/" + str(p_script.resource_path) + " node_class " + p_node_class)
return false
func is_script_valid_for_root(p_script: Script, p_node_class: String):
if p_script == null:
return true
var map_definition = load("res://addons/vsk_map/vsk_map_definition.gd")
var map_definition_runtime = load("res://addons/vsk_map/vsk_map_definition_runtime.gd")
var valid_root_script_whitelist = [map_definition, map_definition_runtime]
if valid_root_script_whitelist.find(p_script) != -1:
return map_validator_const.check_if_script_type_is_valid(p_script, p_node_class)
push_warning("Validator: Unknown root script " + str(p_script) + "/" + str(p_script.resource_path) + " node_class " + p_node_class)
return false
func is_script_valid_for_children(p_script: Script, p_node_class: String):
if p_script == null:
return true
var network_spawn_const = load("res://addons/network_manager/network_spawn.gd")
var vsk_uro_pipeline = load("res://addons/vsk_importer_exporter/vsk_uro_pipeline.gd")
var entity_identity = load("res://addons/network_manager/network_identity.gd")
var entity_network_logic = load("res://addons/network_manager/network_logic.gd")
var entity_transform_notification = load("res://addons/entity_manager/transform_notification.gd")
var entity_entity = load("res://addons/entity_manager/entity.gd")
var hierarchy_component = load("res://addons/entity_manager/hierarchy_component.gd")
var network_hierarchy = load("res://addons/network_manager/network_hierarchy.gd")
var network_transform = load("res://addons/network_manager/network_transform.gd")
var network_model = load("res://addons/network_manager/network_model.gd")
var network_physics = load("res://addons/network_manager/network_physics.gd")
var smoothing = load("res://addons/smoothing/smoothing.gd")
var valid_children_script_whitelist = [
network_spawn_const,
vsk_uro_pipeline,
entity_identity,
entity_network_logic,
entity_transform_notification,
entity_entity,
hierarchy_component,
network_hierarchy,
network_transform,
network_model,
network_physics,
smoothing,
]
if valid_children_script_whitelist.find(p_script) != -1:
return map_validator_const.check_if_script_type_is_valid(p_script, p_node_class)
push_warning("Validator: Unknown children script " + str(p_script) + "/" + str(p_script.resource_path) + " node_class " + p_node_class)
return false
func is_script_valid_for_resource(p_script: Script):
if p_script == null:
return true
if valid_resource_script_whitelist.find(p_script) != -1:
return true
else:
push_warning("Validator: Unknown resource script %s" % [str(p_script) + "/" + str(p_script.resource_path)])
return false
func is_node_type_valid(p_node: Node, p_child_of_canvas: bool) -> bool:
if is_node_type_string_valid(p_node.get_class(), p_child_of_canvas):
if !map_validator_const.is_editor_only(p_node):
return true
push_warning("Validator: Unknown node type " + str(p_node.get_class()) + " (canvas " + str(p_child_of_canvas) + ")")
return false
func is_node_type_string_valid(p_class_str: String, p_child_of_canvas: bool) -> bool:
if p_child_of_canvas:
return valid_canvas_node_whitelist.has(p_class_str)
else:
return valid_node_whitelist.has(p_class_str)
push_warning("Validator: Unknown node type string " + p_class_str + " (canvas " + str(p_child_of_canvas) + ")")
return false
func is_resource_type_valid(p_resource: Resource) -> bool:
if valid_resource_whitelist.has(p_resource.get_class()):
return true
push_warning("Validator: Unknown resource type " + str(p_resource.get_class()))
return false
func is_path_an_entity(p_packed_scene_path: String) -> bool:
if valid_entity_whitelist.find(p_packed_scene_path) != -1:
return true
else:
return false
func is_valid_entity_script(p_script: Script) -> bool:
if p_script == entity_script:
return true
push_warning("Validator: Unknown entity script " + str(p_script) + "/" + str(p_script.resource_path) + " not " + str(entity_script) + "/" + str(entity_script.resource_path))
return false
func validate_value_track(p_subnames: String, p_node_class: String):
match p_node_class:
"MeshInstance3D":
return map_validator_const.check_basic_node_3d_value_targets(p_subnames)
"Node3D":
return map_validator_const.check_basic_node_3d_value_targets(p_subnames)
"DirectionalLight":
return map_validator_const.check_basic_node_3d_value_targets(p_subnames)
"OmniLight":
return map_validator_const.check_basic_node_3d_value_targets(p_subnames)
"SpotLight":
return map_validator_const.check_basic_node_3d_value_targets(p_subnames)
"Camera3D":
return map_validator_const.check_basic_node_3d_value_targets(p_subnames)
"GPUParticles3D":
return map_validator_const.check_basic_node_3d_value_targets(p_subnames)
"CPUParticles":
return map_validator_const.check_basic_node_3d_value_targets(p_subnames)
_:
return false
func get_name() -> String:
return "MapValidator"