public static void RemapShp(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); FileSystem.LoadFromManifest(Game.modData.Manifest); Rules.LoadRules(Game.modData.Manifest, new Map()); var srcPaletteInfo = Rules.Info["player"].Traits.Get <PlayerColorPaletteInfo>(); int[] srcRemapIndex = srcPaletteInfo.RemapIndex; var destMod = args[2].Split(':')[0]; Game.modData = new ModData(destMod); FileSystem.LoadFromManifest(Game.modData.Manifest); Rules.LoadRules(Game.modData.Manifest, new Map()); var destPaletteInfo = Rules.Info["player"].Traits.Get <PlayerColorPaletteInfo>(); int[] destRemapIndex = destPaletteInfo.RemapIndex; int[] ShadowIndex = { }; // 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 = Palette.Load(args[1].Split(':')[1], ShadowIndex); var destPalette = Palette.Load(args[2].Split(':')[1], ShadowIndex); var fullIndexRange = Exts.MakeArray <int>(256, x => x); for (var i = 0; i < 256; i++) { if (!remap.ContainsKey(i)) { remap[i] = fullIndexRange .Where(a => !remap.ContainsValue(a)) .OrderBy(a => ColorDistance(destPalette.Values[a], srcPalette.Values[i])) .First(); } } var srcImage = ShpReader.Load(args[3]); using (var destStream = File.Create(args[4])) ShpWriter.Write(destStream, srcImage.Width, srcImage.Height, srcImage.Frames.Select(im => im.Image.Select(px => (byte)remap[px]).ToArray())); }
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"].Traits.Get <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"].Traits.Get <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())); } }
public static void RemapShp(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 srcPaletteType = Enum <PaletteFormat> .Parse(args[1].Split(':')[0]); var destPaletteType = Enum <PaletteFormat> .Parse(args[2].Split(':')[0]); /* the remap range is always 16 entries, but their location and order changes */ for (var i = 0; i < 16; i++) { remap[PlayerColorRemap.GetRemapIndex(srcPaletteType, i)] = PlayerColorRemap.GetRemapIndex(destPaletteType, i); } /* map everything else to the best match based on channel-wise distance */ var srcPalette = Palette.Load(args[1].Split(':')[1], false); var destPalette = Palette.Load(args[2].Split(':')[1], false); var fullIndexRange = Exts.MakeArray <int>(256, x => x); for (var i = 0; i < 256; i++) { if (!remap.ContainsKey(i)) { remap[i] = fullIndexRange .Where(a => !remap.ContainsValue(a)) .OrderBy(a => ColorDistance(destPalette.Values[a], srcPalette.Values[i])) .First(); } } var srcImage = ShpReader.Load(args[3]); using (var destStream = File.Create(args[4])) ShpWriter.Write(destStream, srcImage.Width, srcImage.Height, srcImage.Frames.Select(im => im.Image.Select(px => (byte)remap[px]).ToArray())); }