コード例 #1
0
        /// <summary>Raised after the game finishes creating the save file or saving.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnSaved(object sender, EventArgs e)
        {
            Log.info("Saved, putting custom farms back...");
            foreach (var entry in Data.FarmTypes)
            {
                GameLocation loc = Game1.getLocationFromName(entry.Key);
                if (loc.GetType() != typeof(Farm))
                {
                    continue;
                }

                Log.debug("Putting custom farm back for " + entry.Key + "=" + entry.Value);
                FarmType type = FarmType.getType(entry.Value);
                if (type == null)
                {
                    Log.error("Custom farm type is missing!");
                    return;
                }

                var newFarm = new CustomFarm(type, loc.name);
                if (Game1.year == 1 && Game1.currentSeason == "spring" && Game1.dayOfMonth == 1)
                {
                    Log.debug("First day? from save");
                    doFirstDayStuff(newFarm, type);
                }
                else
                {
                    CustomFarm.swapFarms(loc as Farm, newFarm);
                }
                Game1.locations.Remove(loc);
                Game1.locations.Add(newFarm);
            }
        }
コード例 #2
0
        /// <summary>Raised after the player loads a save slot.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnSaveLoaded(object sender, EventArgs e)
        {
            if (!(Game1.year == 1 && Game1.currentSeason == "spring" && Game1.dayOfMonth == 0))
            {
                Log.debug($"Loading save data... {Game1.year} {Game1.currentSeason} {Game1.dayOfMonth}");
                Data = Helper.Data.ReadSaveData <SaveData>("custom-farm-types");
                if (Data == null)
                {
                    Data = new SaveData();
                    return;
                }
            }

            foreach (var entry in Data.FarmTypes)
            {
                GameLocation loc = Game1.getLocationFromName(entry.Key);
                if (loc.GetType() != typeof(Farm))
                {
                    continue;
                }

                Log.info($"Custom farm type {entry.Value} for {entry.Key}");
                FarmType type = FarmType.getType(entry.Value);
                if (type == null)
                {
                    Log.error("Custom farm type is missing!");
                    return;
                }

                var newFarm = new CustomFarm(type, loc.Name);
                if (Game1.year == 1 && Game1.currentSeason == "spring" && Game1.dayOfMonth == 1)
                {
                    Log.debug("First day? from load");
                    doFirstDayStuff(newFarm, type);
                }
                else
                {
                    CustomFarm.swapFarms(loc as Farm, newFarm);
                }
                Game1.locations.Remove(loc);
                Game1.locations.Add(newFarm);

                Game1.setGraphicsForSeason();
            }
        }
コード例 #3
0
ファイル: Mod.cs プロジェクト: KamtarGaming/smapi-mod-dump
        private void afterLoad(object sender, EventArgs args)
        {
            if (!(Game1.year == 1 && Game1.currentSeason == "spring" && Game1.dayOfMonth == 0))
            {
                Log.debug("Loading save data... " + Game1.year + " " + Game1.currentSeason + " " + Game1.dayOfMonth);
                Data = Helper.ReadJsonFile <SaveData>(Path.Combine(Constants.CurrentSavePath, "custom-farm-type.json"));
                if (Data == null)
                {
                    Data = new SaveData();
                    return;
                }
            }

            foreach (var entry in Data.FarmTypes)
            {
                GameLocation loc = Game1.getLocationFromName(entry.Key);
                if (loc.GetType() != typeof(Farm))
                {
                    continue;
                }

                Log.info("Custom farm type " + entry.Value + " for " + entry.Key);
                FarmType type = FarmType.getType(entry.Value);
                if (type == null)
                {
                    Log.error("Custom farm type is missing!");
                    return;
                }

                var newFarm = new CustomFarm(type, loc.name);
                if (Game1.year == 1 && Game1.currentSeason == "spring" && Game1.dayOfMonth == 1)
                {
                    Log.debug("First day? from load");
                    doFirstDayStuff(newFarm, type);
                }
                else
                {
                    CustomFarm.swapFarms(loc as Farm, newFarm);
                }
                Game1.locations.Remove(loc);
                Game1.locations.Add(newFarm);

                Game1.setGraphicsForSeason();
            }
        }