Exemplo n.º 1
0
        public static ResourceTemplate RenderResourceType(ResourceTypeInfo info, TileSet tileset, IPalette p)
        {
            var image = ResolveFilename(info.EditorSprite, tileset);
            using (var s = GlobalFileSystem.Open(image))
            {
                // TODO: Do this properly
                var shp = new ShpTDSprite(s);
                var frame = shp.Frames.Last();

                var bitmap = new Bitmap(frame.Size.Width, frame.Size.Height, PixelFormat.Format8bppIndexed);
                bitmap.Palette = p.AsSystemPalette();
                var data = bitmap.LockBits(bitmap.Bounds(),
                    ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

                unsafe
                {
                    var q = (byte*)data.Scan0.ToPointer();
                    var stride = data.Stride;

                    for (var i = 0; i < frame.Size.Width; i++)
                        for (var j = 0; j < frame.Size.Height; j++)
                            q[j * stride + i] = frame.Data[i + frame.Size.Width * j];
                }

                bitmap.UnlockBits(data);
                return new ResourceTemplate { Bitmap = bitmap, Info = info, Value = shp.Frames.Count - 1 };
            }
        }
Exemplo n.º 2
0
        public static ActorTemplate RenderActor(ActorInfo info, TileSet tileset, IPalette p)
        {
            var image = info.Traits.Get<ILegacyEditorRenderInfo>().EditorImage(info);
            using (var s = GlobalFileSystem.OpenWithExts(image, tileset.Extensions))
            {
                var shp = new ShpTDSprite(s);
                var bitmap = RenderShp(shp, p);

                try
                {
                    using (var s2 = GlobalFileSystem.OpenWithExts(image + "2", tileset.Extensions))
                    {
                        var shp2 = new ShpTDSprite(s2);
                        var roofBitmap = RenderShp(shp2, p);

                        using (var g = System.Drawing.Graphics.FromImage(bitmap))
                            g.DrawImage(roofBitmap, 0, 0);
                    }
                }
                catch { }

                return new ActorTemplate
                {
                    Bitmap = bitmap,
                    Info = info,
                    Appearance = info.Traits.GetOrDefault<EditorAppearanceInfo>()
                };
            }
        }
Exemplo n.º 3
0
        public bool TryParseSprite(Stream s, out ISpriteFrame[] frames)
        {
            if (!IsShpTD(s))
            {
                frames = null;
                return(false);
            }

            frames = new ShpTDSprite(s).Frames.ToArray();
            return(true);
        }
Exemplo n.º 4
0
            public ImageHeader(Stream stream, ShpTDSprite reader)
            {
                this.reader = reader;
                var data = stream.ReadUInt32();

                FileOffset = data & 0xffffff;
                Format     = (Format)(data >> 24);

                RefOffset = stream.ReadUInt16();
                RefFormat = (Format)stream.ReadUInt16();
            }
Exemplo n.º 5
0
		public bool TryParseSprite(Stream s, out ISpriteFrame[] frames)
		{
			if (!IsShpTD(s))
			{
				frames = null;
				return false;
			}

			frames = new ShpTDSprite(s).Frames.ToArray();
			return true;
		}
Exemplo n.º 6
0
        public bool TryParseSprite(Stream s, out ISpriteFrame[] frames, out TypeDictionary metadata)
        {
            metadata = null;
            if (!IsShpTD(s))
            {
                frames = null;
                return(false);
            }

            frames = new ShpTDSprite(s).Frames.ToArray();
            return(true);
        }
Exemplo n.º 7
0
		public void Run(ModData modData, string[] args)
		{
			var remap = new Dictionary<int, int>();

			/* the first 4 entries are fixed */
			for (var i = 0; i < 4; i++)
				remap[i] = i;

			var srcMod = args[1].Split(':')[0];

			Game.ModData = new ModData(srcMod);
			GlobalFileSystem.LoadFromManifest(Game.ModData.Manifest);
			var srcRules = Game.ModData.RulesetCache.Load();
			var srcPaletteInfo = srcRules.Actors["player"].TraitInfo<PlayerColorPaletteInfo>();
			var srcRemapIndex = srcPaletteInfo.RemapIndex;

			var destMod = args[2].Split(':')[0];
			Game.ModData = new ModData(destMod);
			GlobalFileSystem.LoadFromManifest(Game.ModData.Manifest);
			var destRules = Game.ModData.RulesetCache.Load();
			var destPaletteInfo = destRules.Actors["player"].TraitInfo<PlayerColorPaletteInfo>();
			var destRemapIndex = destPaletteInfo.RemapIndex;
			var shadowIndex = new int[] { };

			// the remap range is always 16 entries, but their location and order changes
			for (var i = 0; i < 16; i++)
				remap[PlayerColorRemap.GetRemapIndex(srcRemapIndex, i)]
					= PlayerColorRemap.GetRemapIndex(destRemapIndex, i);

			// map everything else to the best match based on channel-wise distance
			var srcPalette = new ImmutablePalette(args[1].Split(':')[1], shadowIndex);
			var destPalette = new ImmutablePalette(args[2].Split(':')[1], shadowIndex);

			for (var i = 0; i < Palette.Size; i++)
				if (!remap.ContainsKey(i))
					remap[i] = Enumerable.Range(0, Palette.Size)
						.Where(a => !remap.ContainsValue(a))
						.MinBy(a => ColorDistance(destPalette[a], srcPalette[i]));

			using (var s = File.OpenRead(args[3]))
			using (var destStream = File.Create(args[4]))
			{
				var srcImage = new ShpTDSprite(s);
				ShpTDSprite.Write(destStream, srcImage.Size,
					srcImage.Frames.Select(im => im.Data.Select(px => (byte)remap[px]).ToArray()));
			}
		}
Exemplo n.º 8
0
        public static ActorTemplate RenderActor(ActorInfo info, SequenceProvider sequenceProvider, TileSet tileset, IPalette p, string race)
        {
            var image = info.Traits.Get<ILegacyEditorRenderInfo>().EditorImage(info, sequenceProvider, race);
            image = ResolveFilename(image, tileset);
            using (var s = GlobalFileSystem.Open(image))
            {
                var shp = new ShpTDSprite(s);
                var bitmap = RenderShp(shp, p);

                return new ActorTemplate
                {
                    Bitmap = bitmap,
                    Info = info,
                    Appearance = info.Traits.GetOrDefault<EditorAppearanceInfo>()
                };
            }
        }
Exemplo n.º 9
0
        static Bitmap RenderShp(ShpTDSprite shp, IPalette p)
        {
            var frame = shp.Frames.First();

            var bitmap = new Bitmap(frame.Size.Width, frame.Size.Height, PixelFormat.Format8bppIndexed);

            bitmap.Palette = p.AsSystemPalette();

            var data = bitmap.LockBits(bitmap.Bounds(),
                ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

            unsafe
            {
                var q = (byte*)data.Scan0.ToPointer();
                var stride2 = data.Stride;

                for (var i = 0; i < frame.Size.Width; i++)
                    for (var j = 0; j < frame.Size.Height; j++)
                        q[j * stride2 + i] = frame.Data[i + frame.Size.Width * j];
            }

            bitmap.UnlockBits(data);
            return bitmap;
        }
Exemplo n.º 10
0
			public ImageHeader(Stream stream, ShpTDSprite reader)
			{
				this.reader = reader;
				var data = stream.ReadUInt32();
				FileOffset = data & 0xffffff;
				Format = (Format)(data >> 24);

				RefOffset = stream.ReadUInt16();
				RefFormat = (Format)stream.ReadUInt16();
			}