|
| 1 | +using Microsoft.Win32.SafeHandles; |
| 2 | +using PearlCalculatorLib.General; |
| 3 | +using PearlCalculatorLib.PearlCalculationLib.Entity; |
| 4 | +using PearlCalculatorLib.PearlCalculationLib.World; |
| 5 | +using System; |
| 6 | +using System.Dynamic; |
| 7 | +using System.IO; |
| 8 | +using System.Runtime.InteropServices.WindowsRuntime; |
| 9 | +using System.Text.Encodings.Web; |
| 10 | +using System.Text.Json; |
| 11 | + |
| 12 | +namespace PCCSettingsGenerator |
| 13 | +{ |
| 14 | + class Program |
| 15 | + { |
| 16 | + private static readonly SettingsJsonConverter JsonConverter = new SettingsJsonConverter(); |
| 17 | + |
| 18 | + private static JsonSerializerOptions WriteSerializerOptions = new JsonSerializerOptions |
| 19 | + { |
| 20 | + Converters = { JsonConverter } , |
| 21 | + WriteIndented = true |
| 22 | + }; |
| 23 | + |
| 24 | + |
| 25 | + static void Main(string[] args) |
| 26 | + { |
| 27 | + string temp = "Start"; |
| 28 | + Console.WriteLine("Welcome to use Pearl Calculator Core Settings Generator."); |
| 29 | + Console.WriteLine("Note :"); |
| 30 | + Console.WriteLine("The settings generated by this applidcation will have a percision lost."); |
| 31 | + Console.WriteLine("Please keed this in mind."); |
| 32 | + Console.WriteLine("If you stil perfer using this application"); |
| 33 | + Console.WriteLine("Press any key to proceed."); |
| 34 | + Console.ReadKey(); |
| 35 | + PearlCalculatorLib.General.Settings settings = new PearlCalculatorLib.General.Settings |
| 36 | + { |
| 37 | + Pearl = new PearlEntity() , |
| 38 | + Offset = new Surface2D() |
| 39 | + }; |
| 40 | + PearlEntity pearl = new PearlEntity(); |
| 41 | + Surface2D chamber = new Surface2D(); |
| 42 | + do |
| 43 | + { |
| 44 | + if(temp == "1" || temp == "Start") |
| 45 | + { |
| 46 | + Console.WriteLine("Please enter the center Of your FTL blast chamber :"); |
| 47 | + chamber = ReadSurface2DFromConsole("FTL blast chamber ceter"); |
| 48 | + } |
| 49 | + if(temp == "2" || temp == "Start") |
| 50 | + { |
| 51 | + Console.WriteLine("Please enter the pearl coordinate :"); |
| 52 | + settings.Pearl.Position = ReadSpace3DFromConsole("Pearl position"); |
| 53 | + } |
| 54 | + if(temp == "3" || temp == "Start") |
| 55 | + { |
| 56 | + Console.WriteLine("Please enter the pearl motion :"); |
| 57 | + settings.Pearl.Motion = ReadSpace3DFromConsole("Pearl Motion"); |
| 58 | + } |
| 59 | + if(temp == "4" || temp == "Start") |
| 60 | + { |
| 61 | + Console.WriteLine("Please enter the north west TNT coordinate :"); |
| 62 | + settings.NorthWestTNT = ReadSpace3DFromConsole("North west TNT position"); |
| 63 | + } |
| 64 | + if(temp == "5" || temp == "Start") |
| 65 | + { |
| 66 | + Console.WriteLine("Please enter the north east TNT coordinate :"); |
| 67 | + settings.NorthEastTNT = ReadSpace3DFromConsole("North east TNT position"); |
| 68 | + } |
| 69 | + if(temp == "6" || temp == "Start") |
| 70 | + { |
| 71 | + Console.WriteLine("Please enter the south west TNT coordinate :"); |
| 72 | + settings.SouthWestTNT = ReadSpace3DFromConsole("South west TNT position"); |
| 73 | + } |
| 74 | + if(temp == "7" || temp == "Start") |
| 75 | + { |
| 76 | + Console.WriteLine("Please enter the south east TNT coordinate :"); |
| 77 | + settings.SouthEastTNT = ReadSpace3DFromConsole("South east TNT position"); |
| 78 | + } |
| 79 | + if(temp == "8" || temp == "Start") |
| 80 | + { |
| 81 | + Console.WriteLine("Please enter the max TNT :"); |
| 82 | + temp = Console.ReadLine(); |
| 83 | + while(!int.TryParse(temp , out settings.MaxTNT)) |
| 84 | + { |
| 85 | + Console.WriteLine("Format Error. Please enter the following value again."); |
| 86 | + Console.WriteLine("Max TNT :"); |
| 87 | + temp = Console.ReadLine(); |
| 88 | + } |
| 89 | + } |
| 90 | + Console.WriteLine("This is the value you have entered."); |
| 91 | + Console.WriteLine("1) FTL blast chamber center " + chamber); |
| 92 | + Console.WriteLine("2) Ender Pearl " + settings.Pearl.Position); |
| 93 | + temp = settings.Pearl.Motion.X.ToString() + " , " + settings.Pearl.Motion.Y.ToString() + " , " + pearl.Motion.Z.ToString(); |
| 94 | + Console.WriteLine("3) Ender Pearl motion : " + temp); |
| 95 | + Console.WriteLine("4) North west TNT " + settings.NorthWestTNT); |
| 96 | + Console.WriteLine("5) North east TNT " + settings.NorthEastTNT); |
| 97 | + Console.WriteLine("6) South west TNT " + settings.SouthWestTNT); |
| 98 | + Console.WriteLine("7) South east TNT " + settings.SouthEastTNT); |
| 99 | + Console.WriteLine("8) Max TNT : " + settings.MaxTNT.ToString()); |
| 100 | + Console.WriteLine("Please confirm if it is all correct. (Y/N)"); |
| 101 | + temp = Console.ReadLine().ToUpper(); |
| 102 | + while(temp != "Y" && temp != "N") |
| 103 | + { |
| 104 | + Console.WriteLine("Unexpected anser. Please confirm if it is all correct. (Y/N)"); |
| 105 | + temp = Console.ReadLine().ToUpper(); |
| 106 | + } |
| 107 | + if(temp == "N") |
| 108 | + { |
| 109 | + Console.WriteLine("Which value you want to chamge."); |
| 110 | + Console.WriteLine("Please type the number of it."); |
| 111 | + temp = Console.ReadLine(); |
| 112 | + while(!(int.TryParse(temp , out int i) && i < 9 && i > 0)) |
| 113 | + { |
| 114 | + Console.WriteLine("Format Error. Please enter the following value again."); |
| 115 | + Console.WriteLine("Which value you want to chamge."); |
| 116 | + Console.WriteLine("Please type the number of it."); |
| 117 | + temp = Console.ReadLine(); |
| 118 | + } |
| 119 | + } |
| 120 | + } while(temp != "Y"); |
| 121 | + settings.NorthWestTNT -= chamber.ToSpace3D(); |
| 122 | + settings.NorthEastTNT -= chamber.ToSpace3D(); |
| 123 | + settings.SouthWestTNT -= chamber.ToSpace3D(); |
| 124 | + settings.SouthEastTNT -= chamber.ToSpace3D(); |
| 125 | + settings.Offset = settings.Pearl.Position.ToSurface2D() - chamber; |
| 126 | + settings.Pearl.Position.X = 0; |
| 127 | + settings.Pearl.Position.Z = 0; |
| 128 | + Console.WriteLine("This is the setting it generated."); |
| 129 | + Console.WriteLine("1) Max TNT : " + settings.MaxTNT.ToString()); |
| 130 | + Console.WriteLine("2) North West TNT " + settings.NorthWestTNT.ToString()); |
| 131 | + Console.WriteLine("3) North East TNT " + settings.NorthEastTNT.ToString()); |
| 132 | + Console.WriteLine("4) South West TNT " + settings.SouthWestTNT.ToString()); |
| 133 | + Console.WriteLine("5) South East TNT " + settings.SouthEastTNT.ToString()); |
| 134 | + Console.WriteLine("6) Ender Pearl Height : " + settings.Pearl.Position.Y.ToString()); |
| 135 | + temp = settings.Pearl.Motion.X.ToString() + " , " + settings.Pearl.Motion.Y.ToString() + " , " + settings.Pearl.Motion.Z.ToString(); |
| 136 | + Console.WriteLine("7) Ender Pearl Motion : " + temp); |
| 137 | + Console.WriteLine("8) Offset " + settings.Offset.ToString()); |
| 138 | + Console.WriteLine("Do you want to output as an settings.json? (Y/N)"); |
| 139 | + temp = Console.ReadLine().ToUpper(); |
| 140 | + while(temp != "Y" && temp != "N") |
| 141 | + { |
| 142 | + Console.WriteLine("Unexpected anser. Do you want to output as an settings.json? (Y/N)"); |
| 143 | + temp = Console.ReadLine().ToUpper(); |
| 144 | + } |
| 145 | + if(temp == "Y") |
| 146 | + { |
| 147 | + SaveSettingsToJson("./settings.json" , settings); |
| 148 | + Console.WriteLine("Settings file generated."); |
| 149 | + } |
| 150 | + Console.WriteLine("Press any key to exit the application."); |
| 151 | + Console.ReadKey(); |
| 152 | + } |
| 153 | + |
| 154 | + private static void SaveSettingsToJson(string path , Settings settings) |
| 155 | + { |
| 156 | + var json = JsonSerializer.SerializeToUtf8Bytes(settings , WriteSerializerOptions); |
| 157 | + |
| 158 | + using var sr = File.OpenWrite(path); |
| 159 | + sr.SetLength(0); |
| 160 | + sr.Write(json.AsSpan()); |
| 161 | + } |
| 162 | + |
| 163 | + |
| 164 | + public static Space3D ReadSpace3DFromConsole(string valueName) |
| 165 | + { |
| 166 | + Space3D result; |
| 167 | + Console.WriteLine(valueName + " X :"); |
| 168 | + string temp = Console.ReadLine(); |
| 169 | + while(!double.TryParse(temp , out result.X)) |
| 170 | + { |
| 171 | + Console.WriteLine("Format Error. Please enter the following value again."); |
| 172 | + Console.WriteLine(valueName + " X :"); |
| 173 | + temp = Console.ReadLine(); |
| 174 | + } |
| 175 | + Console.WriteLine(valueName + " Y :"); |
| 176 | + temp = Console.ReadLine(); |
| 177 | + while(!double.TryParse(temp , out result.Y)) |
| 178 | + { |
| 179 | + Console.WriteLine("Format Error. Please enter the following value again."); |
| 180 | + Console.WriteLine(valueName + " X :"); |
| 181 | + temp = Console.ReadLine(); |
| 182 | + } |
| 183 | + Console.WriteLine(valueName + " Z :"); |
| 184 | + temp = Console.ReadLine(); |
| 185 | + while(!double.TryParse(temp , out result.Z)) |
| 186 | + { |
| 187 | + Console.WriteLine("Format Error. Please enter the following value again."); |
| 188 | + Console.WriteLine(valueName + " Z :"); |
| 189 | + temp = Console.ReadLine(); |
| 190 | + } |
| 191 | + return result; |
| 192 | + } |
| 193 | + |
| 194 | + public static Surface2D ReadSurface2DFromConsole(string valueName) |
| 195 | + { |
| 196 | + Surface2D result = new Surface2D(); |
| 197 | + Console.WriteLine(valueName + " X :"); |
| 198 | + string temp = Console.ReadLine(); |
| 199 | + while(!double.TryParse(temp , out result.X)) |
| 200 | + { |
| 201 | + Console.WriteLine("Format Error. Please enter the following value again."); |
| 202 | + Console.WriteLine(valueName + " X :"); |
| 203 | + temp = Console.ReadLine(); |
| 204 | + } |
| 205 | + Console.WriteLine(valueName + " Z :"); |
| 206 | + temp = Console.ReadLine(); |
| 207 | + while(!double.TryParse(temp , out result.Z)) |
| 208 | + { |
| 209 | + Console.WriteLine("Format Error. Please enter the following value again."); |
| 210 | + Console.WriteLine(valueName + " Z :"); |
| 211 | + temp = Console.ReadLine(); |
| 212 | + } |
| 213 | + return result; |
| 214 | + } |
| 215 | + } |
| 216 | +} |
0 commit comments