public static object getReplacement(ISaveElement ise) { object o = ise.getReplacement(); setDataString(o, getReplacementName(ise)); return(o); }
private static object getReplacement(ISaveElement ise) { object o = checkReplacement(ise.getReplacement()); setDataString(o, getReplacementName(ise)); return(o); }
internal static void removeElements() { OnBeforeRemoving(EventArgs.Empty); findElements(); elements = new List <object>(); elements.AddRange(attachements); elements.AddRange(storage); elements.AddRange(objects); elements.AddRange(animals); elements.AddRange(characters); if (Game1.player.hat is ISaveElement) { ISaveElement element = (ISaveElement)Game1.player.hat; string additionalSaveData = string.Join("/", element.getAdditionalSaveData().Select(x => x.Key + "=" + x.Value)); string type = getTypeName(element); string name = "CEHe/Item/" + type + "/" + additionalSaveData; Hat replacement = (Hat)element.getReplacement(); replacement.name = name; Game1.player.hat = (Hat)replacement; } if (Game1.player.boots is ISaveElement) { ISaveElement element = (ISaveElement)Game1.player.boots; string additionalSaveData = string.Join("/", element.getAdditionalSaveData().Select(x => x.Key + "=" + x.Value)); string type = getTypeName(element); string name = "CEHe/Item/" + type + "/" + additionalSaveData; Boots replacement = (Boots)element.getReplacement(); replacement.name = name; Game1.player.boots = (Boots)replacement; } if (Game1.player.leftRing is ISaveElement) { ISaveElement element = (ISaveElement)Game1.player.leftRing; string additionalSaveData = string.Join("/", element.getAdditionalSaveData().Select(x => x.Key + "=" + x.Value)); string type = getTypeName(element); string name = "CEHe/Item/" + type + "/" + additionalSaveData; Ring replacement = (Ring)element.getReplacement(); replacement.name = name; Game1.player.leftRing = (Ring)replacement; } if (Game1.player.rightRing is ISaveElement) { ISaveElement element = (ISaveElement)Game1.player.rightRing; string additionalSaveData = string.Join("/", element.getAdditionalSaveData().Select(x => x.Key + "=" + x.Value)); string type = getTypeName(element); string name = "CEHe/Item/" + type + "/" + additionalSaveData; Ring replacement = (Ring)element.getReplacement(); replacement.name = name; Game1.player.rightRing = (Ring)replacement; } for (int i = 0; i < elements.Count; i++) { if (elements[i] is List <Item> ) { List <Item> list = (List <Item>)elements[i]; for (int j = 0; j < list.Count; j++) { if (list[j] is ISaveElement) { ISaveElement element = (ISaveElement)list[j]; string additionalSaveData = string.Join("/", element.getAdditionalSaveData().Select(x => x.Key + "=" + x.Value)); string type = getTypeName(element); string name = "CEHe/Item/" + type + "/" + additionalSaveData; Item replacement = (Item)element.getReplacement(); if (replacement is StardewValley.Object obj) { obj.name = name; list[j] = obj; } else if (replacement is Tool tool) { tool.name = name; list[j] = tool; } else { list[j] = replacement; } } } } else if (elements[i] is List <Furniture> ) { List <Furniture> list = (List <Furniture>)elements[i]; for (int j = 0; j < list.Count; j++) { if (list[j] is ISaveElement) { ISaveElement element = (ISaveElement)list[j]; string additionalSaveData = string.Join("/", element.getAdditionalSaveData().Select(x => x.Key + "=" + x.Value)); string type = getTypeName(element); string name = "CEHe/Item/" + type + "/" + additionalSaveData; StardewValley.Object replacement = (StardewValley.Object)element.getReplacement(); replacement.name = name; list[j] = (Furniture)replacement; } } } else if (elements[i] is SerializableDictionary <Vector2, StardewValley.Object> ) { SerializableDictionary <Vector2, StardewValley.Object> changes = new SerializableDictionary <Vector2, StardewValley.Object>(); SerializableDictionary <Vector2, StardewValley.Object> dict = (SerializableDictionary <Vector2, StardewValley.Object>)elements[i]; foreach (Vector2 keyV in dict.Keys) { if (dict[keyV] is ISaveElement) { ISaveElement element = (ISaveElement)dict[keyV]; string additionalSaveData = string.Join("/", element.getAdditionalSaveData().Select(x => x.Key + "=" + x.Value)); string type = getTypeName(element); string name = "CEHe/Object/" + type + "/" + additionalSaveData; StardewValley.Object replacement = (StardewValley.Object)element.getReplacement(); replacement.name = name; changes.Add(keyV, (StardewValley.Object)replacement); } } foreach (Vector2 keyV in changes.Keys) { dict[keyV] = changes[keyV]; } } else if (elements[i] is SerializableDictionary <Vector2, StardewValley.TerrainFeatures.TerrainFeature> ) { SerializableDictionary <Vector2, StardewValley.Object> changes = new SerializableDictionary <Vector2, StardewValley.Object>(); SerializableDictionary <Vector2, StardewValley.TerrainFeatures.TerrainFeature> dict = (SerializableDictionary <Vector2, StardewValley.TerrainFeatures.TerrainFeature>)elements[i]; foreach (Vector2 keyV in dict.Keys) { if (dict[keyV] is ISaveElement) { ISaveElement element = (ISaveElement)dict[keyV]; string additionalSaveData = string.Join("/", element.getAdditionalSaveData().Select(x => x.Key + "=" + x.Value)); string type = getTypeName(element); string name = "CEHe/Terrain/" + type + "/" + additionalSaveData; StardewValley.Object replacement = (StardewValley.Object)element.getReplacement(); replacement.name = name; changes.Add(keyV, (StardewValley.Object)replacement); } } SerializableDictionary <Vector2, StardewValley.Object> objectLayer = (SerializableDictionary <Vector2, StardewValley.Object>)elements[i - 1]; foreach (Vector2 keyV in changes.Keys) { dict[keyV] = new StardewValley.TerrainFeatures.Flooring(0); if (objectLayer.ContainsKey(keyV)) { objectLayer[keyV].name = changes[keyV].name + "#" + objectLayer[keyV].name; } else { objectLayer[keyV] = changes[keyV]; } } } else if (elements[i] is SerializableDictionary <long, FarmAnimal> ) { SerializableDictionary <long, FarmAnimal> changes = new SerializableDictionary <long, FarmAnimal>(); SerializableDictionary <long, FarmAnimal> dict = (SerializableDictionary <long, FarmAnimal>)elements[i]; foreach (long keyL in dict.Keys) { if (dict[keyL] is ISaveElement) { ISaveElement element = (ISaveElement)dict[keyL]; string additionalSaveData = string.Join("/", element.getAdditionalSaveData().Select(x => x.Key + "=" + x.Value)); string type = getTypeName(element); string name = "CEHe/Animal/" + type + "/" + additionalSaveData; FarmAnimal replacement = (FarmAnimal)element.getReplacement(); replacement.name = name; changes.Add(keyL, (FarmAnimal)replacement); } } foreach (long keyL in changes.Keys) { dict[keyL] = changes[keyL]; } } else if (elements[i] is List <NPC> ) { List <NPC> list = (List <NPC>)elements[i]; for (int j = 0; j < list.Count; j++) { if (list[j] is ISaveElement) { ISaveElement element = (ISaveElement)list[j]; string additionalSaveData = string.Join("/", element.getAdditionalSaveData().Select(x => x.Key + "=" + x.Value)); string type = getTypeName(element); string name = "CEHe/NPC/" + type + "/" + additionalSaveData; NPC replacement = (NPC)element.getReplacement(); replacement.name = name; list[j] = (NPC)replacement; } } } else if (elements[i] is StardewValley.Object[]) { StardewValley.Object[] list = (StardewValley.Object[])elements[i]; for (int j = 0; j < list.Length; j++) { if (list[j] is ISaveElement) { ISaveElement element = (ISaveElement)list[j]; string additionalSaveData = string.Join("/", element.getAdditionalSaveData().Select(x => x.Key + "=" + x.Value)); string type = getTypeName(element); string name = "CEHe/Attachement/" + type + "/" + additionalSaveData; StardewValley.Object replacement = (StardewValley.Object)element.getReplacement(); replacement.name = name; list[j] = (StardewValley.Object)replacement; } } } } OnFinishedRemoving(EventArgs.Empty); }