Esempio n. 1
0
    void Test <T>(AssetId id,
                  AssetId[] prerequisites,
                  Func <T, ISerializer, T> serdes,
                  Func <T, T> canonicalize = null) 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);

        if (canonicalize != null)
        {
            baseAsset = canonicalize(baseAsset);
        }

        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();

        var mapping = AssetMapping.Global;

        using (var unpacker = new AssetConverter(
                   mapping,
                   _disk,
                   JsonUtil,
                   new[] { BaseAssetMod },
                   UnpackedAssetMod))
        {
            unpacker.Convert(idStrings, assetTypes, null);
        }

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

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

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