82 lines
2.0 KiB
Python
82 lines
2.0 KiB
Python
bl_info = {
|
|
"name": "AJM Exporter",
|
|
"description": "Exports AJM game data.",
|
|
"author": "Austin Morlan",
|
|
"blender": (2, 93, 0),
|
|
"location": "File > Export > Game (.bin)",
|
|
"category": "Import-Export",
|
|
}
|
|
|
|
import bpy
|
|
from bpy_extras.io_utils import ExportHelper
|
|
from bpy.props import StringProperty
|
|
from bpy.types import Operator
|
|
from bpy.app.handlers import persistent
|
|
|
|
import importlib
|
|
import os
|
|
|
|
from .types import *
|
|
from .data import *
|
|
|
|
#import pdb; pdb.set_trace()
|
|
|
|
# Handle reloading of submodules
|
|
if "bpy" in locals():
|
|
importlib.reload(types)
|
|
importlib.reload(data)
|
|
|
|
def export(path):
|
|
base_name = os.path.splitext(path)[0]
|
|
ext = os.path.splitext(path)[1]
|
|
|
|
scene = Scene()
|
|
|
|
data1_path = base_name + "1" + ext
|
|
data1 = Data1(scene)
|
|
data1.serialize(data1_path)
|
|
|
|
data2_path = base_name + "2" + ext
|
|
data2 = Data2(scene)
|
|
data2.serialize(data2_path)
|
|
|
|
return {'FINISHED'}
|
|
|
|
@persistent
|
|
def manual_export(dummy):
|
|
if "level.blend" in bpy.data.filepath:
|
|
path = bpy.path.abspath("//../../processed/data1.bin")
|
|
scene = Scene()
|
|
data1 = Data1(scene)
|
|
data1.serialize(path)
|
|
|
|
class ExportGame(Operator, ExportHelper):
|
|
bl_idname = "game_export.scene_text"
|
|
bl_label = "Export Game (bin) File"
|
|
filename_ext = ".bin"
|
|
filter_glob: StringProperty(
|
|
default="*.bin",
|
|
options={'HIDDEN'},
|
|
maxlen=255)
|
|
|
|
def execute(self, context):
|
|
return export(self.filepath)
|
|
|
|
def menu_func_export(self, context):
|
|
self.layout.operator(ExportGame.bl_idname, text="Game (.bin) Custom")
|
|
|
|
def register():
|
|
bpy.utils.register_class(ExportGame)
|
|
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
|
|
|
|
if not manual_export in bpy.app.handlers.save_post:
|
|
bpy.app.handlers.save_post.append(manual_export)
|
|
|
|
def unregister():
|
|
bpy.utils.unregister_class(ExportGame)
|
|
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
|
|
|
|
if manual_export in bpy.app.handlers.save_post:
|
|
bpy.app.handlers.save_post.remove(manual_export)
|
|
|