Exemple #1
0
        private static MapCollectionData GetMapEdits(string path)
        {
            ModEntry.SMonitor.Log($"Loading map data from file {path}");
            MapCollectionData collection = ModEntry.SHelper.Data.ReadJsonFile <MapCollectionData>(path) ?? new MapCollectionData();

            return(collection);
        }
Exemple #2
0
        public static void SaveMapTile(string map, Vector2 tileLoc, TileLayers tile)
        {
            if (tile == null)
            {
                ModEntry.mapCollectionData.mapDataDict[map].tileDataDict.Remove(tileLoc);
                if (ModEntry.mapCollectionData.mapDataDict[map].tileDataDict.Count == 0)
                {
                    ModEntry.mapCollectionData.mapDataDict.Remove(map);
                }
            }
            else
            {
                if (!ModEntry.mapCollectionData.mapDataDict.ContainsKey(map))
                {
                    ModEntry.mapCollectionData.mapDataDict[map] = new MapData();
                }

                ModEntry.mapCollectionData.mapDataDict[map].tileDataDict[Game1.currentCursorTile] = new TileLayers(ModEntry.currentTileDict);
            }

            string modPath = ModEntry.SHelper.DirectoryPath;

            if (ModEntry.Config.IncludeGlobalEdits)
            {
                var mapData = GetMapEdits("map_data.json");
                if (tile == null)
                {
                    if (mapData.mapDataDict.ContainsKey(map) && mapData.mapDataDict[map].tileDataDict.ContainsKey(tileLoc))
                    {
                        mapData.mapDataDict[map].tileDataDict.Remove(tileLoc);
                        if (mapData.mapDataDict[map].tileDataDict.Count == 0)
                        {
                            mapData.mapDataDict.Remove(map);
                        }
                        SaveMapData(Path.Combine("map_data.json"), mapData);
                    }
                }
                else if (!ModEntry.Config.UseSaveSpecificEdits || (mapData.mapDataDict.ContainsKey(map) && mapData.mapDataDict[map].tileDataDict.ContainsKey(tileLoc))) // save new to global if not using save specific
                {
                    if (!mapData.mapDataDict.ContainsKey(map))
                    {
                        mapData.mapDataDict[map] = new MapData();
                    }

                    mapData.mapDataDict[map].tileDataDict[tileLoc] = tile;
                    SaveMapData(Path.Combine("map_data.json"), mapData);
                }
            }

            if (Directory.Exists(Path.Combine(modPath, "custom")))
            {
                foreach (string file in Directory.GetFiles(Path.Combine(modPath, "custom"), "*.json"))
                {
                    string relPath = Path.Combine("custom", Path.GetFileName(file));
                    var    mapData = GetMapEdits(relPath);

                    if (mapData.mapDataDict.ContainsKey(map) && mapData.mapDataDict[map].tileDataDict.ContainsKey(tileLoc)) // only edit if custom file contains this
                    {
                        if (tile == null)
                        {
                            mapData.mapDataDict[map].tileDataDict.Remove(tileLoc);
                            if (mapData.mapDataDict[map].tileDataDict.Count == 0)
                            {
                                mapData.mapDataDict.Remove(map);
                            }
                        }
                        else
                        {
                            mapData.mapDataDict[map].tileDataDict[tileLoc] = tile;
                        }
                        SaveMapData(relPath, mapData);
                    }
                }
            }

            if (ModEntry.Config.UseSaveSpecificEdits)
            {
                string relPath = Path.Combine("data", Constants.SaveFolderName + "_map_data.json");
                var    mapData = new MapCollectionData();

                if (!Directory.Exists(Path.Combine(modPath, "data")))
                {
                    Directory.CreateDirectory(Path.Combine(modPath, "data"));
                }
                else
                {
                    mapData = GetMapEdits(relPath);
                }

                if (tile == null)
                {
                    if (mapData.mapDataDict.ContainsKey(map) && mapData.mapDataDict[map].tileDataDict.ContainsKey(tileLoc))
                    {
                        mapData.mapDataDict[map].tileDataDict.Remove(tileLoc);
                        if (mapData.mapDataDict[map].tileDataDict.Count == 0)
                        {
                            mapData.mapDataDict.Remove(map);
                        }
                    }
                }
                else // always save new to save specific
                {
                    if (!mapData.mapDataDict.ContainsKey(map))
                    {
                        mapData.mapDataDict[map] = new MapData();
                    }
                    mapData.mapDataDict[map].tileDataDict[tileLoc] = tile;
                }
                SaveMapData(relPath, mapData);
            }
            ModEntry.cleanMaps.Remove(map);
        }
Exemple #3
0
 public static void SaveMapData(string path, MapCollectionData collection)
 {
     ModEntry.SHelper.Data.WriteJsonFile(path, collection);
     ModEntry.SMonitor.Log($"Saved edits to file {path}");
 }