Пример #1
0
 /// <summary>
 /// Loads assets for this mod.
 /// </summary>
 /// <param name="e">Event args.</param>
 public static void Load(AssetRequestedEventArgs e)
 {
     if (e.Name.IsEquivalentTo(DENYLIST_LOCATION))
     {
         e.LoadFrom(EmptyContainers.GetEmptyDictionary <string, string>, AssetLoadPriority.Medium);
     }
     else if (e.Name.IsEquivalentTo(ADDITIONAL_LOCATIONS_LOCATION))
     {
         e.LoadFrom(GetInitialAdditionalLocations, AssetLoadPriority.High);
     }
 }
 internal static void LoadRepeatTopics(AssetRequestedEventArgs e)
 {
     if (e.NameWithoutLocale.IsEquivalentTo(ModEntry.modContentPath))
     {
         e.LoadFrom(() => modRepeatableConversationTopics.ToDictionary((k) => k, (v) => string.Empty), AssetLoadPriority.Low);
     }
 }
Пример #3
0
    private void OnAssetRequested(object sender, AssetRequestedEventArgs e)
    {
        if (!e.Name.IsEquivalentTo(AssetPath))
        {
            return;
        }

        e.LoadFrom(GetRawBooks, AssetLoadPriority.Low);
    }
Пример #4
0
        private void OnAssetRequested(object sender, AssetRequestedEventArgs e)
        {
            if (e.NameWithoutLocale.IsEquivalentTo("Data\\Blueprints"))
            {
                e.Edit(asset =>
                {
                    var data                              = asset.AsDictionary <string, string>().Data;
                    String[] greenhouse                   = data["Greenhouse"].Split("/");
                    String buildableGreenhouseName        = greenhouse[8];
                    String buildableGreenhouseDescription = greenhouse[9];
                    data.Add("BuildableGreenhouse", $"{BuildMaterialsToString()}/7/6/3/5/-1/-1/Greenhouse/{buildableGreenhouseName}/{buildableGreenhouseDescription}/Buildings/none/64/96/20/null/Farm/{this.Config.BuildPrice}/false");
                });
            }

            if (e.Name.IsEquivalentTo("Buildings\\BuildableGreenhouse"))
            {
                e.LoadFrom(() =>
                {
                    Texture2D greenhouseTexture = this.Helper.GameContent.Load <Texture2D>("Buildings\\Greenhouse");
                    Rectangle newBounds         = greenhouseTexture.Bounds;
                    newBounds.Y      += 160;
                    newBounds.Width  -= 128;
                    newBounds.Height -= 160;

                    Texture2D greenhouse = new Texture2D(graphicsDevice, newBounds.Width, newBounds.Height);
                    Color[] data         = new Color[newBounds.Width * newBounds.Height];
                    greenhouseTexture.GetData(0, newBounds, data, 0, newBounds.Width * newBounds.Height);
                    greenhouse.SetData(data);
                    return(greenhouse);
                }, AssetLoadPriority.High);
            }

            if (e.Name.IsEquivalentTo("Maps\\BuildableGreenhouse"))
            {
                e.LoadFrom(() => this.Helper.GameContent.Load <Map>("Maps\\Greenhouse"), AssetLoadPriority.High);
            }
        }
        private void OnContentAssetRequested(object sender, AssetRequestedEventArgs e)
        {
            if (e.DataType == typeof(TokenModel))
            {
                var companionModel = CompanionManager.companionModels.FirstOrDefault(c => e.Name.IsEquivalentTo($"{CustomCompanions.TOKEN_HEADER}{c.GetId()}"));
                if (companionModel is null)
                {
                    return;
                }

                e.LoadFrom(() => new TokenModel()
                {
                    Companion = JsonParser.Serialize <object>(companionModel)
                }, AssetLoadPriority.Exclusive, companionModel.Owner);
            }
        }
Пример #6
0
        /// <inheritdoc cref="IContentEvents.AssetRequested"/>
        /// <param name="e">The event data.</param>
        public void OnAssetRequested(AssetRequestedEventArgs e)
        {
            // Allow for garages from older versions that didn't get normalized correctly.
            // This can be removed once support for legacy data is dropped.
            if (e.NameWithoutLocale.IsEquivalentTo("Buildings/TractorGarage") && this.GarageTexture != null)
            {
                e.LoadFrom(() => this.GarageTexture, AssetLoadPriority.Low);
            }

            // load tractor or garage texture
            if (e.NameWithoutLocale.IsEquivalentTo($"{this.PublicAssetBasePath}/Tractor") || e.NameWithoutLocale.IsEquivalentTo($"{this.PublicAssetBasePath}/Garage"))
            {
                string key = PathUtilities.GetSegments(e.NameWithoutLocale.Name).Last();
                e.LoadFrom(
                    () => this.TryLoadFromFile(key, out Texture2D? texture, out string?error)
                        ? texture
                        : throw new InvalidOperationException(error),
                    AssetLoadPriority.Exclusive
                    );
            }
        }
Пример #7
0
        /*********
        ** Private methods
        *********/
        /// <inheritdoc cref="IContentEvents.AssetRequested"/>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        private void OnAssetRequested(object?sender, AssetRequestedEventArgs e)
        {
            // add farm type
            if (e.NameWithoutLocale.IsEquivalentTo("Data/AdditionalFarms"))
            {
                e.Edit(editor =>
                {
                    var data = editor.GetData <List <ModFarmType> >();
                    data.Add(new()
                    {
                        ID = this.ModManifest.UniqueID,
                        TooltipStringPath = "Strings/UI:Pathoschild_BeachFarm_Description",
                        MapName           = "Pathoschild_SmallBeachFarm"
                    });
                });
            }

            // add farm description
            else if (e.NameWithoutLocale.IsEquivalentTo("Strings/UI"))
            {
                e.Edit(editor =>
                {
                    var data = editor.AsDictionary <string, string>().Data;
                    data["Pathoschild_BeachFarm_Description"] = $"{I18n.Farm_Name()}_{I18n.Farm_Description()}";
                });
            }

            // load map
            else if (e.NameWithoutLocale.IsEquivalentTo("Maps/Pathoschild_SmallBeachFarm"))
            {
                e.LoadFrom(
                    () =>
                {
                    // load map
                    Map map = this.Helper.ModContent.Load <Map>("assets/farm.tmx");
                    IAssetDataForMap editor    = this.Helper.ModContent.GetPatchHelper(map).AsMap();
                    TileSheet outdoorTilesheet = map.GetTileSheet("untitled tile sheet");
                    Layer buildingsLayer       = map.GetLayer("Buildings");
                    Layer backLayer            = map.GetLayer("Back");

                    // add islands
                    if (this.Config.EnableIslands)
                    {
                        Map islands = this.Helper.ModContent.Load <Map>("assets/overlay_islands.tmx");
                        Size size   = islands.GetSizeInTiles();

                        editor.PatchMap(source: islands, targetArea: new Rectangle(0, 26, size.Width, size.Height));
                    }

                    // add campfire
                    if (this.Config.AddCampfire)
                    {
                        buildingsLayer.Tiles[65, 23] = new StaticTile(buildingsLayer, map.GetTileSheet("zbeach"), BlendMode.Alpha, 157); // driftwood pile
                        buildingsLayer.Tiles[64, 22] = new StaticTile(buildingsLayer, outdoorTilesheet, BlendMode.Alpha, 242);           // campfire
                    }

                    // remove shipping bin path
                    if (!this.Config.ShippingBinPath)
                    {
                        for (int x = 71; x <= 72; x++)
                        {
                            for (int y = 14; y <= 15; y++)
                            {
                                backLayer.Tiles[x, y] = new StaticTile(backLayer, outdoorTilesheet, BlendMode.Alpha, 175);     // grass tile
                            }
                        }
                    }

                    // add fishing pier
                    if (this.Config.AddFishingPier)
                    {
                        // load overlay
                        Map pier  = this.Helper.ModContent.Load <Map>("assets/overlay_pier.tmx");
                        Size size = pier.GetSizeInTiles();

                        // get target position
                        Point position = this.Config.CustomFishingPierPosition;
                        if (position == Point.Zero)
                        {
                            position = new Point(70, 26);
                        }

                        // remove building tiles which block movement on the pier
                        {
                            var pierBack = pier.GetLayer("Back");
                            for (int x = 0; x < size.Width; x++)
                            {
                                for (int y = 0; y < size.Height; y++)
                                {
                                    if (pierBack.Tiles[x, y] is not null)
                                    {
                                        buildingsLayer.Tiles[position.X + x, position.Y + y] = null;
                                    }
                                }
                            }
                        }

                        // apply overlay
                        editor.PatchMap(source: pier, targetArea: new Rectangle(position.X, position.Y, size.Width, size.Height));
                    }

                    // apply tilesheet recolors
                    foreach (TileSheet tilesheet in map.TileSheets)
                    {
                        IAssetName imageSource = this.Helper.GameContent.ParseAssetName(tilesheet.ImageSource);
                        if (imageSource.StartsWith($"{this.TilesheetsPath}/_default/"))
                        {
                            tilesheet.ImageSource = PathUtilities.NormalizeAssetName($"{this.FakeAssetPrefix}/{Path.GetFileNameWithoutExtension(tilesheet.ImageSource)}");
                        }
                    }

                    return(map);
                },
                    AssetLoadPriority.Exclusive
                    );
            }

            // load tilesheet
            else if (e.NameWithoutLocale.StartsWith(this.FakeAssetPrefix))
            {
                e.LoadFrom(
                    () =>
                {
                    string filename = Path.GetFileName(e.NameWithoutLocale.Name);
                    if (!Path.HasExtension(filename))
                    {
                        filename += ".png";
                    }

                    // get relative path to load
                    string?relativePath = new DirectoryInfo(this.GetFullPath(this.TilesheetsPath))
                                          .EnumerateDirectories()
                                          .FirstOrDefault(p => p.Name != "_default" && this.Helper.ModRegistry.IsLoaded(p.Name))
                                          ?.Name;
                    relativePath = Path.Combine(this.TilesheetsPath, relativePath ?? "_default", filename);

                    // load asset
                    Texture2D tilesheet = this.Helper.ModContent.Load <Texture2D>(relativePath);
                    return(tilesheet);
                },
                    AssetLoadPriority.Exclusive
                    );
            }
        }