diff --git a/multi_user/bl_types/bl_gpencil.py b/multi_user/bl_types/bl_gpencil.py index a2a81d5..eed83bf 100644 --- a/multi_user/bl_types/bl_gpencil.py +++ b/multi_user/bl_types/bl_gpencil.py @@ -28,7 +28,7 @@ from replication.protocol import ReplicatedDatablock from .bl_datablock import resolve_datablock_from_uuid from .bl_action import dump_animation_data, load_animation_data, resolve_animation_dependencies from ..utils import get_preferences - +from ..timers import is_annotating STROKE_POINT = [ 'co', @@ -323,7 +323,8 @@ class BlGpencil(ReplicatedDatablock): return bpy.context.mode == 'OBJECT' \ or layer_changed(datablock, data) \ or frame_changed(data) \ - or get_preferences().sync_flags.sync_during_editmode + or get_preferences().sync_flags.sync_during_editmode \ + or is_annotating(bpy.context) _type = bpy.types.GreasePencil _class = BlGpencil diff --git a/multi_user/bl_types/bl_scene.py b/multi_user/bl_types/bl_scene.py index cc02235..c5c9d00 100644 --- a/multi_user/bl_types/bl_scene.py +++ b/multi_user/bl_types/bl_scene.py @@ -403,8 +403,9 @@ class BlScene(ReplicatedDatablock): datablock.world = bpy.data.worlds[data['world']] # Annotation - if 'grease_pencil' in data.keys(): - datablock.grease_pencil = bpy.data.grease_pencils[data['grease_pencil']] + gpencil_uid = data.get('grease_pencil') + if gpencil_uid: + datablock.grease_pencil = resolve_datablock_from_uuid(gpencil_uid, bpy.data.grease_pencils) if get_preferences().sync_flags.sync_render_settings: if 'eevee' in data.keys(): @@ -470,7 +471,6 @@ class BlScene(ReplicatedDatablock): 'name', 'world', 'id', - 'grease_pencil', 'frame_start', 'frame_end', 'frame_step', @@ -530,6 +530,9 @@ class BlScene(ReplicatedDatablock): if datablock.timeline_markers: data['timeline_markers'] = [(m.name, m.frame, getattr(m.camera, 'uuid', None)) for m in datablock.timeline_markers] + if datablock.grease_pencil: + data['grease_pencil'] = datablock.grease_pencil.uuid + return data @staticmethod diff --git a/multi_user/operators.py b/multi_user/operators.py index 7279a0e..47b9778 100644 --- a/multi_user/operators.py +++ b/multi_user/operators.py @@ -285,6 +285,7 @@ class SessionStartOperator(bpy.types.Operator): deleyables.append(session_update) deleyables.append(session_user_sync) deleyables.append(session_listen) + deleyables.append(timers.AnnotationUpdates()) return {"FINISHED"} diff --git a/multi_user/timers.py b/multi_user/timers.py index 6d8ca81..0bfe1cf 100644 --- a/multi_user/timers.py +++ b/multi_user/timers.py @@ -137,12 +137,50 @@ class ApplyTimer(Timer): force=True) +class AnnotationUpdates(Timer): + def __init__(self, timeout=1): + self._annotating = False + self._settings = utils.get_preferences() + + super().__init__(timeout) + + def execute(self): + if session and session.state == STATE_ACTIVE: + ctx = bpy.context + annotation_gp = ctx.scene.grease_pencil + + if annotation_gp and not annotation_gp.uuid: + ctx.scene.update_tag() + + # if an annotation exist and is tracked + if annotation_gp and annotation_gp.uuid: + registered_gp = session.repository.graph.get(annotation_gp.uuid) + if is_annotating(bpy.context): + # try to get the right on it + if registered_gp.owner == RP_COMMON: + self._annotating = True + logging.debug( + "Getting the right on the annotation GP") + porcelain.lock(session.repository, + registered_gp.uuid, + ignore_warnings=True, + affect_dependencies=False) + + if registered_gp.owner == self._settings.username: + porcelain.commit(session.repository, annotation_gp.uuid) + porcelain.push(session.repository, 'origin', annotation_gp.uuid) + + elif self._annotating: + porcelain.unlock(session.repository, + registered_gp.uuid, + ignore_warnings=True, + affect_dependencies=False) + class DynamicRightSelectTimer(Timer): def __init__(self, timeout=.1): super().__init__(timeout) self._last_selection = [] self._user = None - self._annotating = False def execute(self): settings = utils.get_preferences() @@ -153,37 +191,6 @@ class DynamicRightSelectTimer(Timer): self._user = session.online_users.get(settings.username) if self._user: - ctx = bpy.context - annotation_gp = ctx.scene.grease_pencil - - if annotation_gp and not annotation_gp.uuid: - ctx.scene.update_tag() - - # if an annotation exist and is tracked - if annotation_gp and annotation_gp.uuid: - registered_gp = session.repository.graph.get(annotation_gp.uuid) - if is_annotating(bpy.context): - # try to get the right on it - if registered_gp.owner == RP_COMMON: - self._annotating = True - logging.debug( - "Getting the right on the annotation GP") - porcelain.lock(session.repository, - registered_gp.uuid, - ignore_warnings=True, - affect_dependencies=False) - - if registered_gp.owner == settings.username: - gp_node = session.repository.graph.get(annotation_gp.uuid) - porcelain.commit(session.repository, gp_node.uuid) - porcelain.push(session.repository, 'origin', gp_node.uuid) - - elif self._annotating: - porcelain.unlock(session.repository, - registered_gp.uuid, - ignore_warnings=True, - affect_dependencies=False) - current_selection = utils.get_selected_objects( bpy.context.scene, bpy.data.window_managers['WinMan'].windows[0].view_layer