refactor: code factoring

This commit is contained in:
Swann Martinez
2019-09-30 13:35:50 +02:00
parent 158deb623c
commit c855fdaf53
8 changed files with 58 additions and 53 deletions
+2
View File
@@ -5,6 +5,8 @@ from jsondiff import diff
from .. import utils
from .bl_datablock import BlDatablock
# WIP
class BlAction(BlDatablock):
def load(self, data, target):
utils.dump_anything.load(target, data)
+1 -1
View File
@@ -7,7 +7,7 @@ from .. import utils
from .. import presence
from .bl_datablock import BlDatablock
# WIP
class BlArmature(BlDatablock):
def construct(self, data):
return bpy.data.armatures.new(data["name"])
+26 -15
View File
@@ -1,7 +1,8 @@
import bpy
import logging
from . import operators, utils, presence
import bpy
from . import operators, presence, utils
from .bl_types.bl_user import BlUser
from .libs.replication.replication.constants import FETCHED, RP_COMMON
@@ -43,7 +44,6 @@ class Timer(Delayable):
if self._running:
return self._timeout
def execute(self):
"""Main timer loop
"""
@@ -57,6 +57,7 @@ class Timer(Delayable):
self._running = False
class ApplyTimer(Timer):
def __init__(self, timout=1, target_type=None):
self._type = target_type
@@ -76,7 +77,7 @@ class ApplyTimer(Timer):
class DynamicRightSelectTimer(Timer):
def __init__(self, timout=1):
super().__init__(timout)
self.last_selection=[]
self.last_selection = []
def execute(self):
if operators.client:
@@ -85,32 +86,42 @@ class DynamicRightSelectTimer(Timer):
for user in users:
user_ref = operators.client.get(uuid=user)
settings = bpy.context.window_manager.session
# Other user
if user_ref.buffer['name'] != settings.username:
user_selection = user_ref.buffer['selected_objects']
for obj in bpy.data.objects:
obj.hide_select = obj.name in user_ref.buffer['selected_objects']
obj.hide_select = obj.name in user_selection
# Local user
elif user_ref.pointer:
current_selection = utils.get_selected_objects(bpy.context.scene)
current_selection = utils.get_selected_objects(
bpy.context.scene)
if current_selection != self.last_selection:
user_ref.pointer.update_selected_objects(bpy.context)
if operators.client.get_config()['right_strategy'] == RP_COMMON:
obj_common = [o for o in self.last_selection if o not in current_selection]
obj_ours = [o for o in current_selection if o not in self.last_selection]
right_strategy = operators.client.get_config()[
'right_strategy']
if right_strategy == RP_COMMON:
obj_common = [
o for o in self.last_selection if o not in current_selection]
obj_ours = [
o for o in current_selection if o not in self.last_selection]
# change old selection right to common
for obj in obj_common:
_object = bpy.data.objects.get(obj)
node = operators.client.get(reference=_object)
if node and node.owner == settings.username:
operators.client.change_owner(node.uuid, RP_COMMON)
operators.client.change_owner(
node.uuid, RP_COMMON)
# change new selection to our
for obj in obj_ours:
node = operators.client.get(reference=bpy.data.objects[obj])
node = operators.client.get(
reference=bpy.data.objects[obj])
if node and node.owner == RP_COMMON:
operators.client.change_owner(node.uuid, settings.username)
operators.client.change_owner(
node.uuid, settings.username)
self.last_selection = current_selection
+7 -15
View File
@@ -9,34 +9,26 @@ import time
from operator import itemgetter
from pathlib import Path
import msgpack
import bpy
import mathutils
from bpy_extras.io_utils import ExportHelper
from bpy.app.handlers import persistent
from bpy_extras.io_utils import ExportHelper
from . import environment, presence, ui, utils, delayable
import msgpack
from . import bl_types, delayable, environment, presence, ui, utils
from .libs.replication.replication.data import ReplicatedDataFactory
from .libs.replication.replication.interface import Session
from .libs.replication.replication.exception import NonAuthorizedOperationError
from . import bl_types
from .libs.replication.replication.interface import Session
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.setLevel(logging.ERROR)
client = None
delayables = []
ui_context = None
def add_datablock(datablock):
global client
new_uuid = client.add(datablock)
return new_uuid
# TODO: cleanup
def init_supported_datablocks(supported_types_id):
global client
@@ -177,7 +169,7 @@ class SessionStopOperator(bpy.types.Operator):
client.remove(settings.user_uuid)
client.disconnect()
for d in delayables:
try:
d.unregister()
+5 -6
View File
@@ -1,13 +1,12 @@
import bpy
import bgl
import blf
import gpu
import mathutils
import copy
import logging
import math
import bgl
import blf
import bpy
import gpu
import mathutils
from bpy_extras import view3d_utils
from gpu_extras.batch import batch_for_shader
+4 -3
View File
@@ -1,8 +1,9 @@
import bpy
from . import operators
from .libs.replication.replication.constants import FETCHED, ERROR, MODIFIED, UP, ADDED, RP_COMMON
from .bl_types.bl_user import BlUser
from . import operators
from .bl_types.bl_user import BlUser
from .libs.replication.replication.constants import (ADDED, ERROR, FETCHED,
MODIFIED, RP_COMMON, UP)
ICONS_PROP_STATES = ['TRIA_DOWN', # ADDED
'TRIA_UP', # COMMITED
+12 -12
View File
@@ -1,36 +1,36 @@
import json
import logging
import os
import random
import string
import sys
from uuid import uuid4
import json
import os
import string
import random
import bpy
import mathutils
from . import presence, environment
from . import environment, presence
from .libs import dump_anything
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.setLevel(logging.ERROR)
def get_datablock_users(datablock):
users = []
supported_types = bpy.context.window_manager.session.supported_datablock
if hasattr(datablock, 'users_collection') and datablock.users_collection:
if hasattr(datablock, 'users_collection') and datablock.users_collection:
users.extend(list(datablock.users_collection))
if hasattr(datablock, 'users_scene') and datablock.users_scene:
if hasattr(datablock, 'users_scene') and datablock.users_scene:
users.extend(list(datablock.users_scene))
if hasattr(datablock, 'users_group') and datablock.users_scene:
if hasattr(datablock, 'users_group') and datablock.users_scene:
users.extend(list(datablock.users_scene))
for datatype in supported_types:
if datatype.bl_name != 'users':
root = getattr(bpy.data,datatype.bl_name)
root = getattr(bpy.data, datatype.bl_name)
for item in root:
if hasattr(item, 'data') and datablock == item.data or \
datatype.bl_name != 'collections' and hasattr(item, 'children') and datablock in item.children:
datatype.bl_name != 'collections' and hasattr(item, 'children') and datablock in item.children:
users.append(item)
return users
@@ -131,4 +131,4 @@ def dump_datablock_attibutes(datablock=None, attributes=[], depth=1, dickt=None)
except:
pass
return data
return data