Exemplo n.º 1
0
        public MainForm()
        {
            InitializeComponent();
            tick = new Timer();
            if (File.Exists("splits.txt"))
            {
                Splits = File.ReadAllLines("splits.txt");
            }

            hook.KeyPressed += new EventHandler <KeyPressedEventArgs>(hook_KeyPressed);
            hook.RegisterHotKey(0, Keys.F1);
            hook.RegisterHotKey(0, Keys.F2);
            hook.RegisterHotKey(0, Keys.F3);

            MetaFile metaFile = JsonConvert.DeserializeObject <MetaFile>(File.ReadAllText("meta.json"));

            string[] teamNames = metaFile.teams.Select(team => team.name).ToArray();

            timerTickInterval = metaFile.layout.timerTickInterval;
            infoCycleTicks    = metaFile.layout.infoCycleTicks;

            //Programmatic stuff
            meta = new MetaContext(metaFile.splitsToShow, metaFile.splitFocusOffset, Splits,
                                   teamNames, metaFile.games, metaFile.layout, metaFile.features);
            teams = new TeamControl[metaFile.teams.Length];
            //Create team controls based on the meta file.
            int    wide     = Math.Min(metaFile.teamsPerRow, metaFile.teams.Length);
            double height   = Math.Ceiling((double)metaFile.teams.Length / (double)metaFile.teamsPerRow);
            Size   teamSize = new Size(Math.Max(430, meta.layout.boxWidth + 30), Math.Max(350, meta.layout.boxHeight + meta.layout.timerHeight + 56));

            for (int i = 0; i < metaFile.teams.Length; i++)
            {
                teams[i] = new TeamControl();
                int row = i / metaFile.teamsPerRow;
                teams[i].Location = new Point(15 + (i % metaFile.teamsPerRow) * (teamSize.Width + 10), 120 + (teamSize.Height + 10) * row);
                MetaFile.Team team      = metaFile.teams[i];
                var           backImage = team.image != null?Image.FromFile(team.image) : null;

                teams[i].setupTeamControl(this, new TeamInfo(metaFile.games.Length, Splits.Length, team.name, team.name.ToLower() + "-runners.txt",
                                                             ColorTranslator.FromHtml(team.color), backImage, team.splitKey, metaFile.features.teamGameIcons), meta, teamSize);
                this.Controls.Add(teams[i]);
            }
            loadCommentators();
            this.Size = new Size(30 + wide * (teamSize.Width + 10), 150 + (teamSize.Height + 10) * (int)height);
            outputCaptureInformation();
            cycleMainBG();

            if (meta.features.enableRemoteSplitting)
            {
                updater           = new SSMUpdater();
                reader            = new SQSReader();
                sqsTimer          = new Timer();
                sqsTimer.Enabled  = true;
                sqsTimer.Interval = 10 * 1000; //10 second poll
                sqsTimer.Tick    += new EventHandler((o, e) => { handleOutboundMessages(reader.consume()); });
                sqsTimer.Start();
                //broadcastState();
                this.FormClosing += new FormClosingEventHandler((o, e) => { teardownState(); });
            }
        }
Exemplo n.º 2
0
        public void WriteSplitFiles()
        {
            string sep = "|";

            if (File.Exists("splits_output.txt"))
            {
                File.Delete("splits_output.txt");
            }
            string[] lines = new string[Splits.Length + 1];
            //line[0] = "Time   | Mog   | Choco | Tonb  ";
            //Parameterised
            int timePad = Splits.Select(str => str.Length).Max();

            lines[0] = "Time".PadRight(timePad, ' ');
            for (int i = 0; i < Splits.Length; i++)
            {
                lines[i + 1] = Splits[i].PadRight(timePad, ' ');
            }
            for (int i = 0; i < teams.Length; i++)
            {
                TeamControl team = teams[i];
                lines[0] += sep + team.teamInfo.teamName.PadRight(8, ' ');
                for (int j = 0; j < Splits.Length; j++)
                {
                    lines[j + 1] += sep + team.getSplit(j);
                }
            }
            File.WriteAllLines("splits_output.txt", lines);
            if (meta.features.enableRemoteSplitting)
            {
                broadcastState();
            }
        }
Exemplo n.º 3
0
 public void handleOutboundMessages(List <OutboundMessage> messages)
 {
     if (messages.Count == 0)
     {
         return;
     }
     foreach (OutboundMessage m in messages)
     {
         TeamControl team = teams.ToList().Find(t => t.teamInfo.teamName == m.team);
         if (!team.teamInfo.teamFinished)
         {
             TimeSpan lastSplit;
             if (team.teamInfo.teamSplitNum > 0)
             {
                 lastSplit = Util.parseTimeSpan(team.teamInfo.teamSplits[team.teamInfo.teamSplitNum - 1]);
             }
             else
             {
                 lastSplit = new TimeSpan(0);
             }
             double diff = (m.time - lastSplit.Ticks) / 10_000;
             if (diff > 5 * 60 * 1000)
             {
                 //Only split if it's 5 minutes after the most recent one (to prevent duplication)
                 team.splitClick();
                 TimeSpan d = new TimeSpan(m.time);
                 team.setSplit(string.Format("{0:D2}:{1:mm}:{1:ss}", (int)d.TotalHours, d), team.teamInfo.teamSplitNum - 1);
             }
         }
     }
     broadcastState();
 }
Exemplo n.º 4
0
        public VersusWrapper[] fetchOtherTeamInfo(TeamControl self)
        {
            //return teams.Except(new TeamControl[] { self }).Select(tc => new VersusWrapper(tc.teamInfo.teamSplitNum, tc.teamInfo.teamSplits, tc.teamInfo.teamFinished));
            VersusWrapper[] wrapperArray  = new VersusWrapper[teams.Length - 1];
            int             adjustedIndex = 0;

            for (int i = 0; i < teams.Length; i++)
            {
                if (self == teams[i])
                {
                    continue;
                }
                wrapperArray[adjustedIndex] = new VersusWrapper(teams[i].teamInfo.teamSplitNum, teams[i].teamInfo.teamSplits, teams[i].teamInfo.teamFinished);
                adjustedIndex++;
            }
            return(wrapperArray);
        }