private static List <Tuple <ConstructorInfo, string> > ReadTypes(BinaryReader tdbReader) { int count = tdbReader.ReadInt32(); List <Tuple <ConstructorInfo, string> > types = new List <Tuple <ConstructorInfo, string> >(count); for (int i = 0; i < count; ++i) { string typeName = tdbReader.ReadString(); Type t = AssemblyHandler.FindFirstTypeForName(typeName); if (t == null) { Console.WriteLine("failed"); if (!Core.Service) { Console.WriteLine("Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName); if (Console.ReadKey(true).Key == ConsoleKey.Y) { types.Add(null); Console.Write("World: Loading..."); continue; } Console.WriteLine("Types will not be deleted. An exception will be thrown."); } else { Console.WriteLine("Error: Type '{0}' was not found.", typeName); } throw new Exception($"Bad type '{typeName}'"); } ConstructorInfo ctor = t.GetConstructor(m_SerialTypeArray); if (ctor != null) { types.Add(new Tuple <ConstructorInfo, string>(ctor, typeName)); } else { throw new Exception($"Type '{t}' does not have a serialization constructor"); } } return(types); }
public static void LoadRegions() { var path = Path.Join(Core.BaseDirectory, "Data/regions.json"); // Json Deserialization options for custom objects JsonSerializerOptions options = new JsonSerializerOptions(); options.Converters.Add(new MapConverterFactory()); options.Converters.Add(new Point3DConverterFactory()); options.Converters.Add(new Rectangle3DConverterFactory()); List <string> failures = new List <string>(); int count = 0; Console.Write("Regions: Loading..."); var stopwatch = Stopwatch.StartNew(); List <DynamicJson> regions = JsonConfig.Deserialize <List <DynamicJson> >(path); foreach (var json in regions) { Type type = AssemblyHandler.FindFirstTypeForName(json.Type); if (type == null || !typeof(Region).IsAssignableFrom(type)) { failures.Add($"\tInvalid region type {json.Type}"); continue; } var region = ActivatorUtil.CreateInstance(type, json, options) as Region; region?.Register(); count++; } stopwatch.Stop(); Console.ForegroundColor = failures.Count > 0 ? ConsoleColor.Yellow : ConsoleColor.Green; Console.Write("done{0}. ", failures.Count > 0 ? " with failures" : ""); Console.ResetColor(); Console.WriteLine("({0} regions, {1} failures) ({2:F2} seconds)", count, failures.Count, stopwatch.Elapsed.TotalSeconds); if (failures.Count > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(string.Join("\n", failures)); Console.ResetColor(); } }
public static void LoadRegions() { var path = Path.Join(Core.BaseDirectory, "Data/regions.json"); var failures = new List <string>(); var count = 0; Console.Write("Regions: Loading..."); var stopwatch = Stopwatch.StartNew(); var regions = JsonConfig.Deserialize <List <DynamicJson> >(path); foreach (var json in regions) { var type = AssemblyHandler.FindFirstTypeForName(json.Type); if (type == null || !typeof(Region).IsAssignableFrom(type)) { failures.Add($"\tInvalid region type {json.Type}"); continue; } var region = type.CreateInstance <Region>(json, JsonConfig.DefaultOptions); region?.Register(); count++; } stopwatch.Stop(); Console.ForegroundColor = failures.Count > 0 ? ConsoleColor.Yellow : ConsoleColor.Green; Console.Write("done{0}. ", failures.Count > 0 ? " with failures" : ""); Console.ResetColor(); Console.WriteLine( "({0} regions, {1} failures) ({2:F2} seconds)", count, failures.Count, stopwatch.Elapsed.TotalSeconds ); if (failures.Count > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(string.Join("\n", failures)); Console.ResetColor(); } }