public PlacedAugmentorsManager() { this.Locations = new Dictionary <string, AugmentedLocation>(); try { if (!Context.IsMultiplayer || Context.IsMainPlayer) { // Load data from save file SerializablePlacedAugmentors SavedData = MachineAugmentorsMod.ModInstance.Helper.Data.ReadSaveData <SerializablePlacedAugmentors>(SavedDataKey); if (SavedData != null) { foreach (SerializableAugmentedLocation SavedLocation in SavedData.Locations) { string LocationName = SavedLocation.UniqueLocationName; GameLocation GL = Game1.getLocationFromName(LocationName); if (GL == null) { MachineAugmentorsMod.ModInstance.Monitor.Log(string.Format("Warning - Could not find a GameLocation named '{0}'. Some of your augmentors may not have been loaded from your save file!", LocationName), LogLevel.Warn); } else { AugmentedLocation AL = new AugmentedLocation(this, LocationName); Locations.Add(LocationName, AL); foreach (SerializableAugmentedTile SavedTile in SavedLocation.Tiles) { if (!GL.Objects.TryGetValue(new Vector2(SavedTile.TileXPosition, SavedTile.TileYPosition), out Object Item)) { string Warning = string.Format("Warning - GameLocation '{0}' does not have a machine at ({1},{2}). Some of your augmentors may not have been loaded from your save file!", LocationName, SavedTile.TileXPosition, SavedTile.TileYPosition); MachineAugmentorsMod.ModInstance.Monitor.Log(Warning, LogLevel.Warn); } else { AugmentedTile AT = new AugmentedTile(AL, SavedTile.TileXPosition, SavedTile.TileYPosition); AL.Tiles.Add(AugmentedLocation.EncodeTileToString(SavedTile.TileXPosition, SavedTile.TileYPosition), AT); for (int i = 0; i < SavedTile.AugmentorTypes.Length; i++) { AugmentorType Type = SavedTile.AugmentorTypes[i]; int Quantity = SavedTile.AugmentorQuantities[i]; AT.Quantities.Add(Type, Quantity); } } } } } } } } catch (Exception ex) { MachineAugmentorsMod.ModInstance.Monitor.Log("Error while loading augmentor data from ReadSaveData: " + ex, LogLevel.Error); } }
internal void LoadSettings(SerializablePlacedAugmentors Data) { if (Data != null) { foreach (SerializableAugmentedLocation SavedLocation in Data.Locations) { string LocationName = SavedLocation.UniqueLocationName; GameLocation GL = Game1.getLocationFromName(LocationName); if (GL == null) { MachineAugmentorsMod.ModInstance.Monitor.Log(string.Format("Warning - Could not find a GameLocation named '{0}'. Some of your augmentors may not have been loaded from your save file!", LocationName), LogLevel.Warn); } else { AugmentedLocation AL = new AugmentedLocation(this, LocationName); Locations.Add(LocationName, AL); foreach (SerializableAugmentedTile SavedTile in SavedLocation.Tiles) { if (!GL.Objects.TryGetValue(new Vector2(SavedTile.TileXPosition, SavedTile.TileYPosition), out Object Item)) { string Warning = string.Format("Warning - GameLocation '{0}' does not have a machine at ({1},{2}). Some of your augmentors may not have been loaded from your save file!", LocationName, SavedTile.TileXPosition, SavedTile.TileYPosition); MachineAugmentorsMod.ModInstance.Monitor.Log(Warning, LogLevel.Warn); } else { AugmentedTile AT = new AugmentedTile(AL, SavedTile.TileXPosition, SavedTile.TileYPosition); AL.Tiles.Add(AugmentedLocation.EncodeTileToString(SavedTile.TileXPosition, SavedTile.TileYPosition), AT); for (int i = 0; i < SavedTile.AugmentorTypes.Length; i++) { AugmentorType Type = SavedTile.AugmentorTypes[i]; int Quantity = SavedTile.AugmentorQuantities[i]; AT.Quantities.Add(Type, Quantity); } } } } } } }
/// <summary>Checks the given tile position of each augmented location, to find a <see cref="AugmentedTile"/> with the matching Machine.</summary> public bool TryFindAugmentedTile(Object Machine, int TileX, int TileY, out AugmentedTile Result) { Result = null; if (Machine == null || !Machine.bigCraftable || !Machine.isPlaceable()) { return(false); } string Key = AugmentedLocation.EncodeTileToString(TileX, TileY); foreach (AugmentedLocation AL in this.Locations.Values) { AugmentedTile Tile; if (AL.Tiles.TryGetValue(Key, out Tile) && Tile.Machine == Machine) { Result = Tile; return(true); } } return(false); }