Initial Commit

This commit is contained in:
Sebastian Fischlmayr 2022-05-11 21:06:50 +02:00
commit 69a2ef0686
10 changed files with 209 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/bin/*
/obj/*

13
.idea/.idea.RecipeRevamper/.idea/.gitignore generated vendored Normal file
View file

@ -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

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

49
MinecraftRecipe.cs Normal file
View file

@ -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<ItemIngredient> Ingredients = new();
public List<ItemResult> 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);
}
}

View file

@ -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();
}
}
}

71
Program.cs Normal file
View file

@ -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<MinecraftRecipe>(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;
}
}
}
}

14
RecipeRevamper.csproj Normal file
View file

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
</Project>

16
RecipeRevamper.sln Normal file
View file

@ -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