Compare commits
No commits in common. "4bf87914ced9a396a40845adb5fe3585fbd218a4" and "1fb42d55d5dbc211ee1fab3dad06992dc63f12f4" have entirely different histories.
4bf87914ce
...
1fb42d55d5
5 changed files with 9 additions and 62 deletions
13
README.md
13
README.md
|
@ -1,14 +1,3 @@
|
|||
# SpritePacker
|
||||
|
||||
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.
|
||||
An advanced sprite packing tool. Currently work in progress.
|
|
@ -11,13 +11,7 @@ namespace SpritePacker
|
|||
Normal,
|
||||
DisplayHelpText,
|
||||
DisplayVersionText
|
||||
}
|
||||
|
||||
enum OutputFormat
|
||||
{
|
||||
Text,
|
||||
CSV
|
||||
}
|
||||
};
|
||||
|
||||
class Program
|
||||
{
|
||||
|
@ -31,7 +25,6 @@ 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>();
|
||||
|
||||
|
@ -55,9 +48,6 @@ namespace SpritePacker
|
|||
case "--verbose":
|
||||
Verbose = true;
|
||||
break;
|
||||
case "--csv":
|
||||
outputFormat = OutputFormat.CSV;
|
||||
break;
|
||||
default:
|
||||
if(args[i].StartsWith("-"))
|
||||
{
|
||||
|
@ -108,19 +98,8 @@ 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,15 +1,10 @@
|
|||
SpritePacker {version}, by Starbeamrainbowlabs
|
||||
Built at {build-date}
|
||||
|
||||
An advanced sprite packing tool
|
||||
|
||||
Usage:
|
||||
[mono ]./SpritePacker.exe [flags] /path/to/output/file.png [filenames]
|
||||
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,7 +50,6 @@ 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,7 +6,6 @@ using System.IO;
|
|||
using System.Configuration;
|
||||
using System.Drawing.Text;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Text;
|
||||
|
||||
namespace SpritePacker
|
||||
{
|
||||
|
@ -30,7 +29,7 @@ namespace SpritePacker
|
|||
/// <param name="sprite">Sprite.</param>
|
||||
public void Add(Sprite sprite)
|
||||
{
|
||||
if(Verbose) Console.WriteLine("Adding {0}.", sprite);
|
||||
Console.WriteLine("Adding {0}.", sprite);
|
||||
sprites.Add(sprite);
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -98,12 +97,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; // NOTE: Add one here?
|
||||
nextScanLines.Y = probSpr.Bottom + 1;
|
||||
}
|
||||
if(Verbose) Console.WriteLine("Found rightmost problem: {0}", rightProblem);
|
||||
|
||||
// Move up to the position furthest to the right
|
||||
cspr.X = rightProblem.Right; // NOTE: Add one here?
|
||||
cspr.X = rightProblem.Right + 1;
|
||||
}
|
||||
|
||||
if (!foundPosition)
|
||||
|
@ -133,12 +132,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; // NOTE: Add one here?
|
||||
nextScanLines.X = probSpr.Right + 1;
|
||||
}
|
||||
if(Verbose) Console.WriteLine("Found downProblem {0}", downProblem);
|
||||
|
||||
// Move up to the position furthest downwards
|
||||
cspr.Y = downProblem.Bottom; // NOTE: Add one here?
|
||||
cspr.Y = downProblem.Bottom + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,20 +200,6 @@ 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