/// <inheritdoc />
        /// <summary>Initialize the mod.</summary>
        /// <param name="helper">Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</param>
        public override void Entry(IModHelper helper)
        {
            // Load configs
            this.Config         = helper.ReadConfig <ConfigMain>();
            this.TreasureConfig = helper.ReadJsonFile <ConfigTreasure>("treasure.json") ?? new ConfigTreasure();
            this.FishConfig     = helper.ReadJsonFile <ConfigFish>("fish.json") ?? new ConfigFish();

            // Make sure the extra configs are generated
            helper.WriteJsonFile("treasure.json", this.TreasureConfig);
            helper.WriteJsonFile("fish.json", this.FishConfig);

            this.Config.AdditionalLootChance = (float)Math.Min(this.Config.AdditionalLootChance, 0.99);
            helper.WriteConfig(this.Config);

            this.OnLanguageChange(LocalizedContentManager.CurrentLanguageCode);

            // Stop here if the mod is disabled
            if (!this.Config.ModEnabled)
            {
                return;
            }

            // Events
            GameEvents.UpdateTick    += this.UpdateTick;
            ControlEvents.KeyPressed += this.KeyPressed;
            LocalizedContentManager.OnLanguageChange += this.OnLanguageChange;
        }
Exemple #2
0
 private void OnSave(IModHelper helper)
 {
     if (Record)
     {
         helper.WriteJsonFile(GiftInfoPath, GiftLog);
         Monitor.Log($"Saved {GiftInfoPath}");
     }
     else
     {
         Monitor.Log("Session data not saved, recordedGiftInfo flag set to " + Record);
     }
 }
        // Factory function.
        public static ScheduleLibrary Create(IModHelper helper)
        {
            ScheduleLibrary instance = helper.ReadJsonFile <ScheduleLibrary>("CharacterScheduleLibrary.json");

            if (instance == null)
            {
                instance = new ScheduleLibrary();
                helper.WriteJsonFile("CharacterScheduleLibrary.json", instance);
            }

            instance.Helper = helper;
            return(instance);
        }
Exemple #4
0
        /// <summary>Save the configuration file for a content pack.</summary>
        /// <param name="contentPack">The content pack.</param>
        /// <param name="config">The configuration to save.</param>
        /// <param name="modHelper">The mod helper through which to save the file.</param>
        public void Save(IContentPack contentPack, InvariantDictionary <ConfigField> config, IModHelper modHelper)
        {
            string configPath = Path.Combine(contentPack.DirectoryPath, this.Filename);

            // save if settings valid
            if (config.Any())
            {
                InvariantDictionary <string> data = new InvariantDictionary <string>(config.ToDictionary(p => p.Key, p => string.Join(", ", p.Value.Value)));
                modHelper.WriteJsonFile(configPath, data);
            }

            // delete if no settings
            else if (File.Exists(configPath))
            {
                File.Delete(configPath);
            }
        }
        public DataLoader(IModHelper helper)
        {
            Helper    = helper;
            ModConfig = helper.ReadConfig <ModConfig>();
            i18n      = Helper.Translation;

            LooseSpritesName = Helper.Content.GetActualAssetKey("common/LooseSprites.png", ContentSource.ModFolder);
            LooseSprites     = Helper.Content.Load <Texture2D>("common/LooseSprites.png");

            var editors = Helper.Content.AssetEditors;

            editors.Add(new EventsLoader());

            if (!ModConfig.DisableMeat)
            {
                editors.Add(this);
            }

            ToolsSprites = Helper.Content.Load <Texture2D>("tools/Tools.png");
            ToolsLoader  = new ToolsLoader(ToolsSprites, Helper.Content.Load <Texture2D>("tools/MenuTiles.png"), Helper.Content.Load <Texture2D>("common/CustomLetterBG.png"));
            editors.Add(ToolsLoader);
            ToolsLoader.LoadMail();

            if (!ModConfig.DisableMeat)
            {
                RecipeLoader = new RecipesLoader();
                editors.Add(RecipeLoader);
                RecipeLoader.LoadMails();
            }

            AnimalBuildingData = DataLoader.Helper.ReadJsonFile <AnimalBuildingData>("data\\animalBuilding.json") ?? new AnimalBuildingData();
            DataLoader.Helper.WriteJsonFile("data\\animalBuilding.json", AnimalBuildingData);

            AnimalData = DataLoader.Helper.ReadJsonFile <AnimalData>("data\\animals.json") ?? new AnimalData();
            DataLoader.Helper.WriteJsonFile("data\\animals.json", AnimalData);

            CookingData = Helper.ReadJsonFile <CookingData>("data\\cooking.json") ?? new CookingData();
            if (CookingData.Meatloaf.Recipe == null)
            {
                CookingData.CloneRecipeAndAmount(new CookingData());
            }
            Helper.WriteJsonFile("data\\cooking.json", CookingData);

            LivingWithTheAnimalsChannel = new LivingWithTheAnimalsChannel();
        }
Exemple #6
0
        /// <summary>Migrate the legacy <c>TractorModSave.json</c> file to the new config files.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        private void MigrateLegacySaveData(IModHelper helper)
        {
            // get file
            const string filename = "TractorModSave.json";
            FileInfo     file     = new FileInfo(Path.Combine(helper.DirectoryPath, filename));

            if (!file.Exists)
            {
                return;
            }

            // read legacy data
            this.Monitor.Log($"Found legacy {filename}, migrating to new save data...");
            IDictionary <string, CustomSaveData> saves = new Dictionary <string, CustomSaveData>();

            {
                LegacySaveData data = helper.ReadJsonFile <LegacySaveData>(filename);
                if (data.Saves != null && data.Saves.Any())
                {
                    foreach (LegacySaveData.LegacySaveEntry saveData in data.Saves)
                    {
                        saves[$"{saveData.FarmerName}_{saveData.SaveSeed}"] = new CustomSaveData(
                            saveData.TractorHouse.Select(p => new CustomSaveBuilding(new Vector2(p.X, p.Y), this.GarageBuildingType, "Farm", 0))
                            );
                    }
                }
            }

            // write new files
            foreach (var save in saves)
            {
                if (save.Value.Buildings.Any())
                {
                    helper.WriteJsonFile(this.GetDataPath(save.Key), save.Value);
                }
            }

            // delete old file
            file.Delete();
        }
        /// <summary>
        ///     Saves the status of challenges and switches the
        ///     CustomAdventureGuild with AdventureGuild to prevent
        ///     crashing the save process
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public virtual void PresaveData(object sender, EventArgs e)
        {
            string saveDataPath = Path.Combine("saveData", Constants.SaveFolderName + ".json");
            var    saveData     = new SaveData();

            foreach (var slayerChallenge in ChallengeList)
            {
                var save = new ChallengeSave()
                {
                    ChallengeName = slayerChallenge.Info.ChallengeName,
                    Collected     = slayerChallenge.CollectedReward
                };

                saveData.Challenges.Add(save);
            }

            modHelper.WriteJsonFile(saveDataPath, saveData);

            // Remove custom location and add back the original location
            Game1.locations.Remove(customAdventureGuild);
            Game1.locations.Add(adventureGuild);
        }
 public void Save(IModHelper helper, string filename)
 {
     helper.WriteJsonFile(filename, this);
 }
        public override void Entry(IModHelper helper)
        {
            Config = new TimeMultiplierConfig();

            LastTimeInterval = 0;

            SaveEvents.AfterLoad += (sender, e) =>
            {
                LastTimeInterval = 0;

                string configLocation = Path.Combine("data", Constants.SaveFolderName + ".json");
                Config = helper.ReadJsonFile <TimeMultiplierConfig>(configLocation) ?? new TimeMultiplierConfig();

                if (Config.Enabled)
                {
                    timeMultiplierToggled(Config.Enabled);
                }
            };

            SaveEvents.AfterReturnToTitle += (sender, e) =>
            {
                LastTimeInterval = 0;

                string configLocation = Path.Combine("data", Constants.SaveFolderName + ".json");
                helper.WriteJsonFile <TimeMultiplierConfig>(configLocation, Config);

                Config = new TimeMultiplierConfig();
                timeMultiplierToggled(false);
            };

            helper.ConsoleCommands.Add("time_multiplier_change", "Updates time multiplier on the fly", (string command, string[] args) =>
            {
                float multiplierArg;

                if (args.Length != 1)
                {
                    Monitor.Log("Usage: time_multiplier_change 1.00 ", LogLevel.Error);
                    return;
                }
                else if (!float.TryParse(args[0], out multiplierArg))
                {
                    Monitor.Log("Error: '" + args[0] + "' is not a valid decimal. Usage: time_multiplier_change 1.00 ", LogLevel.Error);
                    return;
                }

                Config.TimeMultiplier = multiplierArg;

                string configLocation = Path.Combine("data", Constants.SaveFolderName + ".json");
                helper.WriteJsonFile <TimeMultiplierConfig>(configLocation, Config);

                Monitor.Log("Time now multiplied by " + multiplierArg, LogLevel.Info);
            });

            helper.ConsoleCommands.Add("time_multiplier_toggle", "Updates time multiplier on the fly", (string command, string[] args) =>
            {
                if (!timeMultiplierToggled(!Config.Enabled))
                {
                    return;
                }

                LastTimeInterval = 0;
                Config.Enabled   = !Config.Enabled;

                string configLocation = Path.Combine("data", Constants.SaveFolderName + ".json");
                helper.WriteJsonFile <TimeMultiplierConfig>(configLocation, Config);

                Monitor.Log("Time multiplier enabled: " + Config.Enabled, LogLevel.Info);
            });

            Monitor.Log("Initialized");
        }
Exemple #10
0
 private void SaveData()
 {
     modData.MenuPosition = new Vector2(this.xPositionOnScreen, this.yPositionOnScreen);
     helper.WriteJsonFile("data.json", modData);
 }
Exemple #11
0
        public override void Entry(IModHelper helper)
        {
            instance = this;

            MenuEvents.MenuChanged += menuChanged;

            var savedIds = helper.ReadJsonFile <Dictionary <string, CropData.Ids> >(Path.Combine(Helper.DirectoryPath, "saved-ids.json"));

            if (savedIds != null)
            {
                CropData.savedIds = savedIds;
                foreach (var ids in savedIds)
                {
                    CropData.Ids.MostRecentObject = Math.Max(CropData.Ids.MostRecentObject, Math.Max(ids.Value.Product, ids.Value.Seeds));
                    CropData.Ids.MostRecentCrop   = Math.Max(CropData.Ids.MostRecentCrop, ids.Value.Crop);
                }
            }

            CropData.crops.Clear();
            Log.info("Registering custom crops...");
            foreach (var file in Directory.EnumerateDirectories(Path.Combine(helper.DirectoryPath, "Crops")))
            {
                try
                {
                    var data = helper.ReadJsonFile <CropData>(Path.Combine(file, "crop.json"));
                    if (data == null)
                    {
                        Log.warn("\tFailed to load crop data for " + file);
                        continue;
                    }
                    else if (!File.Exists(Path.Combine(file, "crop.png")))
                    {
                        Log.warn("\tCrop " + file + " has no crop image, skipping");
                        continue;
                    }
                    else if (!File.Exists(Path.Combine(file, "product.png")))
                    {
                        Log.warn("\tCrop " + file + " has no product image, skipping");
                        continue;
                    }
                    else if (!File.Exists(Path.Combine(file, "seeds.png")))
                    {
                        Log.warn("\tCrop " + file + " has no seeds image, skipping");
                        continue;
                    }

                    Log.info("\tCrop: " + data.Id);
                    CropData.Register(data);
                }
                catch (Exception e)
                {
                    Log.warn("\tFailed to load crop data for " + file + ": " + e);
                    continue;
                }
            }
            helper.WriteJsonFile(Path.Combine(Helper.DirectoryPath, "saved-ids.json"), CropData.savedIds);

            var editors = ((IList <IAssetEditor>)helper.Content.GetType().GetProperty("AssetEditors", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).GetValue(Helper.Content));

            editors.Add(new ContentInjector());
        }