Created
July 30, 2017 14:39
-
-
Save Silverfeelin/7e580e521ce09e94894cec12e44ad5d1 to your computer and use it in GitHub Desktop.
Crops a tile out of Starbound's tile frames. Requires Newtonsoft.JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json.Linq; | |
using System; | |
using System.Collections.Generic; | |
using System.Drawing; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace SBMaterialFramesToButton | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Material folder:"); | |
string matPath = Console.ReadLine(); | |
Console.WriteLine("Output folder:"); | |
string outPath = Console.ReadLine(); | |
if (Directory.GetFiles(outPath).Length > 0) | |
{ | |
Console.WriteLine("Output folder must be empty..."); | |
Console.ReadKey(true); | |
return; | |
} | |
foreach (string matFile in Directory.GetFiles(matPath).Where(p => p.EndsWith(".material"))) | |
{ | |
JObject jobj = JObject.Parse(File.ReadAllText(matFile)); | |
string frameFile = Path.Combine(matPath, jobj["renderParameters"]["texture"].Value<string>()); | |
Bitmap matFrames = new Bitmap(frameFile); | |
Bitmap sub = new Bitmap(16, 16); | |
using (Graphics g = Graphics.FromImage(sub)) | |
{ | |
switch (jobj["renderTemplate"].Value<string>()) | |
{ | |
case "/tiles/girdertemplate.config": | |
g.DrawImageUnscaledAndClipped(matFrames.Clone(new Rectangle(0,0,10,10), matFrames.PixelFormat), new Rectangle(3, 3, 10, 10)); | |
break; | |
case "/tiles/pipetemplate.config": | |
g.DrawImageUnscaledAndClipped(matFrames.Clone(new Rectangle(20, 20, 8, 8), matFrames.PixelFormat), new Rectangle(4, 4, 8, 8)); // center | |
g.DrawImageUnscaledAndClipped(matFrames.Clone(new Rectangle(48, 0, 16, 4), matFrames.PixelFormat), new Rectangle(0, 0, 16, 4)); // top | |
g.DrawImageUnscaledAndClipped(matFrames.Clone(new Rectangle(48, 12, 16, 4), matFrames.PixelFormat), new Rectangle(0, 12, 16, 4)); // bottom | |
g.DrawImageUnscaledAndClipped(matFrames.Clone(new Rectangle(56, 16, 4, 16), matFrames.PixelFormat), new Rectangle(0, 0, 4, 16)); // left | |
g.DrawImageUnscaledAndClipped(matFrames.Clone(new Rectangle(52, 16, 4, 16), matFrames.PixelFormat), new Rectangle(12, 0, 4, 16)); // right | |
break; | |
case "/tiles/classicmaterialtemplate.config": | |
case "/tiles/slopedtemplate.config": | |
g.DrawImageUnscaledAndClipped(matFrames.Clone(new Rectangle(0, 8, 16, 16), matFrames.PixelFormat), new Rectangle(0, 0, 16, 16)); | |
break; | |
case "/tiles/rowtemplate.config": | |
case "/tiles/columntemplate.config": | |
case "/tiles/screwtemplate.config": | |
g.DrawImageUnscaledAndClipped(matFrames.Clone(new Rectangle(0, 36, 12, 12), matFrames.PixelFormat), new Rectangle(2, 2, 12, 12)); | |
break; | |
} | |
} | |
sub.Save(Path.Combine(outPath, Path.GetFileName(frameFile)), System.Drawing.Imaging.ImageFormat.Png); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment