Exemplo n.º 1
0
        private static void PrepareBank(AssetFontSheet font, int tileWidth, int tileHeight, FontTypes fontType, int mapHeightBank)
        {
            font.TileWidth  = tileWidth;
            font.TileHeight = tileHeight;

            int fontMapHeight = font.Height / tileHeight;

            switch (fontType)
            {
            case FontTypes.PolychromeStatic:

                if (mapHeightBank <= 0)
                {
                    mapHeightBank = fontMapHeight;
                }
                font.BankCount = fontMapHeight / mapHeightBank;
                break;

            case FontTypes.MonochromeDynamic:
                // en mono il n'y a qu'une seule bank au départ
                mapHeightBank  = fontMapHeight;
                font.BankCount = 1;
                break;
            }

            font.MapHeightBank = mapHeightBank;
            font.FontType      = fontType;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Chargement à partir d'un flux
        /// </summary>
        /// <param name="stream"></param>

        protected virtual async Task LoadAsync(Stream stream)
        {
            using (BinaryReader reader = new BinaryReader(stream, Encoding.UTF8, true))
            {
                this.LoadHeader(reader);

                while (stream.Position != stream.Length)
                {
                    var assetSize = reader.ReadInt32();
                    var assetType = (AssetTypes)reader.ReadInt32();

                    Asset asset = null;

                    switch (assetType)
                    {
                    default:
                        throw new Exception("Unknow assetType '" + assetType + "' !");

                    case AssetTypes.Sprite:
                        asset = new AssetSprite(this);
                        break;

                    case AssetTypes.TileSheet:
                        asset = new AssetTileSheet(this);
                        break;

                    case AssetTypes.FontSheet:
                        asset = new AssetFontSheet(this);
                        break;

                    case AssetTypes.MapTmx:
                        // MapTmx contient une liste d'AssetMap
                        asset = new AssetMapTmx(this);
                        break;

                    case AssetTypes.Sound:
                        asset = new AssetFile(this);
                        break;
                    }

                    asset.Size = assetSize;

                    await asset.ReadAsync(reader);

                    this.assets.Add(asset.Name, asset);
                }
            }

            this.IsLoaded = true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Importation
        /// </summary>
        /// <param name="assetName"></param>
        /// <param name="stream"></param>
        /// <param name="fontType"></param>
        /// <param name="tileWidth"></param>
        /// <param name="tileHeight"></param>
        /// <param name="mapHeightBank"></param>
        /// <returns></returns>

        public static AssetFontSheet Import(Cartridge cartridge, string assetName, Stream stream, int tileWidth, int tileHeight, FontTypes fontType, int mapHeightBank = int.MaxValue)
        {
            AssetFontSheet font = new AssetFontSheet(cartridge);

            font.Name = assetName;
            font.ImportImage(stream);

            font.TileWidth  = tileWidth;
            font.TileHeight = tileHeight;

            if (mapHeightBank == int.MaxValue)
            {
                mapHeightBank = font.Height / font.TileHeight;
            }

            PrepareBank(font, tileWidth, tileHeight, fontType, mapHeightBank);

            return(font);
        }