Skip to content

Instantly share code, notes, and snippets.

@MeinLiX
Last active May 14, 2021 22:06
Show Gist options
  • Save MeinLiX/456a0c43ebb914db2e16c59611bab0d9 to your computer and use it in GitHub Desktop.
Save MeinLiX/456a0c43ebb914db2e16c59611bab0d9 to your computer and use it in GitHub Desktop.
static void Parser()
{
var src = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (src == null) throw new Exception();
src = Path.Combine(src, "..\\..\\..\\assets", "blocks.json");
var blocks = JsonConvert.DeserializeObject<Dictionary<string, Lava.Blocks.json.BlockInfo>>(File.ReadAllText(src));
List<string> b = new List<string>();
foreach (var (name, info) in blocks)
{
var blockName = TextCase.ToPascalCase(name.Split(":")[1]);
blockName = char.ToUpper(blockName[0]) + blockName.Substring(1);
b.Add($"public static {blockName} {blockName} = new {blockName}();\n");
}
using (FileStream fs = File.Create(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "..\\..\\..\\..\\newPalette.cs"))
{
StringBuilder sb = new StringBuilder();
foreach (var temp in b)
sb.Append(temp);
byte[] vs = new UTF8Encoding().GetBytes(sb.ToString());
fs.Write(vs, 0, vs.Length);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment