This commit is contained in:
Swann
2019-02-08 18:34:10 +01:00
parent c86953eb75
commit ead3189b0c
5 changed files with 190 additions and 60 deletions

View File

@ -3,12 +3,32 @@ from . import net_components
session = None
class join(bpy.types.Operator):
bl_idname = "session.join"
bl_label = "connect to net session"
bl_label = "join"
bl_description = "Connect to a net session"
bl_options = {"REGISTER"}
@classmethod
def poll(cls, context):
return True
def execute(self, context):
# global session
if session.join():
bpy.ops.asyncio.loop()
else:
print('fail to create session, avorting loop')
return {"FINISHED"}
class create(bpy.types.Operator):
bl_idname = "session.create"
bl_label = "create"
bl_description = "create to a net session"
bl_options = {"REGISTER"}
@classmethod
def poll(cls, context):
@ -17,31 +37,17 @@ class join(bpy.types.Operator):
def execute(self, context):
global session
session = net_components.Session()
bpy.ops.asyncio.loop()
if session.create():
bpy.ops.asyncio.loop()
else:
print('fail to create session, avorting loop')
return {"FINISHED"}
class host(bpy.types.Operator):
bl_idname = "session.host"
bl_label = "host a net session"
bl_description = "Connect to a net session"
bl_options = {"REGISTER"}
@classmethod
def poll(cls, context):
return True
def execute(self, context):
global session
session = net_components.Session(is_hosting=True)
bpy.ops.asyncio.loop()
return {"FINISHED"}
class send(bpy.types.Operator):
bl_idname = "session.send"
bl_label = "Send a message throught the network"
bl_label = "Send"
bl_description = "Connect to a net session"
bl_options = {"REGISTER"}
@ -54,12 +60,13 @@ class send(bpy.types.Operator):
def execute(self, context):
global session
session.send(b"")
session.send(self.message)
return {"FINISHED"}
class close(bpy.types.Operator):
bl_idname = "session.close"
bl_label = "Send a message throught the network"
bl_label = "Close session"
bl_description = "Connect to a net session"
bl_options = {"REGISTER"}
@ -70,18 +77,33 @@ class close(bpy.types.Operator):
def execute(self, context):
global session
bpy.ops.asyncio.stop()
session.close()
bpy.ops.asyncio.stop()
return {"FINISHED"}
classes = (
join,
host,
send
create,
close,
send,
)
register, unregister = bpy.utils.register_classes_factory(classes)
def register():
global session
session = net_components.Session()
from bpy.utils import register_class
for cls in classes:
register_class(cls)
def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes):
unregister_class(cls)
if __name__ == "__main__":
register()
register()