public ButtonTests() { _exchange = new EventExchange(new LogExchange()); AssetMapping.GlobalIsThreadLocal = true; AssetMapping.Global.Clear() .RegisterAssetType(typeof(Base.Font), AssetType.Font) ; var jsonUtil = new FormatJsonUtil(); var font = MockUniformFont.Font(AssetId.From(Base.Font.RegularFont)); var modApplier = new MockModApplier() .Add(new AssetId(AssetType.MetaFont, (ushort)new MetaFontId(false, FontColor.White)), font) .AddInfo(AssetId.From(Base.Font.RegularFont), MockUniformFont.Info) ; var config = GameConfig.LoadLiteral(Encoding.UTF8.GetBytes(@"{ ""UI"": { ""ButtonDoubleClickIntervalSeconds"": 0.35 } }"), jsonUtil); _exchange .Register(config) .Attach(modApplier) .Attach(new AssetManager()) .Attach(new SpriteManager()) .Attach(new WindowManager { Resolution = (1920, 1080) })
public EventRoundTripTests() { Event.AddEventsFromAssembly(typeof(ActionEvent).Assembly); AssetMapping.GlobalIsThreadLocal = true; var mapping = AssetMapping.Global; var disk = new MockFileSystem(true); var jsonUtil = new FormatJsonUtil(); var baseDir = ConfigUtil.FindBasePath(disk); var assetConfigPath = Path.Combine(baseDir, "mods", "Base", "assets.json"); var assetConfig = AssetConfig.Load(assetConfigPath, mapping, disk, jsonUtil); foreach (var assetType in assetConfig.IdTypes.Values) { var enumType = Type.GetType(assetType.EnumType); if (enumType == null) { throw new InvalidOperationException( $"Could not load enum type \"{assetType.EnumType}\" defined in \"{assetConfigPath}\""); } mapping.RegisterAssetType(assetType.EnumType, assetType.AssetType); } }
static void Main(string[] args) { #if DEBUG PerfTracker.IsTracing = true; #endif PerfTracker.StartupEvent("Entered main"); AssetSystem.LoadEvents(); PerfTracker.StartupEvent("Built event parsers"); var commandLine = new CommandLineOptions(args); if (commandLine.Mode == ExecutionMode.Exit) { return; } PerfTracker.StartupEvent($"Running as {commandLine.Mode}"); var disk = new FileSystem(); var jsonUtil = new FormatJsonUtil(); var baseDir = ConfigUtil.FindBasePath(disk); if (baseDir == null) { throw new InvalidOperationException("No base directory could be found."); } PerfTracker.StartupEvent($"Found base directory {baseDir}"); if (commandLine.Mode == ExecutionMode.ConvertAssets) { using var converter = new AssetConverter( AssetMapping.Global, disk, jsonUtil, commandLine.ConvertFrom, commandLine.ConvertTo); converter.Convert( commandLine.DumpIds, commandLine.DumpAssetTypes, commandLine.ConvertFilePattern); return; } var(exchange, services) = AssetSystem.SetupAsync(baseDir, AssetMapping.Global, disk, jsonUtil).Result; IRenderPass mainPass = null; if (commandLine.NeedsEngine) { mainPass = BuildEngine(commandLine, exchange); } services.Add(new StdioConsoleReader()); var assets = exchange.Resolve <IAssetManager>(); AutodetectLanguage(exchange, assets); switch (commandLine.Mode) // ConvertAssets handled above as it requires a specialised asset system setup { case ExecutionMode.Game: Albion.RunGame(exchange, services, mainPass, baseDir, commandLine); break; case ExecutionMode.BakeIsometric: IsometricTest.Run(exchange, commandLine); break; case ExecutionMode.DumpData: PerfTracker.BeginFrame(); // Don't need to show verbose startup logging while dumping var tf = new TextFormatter(); exchange.Attach(tf); var parsedIds = commandLine.DumpIds?.Select(AssetId.Parse).ToArray(); if ((commandLine.DumpFormats & DumpFormats.Json) != 0) { var dumper = new DumpJson(); exchange.Attach(dumper); dumper.Dump(baseDir, commandLine.DumpAssetTypes, parsedIds); dumper.Remove(); } if ((commandLine.DumpFormats & DumpFormats.Text) != 0) { var dumper = new DumpText(); exchange.Attach(dumper); dumper.Dump(baseDir, commandLine.DumpAssetTypes, parsedIds); dumper.Remove(); } if ((commandLine.DumpFormats & DumpFormats.Png) != 0) { var dumper = new DumpGraphics(commandLine.DumpFormats); exchange.Attach(dumper); dumper.Dump(baseDir, commandLine.DumpAssetTypes, parsedIds); dumper.Remove(); } if ((commandLine.DumpFormats & DumpFormats.Annotated) != 0) { var dumper = new DumpAnnotated(); exchange.Attach(dumper); dumper.Dump(baseDir, commandLine.DumpAssetTypes, parsedIds); dumper.Remove(); } //if ((commandLine.DumpFormats & DumpFormats.Tiled) != 0) // DumpTiled.Dump(baseDir, assets, commandLine.DumpAssetTypes, parsedIds); break; case ExecutionMode.Exit: break; } Console.WriteLine("Exiting"); exchange.Dispose(); }
static void RoundTrip(string file) { AssetMapping.GlobalIsThreadLocal = true; AssetMapping.Global.Clear() .RegisterAssetType(typeof(Base.Automap), AssetType.Automap) .RegisterAssetType(typeof(Base.Chest), AssetType.Chest) .RegisterAssetType(typeof(Base.EventSet), AssetType.EventSet) .RegisterAssetType(typeof(Base.Item), AssetType.Item) .RegisterAssetType(typeof(Base.LargeNpc), AssetType.LargeNpcGraphics) .RegisterAssetType(typeof(Base.LargePartyMember), AssetType.LargePartyGraphics) .RegisterAssetType(typeof(Base.Map), AssetType.Map) .RegisterAssetType(typeof(Base.Merchant), AssetType.Merchant) .RegisterAssetType(typeof(Base.Npc), AssetType.Npc) .RegisterAssetType(typeof(Base.PartyMember), AssetType.Party) .RegisterAssetType(typeof(Base.Portrait), AssetType.Portrait) .RegisterAssetType(typeof(Base.SmallNpc), AssetType.SmallNpcGraphics) .RegisterAssetType(typeof(Base.SmallPartyMember), AssetType.SmallPartyGraphics) .RegisterAssetType(typeof(Base.Spell), AssetType.Spell) .RegisterAssetType(typeof(Base.Switch), AssetType.Switch) .RegisterAssetType(typeof(Base.Ticker), AssetType.Ticker); var mapping = AssetMapping.Global; var jsonUtil = new FormatJsonUtil(); var spellManager = new MockSpellManager(); foreach (var school in Enum.GetValues <SpellClass>()) { for (byte i = 0; i < 30; i++) { var id = new SpellId(AssetType.Spell, (int)school * 30 + i); var spell = new SpellData(id, school, i); spellManager.Add(spell); } } // === Load === using var stream = File.Open(file, FileMode.Open, FileAccess.Read); using var br = new BinaryReader(stream); using var annotationReadStream = new MemoryStream(); using var annotationReader = new StreamWriter(annotationReadStream); using var ar = new AnnotationFacadeSerializer(new AlbionReader(br, stream.Length), annotationReader, FormatUtil.BytesFrom850String); var save = SavedGame.Serdes(null, mapping, ar, spellManager); // === Save === using var ms = new MemoryStream(); using var bw = new BinaryWriter(ms); using var annotationWriteStream = new MemoryStream(); using var annotationWriter = new StreamWriter(annotationWriteStream); using var aw = new AnnotationFacadeSerializer(new AlbionWriter(bw), annotationWriter, FormatUtil.BytesFrom850String); SavedGame.Serdes(save, mapping, aw, spellManager); File.WriteAllText(file + ".json", jsonUtil.Serialize(save)); // write out debugging files and compare round-tripped data br.BaseStream.Position = 0; var originalBytes = br.ReadBytes((int)stream.Length); var roundTripBytes = ms.ToArray(); ApiUtil.Assert(originalBytes.Length == roundTripBytes.Length, $"Save game size changed after round trip (delta {roundTripBytes.Length - originalBytes.Length})"); ApiUtil.Assert(originalBytes.SequenceEqual(roundTripBytes)); var diffs = XDelta.Compare(originalBytes, roundTripBytes).ToArray(); if (diffs.Length != 1) {
static void Main(string[] args) { PerfTracker.StartupEvent("Entered main"); Event.AddEventsFromAssembly(Assembly.GetAssembly(typeof(UAlbion.Api.Event))); Event.AddEventsFromAssembly(Assembly.GetAssembly(typeof(UAlbion.Core.Events.HelpEvent))); Event.AddEventsFromAssembly(Assembly.GetAssembly(typeof(UAlbion.Core.Veldrid.Events.InputEvent))); Event.AddEventsFromAssembly(Assembly.GetAssembly(typeof(UAlbion.Editor.EditorSetPropertyEvent))); Event.AddEventsFromAssembly(Assembly.GetAssembly(typeof(UAlbion.Formats.ScriptEvents.PartyMoveEvent))); Event.AddEventsFromAssembly(Assembly.GetAssembly(typeof(UAlbion.Game.Events.StartEvent))); Event.AddEventsFromAssembly(Assembly.GetAssembly(typeof(UAlbion.Game.Veldrid.Debugging.HideDebugWindowEvent))); Event.AddEventsFromAssembly(Assembly.GetAssembly(typeof(IsoYawEvent))); PerfTracker.StartupEvent("Built event parsers"); var commandLine = new CommandLineOptions(args); if (commandLine.Mode == ExecutionMode.Exit) { return; } PerfTracker.StartupEvent($"Running as {commandLine.Mode}"); var disk = new FileSystem(); var jsonUtil = new FormatJsonUtil(); var baseDir = ConfigUtil.FindBasePath(disk); if (baseDir == null) { throw new InvalidOperationException("No base directory could be found."); } PerfTracker.StartupEvent($"Found base directory {baseDir}"); if (commandLine.Mode == ExecutionMode.ConvertAssets) { ConvertAssets.Convert( disk, jsonUtil, commandLine.ConvertFrom, commandLine.ConvertTo, commandLine.DumpIds, commandLine.DumpAssetTypes, commandLine.ConvertFilePattern); return; } var(exchange, services) = AssetSystem.SetupAsync(baseDir, disk, jsonUtil).Result; if (commandLine.NeedsEngine) { BuildEngine(commandLine, exchange); } services.Add(new StdioConsoleReader()); var assets = exchange.Resolve <IAssetManager>(); AutodetectLanguage(exchange, assets); switch (commandLine.Mode) // ConvertAssets handled above as it requires a specialised asset system setup { case ExecutionMode.Game: Albion.RunGame(exchange, services, baseDir, commandLine); break; case ExecutionMode.BakeIsometric: IsometricTest.Run(exchange, commandLine); break; case ExecutionMode.DumpData: PerfTracker.BeginFrame(); // Don't need to show verbose startup logging while dumping var tf = new TextFormatter(); exchange.Attach(tf); var parsedIds = commandLine.DumpIds?.Select(AssetId.Parse).ToArray(); if ((commandLine.DumpFormats & DumpFormats.Json) != 0) { DumpJson.Dump(baseDir, assets, commandLine.DumpAssetTypes, parsedIds); } if ((commandLine.DumpFormats & DumpFormats.Text) != 0) { DumpText.Dump(assets, baseDir, tf, commandLine.DumpAssetTypes, parsedIds); } if ((commandLine.DumpFormats & DumpFormats.Png) != 0) { var dumper = new DumpGraphics(); exchange.Attach(dumper); dumper.Dump(baseDir, commandLine.DumpAssetTypes, commandLine.DumpFormats, parsedIds); } //if ((commandLine.DumpFormats & DumpFormats.Tiled) != 0) // DumpTiled.Dump(baseDir, assets, commandLine.DumpAssetTypes, parsedIds); break; case ExecutionMode.Exit: break; } Console.WriteLine("Exiting"); exchange.Dispose(); }