writing out layers
parent
b65ea2ca66
commit
f789d5cd7e
|
@ -21,11 +21,17 @@ namespace Palettizer
|
||||||
public GMSpriteCompositeImage CompositeImage { get; set; }
|
public GMSpriteCompositeImage CompositeImage { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public struct GMSpriteLayer
|
||||||
|
{
|
||||||
|
public string Name { get; set; } // this is actually a GUID lol
|
||||||
|
}
|
||||||
|
|
||||||
public struct GMSprite
|
public struct GMSprite
|
||||||
{
|
{
|
||||||
public GMTextureGroupID TextureGroupID { get; set; }
|
public GMTextureGroupID TextureGroupID { get; set; }
|
||||||
public GMSpriteFrame[] Frames { get; set; }
|
public GMSpriteFrame[] Frames { get; set; }
|
||||||
public string ResourceType { get; set; }
|
public GMSpriteLayer[] Layers { get; set; }
|
||||||
|
public string ResourceType { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,9 +27,9 @@ namespace Palettizer
|
||||||
if (GrayscaleToColorMap.ContainsKey((byte)average))
|
if (GrayscaleToColorMap.ContainsKey((byte)average))
|
||||||
{
|
{
|
||||||
var increment = 1;
|
var increment = 1;
|
||||||
for (var i = 0; i < 256 - GrayscaleCount; i += 1)
|
for (var i = 0; i < 256; i += 1)
|
||||||
{
|
{
|
||||||
average += increment;
|
average = (average + increment) % 256;
|
||||||
|
|
||||||
if (!GrayscaleToColorMap.ContainsKey((byte)average))
|
if (!GrayscaleToColorMap.ContainsKey((byte)average))
|
||||||
{
|
{
|
||||||
|
@ -38,7 +38,6 @@ namespace Palettizer
|
||||||
|
|
||||||
increment = ((increment > 0) ? (increment + 1) : (increment - 1)) * -1; // up by 1, down by 2, up by 3, etc
|
increment = ((increment > 0) ? (increment + 1) : (increment - 1)) * -1; // up by 1, down by 2, up by 3, etc
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GrayscaleToColorMap.Add((byte)average, color);
|
GrayscaleToColorMap.Add((byte)average, color);
|
||||||
|
|
|
@ -46,10 +46,6 @@ namespace Palettizer
|
||||||
|
|
||||||
console.Out.Write("Parsing: " + gmProject.Name + "\n");
|
console.Out.Write("Parsing: " + gmProject.Name + "\n");
|
||||||
|
|
||||||
if (Directory.Exists("output"))
|
|
||||||
{
|
|
||||||
Directory.Delete("output", true);
|
|
||||||
}
|
|
||||||
var outputDir = Directory.CreateDirectory("output");
|
var outputDir = Directory.CreateDirectory("output");
|
||||||
|
|
||||||
var palette = new Palette();
|
var palette = new Palette();
|
||||||
|
@ -75,9 +71,10 @@ namespace Palettizer
|
||||||
{
|
{
|
||||||
console.Out.Write(sprite.Name + "\n");
|
console.Out.Write(sprite.Name + "\n");
|
||||||
|
|
||||||
foreach (var spriteFrame in sprite.Frames)
|
for (var i = 0; i < sprite.Frames.Length; i += 1)
|
||||||
{
|
{
|
||||||
ImageResult image;
|
var spriteFrame = sprite.Frames[i];
|
||||||
|
ImageResult image;
|
||||||
byte[] grayscaleImage;
|
byte[] grayscaleImage;
|
||||||
|
|
||||||
var spriteImageFilePath = Path.Combine(spriteDir, spriteFrame.CompositeImage.FrameID.Name + ".png");
|
var spriteImageFilePath = Path.Combine(spriteDir, spriteFrame.CompositeImage.FrameID.Name + ".png");
|
||||||
|
@ -89,17 +86,24 @@ namespace Palettizer
|
||||||
grayscaleImage = AddSpriteToPalette(palette, image, console);
|
grayscaleImage = AddSpriteToPalette(palette, image, console);
|
||||||
}
|
}
|
||||||
|
|
||||||
var spriteWriteDir = Path.Combine(outputDir.FullName, Path.GetRelativePath(projectDir.FullName, spriteDir));
|
var spriteWriteDir = Path.Combine(outputDir.FullName, Path.GetRelativePath(projectDir.FullName, spriteDir));
|
||||||
Directory.CreateDirectory(spriteWriteDir);
|
Directory.CreateDirectory(spriteWriteDir);
|
||||||
|
|
||||||
var spriteWritePath = Path.Combine(spriteWriteDir, spriteFrame.CompositeImage.FrameID.Name + ".png");
|
var spriteWritePath = Path.Combine(spriteWriteDir, spriteFrame.CompositeImage.FrameID.Name + ".png");
|
||||||
// Now write the image to output directory as grayscale
|
// Now write the image to output directory as grayscale
|
||||||
using (var stream = File.OpenWrite(spriteWritePath))
|
using (var stream = File.OpenWrite(spriteWritePath))
|
||||||
{
|
{
|
||||||
writer.WritePng(grayscaleImage, image.Width, image.Height, StbImageWriteSharp.ColorComponents.RedGreenBlueAlpha, stream);
|
writer.WritePng(grayscaleImage, image.Width, image.Height, StbImageWriteSharp.ColorComponents.RedGreenBlueAlpha, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now write out the layer
|
||||||
|
// There's just 1 always because nobody uses GM's shit ass sprite editor
|
||||||
|
var layerSpriteWriteDir = Path.Combine(spriteWriteDir, "layers", sprite.Frames[i].CompositeImage.FrameID.Name);
|
||||||
|
Directory.CreateDirectory(layerSpriteWriteDir);
|
||||||
|
var layerSpriteWritePath = Path.Combine(layerSpriteWriteDir, sprite.Layers[0].Name + ".png");
|
||||||
|
File.Copy(spriteWritePath, layerSpriteWritePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,6 +140,7 @@ namespace Palettizer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// build the alternate rows
|
||||||
for (var j = 1; j < paletteImage.Width; j += 1)
|
for (var j = 1; j < paletteImage.Width; j += 1)
|
||||||
{
|
{
|
||||||
var colorPalette = new Color[256];
|
var colorPalette = new Color[256];
|
||||||
|
|
Loading…
Reference in New Issue