Exemple #1
0
        /// <summary>
        /// Opens an SPR file and creates a <see cref="SpriteResource"/> object for it
        /// </summary>
        /// <param name="filepath">The absolute path to the SPR file to open</param>
        /// <returns>The newly-created <see cref="Sprite"/></returns>
        /// <remarks>
        /// The original game code for reading SPR files can be found <code>ResourceDb::init_imported()</code> 
        /// in src/ORESDB.cpp around line 72. The <code>resName</code> will be "sprite\\NAME.SPR". (There's 
        /// no need to follow the call into <code>File::file_open()</code> in OFILE.cpp. Though the files are 
        /// well-structured, they are considered FLAT by 7KAA.
        /// </remarks>
        public void LoadSprite(string filepath)
        {
            if (this.ActivePalette == null)
                throw new Exception("Cannot load a Sprite if the ActivePalette is null.");

            //cant use the property here or we'll fire the event before we've finished loading
            Sprite spr = new Sprite(this.ActivePalette);
            //this._activeSprite = new Sprite(this.ActivePalette);
            
            using (FileStream spritestream = File.OpenRead(filepath))
            {
                while (spritestream.Position < spritestream.Length)
                {
                    SpriteFrame sf = new SpriteFrame(spr);
                    SprDataHandlers.SprStreamToSpriteFrame(sf, spritestream);
                    sf.ImageBmp = SprDataHandlers.FrameSprToBmp(sf, this.ActivePalette);
                    spr.Frames.Add(sf);
                }
            }

            spr.Resource.FileName = Path.GetFileName(filepath);
            spr.SpriteId = Path.GetFileNameWithoutExtension(filepath);
            DataView dv = this.ActiveGameSet.GetSpriteDataView(spr.SpriteId);
            spr.SetSpriteDataView(dv);
            this.ActiveSprite = spr;
        }