Example #1
0
 private void GameLoop_Saving(object sender, SavingEventArgs e)
 {
     // Now we recreate the save data from our pond list. Again, host only.
     if (Context.IsMainPlayer)
     {
         // First we will go through every pond on the map and add any that are empty to our list.
         IEnumerable <BuildableGameLocation> BuildableLocations =
             from loc in Game1.locations where loc is BuildableGameLocation select loc as BuildableGameLocation;
         foreach (BuildableGameLocation bloc in BuildableLocations)
         {
             IEnumerable <FishPond> FishPonds =
                 from b in bloc.buildings where b is FishPond select b as FishPond;
             foreach (FishPond pond in FishPonds)
             {
                 if (IsEmpty(pond))
                 {
                     if (!EmptyPonds.ContainsKey(pond))
                     {
                         EmptyPonds.Add(pond, new AnythingPondsTracker(bloc.Name, 0));
                     }
                 }
             }
         }
         // Now we will convert our list back into saveable data.
         // We need to make sure each pond still exists and will also reverify it is empty.
         AnythingPondsSaveData saveData = new AnythingPondsSaveData();
         foreach (FishPond pond in EmptyPonds.Keys)
         {
             if (IsEmpty(pond))
             {
                 string key = $"{EmptyPonds[pond].locationName}/{pond.tileX}/{pond.tileY}";
                 saveData.EmptyPonds[key] = EmptyPonds[pond].days;
             }
         }
         Monitor.Log("Writing out empty pond data to save", LogLevel.Trace);
         Helper.Data.WriteSaveData <AnythingPondsSaveData>("EmptyPonds", saveData);
     }
 }
Example #2
0
 private void GameLoop_SaveLoaded(object sender, SaveLoadedEventArgs e)
 {
     // This function only reads the save data and uses it to create our internal pond list
     // Because of this, it is only relevant to the host
     if (Context.IsMainPlayer)
     {
         Monitor.Log("Checking for and restoring empty pond data from save", LogLevel.Trace);
         EmptyPonds = new Dictionary <FishPond, AnythingPondsTracker>();
         AnythingPondsSaveData saveData = Helper.Data.ReadSaveData <AnythingPondsSaveData>("EmptyPonds");
         if (saveData != null)
         {
             foreach (string key in saveData.EmptyPonds.Keys)
             {
                 string[] keySplit         = key.Split(new char[] { '/' });
                 BuildableGameLocation loc = Game1.getLocationFromName(keySplit[0]) as BuildableGameLocation;
                 if (loc != null)
                 {
                     Vector2 tile = new Vector2(Convert.ToInt32(keySplit[1]), Convert.ToInt32(keySplit[2]));
                     // We want to verify the pond exists and is still empty
                     FishPond pond = GetPondAtTile(loc, tile);
                     if (IsEmpty(pond))
                     {
                         EmptyPonds.Add(pond, new AnythingPondsTracker(keySplit[0], saveData.EmptyPonds[key]));
                     }
                 }
             }
         }
     }
     else
     {
         if (Config.Allow_Empty_Ponds_to_Become_Algae_or_Seaweed)
         {
             Monitor.Log("Not main player, so empty pond conversion to algae/seaweed unavailable", LogLevel.Debug);
         }
     }
 }