From f151c61d7baf477265c2a056c24eb38ecb6425b0 Mon Sep 17 00:00:00 2001 From: Swann Date: Thu, 15 Oct 2020 17:21:14 +0200 Subject: [PATCH] feat: mimic blender undo handling --- multi_user/bl_types/bl_datablock.py | 20 ++++++++++++-------- multi_user/operators.py | 10 +++++++--- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/multi_user/bl_types/bl_datablock.py b/multi_user/bl_types/bl_datablock.py index c7996e3..df34f07 100644 --- a/multi_user/bl_types/bl_datablock.py +++ b/multi_user/bl_types/bl_datablock.py @@ -128,9 +128,9 @@ class BlDatablock(ReplicatedDatablock): if instance and hasattr(instance, 'uuid'): instance.uuid = self.uuid - self.diff_method = DIFF_BINARY + # self.diff_method = DIFF_BINARY - def resolve(self): + def resolve(self, construct = True): datablock_ref = None datablock_root = getattr(bpy.data, self.bl_id) datablock_ref = utils.find_from_attr('uuid', self.uuid, datablock_root) @@ -139,15 +139,19 @@ class BlDatablock(ReplicatedDatablock): try: datablock_ref = datablock_root[self.data['name']] except Exception: - name = self.data.get('name') - logging.debug(f"Constructing {name}") - datablock_ref = self._construct(data=self.data) + if construct: + name = self.data.get('name') + logging.debug(f"Constructing {name}") + datablock_ref = self._construct(data=self.data) - if datablock_ref: + if datablock_ref is not None: setattr(datablock_ref, 'uuid', self.uuid) + self.instance = datablock_ref + return True + else: + return False - self.instance = datablock_ref - + def remove_instance(self): """ Remove instance from blender data diff --git a/multi_user/operators.py b/multi_user/operators.py index d5fc58e..b99b522 100644 --- a/multi_user/operators.py +++ b/multi_user/operators.py @@ -686,10 +686,14 @@ def sanitize_deps_graph(dummy): A future solution should be to avoid storing dataclock reference... """ - if session and session.state['STATE'] == STATE_ACTIVE: - for node_key in session.list(): - session.get(node_key).resolve() + if session and session.state['STATE'] == STATE_ACTIVE: + session.lock() + for node_key in session.list(): + node = session.get(node_key) + if node and not node.resolve(construct=False): + session.remove(node_key) + session.unlock() @persistent def load_pre_handler(dummy):