/************************************************************************* * ModernUO * * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: RegionLoader.cs * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * *************************************************************************/ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using Server.Json; using Server.Utilities; namespace Server { internal static class RegionLoader { internal static void LoadRegions() { var path = Path.Join(Core.BaseDirectory, "Data/regions.json"); var failures = new List(); var count = 0; Console.Write("Regions: Loading..."); var stopwatch = Stopwatch.StartNew(); var regions = JsonConfig.Deserialize>(path); foreach (var json in regions) { var type = AssemblyHandler.FindTypeByName(json.Type); if (type == null || !typeof(Region).IsAssignableFrom(type)) { failures.Add($"\tInvalid region type {json.Type}"); continue; } var region = type.CreateInstance(json, JsonConfig.DefaultOptions); region?.Register(); count++; } stopwatch.Stop(); Utility.PushColor(failures.Count > 0 ? ConsoleColor.Yellow : ConsoleColor.Green); Console.Write(failures.Count > 0 ? "done with failures" : "done"); Utility.PopColor(); Console.WriteLine( " ({0} regions, {1} failures) ({2:F2} seconds)", count, failures.Count, stopwatch.Elapsed.TotalSeconds ); if (failures.Count > 0) { Utility.PushColor(ConsoleColor.Red); Console.WriteLine(string.Join(Environment.NewLine, failures)); Utility.PopColor(); } } } }