Example #1
0
        /// <summary>
        /// Creates a new <see cref="SkaaSprite"/> from a stream of SPR-formatted data
        /// </summary>
        /// <param name="str">The stream to read the SPR data from</param>
        /// <param name="pal">The <see cref="ColorPalette"/> to apply to the sprite's images</param>
        /// <returns>A new <see cref="SkaaSprite"/></returns>
        /// <remarks>
        /// The original game code for reading SPR files can be found <c>ResourceDb::init_imported()</c>
        /// in src/ORESDB.cpp around line 72. The <c>resName</c> will be "sprite\\NAME.SPR". SPR files are
        /// are considered <c>FLAT</c> by 7KAA.
        /// </remarks>
        public static SkaaSprite FromSprStream(Stream str, ColorPalette pal)
        {
            SkaaSprite spr = new SkaaSprite();

            if (str is FileStream)
            {
                spr.SpriteId = Path.GetFileNameWithoutExtension(((FileStream)str).Name);
            }
            try
            {
                while (str.Position < str.Length)
                {
                    IndexedBitmap   iBmp = new IndexedBitmap(pal);
                    SkaaSpriteFrame sf   = new SkaaSpriteFrame(spr);
                    sf.IndexedBitmap = iBmp;
                    sf.BitmapOffset  = str.Position;
                    iBmp.SetBitmapFromRleStream(str, FileFormats.SpriteSpr);
                    spr.Frames.Add(sf);
                }
            }
            catch (Exception e)
            {
                Logger.TraceEvent(TraceEventType.Error, 0, $"Failed to load sprite: {spr.SpriteId} (Exception: {e.Message})");
                Debugger.Break();
            }
            return(spr);
        }
 /// <summary>
 /// Initializes a new <see cref="SkaaSpriteFrame"/>.
 /// </summary>
 /// <param name="parentSprite">The <see cref="SkaaSprite"/> containing this <see cref="SkaaSpriteFrame"/></param>
 /// <param name="stream"></param>
 public SkaaSpriteFrame(SkaaSprite parentSprite)
 {
     this.ParentSprite    = parentSprite;
     this.GameSetDataRows = new List <DataRow>();
 }
Example #3
0
 /// <summary>
 /// Creates a new <see cref="SkaaSprite"/> from a stream of SPR-formatted data
 /// </summary>
 /// <param name="str">The stream to read the SPR data from</param>
 /// <param name="pal">The <see cref="ColorPalette"/> to apply to the sprite's images</param>
 /// <returns>A new <see cref="SkaaSprite"/></returns>
 /// <remarks>
 /// The original game code for reading SPR files can be found <c>ResourceDb::init_imported()</c> 
 /// in src/ORESDB.cpp around line 72. The <c>resName</c> will be "sprite\\NAME.SPR". SPR files are 
 /// are considered <c>FLAT</c> by 7KAA. 
 /// </remarks>
 public static SkaaSprite FromSprStream(Stream str, ColorPalette pal)
 {
     SkaaSprite spr = new SkaaSprite();
     if (str is FileStream)
         spr.SpriteId = Path.GetFileNameWithoutExtension(((FileStream)str).Name);
     try
     {
         while (str.Position < str.Length)
         {
             IndexedBitmap iBmp = new IndexedBitmap(pal);
             SkaaSpriteFrame sf = new SkaaSpriteFrame(spr);
             sf.IndexedBitmap = iBmp;
             sf.BitmapOffset = str.Position;
             iBmp.SetBitmapFromRleStream(str, FileFormats.SpriteSpr);
             spr.Frames.Add(sf);
         }
     }
     catch (Exception e)
     {
         Logger.TraceEvent(TraceEventType.Error, 0, $"Failed to load sprite: {spr.SpriteId} (Exception: {e.Message})");
         Debugger.Break();
     }
     return spr;
 }
        /// <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);
        }
Example #5
0
 /// <summary>
 /// Initializes a new <see cref="SkaaSpriteFrame"/>.
 /// </summary>
 /// <param name="parentSprite">The <see cref="SkaaSprite"/> containing this <see cref="SkaaSpriteFrame"/></param>
 /// <param name="stream"></param>
 public SkaaSpriteFrame(SkaaSprite parentSprite)
 {
     this.ParentSprite = parentSprite;
     this.GameSetDataRows = new List<DataRow>();
 }