]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/export_armature.py
Redesign file writing in the Blender exporter
[libs/gl.git] / blender / io_mspgl / export_armature.py
index f3f18c8adcb1c8f2cf1c2e20bfb93535012c1cd2..c2ec67125f64c93f49322a5bbbb3e71bde68e485 100644 (file)
@@ -1,21 +1,30 @@
 class ArmatureExporter:
-       def export(self, context, out_file):
+       def export_to_file(self, context, out_fn):
                obj = context.active_object
+
+               statements = self.export_armature(context, obj)
+
+               with open(out_fn, "w") as out_file:
+                       for s in statements:
+                               s.write_to_file(out_file)
+
+       def export_armature(self, obj):
                if obj.type!="ARMATURE":
-                       raise Exception("Can only export Armature data")
+                       raise Exception("Object is not an armature")
 
                from .armature import Armature
-
                armature = Armature(obj.data)
                armature.sort_links()
 
-               from .outfile import open_outfile
-               out_file = open_outfile(out_file)
+               from .datafile import Statement
+               statements = []
 
                for l in armature.links:
-                       out_file.begin("link", '"{}"'.format(l.name))
-                       out_file.write("index", l.index)
+                       st = Statement("link", l.name)
+                       st.sub.append(Statement("index", l.index))
                        if l.parent:
-                               out_file.write("parent", '"{}"'.format(l.parent.name))
-                       out_file.write("base", *tuple(l.base))
-                       out_file.end()
+                               st.sub.append(Statement("parent", l.parent.name))
+                       st.sub.append(Statement("base", *tuple(l.base)))
+                       statements.append(st)
+
+               return statements