Ejemplo n.º 1
0
        /// <summary>Raised after the game finishes writing data to the save file (except the initial save creation).</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnSaved(object sender, SavedEventArgs e)
        {
            // delete legacy mod data (migrated into save file by this point)
            {
                FileInfo legacyFile = new FileInfo(Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework", "CustomItems.json"));
                if (legacyFile.Exists)
                {
                    legacyFile.Delete();
                }

                DirectoryInfo legacyDir = new DirectoryInfo(Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework"));
                if (legacyDir.Exists && !legacyDir.GetFileSystemInfos().Any())
                {
                    legacyDir.Delete();
                }
            }

            // read data
            this.Monitor.Log("Unpacking custom objects...", LogLevel.Trace);
            ItemEvents.FireBeforeDeserialize();
            IDictionary <string, InstanceState> data = this.Helper.Data.ReadSaveData <Dictionary <string, InstanceState> >("custom-items") ?? new Dictionary <string, InstanceState>();

            this.RestoreItems(data);
            ItemEvents.FireAfterDeserialize();
        }
Ejemplo n.º 2
0
        private void SaveEvents_AfterSave(object s, EventArgs e)
        {
            this.Monitor.Log("Unpacking custom objects...", LogLevel.Trace);
            ItemEvents.FireBeforeDeserialize();
            string path = Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework", "CustomItems.json");
            var    data = this.Helper.ReadJsonFile <Dictionary <string, InstanceState> >(path) ?? new Dictionary <string, InstanceState>();

            foreach (GameLocation loc in Game1.locations)
            {
                foreach (SObject objects in loc.Objects.Values)
                {
                    if (objects is Chest chest)
                    {
                        chest = new Chest(chest.coins.Value, Deserialize(data, chest.items), chest.TileLocation, chest.giftbox.Value, chest.giftboxIndex.Value);
                    }
                }
            }
            Game1.player.Items = Deserialize(data, Game1.player.Items);
            if (Game1.getLocationFromName("FarmHouse") is FarmHouse house)
            {
                house.fridge.Value?.items.Clear();
                if (house.fridge.Value != null)
                {
                    var items = this.Deserialize(data, house.fridge.Value.items);
                    foreach (Item item in items)
                    {
                        house.fridge.Value.addItem(item);
                    }
                }
            }
            ItemEvents.FireAfterDeserialize();
        }
Ejemplo n.º 3
0
        /// <summary>Raised after the player loads a save slot and the world is initialised.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
        {
            // read data
            if (Context.IsMainPlayer)
            {
                this.Monitor.Log("Unpacking custom objects...", LogLevel.Trace);
                ItemEvents.FireBeforeDeserialize();
                IDictionary <string, InstanceState> data = this.Helper.Data.ReadSaveData <Dictionary <string, InstanceState> >("custom-items");
                if (data == null)
                {
                    // read from legacy mod file
                    FileInfo legacyFile = new FileInfo(Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework", "CustomItems.json"));
                    if (legacyFile.Exists)
                    {
                        data = JsonConvert.DeserializeObject <Dictionary <string, InstanceState> >(File.ReadAllText(legacyFile.FullName));
                    }
                }

                if (data == null)
                {
                    data = new Dictionary <string, InstanceState>();
                }
                this.RestoreItems(data);
                ItemEvents.FireAfterDeserialize();
            }
        }
Ejemplo n.º 4
0
        private void RestoreSave()
        {
            if (!Context.IsMainPlayer)
            {
                return;
            }
            // read data
            this.Monitor.Log("Unpacking custom objects...", LogLevel.Trace);
            ItemEvents.FireBeforeDeserialize();
            Dictionary <string, Tuple <bool, InstanceState> > locations = this.Helper.Data.ReadSaveData <Dictionary <string, Tuple <bool, InstanceState> > >("custom-locations") ?? new Dictionary <string, Tuple <bool, InstanceState> >();

            foreach (var location in locations)
            {
                if (location.Value.Item1)
                {
                    return;
                }
                Game1.locations.Remove(Game1.getLocationFromName(location.Key));
                Game1.locations.Add(location.Value.Item2.Restore <GameLocation>());
            }
            IDictionary <string, InstanceState> data = this.Helper.Data.ReadSaveData <Dictionary <string, InstanceState> >("custom-items") ?? new Dictionary <string, InstanceState>();

            this.RestoreItems(data);
            List <Tuple <string, Vector2, InstanceState> > features = this.Helper.Data.ReadSaveData <List <Tuple <string, Vector2, InstanceState> > >("custom-features") ?? new List <Tuple <string, Vector2, InstanceState> >();

            foreach (var feature in features)
            {
                Game1.getLocationFromName(feature.Item1)?.terrainFeatures.Add(feature.Item2, feature.Item3.Restore <TerrainFeature>());
            }
            ItemEvents.FireAfterDeserialize();
        }
Ejemplo n.º 5
0
        /// <summary>Raised after the game finishes writing data to the save file (except the initial save creation).</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnSaved(object sender, SavedEventArgs e)
        {
            // delete legacy mod data (migrated into save file by this point)
            {
                FileInfo legacyFile = new FileInfo(Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework", "CustomItems.json"));
                if (legacyFile.Exists)
                {
                    legacyFile.Delete();
                }

                DirectoryInfo legacyDir = new DirectoryInfo(Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework"));
                if (legacyDir.Exists && !legacyDir.GetFileSystemInfos().Any())
                {
                    legacyDir.Delete();
                }
            }

            // read data
            this.Monitor.Log("Unpacking custom objects...", LogLevel.Trace);
            ItemEvents.FireBeforeDeserialize();
            Dictionary <string, Tuple <bool, InstanceState> > locations = this.Helper.Data.ReadSaveData <Dictionary <string, Tuple <bool, InstanceState> > >("custom-locations") ?? new Dictionary <string, Tuple <bool, InstanceState> >();

            foreach (var location in locations)
            {
                if (location.Value.Item1)
                {
                    return;
                }
                Game1.locations.Remove(Game1.getLocationFromName(location.Key));
                Game1.locations.Add(location.Value.Item2.Restore <GameLocation>());
            }
            IDictionary <string, InstanceState> data = this.Helper.Data.ReadSaveData <Dictionary <string, InstanceState> >("custom-items") ?? new Dictionary <string, InstanceState>();

            this.RestoreItems(data);
            List <Tuple <string, Vector2, InstanceState> > features = this.Helper.Data.ReadSaveData <List <Tuple <string, Vector2, InstanceState> > >("custom-features") ?? new List <Tuple <string, Vector2, InstanceState> >();

            foreach (var feature in features)
            {
                Game1.getLocationFromName(feature.Item1)?.terrainFeatures.Add(feature.Item2, feature.Item3.Restore <TerrainFeature>());
            }
            ItemEvents.FireAfterDeserialize();
        }
Ejemplo n.º 6
0
        private void SaveEvents_AfterSave(object s, EventArgs e)
        {
            this.Monitor.Log("Unpacking custom objects...", LogLevel.Trace);
            ItemEvents.FireBeforeDeserialize();
            string path = Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework", "CustomItems.json");
            Dictionary <string, InstanceState> data = this.Helper.ReadJsonFile <Dictionary <string, InstanceState> >(path) ?? new Dictionary <string, InstanceState>();

            foreach (GameLocation loc in Game1.locations)
            {
                foreach (Chest chest in loc.Objects.Values.OfType <Chest>())
                {
                    this.Deserialize(data, chest.items);
                }
            }

            FarmHouse house = (FarmHouse)Game1.getLocationFromName("FarmHouse");

            this.Deserialize(data, Game1.player.Items);
            this.Deserialize(data, house.fridge.Value.items);
            ItemEvents.FireAfterDeserialize();
        }
Ejemplo n.º 7
0
        private void SaveEvents_AfterSave(object s, EventArgs e)
        {
            this.Monitor.Log("Unpacking custom objects...", LogLevel.Trace);
            ItemEvents.FireBeforeDeserialize();
            string path = Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework", "CustomItems.json");
            var    data = this.Helper.ReadJsonFile <Dictionary <string, InstanceState> >(path) ?? new Dictionary <string, InstanceState>();

            foreach (GameLocation loc in Game1.locations)
            {
                foreach (Chest chest in loc.objects.Where(a => a.Value is Chest).Select(a => (Chest)a.Value))
                {
                    chest.items = Deserialize(data, chest.items);
                }
            }
            Game1.player.items = Deserialize(data, Game1.player.items);
            var house = (Game1.getLocationFromName("FarmHouse") as StardewValley.Locations.FarmHouse);

            if (house.fridge != null)
            {
                house.fridge.items = Deserialize(data, house.fridge.items);
            }
            ItemEvents.FireAfterDeserialize();
        }