commit 69a2ef0686e0f7184a7c97919fc728113a3ca61c Author: Sebastian Fischlmayr Date: Wed May 11 21:06:50 2022 +0200 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c9a06e4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/bin/* +/obj/* diff --git a/.idea/.idea.RecipeRevamper/.idea/.gitignore b/.idea/.idea.RecipeRevamper/.idea/.gitignore new file mode 100644 index 0000000..52d04d9 --- /dev/null +++ b/.idea/.idea.RecipeRevamper/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/contentModel.xml +/projectSettingsUpdater.xml +/.idea.RecipeRevamper.iml +/modules.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.RecipeRevamper/.idea/encodings.xml b/.idea/.idea.RecipeRevamper/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.RecipeRevamper/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.RecipeRevamper/.idea/indexLayout.xml b/.idea/.idea.RecipeRevamper/.idea/indexLayout.xml new file mode 100644 index 0000000..f5a863a --- /dev/null +++ b/.idea/.idea.RecipeRevamper/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.RecipeRevamper/.idea/vcs.xml b/.idea/.idea.RecipeRevamper/.idea/vcs.xml new file mode 100644 index 0000000..9661ac7 --- /dev/null +++ b/.idea/.idea.RecipeRevamper/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MinecraftRecipe.cs b/MinecraftRecipe.cs new file mode 100644 index 0000000..a7f1f46 --- /dev/null +++ b/MinecraftRecipe.cs @@ -0,0 +1,49 @@ +using Newtonsoft.Json; + +namespace RecipeRevamper; + +[JsonObject] +public class MinecraftRecipe +{ + public struct ItemResult + { + public string? Item; + public int? Count; + public double? Chance; + } + public struct ItemIngredient + { + public string? Item; + } + + public string? Type; + public List Ingredients = new(); + public List Results = new(); + public int ProcessingTime = 50; + + public MinecraftRecipe Copy() + { + var newRecipe = new MinecraftRecipe(); + newRecipe.Type = this.Type; + foreach (ItemIngredient ingredient in Ingredients) + { + newRecipe.Ingredients.Add(new ItemIngredient{Item = ingredient.Item,} ); + } + foreach (ItemResult result in Results) + { + newRecipe.Results.Add(new ItemResult + { + Item = result.Item, + Count = result.Count, + Chance = result.Chance + }); + } + + return newRecipe; + } + + public string Serialize() + { + return MinecraftRecipeSerializer.SerializeObject(this); + } +} \ No newline at end of file diff --git a/MinecraftRecipeSerializer.cs b/MinecraftRecipeSerializer.cs new file mode 100644 index 0000000..908a4f7 --- /dev/null +++ b/MinecraftRecipeSerializer.cs @@ -0,0 +1,26 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; + +namespace RecipeRevamper; + +public class MinecraftRecipeSerializer +{ + private static readonly JsonSerializerSettings _settings = new JsonSerializerSettings + { + ContractResolver = new LowerCaseContractResolver(), + NullValueHandling = NullValueHandling.Ignore + }; + + public static string SerializeObject(object o) + { + return JsonConvert.SerializeObject(o, Formatting.Indented, _settings); + } + + public class LowerCaseContractResolver : DefaultContractResolver + { + protected override string ResolvePropertyName(string propertyName) + { + return propertyName.ToLower(); + } + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..432ab71 --- /dev/null +++ b/Program.cs @@ -0,0 +1,71 @@ +using System.Text; +using Newtonsoft.Json; +using Exception = System.Exception; + +namespace RecipeRevamper +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine($"Got {args.Length} recipe files to convert ..."); + foreach (string recipePath in args) + { + MinecraftRecipe recipe; + try + { + recipe = GetRecipeFromFile(recipePath); + } + catch (Exception) + { + Console.WriteLine("Exception occurred during parsing skipping this file ..."); + continue; + } + + WriteRecipeToOutput(recipe, "test"); + } + + + Console.WriteLine("... Done"); + Console.WriteLine("Press ENTER to exit the program ..."); + } + + static MinecraftRecipe ConvertRecipe(MinecraftRecipe oldRecipe) + { + var newRecipe = oldRecipe.Copy(); + return newRecipe; + } + + static void WriteRecipeToOutput(MinecraftRecipe recipe, string name) + { + if (!Directory.Exists("./output")) + { + Directory.CreateDirectory("./output"); + } + + byte[] bytes = Encoding.UTF8.GetBytes(recipe.Serialize()); + var fileStream = File.Create($"./output/{name}.json"); + fileStream.Write(bytes, 0, bytes.Length); + fileStream.Close(); + } + + static MinecraftRecipe GetRecipeFromFile(string path) + { + try + { + return JsonConvert.DeserializeObject(File.ReadAllText(path)) ?? + throw new InvalidOperationException(); + } + catch (FileNotFoundException) + { + Console.WriteLine($"File: {path} could not be found."); + throw; + } + catch (InvalidOperationException) + { + Console.WriteLine($"File: {path} could not be parsed."); + throw; + } + } + } +} \ No newline at end of file diff --git a/RecipeRevamper.csproj b/RecipeRevamper.csproj new file mode 100644 index 0000000..85a4079 --- /dev/null +++ b/RecipeRevamper.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/RecipeRevamper.sln b/RecipeRevamper.sln new file mode 100644 index 0000000..62b19a5 --- /dev/null +++ b/RecipeRevamper.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RecipeRevamper", "RecipeRevamper.csproj", "{22F93A0D-E8D4-4E7F-9D8E-580A52AB9975}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {22F93A0D-E8D4-4E7F-9D8E-580A52AB9975}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {22F93A0D-E8D4-4E7F-9D8E-580A52AB9975}.Debug|Any CPU.Build.0 = Debug|Any CPU + {22F93A0D-E8D4-4E7F-9D8E-580A52AB9975}.Release|Any CPU.ActiveCfg = Release|Any CPU + {22F93A0D-E8D4-4E7F-9D8E-580A52AB9975}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal