feat: library support ground work

This commit is contained in:
Swann Martinez 2019-08-29 18:23:29 +02:00
parent 8c1ef3434a
commit fd4d0d2398
No known key found for this signature in database
GPG Key ID: 414CCAFD8DA720E1
6 changed files with 82 additions and 5 deletions

View File

@ -10,6 +10,7 @@ __all__ = [
'bl_light',
'bl_scene',
'bl_material',
'bl_library',
] # Order here defines execution order
from . import *

View File

@ -3,15 +3,50 @@ import mathutils
from .. import utils
from ..libs.replication.replication.data import ReplicatedDatablock
from ..libs.replication.replication.constants import UP
class BlDatablock(ReplicatedDatablock):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
pointer = kwargs.get('pointer', None)
buffer = self.buffer
if (pointer and hasattr(pointer, 'library') and
pointer.library) or \
(buffer and 'library' in buffer):
self.load = self.load_library
self.dump = self.dump_library
self.construct = self.construct_library
self.diff = self.diff_library
self.resolve_dependencies = self.resolve_dependencies_library
self.apply = self.library_apply
if self.pointer and hasattr(self.pointer, 'uuid'):
self.pointer.uuid = self.uuid
def library_apply(self):
"""Apply stored data
"""
# UP in case we want to reset our pointer data
self.state = UP
def bl_diff(self):
"""Generic datablock diff"""
return self.pointer.name != self.buffer['name']
def construct_library(self, data):
return None
def load_library(self, data, target):
pass
def dump_library(self, pointer=None):
return utils.dump_datablock(pointer, 1)
def diff_library(self):
return False
def resolve_dependencies_library(self):
return [self.pointer.library]

35
bl_types/bl_library.py Normal file
View File

@ -0,0 +1,35 @@
import bpy
import mathutils
from jsondiff import diff
from .. import utils
from .bl_datablock import BlDatablock
class BlLibrary(BlDatablock):
def construct(self, data):
with bpy.data.libraries.load(filepath=data["filepath"], link=True) as (sourceData, targetData):
targetData = sourceData
return sourceData
def load(self, data, target):
pass
def dump(self, pointer=None):
assert(pointer)
return utils.dump_datablock(pointer, 1)
def resolve(self):
assert(self.buffer)
self.pointer = bpy.data.libraries.get(self.buffer['name'])
def diff(self):
return (self.bl_diff())
bl_id = "libraries"
bl_class = bpy.types.Library
bl_rep_class = BlLibrary
bl_delay_refresh = 1
bl_delay_apply = 1
bl_automatic_push = True
bl_icon = 'LIBRARY_DATA_DIRECT'

View File

@ -10,11 +10,11 @@ from ..libs.debug import draw_point
class BlUser(BlDatablock):
def __init__(self, *args, **kwargs):
super().__init__( *args, **kwargs)
# def __init__(self, *args, **kwargs):
# super().__init__( *args, **kwargs)
if self.buffer:
self.load(self.buffer, self.pointer)
# if self.buffer:
# self.load(self.buffer, self.pointer)
def construct(self, name):
return presence.User()

@ -1 +1 @@
Subproject commit 71f0b9832e280db7c206c4d693ab788aba45eb93
Subproject commit 3c2e5fe77338142ed3feab64ad66a75dd82ac17e

View File

@ -132,9 +132,15 @@ class SessionStartOperator(bpy.types.Operator):
delayables.append(delayable.ClientUpdate(
client_uuid=settings.user_uuid))
for node in client.list():
try:
client.commit(node)
except:
continue
# Push all added values
client.push()
# Launch drawing module
if settings.enable_presence:
presence.renderer.run()