Skip to content

Commit dcfaf76

Browse files
committed
Work on level editor addon
1 parent b8612ac commit dcfaf76

File tree

4 files changed

+108
-2
lines changed

4 files changed

+108
-2
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ filesystem/
1212

1313
*.z64
1414

15+
tools/mesh_export.zip
16+
1517
# generated file
1618
src/player/inventory_mapping.c

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,6 @@ check-pairings:
173173
node tools/pairing_checker.js $(SOURCES) src/main.c
174174
.PHONY: check-pairings
175175

176+
tools/mesh_export.zip: tools/mesh_export/__init__.py
177+
cd tools; zip -r mesh_export.zip mesh_export/
176178
-include $(wildcard $(BUILD_DIR)/*.d)

tools/mesh_export/__init__.py

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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()

tools/mesh_export/parse/struct_parse.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ def find_end_curly(file_string: str, starting_at: int):
306306
return -1
307307

308308
def find_enums(file_string: str) -> dict[str, EnumInfo]:
309-
result: dict[str, StructureInfo] = {}
309+
result: dict[str, EnumInfo] = {}
310310

311311
current_position = file_string.find('enum ')
312312

313-
result: dict[str, StructureInfo] = {}
313+
result: dict[str, EnumInfo] = {}
314314

315315
while current_position != -1:
316316
# only look for enums definitons

0 commit comments

Comments
 (0)