/// <summary>
        /// Creates a <see cref="SkaaSprite"/> object from an SPR-formatted file
        /// </summary>
        /// <param name="filePath">The absolute path to the SPR file to open</param>
        /// <returns>The newly-created <see cref="SkaaSprite"/></returns>
        public override SkaaSprite Load(string filePath, params object[] param)
        {
            SkaaSprite spr;

            using (FileStream fs = File.OpenRead(filePath))
                spr = SkaaSprite.FromSprStream(fs, this.PalettePresenter.GameObject);

            this.GameObject = spr;
            this.SpriteId   = spr.SpriteId;

            BuildFramePresenters();
            return(this.GameObject);
        }
示例#2
0
        /// <summary>
        /// Reads all the frame data from the specified file, of type <see cref="FileFormats.ResIdxMultiBmp"/>
        /// </summary>
        /// <param name="filepath">The path to the file</param>
        /// <param name="pal">The <see cref="ColorPalette"/> to use in building the frame's image</param>
        /// <returns>
        /// A <see cref="Tuple{T1, T2}"/> where <c>T1</c> is the new <see cref="SkaaSprite"/> and <c>T2</c> is
        /// the <see cref="DataTable"/> read from the ResIdx header.
        /// </returns>
        /// <remarks>
        /// This differs from loading an SPR file in that the file contains the <see cref="SkaaFrame"/> data
        /// directly in its header rather than in the standard game set (see <see cref="GameSetFile"/>. The
        /// <see cref="DataTable"/> only has fields for FrameName and FrameOffset; any other data is stored
        /// elsewhere, generally in DBF (dBaseIII) files that may or may not be in the standard game set.
        /// </remarks>
        private static Tuple <SkaaSprite, DataTable> ReadFrames(string filepath, ColorPalette pal, bool offsetsOnly)
        {
            SkaaSprite spr = new SkaaSprite();
            DataTable  dt  = new DataTable();

            dt.AddDataSource(Path.GetFileName(filepath));
            dt.Columns.Add(new DataColumn()
            {
                DataType = typeof(string), ColumnName = SkaaGameDataLib.Util.DataRowExtensions.ResIdxFrameNameColumn
            });
            dt.Columns.Add(new DataColumn()
            {
                DataType = typeof(uint), ColumnName = SkaaGameDataLib.Util.DataRowExtensions.ResIdxFrameOffsetColumn
            });

            using (FileStream fs = new FileStream(filepath, FileMode.Open))
            {
                //Read the file definitions from the ResIdx header.
                Dictionary <string, uint> dic = ResourceDefinitionReader.ReadDefinitions(fs, offsetsOnly);
                spr.SpriteId = Path.GetFileNameWithoutExtension(filepath);
                dt.TableName = spr.SpriteId;

                foreach (string key in dic.Keys)
                {
                    SkaaSpriteFrame sf = new SkaaSpriteFrame(null);
                    sf.BitmapOffset = dic[key];
                    fs.Position     = sf.BitmapOffset;
                    sf.Name         = key;
                    IndexedBitmap iBmp = new IndexedBitmap(pal);
                    sf.IndexedBitmap = iBmp;
                    iBmp.SetBitmapFromRleStream(fs, FileFormats.ResIdxFramesSpr);

                    spr.Frames.Add(sf);

                    DataRow row = dt.NewRow();
                    dt.Rows.Add(row);
                    row.BeginEdit();
                    row[SkaaGameDataLib.Util.DataRowExtensions.ResIdxFrameNameColumn]   = key;
                    row[SkaaGameDataLib.Util.DataRowExtensions.ResIdxFrameOffsetColumn] = dic[key];
                    row.AcceptChanges();
                }
            }

            return(new Tuple <SkaaSprite, DataTable>(spr, dt));
        }