Beispiel #1
0
        // Take the prices we get from the web, turn them into Card objects and add them to our cards Dict
        public void loadPrices(string priceContents)
        {
            Regex pattern = new Regex (@"^(.*)\s+\.\.\. (\d+) PLATINUM.*\.\.\.\s+(\d+) GOLD.*");

            if (cards == null) {
                cards = new Dictionary<string, Card> ();  // Shut up error bits
            }
            string cname;
            int plat;
            int gold;
            foreach (string line in priceContents.Split("\n"[0])) {
                // Example Data:
                // Accursed Jerkin ... 1 PLATINUM [23 auctions] ... 247 GOLD [50 auctions]
                if (pattern.IsMatch (line)) {
                    Match match = pattern.Match (line);
                    cname = match.Groups [1].Value;
                    plat = IntFromString (match.Groups [2].Value);
                    gold = IntFromString (match.Groups [3].Value);
                } else {
                    Debug.Log ("Did not match line " + line);
                    continue;
                }
                if (cname == "" || cname == null) {
                    continue;
                }

                if (cards.ContainsKey (cname)) {
                    cards [cname].gold = gold;
                    cards [cname].plat = plat;
                } else {
                    Card c = new Card (cname, gold, plat);
                    cards.Add (c.name, c);
                }
                // Something in here to make sure we have a least 1 of each Booster Pack for
                // price computations
                if (cname.Contains("Booster Pack")){
                    cards [cname].qty = 1;
                }
            }
        }
Beispiel #2
0
 // Load collection information from collection cache file
 public void loadCollection(string collectionCache)
 {
     if (! File.Exists (collectionCache)) {
         string path = Application.dataPath;
         Debug.Log ("Collection Cache '" + collectionCache + "' does not exist in my application data path of " + path);
         return;
     }
     // Save this info for later
     collectionCacheFile = collectionCache;
     string collectionLines = File.ReadAllText (collectionCache);
     Regex pattern = new Regex (@"^(\d+)\s:\s(.*?)\s*$");
     foreach (string line in collectionLines.Split("\n"[0])) {
         // Example line:
         // 5 : Adamanthian Scrivener
         if (pattern.IsMatch (line)) {
             Match match = pattern.Match (line);
             int qty = IntFromString (match.Groups [1].Value);
             string cardName = match.Groups [2].Value;
     //					Debug.Log ("Checking if cards contains the key for " + cardName + " to add " + qty + " copies");
             if (cards.ContainsKey (cardName)) {
     //						Debug.Log ("Adding " + qty + " copies of " + cardName);
                 cards [cardName].qty = qty;
             } else {
     //						Debug.Log ("cards Dict has " + cards.Count + " entries, but none for our card. Creating new card for " + cardName + " and adding " + qty + " copies of it");
                 Card c = new Card (cardName);
                 c.qty = qty;
                 cards.Add (cardName, c);
             }
         }
     }
 }