1
+
2
+ bl_info = {
3
+ "name" : "Level Editor" ,
4
+ "version" : (1 , 0 , 0 ),
5
+ "description" : "Plugin for making blender work better as a level editor" ,
6
+ "blender" : (4 , 0 , 0 ),
7
+ "category" : "Object" ,
8
+ }
9
+
10
+ import bpy
11
+ from bpy .types import Panel , Mesh
12
+ from bpy .path import abspath
13
+ import os .path
14
+ from .parse .struct_parse import find_structs , find_enums
15
+
16
+ class Definitions :
17
+ def __init__ (self ):
18
+ self .definitions = None
19
+ self .enums = None
20
+ self .has_loaded = False
21
+
22
+ def load (self ):
23
+ print ("Loading" )
24
+ if self .has_loaded :
25
+ return
26
+
27
+ self .has_loaded = True
28
+ scene_config_path = self ._find_scene_config ()
29
+ print ("Found scene config path " + str (scene_config_path ))
30
+
31
+ if not scene_config_path :
32
+ return
33
+
34
+ with open (scene_config_path , 'r' ) as file :
35
+ file_contents = file .read ()
36
+ self .definitions = find_structs (file_contents )
37
+ self .enums = find_enums (file_contents )
38
+
39
+ print ("Found definitions " , self .definitions .keys ())
40
+
41
+ def _find_scene_config (self ):
42
+ curr = abspath ("//" )
43
+
44
+ while not os .path .exists (os .path .join (curr , 'src/scene/scene_definition.h' )):
45
+ next = os .path .dirname (curr )
46
+
47
+ if next == curr :
48
+ return None
49
+ else :
50
+ curr = next
51
+
52
+ return os .path .join (curr , 'src/scene/scene_definition.h' )
53
+
54
+ def get_structure_type (self , name ):
55
+ def_type_name = f"{ name } _definition"
56
+
57
+ if not self .has_loaded :
58
+ self .load ()
59
+
60
+ if not self .definitions :
61
+ return None
62
+
63
+ if not def_type_name in self .definitions :
64
+ return None
65
+
66
+ return self .definitions [def_type_name ]
67
+
68
+ _object_definitions = Definitions ()
69
+
70
+ class GameObjectPropertiesPanel (Panel ):
71
+ bl_label = "Game object properties"
72
+ bl_idname = "OBJECT_PT_SPELLCRAFT_GameObject"
73
+ bl_space_type = "PROPERTIES"
74
+ bl_region_type = "WINDOW"
75
+ bl_context = "object"
76
+ bl_options = {"HIDE_HEADER" }
77
+
78
+ @classmethod
79
+ def poll (cls , context ):
80
+ _object_definitions .load ()
81
+ return (
82
+ context .object is not None
83
+ and isinstance (context .object .data , Mesh )
84
+ and 'type' in context .object .data
85
+ )
86
+
87
+ def draw (self , context ):
88
+ col = self .layout .column ().box ()
89
+
90
+ structure_type = _object_definitions .get_structure_type (context .object .data ['type' ])
91
+
92
+ col .box ().label (text = "Game object " + str (structure_type ))
93
+
94
+
95
+ def register ():
96
+ bpy .utils .register_class (GameObjectPropertiesPanel )
97
+
98
+ def unregister ():
99
+ bpy .utils .unregister_class (GameObjectPropertiesPanel )
100
+
101
+ if __name__ == "__main__" :
102
+ register ()
0 commit comments