コード例 #1
0
        public override void Parse(BBGameState gameState)
        {
            this.gameState     = gameState;
            recordedRegexMatch = lastUpdateMatches.Match(gameState.lastUpdate);

            // presence of group 1 means we have multiple bases scoring
            // absence means it was a solo
            if (recordedRegexMatch.Groups.Count == 2)
            {
                scores = System.Convert.ToInt32(recordedRegexMatch.Groups[1].Value);
            }
        }
コード例 #2
0
    internal void ResetPlate(BBAbstractPlay play)
    {
        BBGameState state = play.gameState;

        majorItemsChiron.SetText(state.lastUpdate);
        majorItemsChiron.SetStrikes(state.atBatStrikes);
        majorItemsChiron.SetBalls(state.atBatBalls);
        majorItemsChiron.SetOuts(state.halfInningOuts);
        majorItemsChiron.ShowBase1(Array.IndexOf(state.basesOccupied, 0) > -1);
        majorItemsChiron.ShowBase2(Array.IndexOf(state.basesOccupied, 1) > -1);
        majorItemsChiron.ShowBase3(Array.IndexOf(state.basesOccupied, 2) > -1);
    }
コード例 #3
0
ファイル: GameRunner.cs プロジェクト: KaynSD/bbTV
        public void AddGameUpdate(BBGameState newUpdateState)
        {
            string id = newUpdateState.id;

            if (!Games.ContainsKey(id))
            {
                Games[id] = new BBGame(id);
            }

            BBGame gameToUpdate = Games[id];

            gameToUpdate.AddUpdate(newUpdateState);
        }
コード例 #4
0
ファイル: GameViewer.cs プロジェクト: KaynSD/bbTV
 private void RewindToPoint(int value)
 {
     historicalPlaybackCurrentIndex = value;
     if (historicalPlaybackCurrentIndex != game.HistoryLength)
     {
         BBGameState state = game.GetUpdate(value);
         if (state != null)
         {
             LogUpdate(state);
             ReadyToProcessNewPlay = true;
         }
     }
 }
コード例 #5
0
ファイル: ScoringPanel.cs プロジェクト: KaynSD/bbTV
    public void Setup(BBGameState gameState, bool animateScore = false)
    {
        SetTopOfInnings(gameState.gameComplete ? false : gameState.topOfInning);
        SetBottomOfInnings(gameState.gameComplete ? false :!gameState.topOfInning);
        SetHomeScore(gameState.homeScore);
        SetAwayScore(gameState.awayScore);
        SetMessage($"{gameState.inning + 1} INNING");

        if (firstTime)
        {
            StartCoroutine(SetupImagesCoroutine(gameState.homeTeam, gameState.awayTeam));
            firstTime = false;
        }
    }
コード例 #6
0
ファイル: TitleScreen.cs プロジェクト: KaynSD/bbTV
    private void RefreshDisplay()
    {
        currentGames.RemoveAll(x => x == null);

        foreach (KeyValuePair <string, BBGame> currentGame in gameRunner.Games)
        {
            string gameID = currentGame.Value.GameID;
            if (currentGames.Find(x => x.GameID == gameID))
            {
                continue;
            }

            BBGameState state = currentGame.Value.current;

            GameButtonBehaviour.GameType gametype = GameButtonBehaviour.GameType.FORECAST;
            if (state.gameComplete)
            {
                gametype = GameButtonBehaviour.GameType.HISTORICAL;
            }
            else if (state.gameStart)
            {
                gametype = GameButtonBehaviour.GameType.CURRENT;
            }

            GameObject          newGameButton = Instantiate(GameButtonPrefab);
            GameButtonBehaviour gbb           = newGameButton.GetComponent <GameButtonBehaviour>();
            gbb.gameType = gametype;
            gbb.GameID   = gameID;
            gbb.self.onClick.AddListener(() => ViewGame(gbb));

            switch (gametype)
            {
            case GameButtonBehaviour.GameType.CURRENT:
                newGameButton.transform.SetParent(currentGameList);
                break;

            case GameButtonBehaviour.GameType.FORECAST:
                newGameButton.transform.SetParent(futureGameList);
                break;

            default:
                newGameButton.transform.SetParent(historicalGameList);
                break;
            }

            currentGames.Add(gbb);
        }
    }
コード例 #7
0
        public override void Parse(BBGameState gameState)
        {
            this.gameState     = gameState;
            recordedRegexMatch = lastUpdateMatches.Match(gameState.lastUpdate);
            switch (recordedRegexMatch.Groups[2].Value)
            {
            case "swinging": TypeOfStrikeOut = StrikeOut.SWINGING;
                break;

            case "looking": TypeOfStrikeOut = StrikeOut.LOOKING;
                break;

            default: TypeOfStrikeOut = StrikeOut.UNKNOWN;
                break;
            }
        }
コード例 #8
0
        public override void Parse(BBGameState gameState)
        {
            this.gameState     = gameState;
            recordedRegexMatch = lastUpdateMatches.Match(gameState.lastUpdate);

            switch (recordedRegexMatch.Groups[1].Value)
            {
            case "second": stolenBase = StolenBase.SECOND; break;

            case "third": stolenBase = StolenBase.THIRD; break;

            case "home":
            case "fourth": stolenBase = StolenBase.HOME; break;

            default: stolenBase = StolenBase.UNKNOWN; break;
            }
        }
コード例 #9
0
ファイル: BBStrikePlay.cs プロジェクト: KaynSD/bbTV
        public override void Parse(BBGameState gameState)
        {
            this.gameState = gameState;
            Match match = lastUpdateMatches.Match(gameState.lastUpdate);

            switch (match.Groups[1].Value)
            {
            case "swinging": TypeOfStrike = Strike.SWINGING;
                break;

            case "looking": TypeOfStrike = Strike.LOOKING;
                break;

            default: TypeOfStrike = Strike.UNKNOWN;
                break;
            }
        }
コード例 #10
0
ファイル: GameViewer.cs プロジェクト: KaynSD/bbTV
    void Start()
    {
        game = gameRunner.getFocusedGame();
        if (game == null)
        {
            SceneManager.LoadScene(Constants.SCENE_TITLE);
            return;
        }


        PRNG prng = new ParkMiller(game.GameID);

        PregeneratedRandomValues = new List <float>();
        for (int i = 0; i < 1000; i++)
        {
            PregeneratedRandomValues.Add(prng.next());
        }


        queue = new Queue <BBGameState>();
        queue = new Queue <BBGameState>();
        game.OnUpdateReady   += LogUpdate;
        ReadyToProcessNewPlay = true;

        historicalPlaybackCurrentIndex = game.isRunning ? -1 : 0;
        currentState = game.GetUpdate(historicalPlaybackCurrentIndex);
        if (currentState != null)
        {
            queue.Enqueue(currentState);
        }
        HandleTechnicalDifficulties(null);

        if (game.isRunning)
        {
            Debug.Log("Rewind Off");
            cameraGraphicsMasterControl.DisableRewind();
        }
        else
        {
            Debug.Log("Rewind On");
            cameraGraphicsMasterControl.EnableRewind();
            cameraGraphicsMasterControl.rewindPanel.OnChanged += RewindToPoint;
        }
    }
コード例 #11
0
ファイル: BBFieldersChoice.cs プロジェクト: KaynSD/bbTV
        public override void Parse(BBGameState gameState)
        {
            this.gameState     = gameState;
            recordedRegexMatch = lastUpdateMatches.Match(gameState.lastUpdate);

            switch (recordedRegexMatch.Groups[2].Value)
            {
            case "first": runnerGroundOutOn = RunnerOutOn.FIRST; break;                      // HOW?!

            case "second": runnerGroundOutOn = RunnerOutOn.SECOND; break;

            case "third": runnerGroundOutOn = RunnerOutOn.THIRD; break;

            case "home":
            case "fourth": runnerGroundOutOn = RunnerOutOn.HOME; break;

            default: runnerGroundOutOn = RunnerOutOn.UNKNOWN; break;
            }
        }
コード例 #12
0
ファイル: GameViewer.cs プロジェクト: KaynSD/bbTV
    /// Triggered by a Signal when an animation is complete; or complete as far as the game
    /// renderer is concerned. There may be additional animation elements for idles and waiting
    /// for connection, but the timeline triggers this when the information is shown to the player
    /// and ready for the next part
    public void OnAnimationComplete()
    {
        Logger.Log("Viewer Ready for next update");
        // If we're in history mode, we get the next value immediately from the history
        if (historicalPlaybackCurrentIndex != -1 && historicalPlaybackCurrentIndex != game.HistoryLength - 1)
        {
            historicalPlaybackCurrentIndex++;
            BBGameState state = game.GetUpdate(historicalPlaybackCurrentIndex);
            if (state != null)
            {
                ProcessPlay(state, historicalPlaybackCurrentIndex);
            }
        }

        // Otherwise we wait for the server and follow the queue

        // Either way, ready to process the next play
        ReadyToProcessNewPlay = true;
    }
コード例 #13
0
        public override void Parse(BBGameState gameState)
        {
            this.gameState = gameState;
            Match recordedRegexMatch;

            recordedRegexMatch = lastUpdateMatches.Match(gameState.lastUpdate);
            switch (recordedRegexMatch.Groups[1].Value)
            {
            case "Single": hit = HitType.SINGLE; break;

            case "Double": hit = HitType.DOUBLE; break;

            case "Triple": hit = HitType.TRIPLE; break;
            }

            // presence of a third group means score happened
            if (recordedRegexMatch.Groups.Count == 3)
            {
                scores = System.Convert.ToInt32(recordedRegexMatch.Groups[2]);
            }
        }
コード例 #14
0
        /// <summary>
        /// Add an update to this game.
        /// If it is a legal update (as in, part of this game and not a duplicate) then OnUpdateReady
        /// will be dispatched with the update and the history list will be updated with this one at the end
        /// </summary>
        /// <param name="update">A potential update to add to this game</param>
        public void AddUpdate(BBGameState update)
        {
            // The update doesn't belong to this game. How did we get here?
            if (update.id != GameID)
            {
                return;
            }

            if (current != null)
            {
                // this update is a duplicate. Ignore!
                if (update.lastUpdate == current.lastUpdate)
                {
                    return;
                }
            }

            history.Add(update);
            current = update;
            OnUpdateReady?.Invoke(update);
        }
コード例 #15
0
ファイル: GameViewer.cs プロジェクト: KaynSD/bbTV
    private void ProcessPlay(BBGameState gameState, int index = -1)
    {
        cameraGraphicsMasterControl.rewindPanel.SetLength(game.HistoryLength - 1, historicalPlaybackCurrentIndex);

        if (historicalPlaybackCurrentIndex == -1)
        {
            index = game.HistoryLength;
        }

        previousState = currentState;
        currentState  = gameState;
        currentPlay   = Playbook.GetPlayFromState(gameState, index);
        CleanScene();

        switch (currentPlay)
        {
        case BBBatterAtPlatePlay bBatterAtPlatePlay:
            BatterUp(bBatterAtPlatePlay);
            break;

        case BBStrikePlay bBStrikePlay:
            Strike(bBStrikePlay);
            break;

        case BBBallPlay bBallPlay:
            BallCount(bBallPlay);
            break;

        case BBStrikeOutPlay bBStrikeOutPlay:
            StrikeOut(bBStrikeOutPlay);
            break;


        default:
            HandleTechnicalDifficulties(currentPlay);
            break;
        }
    }
コード例 #16
0
    internal void ShowBallCount(BBAbstractPlay bBBallPlay)
    {
        bool isChangeover = bBBallPlay is BBDrawsAWalkPlay;

        majorItemsChiron.Show();
        BBGameState state = bBBallPlay.gameState;

        majorItemsChiron.Show();
        majorItemsChiron.SetText(state.lastUpdate);
        majorItemsChiron.SetStrikes(state.atBatStrikes);
        if (isChangeover)
        {
            majorItemsChiron.SetBalls(4, true);
        }
        else
        {
            majorItemsChiron.SetBalls(state.atBatBalls, true);
        }
        majorItemsChiron.SetOuts(state.halfInningOuts, isChangeover);
        majorItemsChiron.ShowBase1(Array.IndexOf(state.basesOccupied, 0) > -1);
        majorItemsChiron.ShowBase2(Array.IndexOf(state.basesOccupied, 1) > -1);
        majorItemsChiron.ShowBase3(Array.IndexOf(state.basesOccupied, 2) > -1);
    }
コード例 #17
0
    internal void ShowStrike(BBAbstractPlay bbStrike)
    {
        bool isChangeover = bbStrike is BBStrikeOutPlay;

        majorItemsChiron.Show();
        BBGameState state = bbStrike.gameState;

        majorItemsChiron.SetText(state.lastUpdate);

        if (isChangeover)
        {
            majorItemsChiron.SetStrikes(3, true);
        }
        else
        {
            majorItemsChiron.SetStrikes(state.atBatStrikes, true);
        }

        majorItemsChiron.SetBalls(state.atBatBalls);
        majorItemsChiron.SetOuts(state.halfInningOuts, isChangeover);
        majorItemsChiron.ShowBase1(Array.IndexOf(state.basesOccupied, 0) > -1);
        majorItemsChiron.ShowBase2(Array.IndexOf(state.basesOccupied, 1) > -1);
        majorItemsChiron.ShowBase3(Array.IndexOf(state.basesOccupied, 2) > -1);
    }
コード例 #18
0
        public BBAbstractPlay GetPlayFromState(BBGameState gameState, int playIndex)
        {
            BBAbstractPlay play = new UnknownPlay();

            for (int i = 0; i < regexes.Count; i++)
            {
                Regex regex = regexes[i];
                if (regex.IsMatch(gameState.lastUpdate))
                {
                    play = (BBAbstractPlay)Activator.CreateInstance(types[i]);
                    break;
                }
            }

            if (play is BBAbstractPlayerPlay)
            {
                // Zenject doesn't quite work with Activator. This is a workaround
                ((BBAbstractPlayerPlay)play).Setup(database);
            }

            play.playIndex = playIndex;
            play.Parse(gameState);
            return(play);
        }
コード例 #19
0
 public override void Parse(BBGameState gameState)
 {
     this.gameState     = gameState;
     recordedRegexMatch = lastUpdateMatches.Match(gameState.lastUpdate);
 }
コード例 #20
0
ファイル: BBBottomOfInningPlay.cs プロジェクト: KaynSD/bbTV
 public override void Parse(BBGameState gameState)
 {
     this.gameState = gameState;
 }
コード例 #21
0
 /// <summary>
 /// Parse the game state. Complicated plays will start working out, based
 /// on available resources to it and possible access to a database, what
 /// more complicated information needs to be gleaned for a proper visual
 /// display of what's happening
 ///
 /// This method does NOT validate; it assumes that it has previously
 /// been matched to the lastUpdateMatches regular expression and thus can
 /// be correctly parsed. Match first, THEN parse.
 /// </summary>
 /// <param name="gameState">The game state to attach to this</param>
 abstract public void Parse(BBGameState gameState);
コード例 #22
0
ファイル: GameViewer.cs プロジェクト: KaynSD/bbTV
 private void LogUpdate(BBGameState gameState)
 {
     queue.Enqueue(gameState);
 }
コード例 #23
0
 void Setup(BBGameState gameState)
 {
     scoringPanel.Setup(gameState);
 }
コード例 #24
0
 internal void UpdateScores(BBGameState gameState)
 {
     scoringPanel.Setup(gameState);
 }
コード例 #25
0
ファイル: GameButtonBehaviour.cs プロジェクト: KaynSD/bbTV
    void GameUpdate(BBGameState newData)
    {
        // Only interested in my own data...
        if (newData.id != GameID)
        {
            return;
        }

        switch (gameType)
        {
        case GameType.FORECAST:
            if (newData.gameStart)
            {
                Debug.Log($"Forecast game {GameID} has started!");
                DestroySelf();
                return;
            }
            break;

        case GameType.CURRENT:
            if (newData.gameComplete)
            {
                Debug.Log($"Current game {GameID} has ended!");
                DestroySelf();
                return;
            }
            break;

        case GameType.HISTORICAL:
        default:
            break;
        }
        if (service == null)
        {
            Debug.Log("Service is still null!");
        }

        string leagueName = database.GetLeague().name;

        string season = $"Season {newData.season + 1}";
        string day    = $"Day {newData.day + 1}";

        string series = "";

        string homeID = newData.homeTeam;
        string awayID = newData.awayTeam;

        BBTeam homeTeam = database.GetTeam(homeID);
        BBTeam awayTeam = database.GetTeam(awayID);

        string homeTeamName = homeTeam?.fullName ?? "Unknown Team";
        string awayTeamName = awayTeam?.fullName ?? "Unknown Team";

        string homeColorString = homeTeam?.mainColor ?? "#666666";
        string awayColorString = awayTeam?.mainColor ?? "#666666";

        Color homeColorColor = Color.gray, awayColorColor = Color.gray;

        ColorUtility.TryParseHtmlString(homeColorString, out homeColorColor);
        ColorUtility.TryParseHtmlString(awayColorString, out awayColorColor);
        Color homeColorAlpha = new Color(homeColorColor.r, homeColorColor.g, homeColorColor.b, 0.6f);
        Color awayColorAlpha = new Color(awayColorColor.r, awayColorColor.g, awayColorColor.b, 0.6f);

        gradient.m_topLeftColor     = homeColorColor;
        gradient.m_topRightColor    = awayColorColor;
        gradient.m_bottomLeftColor  = homeColorAlpha;
        gradient.m_bottomRightColor = awayColorAlpha;


        headerText.text = $"{leagueName}, {season}, {day}; {series}";

        if (gameType == GameType.FORECAST)
        {
            mainText.text = $"{homeTeamName} <b>v</b> {awayTeamName}";
        }
        else
        {
            mainText.text = $"{homeTeamName} <b><color={homeColorString}>{newData.homeScore}</color> v <color={awayColorString}>{newData.awayScore}</color></b> {awayTeamName} ";
        }

        string footerTextChange = $"Weather: {Helper.GetWeather(newData.weather)}";

        if (gameType == GameType.CURRENT)
        {
            string inningPos = newData.topOfInning ? "(top)" : "(bottom)";
            footerTextChange += $", {newData.inning + 1} Inning {inningPos}";
        }

        if (gameType != GameType.HISTORICAL)
        {
            string favoured = "";
            int    homeOdds = Mathf.RoundToInt(newData.homeOdds * 100f);
            int    awayOdds = Mathf.RoundToInt(newData.awayOdds * 100f);
            if (homeOdds == awayOdds)
            {
                favoured = "Evens";
            }
            else
            {
                int odds = 0;
                if (homeOdds > awayOdds)
                {
                    favoured = database.GetTeam(homeID)?.nickname ?? "Unknown";
                    odds     = homeOdds;
                }
                else
                {
                    favoured = database.GetTeam(awayID)?.nickname ?? "Unknown";
                    odds     = awayOdds;
                }

                favoured += $" {odds}%";
            }
            footerTextChange += $", Favoured: {favoured}";
        }
        footerText.text = footerTextChange;

        //StartCoroutine("DelayThenRefresh");
    }