Exemple #1
0
        /// <summary>
        /// Disposes of resources.
        /// </summary>
        internal void Unload()
        {
            if (ContentHandler != null)
            {
                ContentHandler.Unload();
                ContentHandler = null;
            }

            if (BgmEntries != null)
            {
                BgmEntries.Clear();
                BgmEntries = null;
            }

            if (ItemDefs != null)
            {
                ItemDefs.Clear();
                ItemDefs = null;
            }

            if (NpcDefs != null)
            {
                NpcDefs.Clear();
                NpcDefs = null;
            }

            if (ProjectileDefs != null)
            {
                ProjectileDefs.Clear();
                ProjectileDefs = null;
            }

            if (TileDefs != null)
            {
                TileDefs.Clear();
                TileDefs = null;
            }

            if (RecipeDefs != null)
            {
                RecipeDefs.Clear();
                RecipeDefs = null;
            }
        }
        private void _genTextureAtlas()
        {
            var       defList  = TileDefs.Where(t => !string.IsNullOrEmpty(t.SpriteName)).ToList();
            const int tileSize = EyeManager.PIXELSPERMETER;

            var dimensionX = (int)Math.Ceiling(Math.Sqrt(defList.Count));
            var dimensionY = (int)Math.Ceiling((float)defList.Count / dimensionX);

            var sheet = new Image <Rgba32>(dimensionX * tileSize, dimensionY * tileSize);

            for (var i = 0; i < defList.Count; i++)
            {
                var def    = defList[i];
                var column = i % dimensionX;
                var row    = i / dimensionX;

                Image <Rgba32> image;
                using (var stream = _resourceCache.ContentFileRead($"/Textures/Tiles/{def.SpriteName}.png"))
                {
                    image = Image.Load(stream);
                }

                if (image.Width != tileSize || image.Height != tileSize)
                {
                    throw new NotSupportedException("Unable to use tiles with a dimension other than 32x32.");
                }

                var point = new Vector2i(column * tileSize, row * tileSize);

                image.Blit(new UIBox2i(0, 0, image.Width, image.Height), sheet, point);

                var w = (float)sheet.Width;
                var h = (float)sheet.Height;

                _tileRegions.Add(def.TileId,
                                 Box2.FromDimensions(
                                     point.X / w, (h - point.Y - EyeManager.PIXELSPERMETER) / h,
                                     tileSize / w, tileSize / h));
            }

            TileTextureAtlas = Texture.LoadFromImage(sheet, "Tile Atlas");
        }
        private void _genTextureAtlas()
        {
            var       defList  = TileDefs.Where(t => !string.IsNullOrEmpty(t.SpriteName)).ToList();
            const int tileSize = EyeManager.PIXELSPERMETER;

            var dimensionX = (int)Math.Ceiling(Math.Sqrt(defList.Count));
            var dimensionY = (int)Math.Ceiling((float)defList.Count / dimensionX);

            var sheet = new Image <Rgba32>(dimensionX * tileSize, dimensionY * tileSize);

            for (var i = 0; i < defList.Count; i++)
            {
                var def    = defList[i];
                var column = i % dimensionX;
                var row    = i / dimensionX;

                Image <Rgba32> image;
                using (var stream = _resourceCache.ContentFileRead($"/Textures/Tiles/{def.SpriteName}.png"))
                {
                    image = Image.Load(stream);
                }

                if (image.Width != tileSize || image.Height != tileSize)
                {
                    throw new NotImplementedException("Unable to use tiles with a dimension other than 32x32.");
                }

                var point = new Point(column * tileSize, row * tileSize);

                sheet.Mutate(x => x.DrawImage(image, point,
                                              PixelColorBlendingMode.Overlay, 1));

                _tileRegions.Add(def.TileId,
                                 UIBox2.FromDimensions(
                                     point.X / (float)sheet.Width, point.Y / (float)sheet.Height,
                                     tileSize / (float)sheet.Width, tileSize / (float)sheet.Height));
            }

            TileTextureAtlas = Texture.LoadFromImage(sheet, "Tile Atlas");
        }