diff --git a/dumper.py b/dumper.py index 8198de3..f121eb4 100644 --- a/dumper.py +++ b/dumper.py @@ -23,6 +23,7 @@ def serialize_selected_nodes_from_node_tree(node_tree: bpy.types.NodeTree): links_data = [Serializer.serialize(link, bl_pointers) for link in selected_links] # Only serialize selected nodes and their links + # Data format corresponds to the bpy.types.NodeTree properties that we want to (de)serialize ntree_data = { "nodes": nodes_data, "links": links_data, @@ -62,10 +63,21 @@ class Serializer(ABC): return None # --- Serialization --- + + @classmethod + def serialize(cls, obj: bpy.types.bpy_struct | Any, bl_pointers_ref: dict) -> Any: + if not isinstance(obj, bpy.types.bpy_struct): + # Primitive type, return directly + return obj + + """Resolve which Serializer class to use""" + serializer = cls.get_serializer(obj) + + return serializer.serialize_obj(obj, bl_pointers_ref) @classmethod @abstractmethod - def serialize(cls, obj: bpy.types.bpy_struct | Any, bl_pointers_ref: dict) -> dict: + def serialize_obj(cls, obj: bpy.types.bpy_struct | Any, bl_pointers_ref: dict) -> dict: """Base serialization method, overridden by subclasses""" # Early recursive return case @@ -96,7 +108,7 @@ class Serializer(ABC): @classmethod def serialize_property(cls, bl_prop: BlenderProperty, bl_pointers_ref: dict) -> Any: - """Serialize node property, special cases for arrays/collections/pointers""" + """Serialize Blender property, special cases for arrays/collections/pointers""" # Property array case if getattr(bl_prop.rep, "is_array", False): # Contained in BoolProperty, IntProperty and FloatProperty @@ -113,7 +125,7 @@ class Serializer(ABC): if not collection: return [] - values = [cls.sub_serialize(sub_prop) for sub_prop in collection] + values = [cls.serialize(sub_prop) for sub_prop in collection] # TODO: Check why the original code has a None check return [v for v in values if v is not None] @@ -127,19 +139,8 @@ class Serializer(ABC): return ptr bl_pointers_ref[ptr] = bl_prop.attr - - return cls.sub_serialize(bl_prop.attr, bl_pointers_ref) - - @classmethod - def sub_serialize(cls, obj: bpy.types.bpy_struct | Any, bl_pointers_ref: dict) -> Any: - if not isinstance(obj, bpy.types.bpy_struct): - # Primitive type, return directly - return obj - - """Resolve which Serializer class to use""" - serializer = cls.get_serializer(obj) - - return serializer.serialize(obj, bl_pointers_ref) + + return cls.serialize(bl_prop.rep, bl_pointers_ref) # --- Deserialization ---