Exemplo n.º 1
0
        private void loadContentPacks()
        {
            foreach (StardewModdingAPI.IContentPack pack in Helper.ContentPacks.GetOwned())
            {
                Animations animations = null;

                if (File.Exists(Path.Combine(pack.DirectoryPath, "settings.json")))
                {
                    animations = pack.ReadJsonFile <Animations>("settings.json");
                }

                if (File.Exists(Path.Combine(pack.DirectoryPath, "walls.png")) && !CustomWallpaper.Walls.ContainsKey(pack.Manifest.UniqueID))
                {
                    Texture2D wallTexture = pack.LoadAsset <Texture2D>("walls.png");

                    if (animations != null)
                    {
                        wallTexture = AnimatedTexture.FromTexture(wallTexture, animations.AnimatedTiles);
                    }

                    CustomWallpaper.Walls.Add(pack.Manifest.UniqueID, wallTexture);
                    string key = Path.Combine(pack.Manifest.UniqueID, "walls");
                    wallTexture.inject(key);

                    int walls = (wallTexture.Width / 16) * (wallTexture.Height / 48);
                    for (int i = 0; i < walls; i++)
                    {
                        if (wallTexture is AnimatedTexture awall && awall.AnimatedTiles.Find(t => !t.Floor && i > t.Index && i < t.Index + t.Frames) != null)
                        {
                            continue;
                        }

                        InventoryItem inv = new InventoryItem(new CustomWallpaper(pack.Manifest.UniqueID, i, false), 0);
                        inv.addToWallpaperCatalogue();
                    }
                }

                if (File.Exists(Path.Combine(pack.DirectoryPath, "floors.png")) && !CustomWallpaper.Floors.ContainsKey(pack.Manifest.UniqueID))
                {
                    Texture2D floorTexture = pack.LoadAsset <Texture2D>("floors.png");

                    if (animations != null)
                    {
                        floorTexture = AnimatedTexture.FromTexture(floorTexture, animations.AnimatedTiles);
                    }

                    CustomWallpaper.Floors.Add(pack.Manifest.UniqueID, floorTexture);
                    string key = Path.Combine(pack.Manifest.UniqueID, "floors");
                    floorTexture.inject(key);

                    int floors = (floorTexture.Width / 32) * (floorTexture.Height / 32);
                    for (int i = 0; i < floors; i++)
                    {
                        if (floorTexture is AnimatedTexture awall && awall.AnimatedTiles.Find(t => t.Floor && i > t.Index && i < t.Index + t.Frames) != null)
                        {
                            continue;
                        }

                        InventoryItem inv = new InventoryItem(new CustomWallpaper(pack.Manifest.UniqueID, i, true), 0);
                        inv.addToWallpaperCatalogue();
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static AnimatedTexture FromTexture(Texture2D texture, List <AnimatedTile> tiles)
        {
            AnimatedTexture result = new AnimatedTexture(texture, tiles);

            return(result);
        }