Esempio n. 1
0
        public override void Execute(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("swift compile <project-name> [platform]");
                return;
            }

            if (!Swift.License.IsRegistered())
            {
                Console.WriteLine("This copy of Swift is unlicensed. Please contact Zach Reedy for your Alpha license key.");
                return;
            }

            string projectName = args[0];

            if (!Directory.Exists(projectName))
            {
                Console.WriteLine("Project directory does not exist.");
                return;
            }

            GameData.PlatformFlags platform;

            if (args.Length > 1 && !args[1].StartsWith("--"))
            {
                if (!Enum.TryParse(args[1], true, out platform))
                {
                    Console.WriteLine("Warning: Unknown target platform \"{0}\", targeting default platform instead.", args[1]);
                    platform = DetectPlatform();
                }
            }
            else
            {
                platform = DetectPlatform();
            }

            if (platform == GameData.PlatformFlags.Unknown)
            {
                Console.WriteLine("Warning: Could not resolve current target platform, games may not compile or run.");
            }

            Stopwatch compileTimer = new Stopwatch();

            compileTimer.Start();

#if !DEBUG
            try
            {
#endif
            GameProject gameProject = new GameProject();
            gameProject.Load(projectName);

            if (File.Exists(gameProject.TargetGameDataPath))
            {
                File.Delete(gameProject.TargetGameDataPath);
            }

            GameData gameData = new GameData(gameProject, platform)
            {
                ExportSheets    = args.Any(arg => arg == "--export-sheets"),
                ShowDisassembly = args.Any(arg => arg == "--disassemble")
            };

            if (gameData.SerializeFromProject())
            {
                if (!gameData.Save(gameProject.TargetGameDataPath))
                {
                    throw new CompilerException("Cannot save game data.");
                }

                compileTimer.Stop();
                Console.WriteLine("Compiled in {0}ms.", compileTimer.ElapsedMilliseconds);
            }
#if !DEBUG
        }

        catch (CompilerException e)
        {
            Console.WriteLine(e.Message);
        }
        catch (IOException e)
        {
            Console.WriteLine(e.Message);
        }
        catch (Exception e)
        {
            Console.WriteLine("UNHANDLED EXCEPTION: {0}", e.Message);
            Console.WriteLine("--- Stack Trace ---");
            Console.WriteLine(e.StackTrace);
        }
#endif
        }
Esempio n. 2
0
        public override void Execute(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("swift run <project-name> [args]");
                return;
            }

            if (!Swift.License.IsRegistered())
            {
                Console.WriteLine("This copy of Swift is unlicensed. Please contact Zach Reedy for your Alpha license key.");
                return;
            }

            if (string.IsNullOrEmpty(Program.EnginePath))
            {
                Console.WriteLine("Error: Cannot locate suitable engine to launch with.");
                return;
            }

            string target = args.First();

            if (!Directory.Exists(target))
            {
                Console.WriteLine("Project directory does not exist.");
                return;
            }

            GameProject project = new GameProject();

            project.Load(target);

            string arguments = "--game \"" + project.TargetGameDataPath + "\" --debug";

            for (int i = 1; i < args.Length; ++i)
            {
                arguments += " " + args[i];
            }

            try
            {
                Console.WriteLine("Running game from \"{0}\"", project.TargetPath);
                Console.WriteLine("{0} {1}", Program.EnginePath, arguments);

                ProcessStartInfo startInfo = new ProcessStartInfo(Program.EnginePath, arguments)
                {
                    WorkingDirectory       = project.TargetPath,
                    RedirectStandardOutput = false,
                    RedirectStandardError  = false,
                    UseShellExecute        = false,
                    CreateNoWindow         = false
                };

                Process engine = Process.Start(startInfo);
                if (engine != null)
                {
                    engine.WaitForExit();

                    Console.WriteLine();

                    if (engine.ExitCode != 0)
                    {
                        Console.WriteLine("Engine returned with exit code {0}", engine.ExitCode);
                    }
                }
                else
                {
                    Console.WriteLine("Cannot start engine, but it was found.");
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Cannot start engine because it wasn't found.");
                Console.WriteLine("Tried to start it from \"{0}\".", Program.EnginePath);
            }
        }