Exemplo n.º 1
0
        public void DeckConversion(string path)
        {
            DeckName = Path.GetFileName(Path.ChangeExtension(Path.Combine(Outputdir, _open.FileName), "txt"));
            DeckYdk deck = BuildDeckTxt(path);

            YdkToTxt(deck);
            MessageBox.Show(String.Format("{0} Converted", DeckName));
            textBox1.Text = @"Select file to convert";
        }
Exemplo n.º 2
0
        public DeckYdk BuildDeckTxt(string path)
        {
            DeckYdk deck = new DeckYdk();

            path = _open.FileName;
            using (StreamReader reader = new StreamReader(path))
            {
                string   text = reader.ReadToEnd();
                string[] s    = text.Split(new[] { "#main", "#extra", "!side" }, StringSplitOptions.None);

                string
                    s1 = s[1],
                    s2 = s[2],
                    s3 = s[3];

                string[]
                s11 = s1.Split(new[] { "\r\n" }, StringSplitOptions.None),
                s22 = s2.Split(new[] { "\r\n" }, StringSplitOptions.None),
                s33 = s3.Split(new[] { "\r\n" }, StringSplitOptions.None);

                foreach (int cardNumber in s11.Where(cardNumber => !String.IsNullOrEmpty(cardNumber)).Select(cardNumber => Convert.ToInt32(cardNumber)))
                {
                    deck.Main.Add(new Card(cardNumber));
                }

                foreach (int cardNumber in s22.Where(cardNumber => !String.IsNullOrEmpty(cardNumber)).Select(cardNumber => Convert.ToInt32(cardNumber)))
                {
                    deck.Extra.Add(new Card(cardNumber));
                }

                foreach (int cardNumber in s33.Where(cardNumber => !String.IsNullOrEmpty(cardNumber)).Select(cardNumber => Convert.ToInt32(cardNumber)))
                {
                    deck.Side.Add(new Card(cardNumber));
                }
            }

            return(deck);
        }
Exemplo n.º 3
0
        public void YdkToTxt(DeckYdk deck)
        {
            Dictionary <Card, int>
            mainDeck      = new Dictionary <Card, int>(new CardComparer()),
                extraDeck = new Dictionary <Card, int>(new CardComparer()),
                sideDeck  = new Dictionary <Card, int>(new CardComparer());

            StringBuilder builder = new StringBuilder();

            List <Card>
            mainList      = deck.Main,
                extraList = deck.Extra,
                sideList  = deck.Side;

            //main deck
            foreach (Card card in mainList)
            {
                if (mainDeck.ContainsKey(card))
                {
                    mainDeck[card]++;
                }
                else
                {
                    mainDeck.Add(card, 1);
                }
            }

            //extra deck
            foreach (Card card in extraList)
            {
                if (extraDeck.ContainsKey(card))
                {
                    extraDeck[card]++;
                }
                else
                {
                    extraDeck.Add(card, 1);
                }
            }

            //side deck
            foreach (Card card in sideList)
            {
                if (sideDeck.ContainsKey(card))
                {
                    sideDeck[card]++;
                }
                else
                {
                    sideDeck.Add(card, 1);
                }
            }

            builder.AppendLine("#main");
            foreach (KeyValuePair <Card, int> card in mainDeck)
            {
                builder.AppendLine(String.Format("{0} {1}", card.Value, GetCardName(card.Key.Id)));
            }

            builder.AppendLine();
            builder.AppendLine("#extra");
            foreach (KeyValuePair <Card, int> card in extraDeck)
            {
                builder.AppendLine(String.Format("{0} {1}", card.Value, GetCardName(card.Key.Id)));
            }

            builder.AppendLine();
            builder.AppendLine("!side");
            foreach (KeyValuePair <Card, int> card in sideDeck)
            {
                builder.AppendLine(String.Format("{0} {1}", card.Value, GetCardName(card.Key.Id)));
            }

            if (!Directory.Exists(Outputdir))
            {
                Directory.CreateDirectory(Outputdir);
            }
            File.WriteAllText(Path.Combine(Outputdir, DeckName), builder.ToString());
        }