feat: factory construction
This commit is contained in:
parent
5dcf2f4230
commit
fefa7ec13e
@ -8,10 +8,3 @@ from ..libs.replication.data import ReplicatedDataFactory
|
|||||||
def types_to_register():
|
def types_to_register():
|
||||||
return __all__
|
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)
|
|
@ -31,8 +31,9 @@ class BlObject(ReplicatedDatablock):
|
|||||||
|
|
||||||
target.matrix_world = mathutils.Matrix(data["matrix_world"])
|
target.matrix_world = mathutils.Matrix(data["matrix_world"])
|
||||||
|
|
||||||
def dump(self, source):
|
def dump(self, pointer=None):
|
||||||
return utils.dump_datablock(source, 1)
|
assert(pointer)
|
||||||
|
return utils.dump_datablock(pointer, 1)
|
||||||
|
|
||||||
|
|
||||||
bl_id = "objects"
|
bl_id = "objects"
|
||||||
|
44
operators.py
44
operators.py
@ -17,7 +17,7 @@ from . import environment, presence, ui, utils
|
|||||||
from .libs import umsgpack
|
from .libs import umsgpack
|
||||||
from .libs.replication.data import ReplicatedDataFactory
|
from .libs.replication.data import ReplicatedDataFactory
|
||||||
from .libs.replication.interface import Client
|
from .libs.replication.interface import Client
|
||||||
from .bl_types import bl_types_factory
|
from . import bl_types
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -88,11 +88,13 @@ execution_queue = queue.Queue()
|
|||||||
# client.set(client_key, client_data[0][1])
|
# client.set(client_key, client_data[0][1])
|
||||||
|
|
||||||
# TODO: cleanup
|
# TODO: cleanup
|
||||||
def init_supported_datablocks(client, suported_types):
|
def init_supported_datablocks(supported_types_id):
|
||||||
for type in suported_types:
|
global client
|
||||||
for block in bpy.data[type.bl_idname]:
|
|
||||||
print(block)
|
for type_id in supported_types_id:
|
||||||
|
for item in getattr(bpy.data,type_id):
|
||||||
|
print(item)
|
||||||
|
client.register(item)
|
||||||
|
|
||||||
|
|
||||||
# def default_tick():
|
# def default_tick():
|
||||||
@ -140,31 +142,33 @@ class SessionStartOperator(bpy.types.Operator):
|
|||||||
# if settings.start_empty:
|
# if settings.start_empty:
|
||||||
# clean_scene()
|
# clean_scene()
|
||||||
|
|
||||||
# Setup data factory
|
bpy_factory = ReplicatedDataFactory()
|
||||||
|
supported_bl_types = []
|
||||||
|
|
||||||
|
# init the factory with supported types
|
||||||
|
for type in bl_types.types_to_register():
|
||||||
|
_type = getattr(bl_types,type)
|
||||||
|
supported_bl_types.append(_type.bl_id)
|
||||||
|
bpy_factory.register_type(_type.bl_class,_type.bl_rep_class)
|
||||||
|
|
||||||
# bpy_factory.register_type(bpy.types.Object,bl_object)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Setup client
|
|
||||||
client = Client(factory=bpy_factory)
|
client = Client(factory=bpy_factory)
|
||||||
|
|
||||||
if settings.init_scene:
|
|
||||||
init_supported_datablocks(client,["objects"])
|
|
||||||
|
|
||||||
if self.host:
|
if self.host:
|
||||||
client.host(
|
client.host(
|
||||||
id=settings.username,
|
id=settings.username,
|
||||||
address=settings.ip,
|
address=settings.ip,
|
||||||
port=settings.port
|
port=settings.port
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if settings.init_scene:
|
||||||
|
init_supported_datablocks(supported_bl_types)
|
||||||
else:
|
else:
|
||||||
client.connect(
|
client.connect(
|
||||||
id=settings.username,
|
id=settings.username,
|
||||||
address=settings.ip,
|
address=settings.ip,
|
||||||
port=settings.port
|
port=settings.port
|
||||||
)
|
)
|
||||||
|
|
||||||
# settings.is_running = True
|
# settings.is_running = True
|
||||||
# bpy.ops.session.refresh()
|
# bpy.ops.session.refresh()
|
||||||
@ -384,7 +388,7 @@ def unregister():
|
|||||||
|
|
||||||
presence.unregister()
|
presence.unregister()
|
||||||
|
|
||||||
if client:
|
if client and client.state == 2:
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
client = None
|
client = None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user