Esempio n. 1
0
        public void PatchFromFile(string path)
        {
            if (!File.Exists(path))
            {
                throw new System.IO.FileNotFoundException("File not found at " + path);
            }
            string[] lines = File.ReadAllLines(path);

            for (int i = 0; i < lines.Length; i++)
            {
                List <string> seperatedLines = new List <string>();
                StringUtil.SplitCSV(lines[i], seperatedLines);

                //Create entry
                ListEntry entry = new ListEntry()
                {
                    values = seperatedLines.ToArray()
                };

                string entryIDPrefix        = ATCSVUtil.GetPrefix(entry.ID);
                string entryIDWithoutPrefix = ATCSVUtil.GetWithoutPrefix(entry.ID);

                //Patch adding
                if (entryIDPrefix == patchAddPrefix)
                {
                    PatchAdd(entry, entryIDWithoutPrefix);
                }
                else
                //Patch over
                if (entryIDPrefix == patchOverPrefix)
                {
                    PatchOver(entry, entryIDWithoutPrefix);
                }
                else
                {
                }
            }
        }
Esempio n. 2
0
        public void PatchFromFile(string path)
        {
            if (!File.Exists(path))
            {
                throw new System.IO.FileNotFoundException("File not found at " + path);
            }
            string[] lines = File.ReadAllLines(path);

            List <MultiElementEntry> patchEntries = new List <MultiElementEntry>();
            MultiElementEntry        currentEntry = null;
            List <string[]>          elements     = new List <string[]>();

            //Parse multi-element entries
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].Length == 0)
                {
                    continue;
                }
                List <string> seperatedLines = new List <string>();
                StringUtil.SplitCSV(lines[i], seperatedLines);

                if (seperatedLines.Count <= 1)
                {
                    continue;
                }

                bool isEmpty = true;
                foreach (string s in seperatedLines)
                {
                    if (s != string.Empty)
                    {
                        isEmpty = false;
                        break;
                    }
                }
                if (isEmpty)
                {
                    continue;
                }

                //If the first element isn't empty, we're starting a new list.
                if (seperatedLines[0] != string.Empty)
                {
                    if (currentEntry != null)
                    {
                        currentEntry.otherEntries = elements.ToArray();
                        elements.Clear();

                        patchEntries.Add(currentEntry);
                    }
                    currentEntry = new MultiElementEntry()
                    {
                        firstValues = seperatedLines.ToArray(),
                    };
                }
                //If the first element IS empty, we're adding to the current list.
                else
                {
                    elements.Add(seperatedLines.ToArray());
                }
            }

            if (currentEntry != null)
            {
                currentEntry.otherEntries = elements.ToArray();
                elements.Clear();
                patchEntries.Add(currentEntry);
            }

            //Patch entries
            foreach (MultiElementEntry patch in patchEntries)
            {
                string idWithoutPrefix = ATCSVUtil.GetWithoutPrefix(patch.ID);
                string prefix          = ATCSVUtil.GetPrefix(patch.ID);

                if (prefix == patchOverPrefix)
                {
                    PatchOver(patch, idWithoutPrefix);
                }
                else if (prefix == patchAddPrefix)
                {
                    PatchAdd(patch, idWithoutPrefix);
                }
                else
                {
                    Debug.Log(string.Format("Patching failed with entry {0}, no prefixes where matched.", patch.ID));
                }
            }
        }
Esempio n. 3
0
        public void PatchOver(MultiElementEntry newEntry, string entryIDWithoutPrefix)
        {
            //If there's no entry to patch, just add this entry.
            if (!entries.ContainsKey(entryIDWithoutPrefix))
            {
                //Set ID to be the non-prefix version
                newEntry.firstValues[0] = entryIDWithoutPrefix;

                //Add the entry
                AddEntry(newEntry);
            }
            else
            {
                //Get Item Entry to add to
                MultiElementEntry patchEntry = entries[entryIDWithoutPrefix];

                //Patch over existing entries
                for (int i = 1; i < newEntry.firstValues.Length; i++)
                {
                    //store element
                    string element = newEntry.firstValues[i];

                    //If element is empty, skip it.
                    if (element == string.Empty || element == elementSkipTag)
                    {
                        continue;
                    }
                    //If the element is the tag to remove, remove the original element.
                    else if (element == elementRemoveTag)
                    {
                        patchEntry.firstValues[i] = string.Empty;
                    }
                    //If the other two checks aren't true, just overwrite.
                    else
                    {
                        patchEntry.firstValues[i] = element;
                    }
                }

                //Add other entries
                int  newI      = 0;
                bool appending = false;
                for (int i = 0; i < newEntry.otherEntries.Length; i++)
                {
                    string firstElem = newEntry.otherEntries[i][1];
                    string prefix    = ATCSVUtil.GetPrefix(firstElem);
                    if (prefix == patchAppendPrefix)
                    {
                        string idWithoutPrefix = ATCSVUtil.GetWithoutPrefix(firstElem);
                        Debug.Log("Hey We are Appending! It's " + idWithoutPrefix);
                        newEntry.otherEntries[i][1] = idWithoutPrefix;


                        //Alright, so if you decided to add a completely new row, it will go here
                        string[][] temp = new string[(newEntry.otherEntries.Length - i) + patchEntry.otherEntries.Length][];
                        Debug.Log("Temp's Length is " + temp.Length + "While PatchEntry's Length is " + patchEntry.otherEntries.Length);
                        //Go through and declare each array size (because I dont think there are more than that many fields for each row)
                        for (int z = 0; z < temp.Length; z++)
                        {
                            if (z < patchEntry.otherEntries.Length)
                            {
                                temp[z] = new string[patchEntry.otherEntries[z].Length];
                            }
                            else
                            {
                                temp[z] = new string[4];
                            }
                        }
                        // We need to make a new array of arrays that is as big as newEntry but also has all of PatchEntries stuff
                        Debug.Log("Bouta fit patchEntries into temp!");
                        for (int k = 0; k < patchEntry.otherEntries.Length; k++)
                        {
                            Debug.Log("Starting k again!");
                            for (int l = 0; l < patchEntry.otherEntries[k].Length; l++)
                            {
                                Debug.Log("k is" + k + " and l is " + l);
                                temp[k][l] = patchEntry.otherEntries[k][l];
                            }
                        }

                        //Now, lets turn that extra space from null to empty!
                        for (int x = 0; x < temp.Length; x++)
                        {
                            for (int y = 0; y < temp[x].Length; y++)
                            {
                                bool nullOrEmpty = string.IsNullOrEmpty(temp[x][y]);
                                if (nullOrEmpty)
                                {
                                    temp[x][y] = string.Empty;
                                }
                            }
                        }
                        //Now we have to change i so that it's at the proper place at the end of the old patchEntry.otherEntries list, so now it'll add these things to the end of PatchEntry!
                        //But we also have to note that now the i value is out of sync with both NewEntry and PatchEntry, so we must declare a new variable to keep track of patchEntry's length
                        newI      = patchEntry.otherEntries.Length;
                        appending = true;
                        patchEntry.otherEntries = temp;
                        Debug.Log("patchEntry Length is now " + patchEntry.otherEntries.Length);
                    }



                    for (int j = 0; j < newEntry.otherEntries[i].Length; j++)
                    {
                        //store element
                        Debug.Log("I sure hope it is not having a problem storing an element? I is " + i + "and j is " + j);
                        string element = newEntry.otherEntries[i][j];

                        //If element is empty, skip it.
                        if (element == string.Empty || element == elementSkipTag)
                        {
                            continue;
                        }
                        //If the element is the tag to remove, remove the original element.
                        else if (element == elementRemoveTag)
                        {
                            if (appending)
                            {
                                Debug.Log("Appending a Empty");
                                patchEntry.otherEntries[newI][j] = string.Empty;
                            }
                            else
                            {
                                patchEntry.otherEntries[i][j] = string.Empty;
                            }
                        }
                        //If the other two checks aren't true, just overwrite.
                        else
                        {
                            if (appending)
                            {
                                Debug.Log("Appending a new entry, its " + patchEntry.otherEntries[newI][j]);
                                patchEntry.otherEntries[newI][j] = element;
                            }
                            else
                            {
                                patchEntry.otherEntries[i][j] = element;
                            }
                        }
                    }

                    if (appending)
                    {
                        newI++;
                        Debug.Log("NewI is now " + newI);
                    }
                }

                entries[entryIDWithoutPrefix] = patchEntry;
            }
        }
Esempio n. 4
0
        public void PatchFromFile(string path)
        {
            if (!File.Exists(path))
            {
                throw new System.IO.FileNotFoundException("File not found at " + path);
            }
            string[] lines = File.ReadAllLines(path);

            for (int i = 0; i < lines.Length; i++)
            {
                List <string> seperatedLines = new List <string>();
                StringUtil.SplitCSV(lines[i], seperatedLines);

                //Create entry
                ListEntry entry = new ListEntry()
                {
                    values = seperatedLines.ToArray()
                };

                string entryIDPrefix        = null;
                string entryIDWithoutPrefix = null;

                //If you are using groups or Shop List CSV
                if (useGroups || shopList)
                {
                    entryIDPrefix        = ATCSVUtil.GetPrefix(entry.ID);
                    entryIDWithoutPrefix = ATCSVUtil.GetWithoutPrefix(entry.ID);
                    entry.rowNumber      = ++totRowCount;
                }
                //If you are using Anim Actions CSV
                else if (animList)
                {
                    entryIDPrefix        = ATCSVUtil.GetPrefix(entry.ID);
                    entryIDWithoutPrefix = ATCSVUtil.GetWithoutPrefix(entry.ID);
                    //Puts row number specified in Anim Actions Patch to row number of new entry
                    try
                    {
                        entry.rowNumber = Convert.ToInt32(entry.group);
                    }
                    catch (FormatException e)
                    {
                        Debug.Log("Error Patching Anim Actions - Input string is not a sequence of digits. " + entry.group);
                    }
                    catch (OverflowException e)
                    {
                        Debug.Log("Error Patching Anim Actions - Row Number cannot fir in an Int32." + entry.group);
                    }
                }
                else
                {
                    entryIDPrefix        = ATCSVUtil.GetPrefix(entry.group);
                    entryIDWithoutPrefix = ATCSVUtil.GetWithoutPrefix(entry.group);
                }

                //Patch adding
                if (entryIDPrefix == patchAddPrefix)
                {
                    PatchAdd(entry, entryIDWithoutPrefix);
                }
                else
                //Patch over
                if (entryIDPrefix == patchOverPrefix)
                {
                    PatchOver(entry, entryIDWithoutPrefix);
                }
                else
                //Patch Anim Actions CSV
                if (entryIDPrefix == patchAnimPrefix)
                {
                    AnimPatchAdd(entry, entryIDWithoutPrefix);
                }
            }
        }