using System; using StardewValley; using StardewModdingAPI; using System.IO; /* TO DO: */ namespace Stardew_Save_Anywhere_Mod { public class Class1 : Mod { string key_binding="R"; bool game_loaded = false; public override void Entry(params object[] objects) { //set up all of my events here StardewModdingAPI.Events.PlayerEvents.LoadedGame += PlayerEvents_LoadedGame; StardewModdingAPI.Events.ControlEvents.KeyPressed += ControlEvents_KeyPressed; } public void ControlEvents_KeyPressed(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e) { if (e.KeyPressed.ToString() == key_binding) //if the key is pressed, load my cusom save function { if (StardewValley.Game1.player.currentLocation.name == "ArchaeologyHouse") { my_save(); } else { Log.Info("You can't rearrange the museum here!"); } } //DataLoader_Settings(); //update the key if players changed it while playing. } public void PlayerEvents_LoadedGame(object sender, StardewModdingAPI.Events.EventArgsLoadedGameChanged e) { game_loaded = true; DataLoader_Settings(); MyWritter_Settings(); } void DataLoader_Settings() { //loads the data to the variables upon loading the game. string myname = StardewValley.Game1.player.name; string mylocation = Path.Combine(PathOnDisk, "Museum_Rearrange_Config"); string mylocation2 = mylocation; string mylocation3 = mylocation2 + ".txt"; if (!File.Exists(mylocation3)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out. { // Console.WriteLine("Can't load custom save info since the file doesn't exist."); key_binding = "R"; // Log.Info("KEY TIME"); } else { // Console.WriteLine("HEY THERE IM LOADING DATA"); string[] readtext = File.ReadAllLines(mylocation3); key_binding = Convert.ToString(readtext[3]); // Log.Info(key_binding); // Log.Info(Convert.ToString(readtext[3])); } } void MyWritter_Settings() { //write all of my info to a text file. string myname = StardewValley.Game1.player.name; string mylocation = Path.Combine(PathOnDisk, "Museum_Rearrange_Config"); string mylocation2 = mylocation; string mylocation3 = mylocation2 + ".txt"; string[] mystring3 = new string[20]; if (!File.Exists(mylocation3)) { Console.WriteLine("The custom character save info doesn't exist. It will be created when the custom saving method is run. Which is now."); mystring3[0] = "Config: Museum_Rearranger. Feel free to mess with these settings."; mystring3[1] = "===================================================================================="; mystring3[2] = "Key binding for saving anywhere. Press this key to save anywhere!"; mystring3[3] = key_binding.ToString(); File.WriteAllLines(mylocation3, mystring3); } else { //write out the info to a text file at the end of a day. This will run if it doesnt exist. mystring3[0] = "Config: Save_Anywhere Info. Feel free to mess with these settings."; mystring3[1] = "===================================================================================="; mystring3[2] = "Key binding for saving anywhere. Press this key to save anywhere!"; mystring3[3] = key_binding.ToString(); File.WriteAllLines(mylocation3, mystring3); } } void my_save() { // Game1.activeClickableMenu = new StardewValley.Menus.SaveGameMenu(); //This command is what allows the player to save anywhere as it calls the saving function. Game1.activeClickableMenu = new StardewValley.Menus.MuseumMenu(); } } } //end class