diff --git a/bl_types/__init__.py b/bl_types/__init__.py index 5543d7c..34681c2 100644 --- a/bl_types/__init__.py +++ b/bl_types/__init__.py @@ -8,10 +8,3 @@ from ..libs.replication.data import ReplicatedDataFactory def types_to_register(): return __all__ -def bl_types_factory(): - bpy_factory = ReplicatedDataFactory() - module = __import__(__name__) - - for type in types_to_register(): - _type = getattr(module,type) - bpy_factory.register_type(_type.bl_class,_type.bl_rep_class) \ No newline at end of file diff --git a/bl_types/bl_object.py b/bl_types/bl_object.py index 390988e..e016346 100644 --- a/bl_types/bl_object.py +++ b/bl_types/bl_object.py @@ -31,8 +31,9 @@ class BlObject(ReplicatedDatablock): target.matrix_world = mathutils.Matrix(data["matrix_world"]) - def dump(self, source): - return utils.dump_datablock(source, 1) + def dump(self, pointer=None): + assert(pointer) + return utils.dump_datablock(pointer, 1) bl_id = "objects" diff --git a/operators.py b/operators.py index 072bd29..c688330 100644 --- a/operators.py +++ b/operators.py @@ -17,7 +17,7 @@ from . import environment, presence, ui, utils from .libs import umsgpack from .libs.replication.data import ReplicatedDataFactory from .libs.replication.interface import Client -from .bl_types import bl_types_factory +from . import bl_types logger = logging.getLogger(__name__) @@ -88,11 +88,13 @@ execution_queue = queue.Queue() # client.set(client_key, client_data[0][1]) # TODO: cleanup -def init_supported_datablocks(client, suported_types): - for type in suported_types: - for block in bpy.data[type.bl_idname]: - print(block) - +def init_supported_datablocks(supported_types_id): + global client + + for type_id in supported_types_id: + for item in getattr(bpy.data,type_id): + print(item) + client.register(item) # def default_tick(): @@ -140,31 +142,33 @@ class SessionStartOperator(bpy.types.Operator): # if settings.start_empty: # clean_scene() - # Setup data factory - + bpy_factory = ReplicatedDataFactory() + supported_bl_types = [] + + # init the factory with supported types + for type in bl_types.types_to_register(): + _type = getattr(bl_types,type) + supported_bl_types.append(_type.bl_id) + bpy_factory.register_type(_type.bl_class,_type.bl_rep_class) - # bpy_factory.register_type(bpy.types.Object,bl_object) - - - - # Setup client client = Client(factory=bpy_factory) - if settings.init_scene: - init_supported_datablocks(client,["objects"]) if self.host: client.host( - id=settings.username, - address=settings.ip, - port=settings.port + id=settings.username, + address=settings.ip, + port=settings.port ) + + if settings.init_scene: + init_supported_datablocks(supported_bl_types) else: client.connect( id=settings.username, address=settings.ip, port=settings.port - ) + ) # settings.is_running = True # bpy.ops.session.refresh() @@ -384,7 +388,7 @@ def unregister(): presence.unregister() - if client: + if client and client.state == 2: client.disconnect() client = None