From 3f834d0828bf5ca1f90e496a6e035e95df5b9ddf Mon Sep 17 00:00:00 2001 From: Swann Martinez Date: Tue, 2 Jul 2019 15:55:57 +0200 Subject: [PATCH] feat: replicated datablock configuration --- __init__.py | 43 +++++++++++++++++++++++++++++++++++-------- environment.py | 21 +++++++++++++++++++-- operators.py | 1 - 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/__init__.py b/__init__.py index cf47430..8210080 100644 --- a/__init__.py +++ b/__init__.py @@ -16,7 +16,7 @@ import string import sys import os import bpy -from . import environment +from . import environment DEPENDENCIES = { @@ -62,17 +62,30 @@ def randomColor(): b = random.random() return [r, v, b] + def save_session_config(self,context): config = environment.load_config() - config["username"] = self.username + config["username"] = self.username config["ip"] = self.ip - config["port"] = self.port - config["start_empty"] = self.start_empty - config["enable_presence"] = self.enable_presence + config["port"] = self.port + config["start_empty"] = self.start_empty + config["enable_presence"] = self.enable_presence config["client_color"] = [self.client_color.r,self.client_color.g,self.client_color.b] + + rep_type = {} + for bloc in self.supported_datablock: + rep_type[bloc.id] = bloc.is_replicated + + config["replicated_types"] = rep_type + environment.save_config(config) +class ReplicatedDatablock(bpy.types.PropertyGroup): + '''name = StringProperty() ''' + id = bpy.props.StringProperty() + is_replicated = bpy.props.BoolProperty() + class SessionProps(bpy.types.PropertyGroup): username: bpy.props.StringProperty( name="Username", @@ -120,7 +133,8 @@ class SessionProps(bpy.types.PropertyGroup): client_color: bpy.props.FloatVectorProperty( name="client_instance_color", subtype='COLOR', - default=randomColor()) + default=randomColor(), + update=save_session_config) clients: bpy.props.EnumProperty( name="clients", description="client enum", @@ -132,11 +146,14 @@ class SessionProps(bpy.types.PropertyGroup): default=True, update=save_session_config ) + supported_datablock: bpy.props.CollectionProperty( + type=ReplicatedDatablock + ) def load(self): config = environment.load_config() logger.info(config) - if config: + if "username" in config: self.username = config["username"] self.ip = config["ip"] self.port = config["port"] @@ -144,12 +161,22 @@ class SessionProps(bpy.types.PropertyGroup): self.enable_presence = config["enable_presence"] self.client_color = config["client_color"] else: - logger.error("Fail to read config") + logger.error("Fail to read user config") + + for datablock, enabled in config["replicated_types"].items(): + rep_value = self.supported_datablock.add() + rep_value.id = datablock + rep_value.is_replicated = enabled + + + classes = { + ReplicatedDatablock, SessionProps, + } diff --git a/environment.py b/environment.py index 1bfb1c7..c22816c 100644 --- a/environment.py +++ b/environment.py @@ -13,6 +13,23 @@ CONFIG = os.path.join(CONFIG_DIR, "app.yaml") THIRD_PARTY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libs") PYTHON_PATH = None SUBPROCESS_DIR = None +DEFAULT_CONFIG = { + "replicated_types" : { + 'Client':True, + 'Texture':True, + 'Curve':True, + 'Material':True, + 'Light':True, + 'Camera':True, + 'Mesh':True, + 'Armature':True, + 'GreasePencil':True, + 'Object':True, + 'Action':True, + 'Collection':True, + 'Scene':True + } + } def load_config(): @@ -21,8 +38,8 @@ def load_config(): return yaml.safe_load(config_file) except FileNotFoundError: logger.info("no config") - - return {} + + return DEFAULT_CONFIG def save_config(config): logger.info("saving config") diff --git a/operators.py b/operators.py index 4327dfc..fc35907 100644 --- a/operators.py +++ b/operators.py @@ -250,7 +250,6 @@ class SessionHostOperator(bpy.types.Operator): if net_settings.init_scene: init_datablocks() - # client_instance.init() net_settings.is_admin = True return {"FINISHED"}