예제 #1
0
        private async Task <ICompiledAssetFs> SetupCompiledFs(OperationArguments args)
        {
            var platform       = args.Platforms.First();
            var targetPlatform = (TargetPlatform)Enum.Parse(typeof(TargetPlatform), platform);

            var sourcePath = Path.Combine(Environment.CurrentDirectory, "assets", ".source");

            if (!File.Exists(sourcePath))
            {
                throw new InvalidOperationException("No source asset folder!  Make sure at least one folder in your content project has Source=\"True\"!");
            }
            using (var reader = new StreamReader(sourcePath))
            {
                sourcePath = reader.ReadLine();
            }

            Console.WriteLine("Hosting compiled assets for " + platform + " platform...");

            var kernel = new StandardKernel();

            kernel.Load <ProtogameAssetModule>();
            kernel.Unbind <IAssetFsLayer>();
            kernel.Bind <IAssetFsLayer>().ToMethod(ctx => ctx.Kernel.Get <LocalFilesystemAssetFsLayer>(new NamedConstructorArgument("basePath", sourcePath)));
            kernel.Bind <IAssetFsLayer>().ToMethod(ctx => ctx.Kernel.Get <LocalFilesystemAssetFsLayer>(new NamedConstructorArgument("basePath", Path.Combine(Environment.CurrentDirectory, "assets", targetPlatform.ToString()))));
            kernel.Unbind <ICompiledAssetFs>();
            kernel.Rebind <ICompiledAssetFs>().ToMethod(ctx => ctx.Kernel.Get <HostCompiledAssetFs>(new NamedConstructorArgument("targetPlatform", targetPlatform)));
            kernel.Rebind <IRenderBatcher>().To <NullRenderBatcher>();
            kernel.Unbind <IAssetCompiler>();
            (new ProtogameAssetModule()).LoadRawAssetStrategies(kernel);
            CompileOperation.LoadAndBindTypes(kernel, args.Assemblies);

            return(kernel.Get <ICompiledAssetFs>());
        }
예제 #2
0
        public static void Main(string[] args)
        {
            var    assemblies           = new List <string>();
            var    platforms            = new List <string>();
            var    output               = string.Empty;
            var    operation            = string.Empty;
            string androidPlatformTools = null;

            var options = new OptionSet
            {
                { "a|assembly=", "Load an assembly.", v => assemblies.Add(v) },
                { "p|platform=", "Specify one or more platforms to target.", v => platforms.Add(v) },
                { "o|output=", "Specify the output folder for the compiled assets.", v => output = v },
                { "m|operation=", "Specify the mode of operation (either 'compile', 'server' or 'builtin', default is 'compile').", v => operation = v },
                { "android-platform-tools=", "Specifies the path to ADB (used for connecting to a game running on an Android device)", v => androidPlatformTools = v },
            };

            try
            {
                options.Parse(args);
            }
            catch (OptionException ex)
            {
                Console.Write("ProtogameAssetTool.exe: ");
                Console.WriteLine(ex.Message);
                Console.WriteLine("Try `ProtogameAssetTool.exe --help` for more information.");
                Environment.Exit(1);
                return;
            }

            var operationArguments = new OperationArguments
            {
                Assemblies           = assemblies.ToArray(),
                Platforms            = platforms.ToArray(),
                AndroidPlatformTools = androidPlatformTools,
                OutputPath           = output
            };

            IOperation operationInst;

            switch (operation)
            {
            case "remote":
                throw new NotSupportedException();

            case "server":
                operationInst = new ServerOperation();
                break;

            case "builtin":
                operationInst = new BuiltinOperation();
                break;

            case "compile":
            default:
                operationInst = new CompileOperation();
                break;
            }

            var task = Task.Run(async() => await operationInst.Run(operationArguments).ConfigureAwait(false));

            task.Wait();
        }