Exemplo n.º 1
0
        public Result Read(FastAccessImage image, string setName = null)
        {
            Result result = new Result();

            foreach (var lookup in this.timeRemainingLookups)
            {
                string timeRemainingString = ImageParser.Read(image, lookup, this.timeRemainingRectangle);
                result.TimeRemaining = this.ParseTimeRemainingString(timeRemainingString);
                if (result.TimeRemaining != TimeSpan.Zero)
                {
                    break;
                }
            }

            string countString = ImageParser.Read(image, this.countLookup, this.countRectangle);

            result.Count           = this.ParseCountString(countString);
            result.CardsByPosition = new OldCard[15];

            if (result.Count != 0 ||
                !image.Matches(this.pickAccepted, this.pickAcceptedRectangle) ||
                !image.Matches(this.submittingPick, this.submittingPickRectangle) ||
                this.cardImageRectangles.TrueForAll(r => !image.CloselyMatches(this.cardImageLoading, r, 10, 0.75)))
            {
                List <string> cardNamePrefixes = ImageParser.Read(image, this.cardNameLookup, this.cardNameRectangles);
                if (setName == null && cardNamePrefixes.Exists(s => s != string.Empty))
                {
                    setName = GuessSetName(cardNamePrefixes.Where(s => s != string.Empty));
                }

                result.CardsByPosition = cardNamePrefixes.ConvertAll(s => s == string.Empty ? null : OldCard.FindOne(setName, s + ".*")).ToArray();
            }

            return(result);
        }
Exemplo n.º 2
0
        private void DoWork(object sender, DoWorkEventArgs e)
        {
            DraftParser draftImageParser = new DraftParser();

            DraftParser.Result lastResult = null;
            string             setName    = null;
            string             subFolder  = null;

            this.Log("Starting");
            while (true)
            {
                System.Threading.Thread.Sleep(this.pauseTime);
                if (All.GetForegroundProcess().MainWindowTitle != string.Empty)
                {
                    continue;
                }

                Bitmap bmp = All.ScreenCaptureProcess(this.magicProgramName);
                if (bmp == null)
                {
                    continue;
                }

                FastAccessImage    fai    = new FastAccessImage(bmp);
                DraftParser.Result result = draftImageParser.Read(fai, setName);
                if (result.HasCards && (lastResult == null || result.Count != lastResult.Count))
                {
                    if (setName == null)
                    {
                        setName = result.Cards.First().SetName;
                        this.setNameCombo.BeginInvoke(new System.Action(() =>
                        {
                            this.setNameCombo.Text = setName;
                        }));
                    }

                    if (subFolder == null || result.Count == 0)
                    {
                        subFolder = this.rootDirectory + "\\" + DateTime.Now.ToFileTime().ToString();
                        System.IO.Directory.CreateDirectory(subFolder);
                        this.folderCombo.BeginInvoke(new System.Action(() =>
                        {
                            this.folderCombo.Text = subFolder;
                        }));
                    }

                    string file = subFolder + "\\" + DateTime.Now.ToFileTime() + ".png";
                    bmp.Save(file, ImageFormat.Png);
                    string logMessage = string.Format("{0} : wrote to {1}", DateTime.Now, file);
                    this.Log(logMessage);
                    lastResult = result;
                }
            }
        }
Exemplo n.º 3
0
 private void Initialize()
 {
     this.cardNameLookup = new ImageParser.GlyphLookup(
         "Data\\draft_card_font.png",
         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'-,Æ".Select(c => c.ToString()).ToList(),
         4);
     this.cardNameRectangles = new List <Rectangle>()
     {
         new Rectangle(163, 512, 75, 10),
         new Rectangle(269, 512, 75, 10),
         new Rectangle(375, 512, 75, 10),
         new Rectangle(479, 512, 75, 10),
         new Rectangle(585, 512, 75, 10),
         new Rectangle(691, 512, 75, 10),
         new Rectangle(797, 512, 75, 10),
         new Rectangle(902, 512, 75, 10),
         new Rectangle(163, 635, 75, 10),
         new Rectangle(269, 635, 75, 10),
         new Rectangle(375, 635, 75, 10),
         new Rectangle(479, 635, 75, 10),
         new Rectangle(585, 635, 75, 10),
         new Rectangle(691, 635, 75, 10),
         new Rectangle(797, 635, 75, 10)
     };
     this.cardImageLoading    = FastAccessImage.FromPath("Data\\draft_card_image_loading.png");
     this.cardImageRectangles = this.cardNameRectangles.ConvertAll(
         r => new Rectangle(r.X, r.Y + 11, this.cardImageLoading.Width, this.cardImageLoading.Height));
     this.countLookup = new ImageParser.GlyphLookup(
         "Data\\draft_count_font.png",
         "0123456789".Select(c => c.ToString()).ToList(),
         4);
     this.countRectangle       = new Rectangle(21, 728, 26, 9);
     this.timeRemainingLookups = new List <ImageParser.GlyphLookup>()
     {
         new ImageParser.GlyphLookup(
             "Data\\draft_clock_font.png",
             "0123456789:-".Select(c => c.ToString()).ToList(),
             4),
         new ImageParser.GlyphLookup(
             "Data\\draft_clock_yellow_font.png",
             "0123456789:-".Select(c => c.ToString()).ToList(),
             4),
         new ImageParser.GlyphLookup(
             "Data\\draft_clock_red_font.png",
             "0123456789:-".Select(c => c.ToString()).ToList(),
             4)
     };
     this.timeRemainingRectangle  = new Rectangle(59, 492, 36, 8);
     this.pickAccepted            = FastAccessImage.FromPath("Data\\pick_accepted.png");
     this.pickAcceptedRectangle   = new Rectangle(190, 512, this.pickAccepted.Width, this.pickAccepted.Height);
     this.submittingPick          = FastAccessImage.FromPath("Data\\submitting_pick.png");
     this.submittingPickRectangle = new Rectangle(190, 512, this.submittingPick.Width, this.submittingPick.Height);
 }
Exemplo n.º 4
0
        public static void ReadDirectory()
        {
            DraftParser parser = new DraftParser();

            foreach (string file in Directory.GetFiles(DraftImageDirectory))
            {
                if (DraftImageExtensions.Contains(new FileInfo(file).Extension))
                {
                    DraftParser.Result result = parser.Read(FastAccessImage.FromPath(file));
                    Console.WriteLine(file + " = " + result);
                }
            }
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            string draftImageDirectory = @"P:\Code\svn\Projects\magic\cs\Magic.App\bin\Debug\Screenshot\1";

            string[] draftImageExtensions = new string[] { ".png", ".bmp" };

            DraftParser parser = new DraftParser();

            foreach (string file in Directory.GetFiles(draftImageDirectory))
            {
                if (draftImageExtensions.Contains(new FileInfo(file).Extension))
                {
                    DraftParser.Result result = parser.Read(FastAccessImage.FromPath(file));
                    Console.WriteLine(file + " = " + result);
                }
            }
        }