Beispiel #1
0
        void Test <T>(AssetId id,
                      AssetId[] prerequisites,
                      Func <T, ISerializer, T> serdes) where T : class
        {
            prerequisites ??= Array.Empty <AssetId>();
            var allIds = prerequisites.Append(id);

            var resultsDir = Path.Combine(_baseDir, "re", "ConversionTests");

            var baseAsset = (T)_baseApplier.LoadAsset(id);

            var(baseBytes, baseNotes) = Asset.Save(baseAsset, serdes);
            var baseJson = Asset.SaveJson(baseAsset, JsonUtil);

            var idStrings  = allIds.Select(x => $"{x.Type}.{x.Id}").ToArray();
            var assetTypes = allIds.Select(x => x.Type).Distinct().ToHashSet();

            ConvertAssets.Convert(
                _disk,
                JsonUtil,
                BaseAssetMod,
                UnpackedAssetMod,
                idStrings,
                assetTypes,
                null);

            var unpackedAsset = (T)BuildApplier(UnpackedAssetMod).LoadAsset(id);

            Assert.NotNull(unpackedAsset);
            var(unpackedBytes, unpackedNotes) = Asset.Save(unpackedAsset, serdes);
            var unpackedJson = Asset.SaveJson(unpackedAsset, JsonUtil);

            Asset.Compare(resultsDir,
                          id.Type.ToString(),
                          baseBytes,
                          unpackedBytes,
                          new[]
Beispiel #2
0
        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();
        }