/// <summary> /// Writes the sprite file, importing all the existing sprites either from the /// their sources, or sprite cache, - whatever is present (in that order). /// </summary> public static void WriteSpriteFileFromSources(string filename, IWorkProgress progress) { int storeFlags = 0; if (Factory.AGSEditor.CurrentGame.Settings.OptimizeSpriteStorage) { storeFlags |= (int)Native.SpriteFileWriter.StorageFlags.OptimizeForSize; } var compressSprites = Factory.AGSEditor.CurrentGame.Settings.CompressSpritesType; SpriteFolder folder = Factory.AGSEditor.CurrentGame.RootSpriteFolder; var sprites = folder.GetAllSpritesFromAllSubFolders(); var orderedSprites = sprites.OrderBy(sprite => sprite.Number); progress.Total = orderedSprites.Count(); progress.Current = 0; var writer = new Native.SpriteFileWriter(filename); writer.Begin(storeFlags, compressSprites); int spriteIndex = 0; int realSprites = 0; foreach (Sprite sprite in orderedSprites) { // NOTE: we must add empty slots to fill all the gaps in sprite IDs! for (; spriteIndex < sprite.Number; ++spriteIndex) { writer.WriteEmptySlot(); } // Try get the image, first from source, then from editor's cache var bmp = LoadBitmapFromSource(sprite); // TODO: this is quite suboptimal, find a way to retrieve a native handle instead? if (bmp == null) { bmp = Factory.NativeProxy.GetBitmapForSprite(sprite.Number, sprite.Width, sprite.Height); } if (bmp != null) { writer.WriteBitmap(bmp, sprite.TransparentColour, sprite.RemapToGamePalette, sprite.RemapToRoomPalette, sprite.AlphaChannel); bmp.Dispose(); } else { bmp = new Bitmap(sprite.Width, sprite.Height); writer.WriteBitmap(bmp); bmp.Dispose(); } progress.Current = ++realSprites; spriteIndex++; } writer.End(); }
/// <summary> /// Writes a dummy sprite file with one 1x1 clear sprite at index 0. /// </summary> public static void WriteDummySpriteFile(string filename) { int storeFlags = 0; if (Factory.AGSEditor.CurrentGame.Settings.OptimizeSpriteStorage) { storeFlags |= (int)Native.SpriteFileWriter.StorageFlags.OptimizeForSize; } var compressSprites = Factory.AGSEditor.CurrentGame.Settings.CompressSpritesType; var writer = new Native.SpriteFileWriter(filename); writer.Begin(storeFlags, compressSprites); var bmp = new Bitmap(1, 1); writer.WriteBitmap(bmp); bmp.Dispose(); writer.End(); }