Esempio n. 1
0
        ImmutablePalette IProvidesCursorPaletteInfo.ReadPalette(IReadOnlyFileSystem fileSystem)
        {
            var colors = new uint[Palette.Size];

            var mobd    = new Mobd(fileSystem.Open(Filename) as SegmentStream, Version.KKND2);
            var frame   = mobd.Animations.FirstOrDefault(a => a.Frames.Length > 0) ?? mobd.HardcodedAnimations.FirstOrDefault(a => a.Frames.Length > 0);
            var palette = frame.Frames.First().RenderFlags.Palette;

            // TODO when we have all kknd2 palettes done, remove this. It will simply extract palettes for easier determination of player indices.

            /*if (Filename != null) {
             *      var bitmap = new Bitmap(palette.Length / 8, 8);
             *      for (var i = 1; i < palette.Length; i++)
             *              bitmap.SetPixel(i % bitmap.Width, i / bitmap.Width, palette[i]);
             *      bitmap.Save(Filename.Substring(8) + ".png");
             *      bitmap.Dispose();
             * }*/

            for (var i = 1; i < Math.Min(colors.Length, palette.Length); i++)
            {
                colors[i] = palette[i];
            }

            return(new ImmutablePalette(colors));
        }
Esempio n. 2
0
        ImmutablePalette IProvidesCursorPaletteInfo.ReadPalette(IReadOnlyFileSystem fileSystem)
        {
            var colors = new uint[Palette.Size];

            if (fileSystem.Open(this.Filename) is not SegmentStream segmentStream)
            {
                return(new(colors));
            }

            var mobd  = new Mobd(segmentStream);
            var frame = mobd.RotationalAnimations.FirstOrDefault(a => a.Frames.Length > 0) ?? mobd.SimpleAnimations.FirstOrDefault(a => a.Frames.Length > 0);

            if (frame == null)
            {
                return(new(colors));
            }

            var palette = frame.Frames.FirstOrDefault()?.RenderFlags.Palette;

            if (palette == null)
            {
                return(new(colors));
            }

            for (var i = 1; i < Math.Min(colors.Length, palette.Length); i++)
            {
                colors[i] = palette[i];
            }

            return(new(colors));
        }
Esempio n. 3
0
        public bool TryParseSprite(Stream stream, string filename, out ISpriteFrame[]?frames, out TypeDictionary?metadata)
        {
            if (!filename.EndsWith(".mobd") || stream is not SegmentStream segmentStream)
            {
                metadata = null;
                frames   = null;

                return(false);
            }

            // This is damn ugly, but MOBD uses offsets from LVL start.
            segmentStream.BaseStream.Position = segmentStream.BaseOffset;
            var mobd = new Mobd(segmentStream.BaseStream);
            var tmp  = new List <MobdSpriteFrame>();

            tmp.AddRange(mobd.RotationalAnimations.SelectMany(mobdAnimation => mobdAnimation.Frames, (_, mobdFrame) => new MobdSpriteFrame(mobdFrame)));
            tmp.AddRange(mobd.SimpleAnimations.SelectMany(mobdAnimation => mobdAnimation.Frames, (_, mobdFrame) => new MobdSpriteFrame(mobdFrame)));

            uint[]? palette = null;
            var points = new Dictionary <int, Offset[]>();

            for (var i = 0; i < tmp.Count; i++)
            {
                if (tmp[i].Points != null)
                {
                    var mobdPoints = tmp[i].Points;

                    if (mobdPoints != null)
                    {
                        points.Add(i, mobdPoints.Select(point => new Offset(point.Id, point.X, point.Y)).ToArray());
                    }
                }

                if (tmp[i].Palette != null)
                {
                    palette = tmp[i].Palette;
                }
            }

            frames = tmp.Select(e => e as ISpriteFrame).ToArray();

            metadata = new() { new EmbeddedSpriteOffsets(points) };

            if (palette != null)
            {
                metadata.Add(new EmbeddedSpritePalette(palette));
            }

            return(true);
        }
    }
Esempio n. 4
0
        public bool TryParseSprite(Stream stream, out ISpriteFrame[] frames, out TypeDictionary metadata)
        {
            Version version;

            if (!IsMobd(stream, out version))
            {
                metadata = null;
                frames   = null;
                return(false);
            }

            var mobd = new Mobd(stream as SegmentStream, version);
            var tmp  = new List <MobdSpriteFrame>();

            tmp.AddRange(from mobdAnimation in mobd.Animations
                         from mobdFrame in mobdAnimation.Frames
                         select new MobdSpriteFrame(mobdFrame));
            tmp.AddRange(from mobdAnimation in mobd.HardcodedAnimations
                         from mobdFrame in mobdAnimation.Frames
                         select new MobdSpriteFrame(mobdFrame));

            uint[] palette = null;
            var    points  = new Dictionary <int, Offset[]>();

            for (var i = 0; i < tmp.Count; i++)
            {
                if (tmp[i].Points != null)
                {
                    points.Add(i, tmp[i].Points.Select(point => new Offset {
                        Id = point.Id, X = point.X, Y = point.Y
                    }).ToArray());
                }

                if (tmp[i].Palette != null)
                {
                    palette = tmp[i].Palette;
                }
            }

            frames = tmp.ToArray();

            metadata = new TypeDictionary {
                new EmbeddedSpritePalette(palette), new EmbeddedSpriteOffsets(points)
            };

            return(true);
        }
Esempio n. 5
0
        public bool TryParseSprite(Stream stream, string filename, out ISpriteFrame[] frames, out TypeDictionary metadata)
        {
            if (!filename.EndsWith(".mobd"))
            {
                metadata = null;
                frames   = null;
                return(false);
            }

            var mobd = new Mobd(stream as SegmentStream);
            var tmp  = new List <MobdSpriteFrame>();

            tmp.AddRange(from mobdAnimation in mobd.RotationalAnimations
                         from mobdFrame in mobdAnimation.Frames
                         select new MobdSpriteFrame(mobdFrame));
            tmp.AddRange(from mobdAnimation in mobd.SimpleAnimations
                         from mobdFrame in mobdAnimation.Frames
                         select new MobdSpriteFrame(mobdFrame));

            uint[] palette = null;
            var    points  = new Dictionary <int, Offset[]>();

            for (var i = 0; i < tmp.Count; i++)
            {
                if (tmp[i].Points != null)
                {
                    points.Add(i, tmp[i].Points.Select(point => new Offset(point.Id, point.X, point.Y)).ToArray());
                }

                if (tmp[i].Palette != null)
                {
                    palette = tmp[i].Palette;
                }
            }

            frames = tmp.ToArray();

            metadata = new TypeDictionary {
                new EmbeddedSpritePalette(palette), new EmbeddedSpriteOffsets(points)
            };

            return(true);
        }