Example #1
0
        private void GameLoop_Saving(object sender, StardewModdingAPI.Events.SavingEventArgs e)
        {
            UtilitySystemDictData dict = new UtilitySystemDictData();

            Monitor.Log($"writing grid data for {utilitySystemDict.Count} locations from save");
            foreach (var kvp in utilitySystemDict)
            {
                UtilitySystemData gridData = new UtilitySystemData(kvp.Value[GridType.water].pipes, kvp.Value[GridType.electric].pipes);
                dict.dict[kvp.Key] = gridData;
                Monitor.Log($"writing {gridData.electricData.Count} ep and {gridData.waterData.Count} wp for location {kvp.Key} to save");
            }
            Helper.Data.WriteSaveData(saveKey, dict);
        }
Example #2
0
        private void GameLoop_SaveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e)
        {
            utilitySystemDict = new Dictionary <string, Dictionary <GridType, UtilitySystem> >();
            ShowingGrid       = false;
            CurrentRotation   = 0;
            CurrentTile       = 0;
            try
            {
                utilityObjectDict = SHelper.Content.Load <Dictionary <string, UtilityObject> >(dictPath, ContentSource.GameContent);
                UtilitySystemDictData systemDataDict = Helper.Data.ReadSaveData <UtilitySystemDictData>(saveKey) ?? new UtilitySystemDictData();

                Monitor.Log($"reading grid data for {systemDataDict.dict.Count} locations from save");
                foreach (var kvp in systemDataDict.dict)
                {
                    Monitor.Log($"reading {kvp.Value.electricData.Count} ep and {kvp.Value.waterData.Count} wp for location {kvp.Key}");
                    utilitySystemDict[kvp.Key] = new Dictionary <GridType, UtilitySystem>();
                    utilitySystemDict[kvp.Key][GridType.electric] = new UtilitySystem();
                    utilitySystemDict[kvp.Key][GridType.water]    = new UtilitySystem();
                    foreach (var arr in kvp.Value.waterData)
                    {
                        utilitySystemDict[kvp.Key][GridType.water].pipes[new Vector2(arr[0], arr[1])] = new GridPipe()
                        {
                            index = arr[2], rotation = arr[3]
                        };
                    }
                    foreach (var arr in kvp.Value.electricData)
                    {
                        utilitySystemDict[kvp.Key][GridType.electric].pipes[new Vector2(arr[0], arr[1])] = new GridPipe()
                        {
                            index = arr[2], rotation = arr[3]
                        };
                    }
                    RemakeAllGroups(kvp.Key);
                }
            }
            catch
            {
                Monitor.Log("Invalid utility system in save file... starting fresh", LogLevel.Warn);
            }
        }