//============================================================================= private static bool LoadItemsList() { if (isItemListLoaded) { return(true); } isItemListLoaded = true; StringReader reader = null; if (PlayerPrefs.HasKey(PreHelpers.GetLiveDataVersionString()) && false) { // Load locally string DocPath = PreHelpers.GetFileFolderPath(); string FilePath = DocPath + "Fairies.txt"; // Read file string Contents = null; try { StreamReader CurFile = new StreamReader(FilePath); Contents = CurFile.ReadToEnd(); // Close file CurFile.Close(); } catch { PlayerPrefsWrapper.DeleteKey(PreHelpers.GetLiveDataVersionString()); } reader = new StringReader(Contents); } else { // Load from resources string fullpath = "Fairies/Fairies"; TextAsset textAsset = (TextAsset)Resources.Load(fullpath, typeof(TextAsset)); if (textAsset == null) { Debug.Log(fullpath + " file not found."); return(false); } reader = new StringReader(textAsset.text); } // Create the fairies item list if one doesn't exist if (null == itemList) { itemList = new List <FairyItemData>(64); } // Clear the dictionary itemList.Clear(); string dataVal = string.Empty; string intext = string.Empty; // [ Fairy | Unlock Cost | Level 1 Cost | Level 2 Cost | Level 3 Cost ] int maxColumns = 5; int columnCount = 0; int itemCount = 0; // First parse through rows until we find the starting one // The 'fairies.txt' file has loads of info at the start that we can ignore as it's all excel settings int RowCount = 0; while (true) { intext = reader.ReadLine(); int Idx = intext.IndexOf("<Row"); if (Idx != -1) { RowCount++; } if (RowCount == 6) { break; } } // Start of text data, begin parsing the rows while (true) { int Idx, Idx2, Idx3, Idx4; bool isIdValid = false; columnCount = 0; // Read cell containing text code intext = reader.ReadLine(); // intext might look something like this now: // <Cell ss:StyleID="s32"><Data ss:Type="String">0001</Data></Cell> // Find the data in the cell - in this case it's "Item ID" Idx4 = intext.IndexOf("><"); if (Idx4 != -1) { Idx2 = intext.IndexOf(">", Idx4 + 2); if (Idx2 != -1) { Idx3 = intext.IndexOf("<", Idx2); if (Idx3 != -1) { // String is between Idx2 and Idx3 - this is the text 'ItemId' - "0001" dataVal = intext.Substring(Idx2 + 1, Idx3 - Idx2 - 1); itemList.Add(new FairyItemData()); UpdateItemData(itemCount, columnCount, dataVal); isIdValid = true; } } ++columnCount; } // If we've found an itemId continue reading the item data for this item if (isIdValid) { while (columnCount < maxColumns) { // Read cell containing text code intext = reader.ReadLine(); Idx4 = intext.IndexOf("><"); if (Idx4 != -1) { Idx2 = intext.IndexOf(">", Idx4 + 2); if (Idx2 != -1) { Idx3 = intext.IndexOf("<", Idx2); if (Idx3 != -1) { // String is between Idx2 and Idx3 - this is the text 'ItemId' - "0001" dataVal = intext.Substring(Idx2 + 1, Idx3 - Idx2 - 1); UpdateItemData(itemCount, columnCount, dataVal); } } } ++columnCount; } ++itemCount; } // Find the end of this row by looking for the start of the next row while (true) { intext = reader.ReadLine(); Idx = intext.IndexOf("<Row"); if (Idx != -1) { // Found end of row break; } else { Idx = intext.IndexOf("Table>"); if (Idx != -1) { // Found end of table //Debug.Log("Finished loading fairies items data list."); reader.Dispose(); // Order list by priority //itemList.Sort((x,y) => x.GetOrderPriority() - y.GetOrderPriority()); return(true); } } } } }
//============================================================================= private static bool LoadItemsList() { if (isItemListLoaded) { return(true); } isItemListLoaded = true; StringReader reader = null; if (PlayerPrefs.HasKey(PreHelpers.GetLiveDataVersionString()) && false) { // Load locally string DocPath = PreHelpers.GetFileFolderPath(); string FilePath = DocPath + "Cards.txt"; // Read file string Contents = null; try { StreamReader CurFile = new StreamReader(FilePath); Contents = CurFile.ReadToEnd(); // Close file CurFile.Close(); } catch { PlayerPrefsWrapper.DeleteKey(PreHelpers.GetLiveDataVersionString()); } reader = new StringReader(Contents); } else { // Load from resources string fullpath = "Cards/Cards"; TextAsset textAsset = (TextAsset)Resources.Load(fullpath, typeof(TextAsset)); if (textAsset == null) { Debug.Log(fullpath + " file not found."); return(false); } reader = new StringReader(textAsset.text); } // Create the TradingCard item list if one doesn't exist if (null == itemList) { itemList = new List <TradingCardSpreadsheetItem>(64); } // Clear the dictionary itemList.Clear(); string dataVal = string.Empty; string intext = string.Empty; // [ ItemID | Classification | Value | ValueScuffed | Rarity | Wait Time | Reveal Price | Page | Position | SmallGUI - 2D | LargeGUI - 2D ] int maxColumns = 11; int columnCount = 0; int itemCount = 0; // First parse through rows until we find the starting one // The 'TradingCarditems.txt' file has loads of info at the start that we can ignore as it's all excel settings int RowCount = 0; while (true) { intext = reader.ReadLine(); int Idx = intext.IndexOf("<Row"); if (Idx != -1) { RowCount++; } if (RowCount == 6) { break; } } // Start of text data, begin parsing the rows while (true) { int Idx, Idx2, Idx3, Idx4; bool isIdValid = false; columnCount = 0; // Read cell containing text code intext = reader.ReadLine(); // intext might look something like this now: // <Cell ss:StyleID="s32"><Data ss:Type="String">0001</Data></Cell> // Find the data in the cell - in this case it's "Item ID" Idx4 = intext.IndexOf("><"); if (Idx4 != -1) { Idx2 = intext.IndexOf(">", Idx4 + 2); if (Idx2 != -1) { Idx3 = intext.IndexOf("<", Idx2); if (Idx3 != -1) { // String is between Idx2 and Idx3 - this is the text 'ItemId' - "0001" dataVal = intext.Substring(Idx2 + 1, Idx3 - Idx2 - 1); itemList.Add(new TradingCardSpreadsheetItem()); UpdateItemData(itemCount, columnCount, dataVal); isIdValid = true; } } ++columnCount; } // If we've found an itemId continue reading the item data for this item if (isIdValid) { while (columnCount < maxColumns) { // Read cell containing text code intext = reader.ReadLine(); Idx4 = intext.IndexOf("><"); if (Idx4 != -1) { Idx2 = intext.IndexOf(">", Idx4 + 2); if (Idx2 != -1) { Idx3 = intext.IndexOf("<", Idx2); if (Idx3 != -1) { // String is between Idx2 and Idx3 - this is the text 'ItemId' - "0001" dataVal = intext.Substring(Idx2 + 1, Idx3 - Idx2 - 1); UpdateItemData(itemCount, columnCount, dataVal); } } } ++columnCount; } ++itemCount; } // Find the end of this row by looking for the start of the next row while (true) { intext = reader.ReadLine(); Idx = intext.IndexOf("<Row"); if (Idx != -1) { // Found end of row break; } else { Idx = intext.IndexOf("Table>"); if (Idx != -1) { // Found end of table //Debug.Log("Finished loading TradingCard items data list."); reader.Dispose(); // Order list by priority //itemList.Sort((x,y) => x.GetOrderPriority() - y.GetOrderPriority()); // Expand each item type into individual page sections int NumWinxPages = GetPageCount(eTradingCardClassification.WINX); int NumWildPages = GetPageCount(eTradingCardClassification.WILD); int NumStoryPages = GetPageCount(eTradingCardClassification.STORY); int NumStandardPages = GetPageCount(eTradingCardClassification.STANDARD); pageTypeOffsets[(int)eTradingCardClassification.WINX] = 0; pageTypeOffsets[(int)eTradingCardClassification.WILD] = NumWinxPages; pageTypeOffsets[(int)eTradingCardClassification.STORY] = NumWinxPages + NumWildPages; pageTypeOffsets[(int)eTradingCardClassification.STANDARD] = NumWinxPages + NumWildPages + NumStoryPages; OffsetPageCount(eTradingCardClassification.WINX, pageTypeOffsets[(int)eTradingCardClassification.WINX]); OffsetPageCount(eTradingCardClassification.WILD, pageTypeOffsets[(int)eTradingCardClassification.WILD]); OffsetPageCount(eTradingCardClassification.STORY, pageTypeOffsets[(int)eTradingCardClassification.STORY]); OffsetPageCount(eTradingCardClassification.STANDARD, pageTypeOffsets[(int)eTradingCardClassification.STANDARD]); return(true); } } } } }