feat: automatic type implementation registering

This commit is contained in:
Swann Martinez
2019-08-08 11:43:12 +02:00
parent 318f99967d
commit 5dcf2f4230
5 changed files with 49 additions and 82 deletions
+1 -1
View File
@@ -110,7 +110,7 @@ class SessionProps(bpy.types.PropertyGroup):
buffer: bpy.props.StringProperty(name="None")
is_admin: bpy.props.BoolProperty(name="is_admin", default=False)
load_data: bpy.props.BoolProperty(name="load_data", default=True)
init_scene: bpy.props.BoolProperty(name="load_data", default=True)
init_scene: bpy.props.BoolProperty(name="init_scene", default=True)
start_empty: bpy.props.BoolProperty(
name="start_empty",
default=False,
+17
View File
@@ -0,0 +1,17 @@
__all__ = [
'bl_object',
] # Order here defines execution order
from . import *
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)
@@ -1,9 +1,10 @@
from libs.replication.data import ReplicatedDatablock
import bpy
import mathutils
import utils
class RepObject(ReplicatedDatablock):
from .. import utils
from ..libs.replication.data import ReplicatedDatablock
class BlObject(ReplicatedDatablock):
def load(self, data, target):
if target is None:
pointer = None
@@ -31,4 +32,10 @@ class RepObject(ReplicatedDatablock):
target.matrix_world = mathutils.Matrix(data["matrix_world"])
def dump(self, source):
return utils.dump_datablock(source, 1)
return utils.dump_datablock(source, 1)
bl_id = "objects"
bl_class = bpy.types.Object
bl_rep_class = BlObject
+20 -77
View File
@@ -1,23 +1,23 @@
import asyncio
import logging
import os
import queue
import random
import string
import subprocess
import time
import queue
from operator import itemgetter
from pathlib import Path
import bpy
from bpy_extras.io_utils import ExportHelper
import mathutils
from pathlib import Path
from bpy_extras.io_utils import ExportHelper
from . import environment, presence, ui, utils
from .libs import umsgpack
from .libs.replication.interface import Client
from .libs.replication.data import ReplicatedDataFactory
from .libs.replication.interface import Client
from .bl_types import bl_types_factory
logger = logging.getLogger(__name__)
@@ -88,13 +88,11 @@ execution_queue = queue.Queue()
# client.set(client_key, client_data[0][1])
# TODO: cleanup
# def init_datablocks():
# for datatype in environment.rtypes:
# if bpy.context.window_manager.session.supported_datablock[datatype].is_replicated:
# for item in getattr(bpy.data, utils.BPY_TYPES[datatype]):
# item.id = bpy.context.window_manager.session.username
# key = "{}/{}".format(datatype, item.name)
# client.set(key)
def init_supported_datablocks(client, suported_types):
for type in suported_types:
for block in bpy.data[type.bl_idname]:
print(block)
# def default_tick():
@@ -139,15 +137,22 @@ class SessionStartOperator(bpy.types.Operator):
settings.save(context)
# Scene setup
if settings.start_empty:
clean_scene()
# if settings.start_empty:
# clean_scene()
# Setup data factory
bpy_factory = ReplicatedDataFactory()
# 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,
@@ -366,68 +371,6 @@ classes = (
SessionSaveConfig,
)
"""
def get_datablock_from_update(update,context):
item_type = update.id.__class__.__name__
item_id = update.id.name
datablock_ref = None
if item_id == 'Master Collection':
datablock_ref= bpy.context.scene
elif item_type in utils.BPY_TYPES.keys():
datablock_ref = getattr(bpy.data, utils.BPY_TYPES[update.id.__class__.__name__])[update.id.name]
else:
if item_id in bpy.data.lights.keys():
datablock_ref = bpy.data.lights[item_id]
return datablock_ref
def depsgraph_update(scene):
ctx = bpy.context
if client and client.state() == 3:
if ctx.mode in ['OBJECT','PAINT_GPENCIL']:
updates = ctx.view_layer.depsgraph.updates
username = ctx.window_manager.session.username
selected_objects = utils.get_selected_objects(scene)
for update in reversed(updates):
if is_replicated(update):
if update.id.id == username or update.id.id == 'Common':
toogle_update_dirty(ctx, update)
else:
item = get_datablock_from_update(update,ctx)
# get parent authority
if hasattr(item,"id"):
parent_id = ctx.collection.id if ctx.collection.id != 'None' else ctx.scene.id
if parent_id == username or parent_id == 'Common':
item.id = username
item_type = item.__class__.__name__
if 'Light'in item.__class__.__name__:
item_type = 'Light'
key = "{}/{}".format(item_type , item.name)
client.set(key)
else:
try:
getattr(bpy.data, utils.BPY_TYPES[update.id.__class__.__name__]).remove(item)
except:
pass
break
update_client_selected_object(ctx)
"""
def register():
from bpy.utils import register_class
for cls in classes:
View File