feat: replicated datablock configuration
This commit is contained in:
33
__init__.py
33
__init__.py
@ -62,6 +62,7 @@ def randomColor():
|
|||||||
b = random.random()
|
b = random.random()
|
||||||
return [r, v, b]
|
return [r, v, b]
|
||||||
|
|
||||||
|
|
||||||
def save_session_config(self,context):
|
def save_session_config(self,context):
|
||||||
config = environment.load_config()
|
config = environment.load_config()
|
||||||
|
|
||||||
@ -71,8 +72,20 @@ def save_session_config(self,context):
|
|||||||
config["start_empty"] = self.start_empty
|
config["start_empty"] = self.start_empty
|
||||||
config["enable_presence"] = self.enable_presence
|
config["enable_presence"] = self.enable_presence
|
||||||
config["client_color"] = [self.client_color.r,self.client_color.g,self.client_color.b]
|
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)
|
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):
|
class SessionProps(bpy.types.PropertyGroup):
|
||||||
username: bpy.props.StringProperty(
|
username: bpy.props.StringProperty(
|
||||||
name="Username",
|
name="Username",
|
||||||
@ -120,7 +133,8 @@ class SessionProps(bpy.types.PropertyGroup):
|
|||||||
client_color: bpy.props.FloatVectorProperty(
|
client_color: bpy.props.FloatVectorProperty(
|
||||||
name="client_instance_color",
|
name="client_instance_color",
|
||||||
subtype='COLOR',
|
subtype='COLOR',
|
||||||
default=randomColor())
|
default=randomColor(),
|
||||||
|
update=save_session_config)
|
||||||
clients: bpy.props.EnumProperty(
|
clients: bpy.props.EnumProperty(
|
||||||
name="clients",
|
name="clients",
|
||||||
description="client enum",
|
description="client enum",
|
||||||
@ -132,11 +146,14 @@ class SessionProps(bpy.types.PropertyGroup):
|
|||||||
default=True,
|
default=True,
|
||||||
update=save_session_config
|
update=save_session_config
|
||||||
)
|
)
|
||||||
|
supported_datablock: bpy.props.CollectionProperty(
|
||||||
|
type=ReplicatedDatablock
|
||||||
|
)
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
config = environment.load_config()
|
config = environment.load_config()
|
||||||
logger.info(config)
|
logger.info(config)
|
||||||
if config:
|
if "username" in config:
|
||||||
self.username = config["username"]
|
self.username = config["username"]
|
||||||
self.ip = config["ip"]
|
self.ip = config["ip"]
|
||||||
self.port = config["port"]
|
self.port = config["port"]
|
||||||
@ -144,12 +161,22 @@ class SessionProps(bpy.types.PropertyGroup):
|
|||||||
self.enable_presence = config["enable_presence"]
|
self.enable_presence = config["enable_presence"]
|
||||||
self.client_color = config["client_color"]
|
self.client_color = config["client_color"]
|
||||||
else:
|
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 = {
|
classes = {
|
||||||
|
ReplicatedDatablock,
|
||||||
SessionProps,
|
SessionProps,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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")
|
THIRD_PARTY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libs")
|
||||||
PYTHON_PATH = None
|
PYTHON_PATH = None
|
||||||
SUBPROCESS_DIR = 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():
|
def load_config():
|
||||||
@ -22,7 +39,7 @@ def load_config():
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logger.info("no config")
|
logger.info("no config")
|
||||||
|
|
||||||
return {}
|
return DEFAULT_CONFIG
|
||||||
|
|
||||||
def save_config(config):
|
def save_config(config):
|
||||||
logger.info("saving config")
|
logger.info("saving config")
|
||||||
|
@ -250,7 +250,6 @@ class SessionHostOperator(bpy.types.Operator):
|
|||||||
if net_settings.init_scene:
|
if net_settings.init_scene:
|
||||||
init_datablocks()
|
init_datablocks()
|
||||||
|
|
||||||
# client_instance.init()
|
|
||||||
net_settings.is_admin = True
|
net_settings.is_admin = True
|
||||||
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
Reference in New Issue
Block a user