예제 #1
0
        private string GetDefaultFilePath()
        {
            // Use the BabyWhite Chicken image as default for anything that could not be found
            WhiteVariation WhiteFarmAnimals = new WhiteVariation();

            return(this.GetAssetDirectory() + this.GetBaby() + WhiteFarmAnimals.ApplyPrefix(FarmAnimals.Type.ConvertBaseToString(FarmAnimals.Type.Base.Chicken)));
        }
        private void FixSave(string saveFolder)
        {
            string saveFile = Path.Combine(saveFolder, Path.GetFileName(saveFolder));

            if (!File.Exists(saveFile))
            {
                this.Monitor.Log($"{saveFile} does not exist", LogLevel.Error);
                return;
            }

            // Baseline
            FarmAnimalsData data = new FarmAnimalsData();

            WhiteVariation whiteVariation        = new WhiteVariation();
            string         coopDwellerSubstitute = whiteVariation.ApplyPrefix(Paritee.StardewValleyAPI.FarmAnimals.Type.Base.Chicken.ToString());
            string         barnDwellerSubstitute = whiteVariation.ApplyPrefix(Paritee.StardewValleyAPI.FarmAnimals.Type.Base.Cow.ToString());

            this.Monitor.Log($"Searching {saveFolder} for problematic farm animal types", LogLevel.Trace);

            // Replace barn animals with White Cows and coop animals with White Chickens
            XmlDocument doc = new XmlDocument();

            // Track the types to be substituted
            List <string> typesToBeSubstituted = new List <string>();

            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(doc.NameTable);

            namespaceManager.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

            // Load the xml
            doc.Load(saveFile);

            XmlNodeList buildings = doc.SelectNodes("//GameLocation[@xsi:type='Farm']/buildings/Building[@xsi:type='Barn' or @xsi:type='Coop']", namespaceManager);

            this.Monitor.Log($"- Checking {buildings.Count} buildings", LogLevel.Trace);

            // Go through each building
            for (int i = 0; i < buildings.Count; i++)
            {
                XmlNode building = buildings[i];

                bool isCoop = building.Attributes["xsi:type"].Value.Equals("Coop");

                // Grab only the animal types
                XmlNodeList types = building.SelectNodes(".//FarmAnimal/type");

                for (int k = 0; k < types.Count; k++)
                {
                    XmlNode type = types[k];

                    // If the type can't be found in the data entries
                    // then substitute it with an appropriate basic animal
                    if (!data.GetEntries().ContainsKey(type.InnerText))
                    {
                        typesToBeSubstituted.Add(type.InnerText);

                        type.InnerText = isCoop ? coopDwellerSubstitute : barnDwellerSubstitute;
                    }
                }
            }

            if (typesToBeSubstituted.Count > 0)
            {
                // save the XmlDocument back to disk
                doc.Save(saveFile);

                this.Monitor.Log($"- Converted {typesToBeSubstituted.Count} farm animals to White Cows or White Chickens: {String.Join(", ", typesToBeSubstituted.Distinct())}", LogLevel.Trace);
            }
            else
            {
                this.Monitor.Log($"- No problematic farm animals found", LogLevel.Trace);
            }
        }