feat: replicated datablock configuration

This commit is contained in:
Swann Martinez
2019-07-02 15:55:57 +02:00
parent 2b7f40942b
commit 3f834d0828
3 changed files with 54 additions and 11 deletions

View File

@ -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,
}

View File

@ -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")

View File

@ -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"}