示例#1
0
        // Any custom locations with given location on the map
        private void LoadCustomMapLocations()
        {
            foreach (var mapVectors in ModMain.CustomData.CustomMapLocations)
            {
                var mapVectorArr = new MapVector[mapVectors.Value.Length];
                for (var i = 0; i < mapVectors.Value.Length; i++)
                {
                    var mapVector = mapVectors.Value[i];

                    // Marker doesn't need to specify corresponding Tile position
                    if (mapVector.GetValue("TileX") == null || mapVector.GetValue("TileY") == null)
                    {
                        mapVectorArr[i] = new MapVector(
                            (int)mapVector.GetValue("MapX"),
                            (int)mapVector.GetValue("MapY")
                            );
                    }
                    // Region must specify corresponding Tile positions for
                    // Calculations on movement within location
                    else
                    {
                        mapVectorArr[i] = new MapVector(
                            (int)mapVector.GetValue("MapX"),
                            (int)mapVector.GetValue("MapY"),
                            (int)mapVector.GetValue("TileX"),
                            (int)mapVector.GetValue("TileY")
                            );
                    }
                }

                MapVectors.Add(mapVectors.Key, mapVectorArr);
            }

            // Automatically adjust tracking for modded maps that are sized differently from vanilla map
            foreach (var location in Game1.locations)
            {
                var locationName = location.uniqueName.Value ?? location.Name;

                if (!location.IsOutdoors || locationName == "Summit" || MapVectors.ContainsKey(locationName) ||
                    !ModConstants.MapVectors.TryGetValue(locationName, out var mapVector))
                {
                    continue;
                }
                if (mapVector.LastOrDefault().TileX != location.Map.DisplayWidth / Game1.tileSize ||
                    mapVector.LastOrDefault().TileY != location.Map.DisplayHeight / Game1.tileSize)
                {
                    MapVectors.Add(locationName,
                                   new[]
                    {
                        mapVector.FirstOrDefault(),
                        new MapVector(
                            mapVector.LastOrDefault().MapX,
                            mapVector.LastOrDefault().MapY,
                            location.Map.DisplayWidth / Game1.tileSize,
                            location.Map.DisplayHeight / Game1.tileSize
                            )
                    });
                }
            }

            var customLocations = MapVectors.Keys.ToArray();

            if (MapVectors.Keys.Count > 0)
            {
                if (customLocations.Length == 1)
                {
                    ModMain.IMonitor.Log($"Handled tracking for custom location: {customLocations[0]}.", LogLevel.Debug);
                }
                else
                {
                    var locationList = "";
                    for (var i = 0; i < customLocations.Length; i++)
                    {
                        locationList += customLocations[i] + (i + 1 == customLocations.Length ? "" : ", ");
                    }

                    ModMain.IMonitor.Log($"Handled tracking for custom locations: {locationList}.", LogLevel.Debug);
                }
            }
        }
示例#2
0
        // { "customLocation": [{x, y}] } where x, y are relative to map (for a custom location ex. a new house)
        // { "customRegion": [{x1, y1}, {x2, y2}] where x, y are relative to map (for a custom region ex. a new farm)
        // Any custom locations with given location on the map
        private void LoadCustomMapLocations()
        {
            // Merge SVE Config with main config
            var CustomMapLocations = SVEConfig != null
        ? ModMain.Config.CustomMapLocations.Concat(SVEConfig.CustomMapLocations).ToLookup(x => x.Key, x => x.Value)
                                     .ToDictionary(x => x.Key, g => g.First())
        : ModMain.Config.CustomMapLocations;

            foreach (var mapVectors in CustomMapLocations)
            {
                var mapVectorArr = new MapVector[mapVectors.Value.Length];
                for (var i = 0; i < mapVectors.Value.Length; i++)
                {
                    // Don't use IF2R config for greenhouse if not default farm (hard-coded location)
                    if (ModMain.IsSVE && mapVectors.Key == "Greenhouse" && Game1.whichFarm != 0)
                    {
                        mapVectorArr[i] = ModConstants.MapVectors["Greenhouse"].FirstOrDefault();
                    }
                    else
                    {
                        var mapVector = mapVectors.Value[i];

                        // Marker doesn't need to specify corresponding Tile position
                        if (mapVector.GetValue("TileX") == null || mapVector.GetValue("TileY") == null)
                        {
                            mapVectorArr[i] = new MapVector(
                                (int)mapVector.GetValue("MapX"),
                                (int)mapVector.GetValue("MapY")
                                );
                        }
                        // Region must specify corresponding Tile positions for
                        // Calculations on movement within location
                        else
                        {
                            mapVectorArr[i] = new MapVector(
                                (int)mapVector.GetValue("MapX"),
                                (int)mapVector.GetValue("MapY"),
                                (int)mapVector.GetValue("TileX"),
                                (int)mapVector.GetValue("TileY")
                                );
                        }
                    }
                }
                MapVectors.Add(mapVectors.Key, mapVectorArr);
            }

            foreach (var location in ModMain.Config.CustomMapTextures)
            {
                Locations.Add(location.Key, new CustomLocation(location.Value));
            }

            // Automatically adjust tracking for modded maps that are sized differently from vanilla map
            foreach (var location in Game1.locations)
            {
                var locationName = location.uniqueName.Value ?? location.Name;

                if (!location.IsOutdoors || locationName == "Summit" || MapVectors.ContainsKey(locationName) ||
                    !ModConstants.MapVectors.TryGetValue(locationName, out var mapVector))
                {
                    continue;
                }
                if (mapVector.LastOrDefault().TileX != location.Map.DisplayWidth / Game1.tileSize ||
                    mapVector.LastOrDefault().TileY != location.Map.DisplayHeight / Game1.tileSize)
                {
                    MapVectors.Add(locationName,
                                   new[]
                    {
                        mapVector.FirstOrDefault(),
                        new MapVector(
                            mapVector.LastOrDefault().MapX,
                            mapVector.LastOrDefault().MapY,
                            location.Map.DisplayWidth / Game1.tileSize,
                            location.Map.DisplayHeight / Game1.tileSize
                            )
                    });
                }
            }

            var customLocations = MapVectors.Keys.ToArray();

            if (MapVectors.Keys.Count > 0)
            {
                if (customLocations.Length == 1)
                {
                    Monitor.Log($"Handled tracking for custom location: {customLocations[0]}.", LogLevel.Debug);
                }
                else
                {
                    var locationList = "";
                    for (var i = 0; i < customLocations.Length; i++)
                    {
                        locationList += customLocations[i] + (i + 1 == customLocations.Length ? "" : ", ");
                    }

                    Monitor.Log($"Handled tracking for custom locations: {locationList}.", LogLevel.Debug);
                }
            }
        }