Beispiel #1
0
        public ReconnectionManager(AutoController scene)
        {
            this.scene = scene;
            tickHelper = new TickingJanitor(scene.Game, this);
            scene.ActivatableList.Add(tickHelper);

            state = scene.Components.GetOrRegister <StateMachine>((int)ComponentKeys.ReconnectionState, StateMachine.Create);
            state.EnterStateMessenger.Subscribe(new SimpleListener <int>((s) => UnityEngine.Debug.LogError(
                                                                             string.Format("{1}: Reconnection state: {0}", (ReconnectionState)s, scene.Game.TickCount))));

            connHelper           = scene.Game.Components.Get <ConnectionHelper>((int)ComponentKeys.ConnectionHelper);
            sendGameState        = scene.Game.Components.Get <Command <NetworkGameState> >((int)ComponentKeys.LoadingGameStateSend);
            stopRefreshGameState = scene.Game.Components.Get <Command>((int)ComponentKeys.LoadingGameStateStopRefreshing);
            sendReady            = scene.Game.Components.Get <Command <bool> >((int)ComponentKeys.LoadingReadySend);
            newBoardMessage      = scene.Components.GetOrRegister((int)ComponentKeys.BoardCreatedMessage, Message <Board> .Create);
            compileGameState     = scene.Components.GetOrRegister <Query <NetworkGameState> >
                                       ((int)ComponentKeys.CompileCurrentGameState, Query <NetworkGameState> .Create);
            createBoard = scene.Components.GetOrRegister <Query <Board, NetworkGameState> >
                              ((int)ComponentKeys.CreateBoardCommand, Query <Board, NetworkGameState> .Create);
            exitToLobby = scene.Components.GetOrRegister <Command>((int)ComponentKeys.EndScreenExitPressed, Command.Create);

            scene.ActivatableList.Add(new ListenerJanitor <IListener <NetworkGameState> >(
                                          scene.Game.Components.Get <IMessage <NetworkGameState> >((int)ComponentKeys.LoadingGameStateReceived),
                                          new SimpleListener <NetworkGameState>(OnReconnectionReplyReceived)));
            scene.ActivatableList.Add(new ListenerJanitor <IListener>(
                                          scene.Game.Components.Get <IMessage>((int)ComponentKeys.LoadingExitReceived),
                                          new SimpleListener(OnAllReadyReceived)));
            scene.ActivatableList.Add(new ListenerJanitor <IListener>(
                                          scene.Game.Components.Get <IMessage>((int)ComponentKeys.LoadingErrorReceived),
                                          new SimpleListener(OnErrorReceived)));

            GameDatabase db = scene.Game.Components.Get <GameDatabase>((int)ComponentKeys.GameDatabase);

            connHelper.SetGameInProgress(true);
            connHelper.WriteRejoinFile(db.ModFolder);
            scene.ActivatableList.Add(new ListenerJanitor <IListener <int> >(
                                          connHelper.Connection.EnterStateMessenger,
                                          new SimpleListener <int>((s) => CheckConnection())));

            state.State = (int)ReconnectionState.FirstCheck;
            state.EnterStateMessenger.Subscribe(new SimpleListener <int>((s) => OnStateChange()));

            scene.Components.GetOrRegister <Message <GameEndType> >((int)ComponentKeys.GameEnd, Message <GameEndType> .Create)
            .Subscribe(new SimpleListener <GameEndType>(OnGameEnd));
        }
Beispiel #2
0
        public TurnChooser(ChessScene scene)
        {
            //scene.Components.GetOrRegister<Message<Board>>((int)ComponentKeys.BoardCreatedMessage, Message<Board>.Create)
            //    .Subscribe(new SimpleListener<Board>((b) => board = b));
            //db = scene.Game.Components.Get<GameDatabase>((int)ComponentKeys.GameDatabase);

            tickHelper = new TickingJanitor(scene.Game, this);
            tickHelper.ForceInactive = true;
            scene.ActivatableList.Add(tickHelper);

            states = scene.Components.GetOrRegister <StateMachine>((int)ComponentKeys.TurnChooserState, StateMachine.Create);
            states.EnterStateMessenger.Subscribe(new SimpleListener <int>((s) => OnEnterChoosingState()));

            backBtn = scene.Components.GetOrRegister <SubscribableBool>((int)ComponentKeys.PlayerSelectionCancelBtn, SubscribableBool.Create);
            backBtn.Subscribe(new TriggerListener(OnBackBtnTrigger));
            choiceMadeEvent = scene.Components.GetOrRegister <Message <TurnAction> >((int)ComponentKeys.MoveChoiceMadeEvent, Message <TurnAction> .Create);
            chosenPiece     = scene.Components.GetOrRegister <SubscribableInt>((int)ComponentKeys.TurnChooserChosenPiece, SubscribableInt.Create);
            chosenPiece.Subscribe(new SimpleListener <int>(OnPieceChosen));
            chosenAction = scene.Components.GetOrRegister <SubscribableObject <TurnAction> >
                               ((int)ComponentKeys.TurnChooserChosenAction, SubscribableObject <TurnAction> .Create);
            chosenAction.Subscribe(new SimpleListener <TurnAction>(OnActionChosen));

            scene.Components.GetOrRegister <Command>((int)ComponentKeys.StartTurnChoosingCommand, Command.Create)
            .Handler = ChoosingStartCommand;
            scene.Components.GetOrRegister <Command>((int)ComponentKeys.StopTurnChoosingCommand, Command.Create)
            .Handler = ChoosingStopCommand;
            scene.Components.GetOrRegister <Command>((int)ComponentKeys.ForfeitGame, Command.Create)
            .Handler = ForfeitGameCommand;

            requestSendAction = scene.Game.Components.Get <Command <TurnAction> >((int)ComponentKeys.SendTurnAction);

            connectionState = scene.Components.GetOrRegister <StateMachine>((int)ComponentKeys.ReconnectionState, StateMachine.Create);
            connectionState.EnterStateMessenger.Subscribe(new SimpleListener <int>((s) => OnConnectionStateChange()));

            new PieceChooser(scene);
            new BoardSpaceChooser(scene);
        }
 public ReadyCheckSender(Game game, float resendPeriod, Action <bool> callback)
 {
     this.resendPeriod = resendPeriod;
     this.callback     = callback;
     tickHelper        = new TickingJanitor(game, this);
 }
        public TurnOrderSelectionController(AutoController scene)
        {
            tickHelper        = new TickingJanitor(scene.Game, this);
            tickHelper.Active = false;

            ComponentRegistry guiComps = scene.Components.Get <ComponentRegistry>((int)ComponentKeys.LobbyGUIMessages);

            btnsInteractable       = guiComps.GetOrRegister <SubscribableBool>((int)GUICompKeys.TOSInteractable, SubscribableBool.Create);
            btnsInteractable.Value = true;

            toggleValues    = new SubscribableBool[3];
            toggleValues[0] = new SubscribableBool(false);
            guiComps.Register((int)GUICompKeys.TOSOpt1Set, toggleValues[0]);
            toggleValues[1] = new SubscribableBool(false);
            guiComps.Register((int)GUICompKeys.TOSOpt2Set, toggleValues[1]);
            toggleValues[2] = new SubscribableBool(false);
            guiComps.Register((int)GUICompKeys.TOSOpt3Set, toggleValues[2]);

            Message <bool>[] toggleChanges = new Message <bool> [3];
            toggleChanges[0] = new Message <bool>();
            guiComps.Register((int)GUICompKeys.TOSOpt1Change, toggleChanges[0]);
            toggleChanges[1] = new Message <bool>();
            guiComps.Register((int)GUICompKeys.TOSOpt2Change, toggleChanges[1]);
            toggleChanges[2] = new Message <bool>();
            guiComps.Register((int)GUICompKeys.TOSOpt3Change, toggleChanges[2]);
            for (int i = 0; i < toggleChanges.Length; i++)
            {
                int index = i;
                toggleChanges[i].Subscribe(new SimpleListener <bool>((v) => OnToggleChange(index, v)));
            }

            choiceBtnIndex = new Dictionary <LobbyTurnOrderChoice, int>();
            choiceBtnIndex[LobbyTurnOrderChoice.HostIsFirst]   = 0;
            choiceBtnIndex[LobbyTurnOrderChoice.ClientIsFirst] = 1;
            choiceBtnIndex[LobbyTurnOrderChoice.Random]        = 2;
            choiceBtnIndex[LobbyTurnOrderChoice.None]          = -1;

            otherSelLabel = new SubscribableObject <string>("");
            guiComps.Register((int)GUICompKeys.TOSOtherSelectionLabel, otherSelLabel);
            otherSelValue = new SubscribableObject <string>("");
            guiComps.Register((int)GUICompKeys.TOSOtherSelectionValue, otherSelValue);

            allowTogglesOff = new SubscribableBool(false);
            guiComps.Register((int)GUICompKeys.TOSAllowAllTogglesOff, allowTogglesOff);

            prevChoices = scene.Game.Components.Get <LobbyChoices>((int)ComponentKeys.LobbyChoices);

            selected = new SubscribableInt(0);
            //scene.SceneComponents.Register((int)ComponentKeys.LobbyTurnOrderSelected, selected);

            initStatus = scene.Components.GetOrRegister <StateMachine>((int)ComponentKeys.LobbyInitStatus, StateMachine.Create);
            initStatus.EnterStateMessenger.Subscribe(new SimpleListener <int>((s) => InitStatusChange()));

            reqSendPick = scene.Game.Components.Get <Command <LobbyTurnOrderChoice> >((int)ComponentKeys.LobbyTurnOrderChoiceNotify);
            scene.ActivatableList.Add(new ListenerJanitor <IListener <LobbyTurnOrderChoice> >(
                                          scene.Game.Components.Get <IMessage <LobbyTurnOrderChoice> >((int)ComponentKeys.LobbyTurnOrderChoiceReceived),
                                          new SimpleListener <LobbyTurnOrderChoice>(OnNetworkPickReceived)));

            readyStatus = scene.Components.GetOrRegister <SubscribableBool>((int)ComponentKeys.LobbyReadyStatus, SubscribableBool.Create);
            readyStatus.Subscribe(new SimpleListener <bool>((v) => OnReadyStatusChange()));

            screen = scene.Components.Get <StateMachine>((int)ComponentKeys.LobbyScreen);
            screen.EnterStateMessenger.Subscribe(new SimpleListener <int>((s) => {
                isHost = s == (int)LobbyScreen.HostGamePrefs;
                if (s == (int)LobbyScreen.HostGamePrefs || s == (int)LobbyScreen.ClientGamePrefs)
                {
                    ScreenEnter();
                }
            }));
        }