2016-11-25 06:05:29 +00:00
|
|
|
|
namespace SpriteCompiler
|
|
|
|
|
{
|
2016-12-05 05:14:51 +00:00
|
|
|
|
using Fclp;
|
2018-04-15 18:51:05 +00:00
|
|
|
|
using SpriteCompiler.Helpers;
|
2016-12-05 05:14:51 +00:00
|
|
|
|
using SpriteCompiler.Problem;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-12-06 03:55:04 +00:00
|
|
|
|
using System.Drawing;
|
2016-12-05 05:14:51 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2016-12-06 05:17:31 +00:00
|
|
|
|
public static class ExtensionMethods
|
|
|
|
|
{
|
2018-04-15 18:51:05 +00:00
|
|
|
|
public static void Dump(this SpriteCompiler.Helpers.BrutalDeluxeClassifier.ByteColor[,] array)
|
2016-12-06 05:17:31 +00:00
|
|
|
|
{
|
|
|
|
|
var rows = array.GetLength(1);
|
|
|
|
|
var cols = array.GetLength(0);
|
|
|
|
|
|
|
|
|
|
for (int r = 0; r < rows; r++)
|
|
|
|
|
{
|
|
|
|
|
for (int c = 0; c < cols; c++)
|
|
|
|
|
{
|
2018-04-15 18:51:05 +00:00
|
|
|
|
char chr = ' ';
|
|
|
|
|
switch (array[c, r])
|
|
|
|
|
{
|
|
|
|
|
case BrutalDeluxeClassifier.ByteColor.BLUE: chr = 'B'; break;
|
|
|
|
|
case BrutalDeluxeClassifier.ByteColor.GREEN: chr = 'G'; break;
|
|
|
|
|
case BrutalDeluxeClassifier.ByteColor.ORANGE: chr = 'O'; break;
|
|
|
|
|
case BrutalDeluxeClassifier.ByteColor.PURPLE: chr = 'P'; break;
|
|
|
|
|
case BrutalDeluxeClassifier.ByteColor.RED: chr = 'R'; break;
|
|
|
|
|
case BrutalDeluxeClassifier.ByteColor.YELLOW: chr = 'Y'; break;
|
|
|
|
|
}
|
|
|
|
|
Console.Write(chr);
|
2016-12-06 05:17:31 +00:00
|
|
|
|
}
|
|
|
|
|
Console.Write(Environment.NewLine);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-15 18:51:05 +00:00
|
|
|
|
public static void Dump(this int[,] array)
|
|
|
|
|
{
|
|
|
|
|
var rows = array.GetLength(1);
|
|
|
|
|
var cols = array.GetLength(0);
|
|
|
|
|
|
|
|
|
|
for (int r = 0; r < rows; r++)
|
|
|
|
|
{
|
|
|
|
|
for (int c = 0; c < cols; c++)
|
|
|
|
|
{
|
|
|
|
|
Console.Write(array[c, r].ToString("X2"));
|
|
|
|
|
}
|
|
|
|
|
Console.Write(Environment.NewLine);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-06 05:17:31 +00:00
|
|
|
|
}
|
2018-04-15 18:51:05 +00:00
|
|
|
|
|
2016-12-05 05:14:51 +00:00
|
|
|
|
public class ApplicationArguments
|
|
|
|
|
{
|
|
|
|
|
public List<string> Data { get; set; }
|
|
|
|
|
public List<string> Mask { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-25 06:05:29 +00:00
|
|
|
|
public class Program
|
|
|
|
|
{
|
2016-12-05 05:14:51 +00:00
|
|
|
|
public static void WriteOutSolution(IEnumerable<SpriteGeneratorSearchNode> solution)
|
|
|
|
|
{
|
|
|
|
|
foreach (var step in solution.Skip(1))
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(step.Action.Emit());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(string.Format("; Total Cost = {0} cycles", (int)solution.Last().PathCost));
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-25 06:05:29 +00:00
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
2016-12-06 05:17:31 +00:00
|
|
|
|
var data = new List<byte>();
|
|
|
|
|
var mask = new List<byte>();
|
|
|
|
|
var filename = (string)null;
|
|
|
|
|
Color? maskColor = null;
|
2016-12-11 03:56:27 +00:00
|
|
|
|
int? maxCycles = null;
|
2016-12-06 05:17:31 +00:00
|
|
|
|
var sprite = new List<SpriteByte>();
|
2016-12-11 03:56:27 +00:00
|
|
|
|
bool verbose = false;
|
2016-12-05 05:14:51 +00:00
|
|
|
|
|
2016-12-06 05:17:31 +00:00
|
|
|
|
var p = new FluentCommandLineParser();
|
|
|
|
|
|
|
|
|
|
p.Setup<List<string>>('d', "data")
|
|
|
|
|
.Callback(_ => data = _.Select(s => Convert.ToByte(s, 16)).ToList());
|
|
|
|
|
|
|
|
|
|
p.Setup<List<string>>('m', "mask")
|
2016-12-09 05:15:59 +00:00
|
|
|
|
.Callback(_ => mask = _.Select(s => Convert.ToByte(s, 16)).ToList());
|
2016-12-06 05:17:31 +00:00
|
|
|
|
|
|
|
|
|
p.Setup<string>('i', "image")
|
|
|
|
|
.Callback(_ => filename = _);
|
|
|
|
|
|
2016-12-11 03:56:27 +00:00
|
|
|
|
p.Setup<string>('l', "limit")
|
|
|
|
|
.Callback(_ => maxCycles = int.Parse(_));
|
|
|
|
|
|
|
|
|
|
p.Setup<string>('v', "verbose")
|
|
|
|
|
.Callback(_ => verbose = true);
|
|
|
|
|
|
2016-12-06 05:17:31 +00:00
|
|
|
|
p.Setup<string>("bg-color")
|
|
|
|
|
.Callback(_ => maskColor = Color.FromArgb(0xFF, Color.FromArgb(Convert.ToInt32(_, 16))));
|
|
|
|
|
|
|
|
|
|
p.Parse(args);
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Manual data has " + data.Count + " bytes");
|
|
|
|
|
Console.WriteLine("Manual mask has " + mask.Count + " bytes");
|
|
|
|
|
Console.WriteLine("Input filename is " + filename);
|
|
|
|
|
Console.WriteLine("Image mask color is " + (maskColor.HasValue ? maskColor.ToString() : "(none)"));
|
|
|
|
|
|
2016-12-11 03:56:27 +00:00
|
|
|
|
// Set the global state
|
|
|
|
|
var problem = SpriteGeneratorSearchProblem.CreateSearchProblem();
|
|
|
|
|
var search = maxCycles.HasValue ?
|
|
|
|
|
SpriteGeneratorSearchProblem.Create(maxCycles.Value) :
|
|
|
|
|
SpriteGeneratorSearchProblem.Create();
|
|
|
|
|
|
|
|
|
|
SpriteGeneratorState initialState = null;
|
|
|
|
|
|
|
|
|
|
// Handle the difference command line cases
|
2016-12-06 05:17:31 +00:00
|
|
|
|
if (!String.IsNullOrEmpty(filename))
|
2016-12-06 03:55:04 +00:00
|
|
|
|
{
|
2016-12-06 05:17:31 +00:00
|
|
|
|
var bitmap = new Bitmap(filename);
|
2018-04-15 18:51:05 +00:00
|
|
|
|
var record = BrutalDeluxeClassifier.Decompose(bitmap, maskColor);
|
2016-12-06 05:17:31 +00:00
|
|
|
|
|
2018-04-15 18:51:05 +00:00
|
|
|
|
record.Data.Dump();
|
2016-12-06 05:17:31 +00:00
|
|
|
|
Console.WriteLine();
|
2018-04-15 18:51:05 +00:00
|
|
|
|
record.Mask.Dump();
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
record.Classes.Dump();
|
2016-12-11 03:56:27 +00:00
|
|
|
|
|
2018-04-15 18:51:05 +00:00
|
|
|
|
//initialState = SpriteGeneratorState.Init(sprite);
|
2016-12-11 03:56:27 +00:00
|
|
|
|
}
|
|
|
|
|
else if (data.Count == mask.Count)
|
|
|
|
|
{
|
|
|
|
|
initialState = SpriteGeneratorState.Init(data, mask);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
initialState = SpriteGeneratorState.Init(data);
|
2016-12-06 05:17:31 +00:00
|
|
|
|
}
|
2016-12-05 05:14:51 +00:00
|
|
|
|
|
2018-04-15 18:51:05 +00:00
|
|
|
|
//var solution = search.Search(problem, initialState);
|
|
|
|
|
//WriteOutSolution(solution);
|
2016-11-25 06:05:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|