コード例 #1
0
        private void Start()
        {
            _gem = _locator.GetService <IEntityManager>();
            _map = _locator.GetService <IHexMap>();

            _inputMachine = new InputStateMachine();
            _inputMachine.SetState(null);

            var input = _locator.GetService <IGameInputManager>();

            input.RegisterProcessor(_inputMachine);

            _jconverter = _locator.GetService <IJsonConverter>();
            _jobManager = _locator.GetService <IJobManager>();
            _networker  = _locator.GetService <INetworker>();

            var networkDataHandler = new Dictionary <EventCode, Action <string> >();

            _networker.DataReceived += (code, data) =>
            {
                if (networkDataHandler.ContainsKey(code))
                {
                    networkDataHandler[code].Invoke(data);
                }
                else
                {
                    Debug.Log($"[GameManager] unhandeled event code received: {code}\n{data}");
                }
            };

            networkDataHandler.Add(EventCode.GameStart, MakeHandlerBridge <GameConfiguration>(StartGame));
            networkDataHandler.Add(EventCode.GameAbort, MakeHandlerBridge <GameAbortData>(GameAborted));
            networkDataHandler.Add(EventCode.StartTurn, MakeHandlerBridge <StartTurnData>(StartNextTurn));
            networkDataHandler.Add(EventCode.DoJob, MakeHandlerBridge <IJob>(OnDoJob));
        }
コード例 #2
0
        public static void Sync(INetworker networker)
        {
            // For now, allowing both sides to push. This behaviour needs to be replaced in general anyways
            if (networker.Hosting || true)
            {
                var save = Scene.Current.FindComponent <GamePieces>()?.GetSave();

                if (!save.HasValue || save.Value.Res == null)
                {
                    Logs.Game.WriteWarning("Attempted to sync, but no gave save found.");
                    OldContext.ShowNotification("Error", "Failed to start sync.", 3);
                }
                else
                {
                    SendSave(networker, save.Value.Res);
                    OldContext.ShowNotification("Info", "Sync started.", 3);
                }
            }

            else if (networker.Connected)
            {
                networker.SendData(CommandChannel, "Sync");
                OldContext.ShowNotification("Info", "Sync requested.", 3);
            }

            else
            {
                Logs.Game.WriteWarning($"Cannot try to sync while {networker.Status.ToString().ToLower()}");
            }
        }
コード例 #3
0
ファイル: MainWindow.cs プロジェクト: kruzifix/Klaesh-Proto
        protected override void Init()
        {
            _networker            = _locator.GetService <INetworker>();
            _networker.Connected += OnConnection;

            ConnectGroup.SetActive(true);
            StatusGroup.SetActive(false);

            AddSubscription(_bus.Subscribe <GameStartedMessage>(OnGameStarted));
        }
コード例 #4
0
 private static void SendSave(INetworker networker, Save save)
 {
     using (var stream = new MemoryStream())
     {
         Serializer.WriteObject(save, stream);
         // This seems a bit silly. Is there a better way to get a string from Duality's Serialization?
         // Especially since UTF8 is a reasonable guess, not a guarantee.
         networker.SendData(SaveChannel, Encoding.UTF8.GetString(stream.ToArray()));
     }
 }
コード例 #5
0
        public static void SendSpin(INetworker networker, float targetAngle, string name)
        {
            if (!networker.Connected)
            {
                return;
            }

            using (var stream = new MemoryStream())
            {
                Serializer.WriteObject(new SpinMessage
                {
                    Name  = name,
                    Angle = targetAngle
                }, stream);

                networker.SendData(SpinChannel, Encoding.UTF8.GetString(stream.ToArray()));
            }
        }
コード例 #6
0
        public static void SendMovement(INetworker networker, DragAction action, string name, Vector3?pos = null)
        {
            if (!networker.Connected)
            {
                return;
            }

            using (var stream = new MemoryStream())
            {
                Serializer.WriteObject(new DragMessage {
                    Action = action,
                    Name   = name,
                    Pos    = pos
                }, stream);

                networker.SendData(DragChannel, Encoding.UTF8.GetString(stream.ToArray()));
            }
        }
コード例 #7
0
        public static void SendDiceRoll(INetworker networker, string diceID, float time, int side)
        {
            if (!networker.Connected)
            {
                return;
            }

            using (var stream = new MemoryStream())
            {
                Serializer.WriteObject(new DiceMessage
                {
                    Time   = time,
                    DiceID = diceID,
                    Side   = side
                }, stream);

                networker.SendData(DiceChannel, Encoding.UTF8.GetString(stream.ToArray()));
            }
        }
コード例 #8
0
        public static void ParseIncomingData(INetworker networker, DataRecievedEventArgs e)
        {
            if (e.Channel == CommandChannel)
            {
                Logs.Game.Write("Command Recieved: " + e.Data);

                if (e.Data == "Sync")
                {
                    if (!networker.Hosting)
                    {
                        Logs.Game.WriteWarning($"Recived a Sync command while {networker.Status.ToString().ToLower()}");
                    }

                    else
                    {
                        Sync(networker);
                    }
                }
            }

            else if (e.Channel == SaveChannel)
            {
                ParseIncomingSave(e);
            }

            else if (e.Channel == DragChannel)
            {
                ParseIncomingDragMessage(e);
            }

            else if (e.Channel == DiceChannel)
            {
                ParseIncomingDiceMessage(e);
            }

            else if (e.Channel == SpinChannel)
            {
                ParseIncomingSpinMessage(e);
            }
        }
コード例 #9
0
 public View(INetworker networkComponent, IRenderer rendererComponent)
 {
     this._networkComponent  = networkComponent;
     this._rendererComponent = rendererComponent;
 }