Exemplo n.º 1
0
        public bool RemoveSpousePatio(string spouse)
        {
            string path = Path.Combine("assets", "outdoor-areas.json");

            if (!File.Exists(Path.Combine(ModEntry.SHelper.DirectoryPath, path)))
            {
                path = "outdoor-areas.json";
            }
            OutdoorAreaData json = ModEntry.SHelper.Data.ReadJsonFile <OutdoorAreaData>(path) ?? new OutdoorAreaData();

            if (json.areas.ContainsKey(spouse))
            {
                json.areas.Remove(spouse);
                ModEntry.SHelper.Data.WriteJsonFile(path, json);
                ModEntry.SMonitor.Log($"removed spouse {spouse} from {path}");
            }
            else
            {
                foreach (IContentPack contentPack in ModEntry.SHelper.ContentPacks.GetOwned())
                {
                    json = contentPack.ReadJsonFile <OutdoorAreaData>("content.json") ?? new OutdoorAreaData();
                    if (json.areas.ContainsKey(spouse))
                    {
                        ModEntry.SMonitor.Log($"Spouse patio in content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}. Not removing!", LogLevel.Warn);
                        return(false);

                        json.areas.Remove(spouse);
                        contentPack.WriteJsonFile("content.json", json);
                        ModEntry.SMonitor.Log($"removed spouse {spouse} from {contentPack.DirectoryPath}");
                    }
                }
            }
            ReloadPatios();
            return(true);
        }
Exemplo n.º 2
0
        public void AddSpousePatioHere(string spouse_tilesOf, Point cursorLoc)
        {
            string      spouse      = spouse_tilesOf.Split('_')[0];
            string      tilesOf     = spouse_tilesOf.Split('_')[1];
            OutdoorArea outdoorArea = new OutdoorArea()
            {
                useDefaultTiles = true,
                location        = cursorLoc,
                npcOffset       = ModEntry.spousePatioOffsets.ContainsKey(spouse) ? ModEntry.spousePatioOffsets[spouse] : new Point(2, 4),
                useTilesOf      = tilesOf,
            };
            string path = Path.Combine("assets", "outdoor-areas.json");

            if (!File.Exists(Path.Combine(ModEntry.SHelper.DirectoryPath, path)))
            {
                path = "outdoor-areas.json";
            }

            OutdoorAreaData json = ModEntry.SHelper.Data.ReadJsonFile <OutdoorAreaData>(path) ?? new OutdoorAreaData();

            json.areas[spouse] = outdoorArea;
            ModEntry.SHelper.Data.WriteJsonFile(path, json);
            ModEntry.SMonitor.Log($"Added spouse {spouse} to {path}");
            ReloadPatios();
        }
        public void AddSpousePatioHere(string spouse_tilesOf)
        {
            string      spouse         = spouse_tilesOf.Split('_')[0];
            string      tilesOf        = spouse_tilesOf.Split('_')[1];
            Point       playerLocation = Utility.Vector2ToPoint(Game1.player.getTileLocation());
            OutdoorArea outdoorArea    = new OutdoorArea()
            {
                useDefaultTiles = true,
                location        = playerLocation,
                npcOffset       = new Point(playerLocation.X + 2, playerLocation.Y + 4),
                useTilesOf      = tilesOf,
            };
            string path = Path.Combine("assets", "outdoor-areas.json");

            if (!File.Exists(Path.Combine(ModEntry.SHelper.DirectoryPath, path)))
            {
                path = "outdoor-areas.json";
            }

            OutdoorAreaData json = ModEntry.SHelper.Data.ReadJsonFile <OutdoorAreaData>(path) ?? new OutdoorAreaData();

            json.areas[spouse] = outdoorArea;
            ModEntry.SHelper.Data.WriteJsonFile(path, json);
            ModEntry.SMonitor.Log($"Added spouse {spouse} to {path}");
            ReloadPatios();
        }
Exemplo n.º 4
0
        public static void LoadSpouseAreaData()
        {
            SMonitor.Log($"loading outdoor patios, clearing outdoorAreas {outdoorAreas.Count}");
            outdoorAreas.Clear();

            string path = Path.Combine("assets", "outdoor-areas.json");

            if (!File.Exists(Path.Combine(SHelper.DirectoryPath, path)))
            {
                path = "outdoor-areas.json";
            }

            try
            {
                OutdoorAreaData json = SHelper.Data.ReadJsonFile <OutdoorAreaData>(path) ?? null;

                if (json != null)
                {
                    if (json.areas != null && json.areas.Count > 0)
                    {
                        foreach (KeyValuePair <string, OutdoorArea> area in json.areas)
                        {
                            if (area.Key == "default")
                            {
                                if (Game1.MasterPlayer.spouse != null)
                                {
                                    outdoorAreas[Game1.MasterPlayer.spouse] = area.Value;
                                    SMonitor.Log($"Added outdoor area at {area.Value.location} or {area.Value.GetLocation()} for {area.Key} ({Game1.MasterPlayer.spouse})", LogLevel.Debug);
                                }
                            }
                            else
                            {
                                outdoorAreas[area.Key] = area.Value;
                                SMonitor.Log($"Added outdoor area at {area.Value.location} or {area.Value.GetLocation()} for {area.Key}", LogLevel.Debug);
                            }
                        }
                    }
                }
                else
                {
                    SMonitor.Log($"Couldn't get spouse areas from {path}", LogLevel.Debug);
                }
            }
            catch (Exception ex)
            {
                SMonitor.Log($"Error reading {path}:\r\n {ex}", LogLevel.Error);
            }

            foreach (IContentPack contentPack in SHelper.ContentPacks.GetOwned())
            {
                SMonitor.Log($"Reading content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}", LogLevel.Debug);
                try
                {
                    OutdoorAreaData json = contentPack.ReadJsonFile <OutdoorAreaData>("content.json") ?? null;

                    if (json != null)
                    {
                        if (json.areas != null && json.areas.Count > 0)
                        {
                            foreach (KeyValuePair <string, OutdoorArea> area in json.areas)
                            {
                                if (area.Key == "default")
                                {
                                    if (Game1.MasterPlayer.spouse != null)
                                    {
                                        outdoorAreas[Game1.MasterPlayer.spouse] = area.Value;
                                        SMonitor.Log($"Added outdoor area at {area.Value.location} or {area.Value.GetLocation()} for {area.Key} ({Game1.MasterPlayer.spouse})", LogLevel.Debug);
                                    }
                                }
                                else if (!outdoorAreas.ContainsKey(area.Key))
                                {
                                    outdoorAreas[area.Key] = area.Value;
                                    SMonitor.Log($"Added outdoor area at {area.Value.location} or {area.Value.GetLocation()} for {area.Key}", LogLevel.Debug);
                                }
                                else
                                {
                                    SMonitor.Log($"Outdoor area already exists for {area.Key}, not adding duplicate from content pack", LogLevel.Debug);
                                }
                            }
                        }
                        if (json.tileSheetsToAdd != null)
                        {
                            foreach (KeyValuePair <string, TileSheetInfo> kvp in json.tileSheetsToAdd)
                            {
                                string name = "zzz_custom_spouse_patio_" + kvp.Key;
                                if (tileSheetsToAdd.ContainsKey(name))
                                {
                                    SMonitor.Log($"Duplicate tilesheet {name} in list of tilesheets to add", LogLevel.Warn);
                                    continue;
                                }
                                tileSheetsToAdd.Add(name, kvp.Value);
                                tileSheetsToAdd[name].realPath = contentPack.GetActualAssetKey(kvp.Value.path);
                                SMonitor.Log($"Added tilesheet {name} to list of tilesheets to add", LogLevel.Debug);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    SMonitor.Log($"error reading content.json file in content pack {contentPack.Manifest.Name}.\r\n{ex}", LogLevel.Error);
                }
            }
            SMonitor.Log($"Total outdoor spouse areas: {outdoorAreas.Count}", LogLevel.Debug);
        }
Exemplo n.º 5
0
        public bool MoveSpousePatio(string spouse_dir, Point cursorLoc)
        {
            Game1.getFarm().loadMap(Game1.getFarm().mapPath.Value, true);
            string      spouse      = spouse_dir.Split('_')[0];
            string      dir         = spouse_dir.Split('_')[1];
            bool        success     = false;
            OutdoorArea outdoorArea = (OutdoorArea)ModEntry.outdoorAreas[spouse];

            switch (dir)
            {
            case "cursorLoc":
                outdoorArea.location = cursorLoc;
                success = true;
                break;

            case "up":
                if (outdoorArea.location.Y <= 0)
                {
                    break;
                }
                outdoorArea.location.Y--;
                success = true;
                break;

            case "down":
                if (outdoorArea.location.Y >= Game1.getFarm().map.Layers[0].LayerHeight - 1)
                {
                    break;
                }
                outdoorArea.location.Y++;
                success = true;
                break;

            case "left":
                if (outdoorArea.location.X == 0)
                {
                    break;
                }
                outdoorArea.location.X--;
                success = true;
                break;

            case "right":
                if (outdoorArea.location.X >= Game1.getFarm().map.Layers[0].LayerWidth - 1)
                {
                    break;
                }
                outdoorArea.location.X++;
                success = true;
                break;
            }
            string path = Path.Combine("assets", "outdoor-areas.json");

            if (!File.Exists(Path.Combine(ModEntry.SHelper.DirectoryPath, path)))
            {
                path = "outdoor-areas.json";
            }

            OutdoorAreaData json = ModEntry.SHelper.Data.ReadJsonFile <OutdoorAreaData>(path) ?? new OutdoorAreaData();

            json.areas[spouse] = outdoorArea;
            ModEntry.SHelper.Data.WriteJsonFile(path, json);

            ReloadSpouseAreaData();
            AddTileSheets();
            ShowSpouseAreas();
            PlaceSpouses();
            ModEntry.SMonitor.Log($"Added spouse {spouse} to {path}");
            return(success);
        }