Compare commits
3 commits
1fb42d55d5
...
4bf87914ce
Author | SHA1 | Date | |
---|---|---|---|
4bf87914ce | |||
6b158a1adf | |||
345dd1651c |
5 changed files with 63 additions and 10 deletions
13
README.md
13
README.md
|
@ -1,3 +1,14 @@
|
|||
# SpritePacker
|
||||
|
||||
An advanced sprite packing tool. Currently work in progress.
|
||||
An advanced sprite packing tool. Currently a work in progress.
|
||||
|
||||
## Getting Started
|
||||
* Clone or download this repo, and build the included solution.
|
||||
* Windows GUI: Open the solution in Visual Studio and hit build (CTRL + SHIFT + B).
|
||||
* Windows Command Line: Run `msbuild` from the root of this repo (I assume).
|
||||
* Linux GUI: Open the solution in MonoDevelop and hit build (F8)
|
||||
* Linux Command Line: Run `xbuild` from the root of this repo.
|
||||
* Run `./SpritePacker.exe --help` to learn how to use it.
|
||||
|
||||
## License
|
||||
This tool is licensed under the Mozilla Public License version 2.0. You can view the full license text in the `LICENSE` file in this repo. Alternatively, [tl;dr legal](https://tldrlegal.com/) has a [summary](https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2)) of this license.
|
||||
|
|
|
@ -11,7 +11,13 @@ namespace SpritePacker
|
|||
Normal,
|
||||
DisplayHelpText,
|
||||
DisplayVersionText
|
||||
};
|
||||
}
|
||||
|
||||
enum OutputFormat
|
||||
{
|
||||
Text,
|
||||
CSV
|
||||
}
|
||||
|
||||
class Program
|
||||
{
|
||||
|
@ -25,6 +31,7 @@ namespace SpritePacker
|
|||
|
||||
private static SpritePacker spritePacker;
|
||||
|
||||
private static OutputFormat outputFormat = OutputFormat.Text;
|
||||
private static string outputFilename = "spritesheet.png";
|
||||
private static List<string> values = new List<string>();
|
||||
|
||||
|
@ -48,6 +55,9 @@ namespace SpritePacker
|
|||
case "--verbose":
|
||||
Verbose = true;
|
||||
break;
|
||||
case "--csv":
|
||||
outputFormat = OutputFormat.CSV;
|
||||
break;
|
||||
default:
|
||||
if(args[i].StartsWith("-"))
|
||||
{
|
||||
|
@ -98,8 +108,19 @@ namespace SpritePacker
|
|||
spritePacker = new SpritePacker(Verbose);
|
||||
addSprites(values);
|
||||
spritePacker.Arrange();
|
||||
Console.WriteLine(spritePacker.ToString());
|
||||
spritePacker.Output(outputFilename);
|
||||
switch(outputFormat)
|
||||
{
|
||||
case OutputFormat.CSV:
|
||||
Console.WriteLine(spritePacker.GetSpritePositionsCSV().Trim());
|
||||
break;
|
||||
case OutputFormat.Text:
|
||||
Console.WriteLine(spritePacker.ToString());
|
||||
break;
|
||||
default:
|
||||
Console.Error.WriteLine("Error: Invalid output format!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void addSprites(List<string> filenames)
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
SpritePacker {version}, by Starbeamrainbowlabs
|
||||
Built at {build-date}
|
||||
|
||||
Usage:
|
||||
mono ./SpritePacker.exe [flags] /path/to/output/file.png [filenames]
|
||||
An advanced sprite packing tool
|
||||
|
||||
Usage:
|
||||
[mono ]./SpritePacker.exe [flags] /path/to/output/file.png [filenames]
|
||||
|
||||
Option Meaning
|
||||
-------------------------------------------------------------------------------
|
||||
--help Shows this help message.
|
||||
--version Shows the version information.
|
||||
--csv Outputs the final sprite positions in CSV.
|
||||
|
||||
More information can be found at https://git.starbeamrainbowlabs.com/sbrl/SpritePacker
|
||||
|
|
|
@ -50,6 +50,7 @@ namespace SpritePacker
|
|||
public int Right { get { return area.Right; } }
|
||||
|
||||
public int AreaSize { get { return area.Width * area.Height; } }
|
||||
public int MaxSideLength { get { return Math.Max(area.Width, area.Height); } }
|
||||
|
||||
public Sprite(string inFilename)
|
||||
{
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.IO;
|
|||
using System.Configuration;
|
||||
using System.Drawing.Text;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Text;
|
||||
|
||||
namespace SpritePacker
|
||||
{
|
||||
|
@ -29,7 +30,7 @@ namespace SpritePacker
|
|||
/// <param name="sprite">Sprite.</param>
|
||||
public void Add(Sprite sprite)
|
||||
{
|
||||
Console.WriteLine("Adding {0}.", sprite);
|
||||
if(Verbose) Console.WriteLine("Adding {0}.", sprite);
|
||||
sprites.Add(sprite);
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -97,12 +98,12 @@ namespace SpritePacker
|
|||
// move the next scan line up a bit.
|
||||
// Also make sure that the next scan line and the current scan line don't touch or cross.
|
||||
if (probSpr.Bottom < nextScanLines.Y && probSpr.Bottom > scanLines.Y)
|
||||
nextScanLines.Y = probSpr.Bottom + 1;
|
||||
nextScanLines.Y = probSpr.Bottom; // NOTE: Add one here?
|
||||
}
|
||||
if(Verbose) Console.WriteLine("Found rightmost problem: {0}", rightProblem);
|
||||
|
||||
// Move up to the position furthest to the right
|
||||
cspr.X = rightProblem.Right + 1;
|
||||
cspr.X = rightProblem.Right; // NOTE: Add one here?
|
||||
}
|
||||
|
||||
if (!foundPosition)
|
||||
|
@ -132,12 +133,12 @@ namespace SpritePacker
|
|||
// move the enxt scan line up to meet it.
|
||||
// Also make sure that the next scan line and the current scan line don't touch or cross.
|
||||
if (probSpr.Right < nextScanLines.X && probSpr.Right > scanLines.X)
|
||||
nextScanLines.X = probSpr.Right + 1;
|
||||
nextScanLines.X = probSpr.Right; // NOTE: Add one here?
|
||||
}
|
||||
if(Verbose) Console.WriteLine("Found downProblem {0}", downProblem);
|
||||
|
||||
// Move up to the position furthest downwards
|
||||
cspr.Y = downProblem.Bottom + 1;
|
||||
cspr.Y = downProblem.Bottom; // NOTE: Add one here?
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,6 +201,20 @@ namespace SpritePacker
|
|||
finalImage.Dispose();
|
||||
}
|
||||
|
||||
public string GetSpritePositionsCSV(bool header = true)
|
||||
{
|
||||
StringWriter result = new StringWriter();
|
||||
if (header)
|
||||
result.WriteLine("index,filename,x,y,width,height");
|
||||
int i = 0;
|
||||
foreach(Sprite spr in sprites)
|
||||
{
|
||||
result.WriteLine("{0},{1},{2},{3},{4},{5}", new object[] { i, spr.Filename, spr.X, spr.Y, spr.Width, spr.Height });
|
||||
i++;
|
||||
}
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sorts the sprites by size.
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in a new issue