Exemplo n.º 1
0
        /// <summary>
        /// Handles the passed in flags. This method is used for both command line
        /// and interactive mode commands.
        /// </summary>
        /// <param name="modelViewer">ModelViewer object to apply commands on</param>
        /// <param name="flags">Array of flags to apply</param>
        /// <param name="isInteractive">Determines if currently in interactive mode</param>
        /// <returns>If the caller should enter interactive mode. If in interactive mode, this determines if input should continue.</returns>
        private static bool HandleFlags(ModelViewer modelViewer, string[] flags, bool isInteractive)
        {
            bool startInteractive = false;

            for (int i = 0; i < flags.Length; i++)
            {
                string flag = flags[i];
                switch (flag)
                {
                case HELP_FLAG:
                    DisplayHelp();
                    WriteCommandSuccess(flag);
                    break;

                case INTERACTIVE_HELP_FLAG:
                    DisplayInteractiveHelp();
                    WriteCommandSuccess(flag);
                    break;

                case INTERACTIVE_FLAG:
                    startInteractive = true;
                    if (!isInteractive)
                    {
                        WriteCommandSuccess(flag);
                    }
                    break;

                case QUIT_FLAG:
                    if (isInteractive)
                    {
                        WriteCommandSuccess(flag);
                        return(false);
                    }
                    break;

                case GAME_FLAG:
                    if (i < flags.Length - 1)
                    {
                        try
                        {
                            string             gameOrig = flags[i + 1];
                            bool               valid    = false;
                            LibGxFormat.GxGame game     = LibGxFormat.GxGame.SuperMonkeyBall;
                            switch (gameOrig)
                            {
                            case "smb":
                                game  = LibGxFormat.GxGame.SuperMonkeyBall;
                                valid = true;
                                break;

                            case "deluxe":
                                game  = LibGxFormat.GxGame.SuperMonkeyBallDX;
                                valid = true;
                                break;

                            case "fzero":
                                game  = LibGxFormat.GxGame.FZeroGX;
                                valid = true;
                                break;
                            }
                            if (valid)
                            {
                                modelViewer.SetSelectedGame(game);
                                WriteCommandSuccess(flag);
                            }
                            else
                            {
                                WriteCommandError(flag, "Game selected does not exist->" + gameOrig);
                            }
                        }
                        catch (Exception ex)
                        {
                            WriteCommandError(flag, "Error setting game->" + ex.Message);
                        }
                        finally
                        {
                            // Skip the command argument
                            i++;
                        }
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case MIPMAPS_FLAG:
                    if (i < flags.Length - 1)
                    {
                        int  value;
                        bool validInt = int.TryParse(flags[i + 1], out value);
                        if (validInt && value >= 0)
                        {
                            modelViewer.SetNumMipmaps(value);
                            WriteCommandSuccess(flag);
                        }
                        else
                        {
                            WriteCommandError(flag, "Value is not a valid (positive/zero) int->" + flags[i + 1]);
                        }
                        i++;
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case INTERPOLATION_FLAG:
                    if (i < flags.Length - 1)
                    {
                        string interpolateString = flags[i + 1];
                        bool   valid             = false;
                        LibGxFormat.GxInterpolationFormat format = LibGxFormat.GxInterpolationFormat.HighQualityBicubic;
                        switch (interpolateString)
                        {
                        case "bicubic":
                            format = LibGxFormat.GxInterpolationFormat.HighQualityBicubic;
                            valid  = true;
                            break;

                        case "nearest":
                        case "nn":
                            format = LibGxFormat.GxInterpolationFormat.NearestNeighbor;
                            valid  = true;
                            break;

                        case "csharpdefault":
                            format = LibGxFormat.GxInterpolationFormat.CSharpDefault;
                            valid  = true;
                            break;
                        }
                        if (valid)
                        {
                            modelViewer.SetSelectedMipmap(format);
                            WriteCommandSuccess(flag);
                        }
                        else
                        {
                            WriteCommandError(flag, "Value is not a valid interpolation type->" + interpolateString);
                        }
                        i++;
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case FIX_SCROLLING_TEXTURES:
                    try
                    {
                        modelViewer.FixScrollingTextures();
                        WriteCommandSuccess(flag);
                    }
                    catch (Exception ex)
                    {
                        WriteCommandError(flag, "Error updating flags for scrollable textures->" + ex.Message + "\n" + ex.StackTrace);
                    }
                    break;

                case FIX_TRANSPARENCY:
                    try
                    {
                        modelViewer.FixTransparency();
                        WriteCommandSuccess(flag);
                    }
                    catch (Exception ex)
                    {
                        WriteCommandError(flag, "Error updating flags for transparent meshes->" + ex.Message + "\n" + ex.StackTrace);
                    }
                    break;

                case IMPORT_OBJ_MTL_FLAG:
                    if (i < flags.Length - 1)
                    {
                        try {
                            modelViewer.ImportObjMtl(flags[i + 1], true);
                            WriteCommandSuccess(flag);
                        }
                        catch (Exception ex)
                        {
                            WriteCommandError(flag, "Error loading the OBJ file->" + ex.Message);
                        }
                        finally
                        {
                            // Skip the command argument
                            i++;
                        }
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case IMPORT_TPL_FLAG:
                    if (i < flags.Length - 1)
                    {
                        try
                        {
                            modelViewer.LoadTplFile(flags[i + 1]);
                            WriteCommandSuccess(flag);
                        }
                        catch (Exception ex)
                        {
                            WriteCommandError(flag, "Error loading the TPL file->" + ex.Message);
                        }
                        finally
                        {
                            // Skip the command argument
                            i++;
                        }
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case IMPORT_GMA_FLAG:
                    if (i < flags.Length - 1)
                    {
                        try
                        {
                            modelViewer.LoadGmaFile(flags[i + 1]);
                            WriteCommandSuccess(flag);
                        }
                        catch (Exception ex)
                        {
                            WriteCommandError(flag, "Error loading the GMA file->" + ex.Message);
                        }
                        finally
                        {
                            // Skip the command argument
                            i++;
                        }
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case MERGE_GMATPL_FLAG:
                    if (i < flags.Length - 1 && flags[i + 1].Split(',').Length == 2)
                    {
                        try
                        {
                            string newgmapath = flags[i + 1].Split(',')[0];
                            string newtplpath = flags[i + 1].Split(',')[1];
                            modelViewer.MergeGMATPLFiles(newgmapath, newtplpath);
                            WriteCommandSuccess(flag);
                        }
                        catch (Exception ex)
                        {
                            WriteCommandError(flag, "Error merging in the file GMA and TPL files->" + ex.Message);
                        }
                        finally
                        {
                            // Skip the command argument
                            i++;
                        }
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command, provide GMA filepath and TPL filepath separated by comma (Ex: dir1/file.gma,dir2/file.tpl)");
                    }
                    break;

                case EXPORT_OBJ_MTL_FLAG:
                    if (i < flags.Length - 1)
                    {
                        try
                        {
                            modelViewer.ExportObjMtl(flags[i + 1]);
                            WriteCommandSuccess(flag);
                        }
                        catch (Exception ex)
                        {
                            WriteCommandError(flag, "Error saving the OBJ/MTL file->" + ex.Message);
                        }
                        finally
                        {
                            // Skip the command argument
                            i++;
                        }
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case EXPORT_TPL_FLAG:
                    if (i < flags.Length - 1)
                    {
                        try
                        {
                            modelViewer.SaveTplFile(flags[i + 1]);
                            WriteCommandSuccess(flag);
                        }
                        catch (Exception ex)
                        {
                            WriteCommandError(flag, "Error saving the TPL file->" + ex.Message);
                        }
                        finally
                        {
                            // Skip the command argument
                            i++;
                        }
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case EXPORT_GMA_FLAG:
                    if (i < flags.Length - 1)
                    {
                        try
                        {
                            modelViewer.SaveGmaFile(flags[i + 1]);
                            WriteCommandSuccess(flag);
                        }
                        catch (Exception ex)
                        {
                            WriteCommandError(flag, "Error saving the GMA file->" + ex.Message);
                        }
                        finally
                        {
                            // Skip the command argument
                            i++;
                        }
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case SET_ALL_MIPMAPS:
                    if (i < flags.Length - 1)
                    {
                        int  value;
                        bool validInt = int.TryParse(flags[i + 1], out value);
                        if (validInt && value >= 0)
                        {
                            try
                            {
                                modelViewer.setAllMipmaps(value);
                                WriteCommandSuccess(flag);
                            }
                            catch (Exception ex)
                            {
                                WriteCommandError(flag, "Error setting mipmap values->" + ex.Message);
                            }
                        }
                        else
                        {
                            WriteCommandError(flag, "Value is not a valid (positive/zero) int->" + flags[i + 1]);
                        }
                        i++;
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case REMOVE_UNUSED_TEXTURES:
                    try
                    {
                        modelViewer.DeleteUnusedTextures();
                        WriteCommandSuccess(flag);
                    }
                    catch (Exception ex)
                    {
                        WriteCommandError(flag, "Error removing unused textures->" + ex.Message + "\n" + ex.StackTrace);
                    }
                    break;

                case PRESET_FOLDER_FLAG:
                    if (i < flags.Length - 1)
                    {
                        bool exists = Directory.Exists(flags[i + 1]);
                        if (exists)
                        {
                            modelViewer.presetFolder = flags[i + 1];
                            WriteCommandSuccess(flag);
                        }
                        else
                        {
                            WriteCommandError(flag, "Directory does not exist->" + flags[i + 1]);
                        }

                        i++;
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                default:
                    WriteCommandError(flag, "Unknown command");
                    break;
                }
            }

            // Interactive mode returns false to continue reading, true to quit
            if (isInteractive)
            {
                return(true);
            }
            return(startInteractive);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the passed in flags. This method is used for both command line
        /// and interactive mode commands.
        /// </summary>
        /// <param name="modelViewer">ModelViewer object to apply commands on</param>
        /// <param name="flags">Array of flags to apply</param>
        /// <param name="isInteractive">Determines if currently in interactive mode</param>
        /// <returns>If the caller should enter interactive mode. If in interactive mode, this determines if input should continue.</returns>
        private static bool HandleFlags(ModelViewer modelViewer, string[] flags, bool isInteractive)
        {
            bool startInteractive = false;

            for (int i = 0; i < flags.Length; i++)
            {
                string flag = flags[i];
                switch (flag)
                {
                case HELP_FLAG:
                    DisplayHelp();
                    WriteCommandSuccess(flag);
                    break;

                case INTERACTIVE_HELP_FLAG:
                    DisplayInteractiveHelp();
                    WriteCommandSuccess(flag);
                    break;

                case INTERACTIVE_FLAG:
                    startInteractive = true;
                    if (!isInteractive)
                    {
                        WriteCommandSuccess(flag);
                    }
                    break;

                case QUIT_FLAG:
                    if (isInteractive)
                    {
                        WriteCommandSuccess(flag);
                        return(false);
                    }
                    break;

                case GAME_FLAG:
                    if (i < flags.Length - 1)
                    {
                        try
                        {
                            string             gameOrig = flags[i + 1];
                            bool               valid    = false;
                            LibGxFormat.GxGame game     = LibGxFormat.GxGame.SuperMonkeyBall;
                            switch (gameOrig)
                            {
                            case "smb":
                                game  = LibGxFormat.GxGame.SuperMonkeyBall;
                                valid = true;
                                break;

                            case "deluxe":
                                game  = LibGxFormat.GxGame.SuperMonkeyBallDX;
                                valid = true;
                                break;

                            case "fzero":
                                game  = LibGxFormat.GxGame.FZeroGX;
                                valid = true;
                                break;
                            }
                            if (valid)
                            {
                                modelViewer.SetSelectedGame(game);
                                WriteCommandSuccess(flag);
                            }
                            else
                            {
                                WriteCommandError(flag, "Game selected does not exist->" + gameOrig);
                            }
                        }
                        catch (Exception ex)
                        {
                            WriteCommandError(flag, "Error setting game->" + ex.Message);
                        }
                        finally
                        {
                            // Skip the command argument
                            i++;
                        }
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case MIPMAPS_FLAG:
                    if (i < flags.Length - 1)
                    {
                        int  value;
                        bool validInt = int.TryParse(flags[i + 1], out value);
                        if (validInt && value >= 0)
                        {
                            modelViewer.SetNumMipmaps(value);
                            WriteCommandSuccess(flag);
                        }
                        else
                        {
                            WriteCommandError(flag, "Value is not a valid (positive/zero) int->" + flags[i + 1]);
                        }
                        i++;
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case INTERPOLATION_FLAG:
                    if (i < flags.Length - 1)
                    {
                        string interpolateString = flags[i + 1];
                        bool   valid             = false;
                        LibGxFormat.GxInterpolationFormat format = LibGxFormat.GxInterpolationFormat.CSharpDefault;
                        switch (interpolateString)
                        {
                        case "default":
                            format = LibGxFormat.GxInterpolationFormat.CSharpDefault;
                            valid  = true;
                            break;

                        case "nearest":
                        case "nn":
                            format = LibGxFormat.GxInterpolationFormat.NearestNeighbor;
                            valid  = true;
                            break;
                        }
                        if (valid)
                        {
                            modelViewer.SetSelectedMipmap(format);
                            WriteCommandSuccess(flag);
                        }
                        else
                        {
                            WriteCommandError(flag, "Value is not a valid interpolation type->" + interpolateString);
                        }
                        i++;
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case IMPORT_OBJ_MTL_FLAG:
                    if (i < flags.Length - 1)
                    {
                        try {
                            modelViewer.ImportObjMtl(flags[i + 1], true);
                            WriteCommandSuccess(flag);
                        }
                        catch (Exception ex)
                        {
                            WriteCommandError(flag, "Error loading the OBJ file->" + ex.Message);
                        }
                        finally
                        {
                            // Skip the command argument
                            i++;
                        }
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case IMPORT_TPL_FLAG:
                    if (i < flags.Length - 1)
                    {
                        try
                        {
                            modelViewer.LoadTplFile(flags[i + 1]);
                            WriteCommandSuccess(flag);
                        }
                        catch (Exception ex)
                        {
                            WriteCommandError(flag, "Error loading the TPL file->" + ex.Message);
                        }
                        finally
                        {
                            // Skip the command argument
                            i++;
                        }
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case IMPORT_GMA_FLAG:
                    if (i < flags.Length - 1)
                    {
                        try
                        {
                            modelViewer.LoadGmaFile(flags[i + 1]);
                            WriteCommandSuccess(flag);
                        }
                        catch (Exception ex)
                        {
                            WriteCommandError(flag, "Error loading the GMA file->" + ex.Message);
                        }
                        finally
                        {
                            // Skip the command argument
                            i++;
                        }
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case EXPORT_OBJ_MTL_FLAG:
                    if (i < flags.Length - 1)
                    {
                        try
                        {
                            modelViewer.ExportObjMtl(flags[i + 1]);
                            WriteCommandSuccess(flag);
                        }
                        catch (Exception ex)
                        {
                            WriteCommandError(flag, "Error saving the OBJ/MTL file->" + ex.Message);
                        }
                        finally
                        {
                            // Skip the command argument
                            i++;
                        }
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case EXPORT_TPL_FLAG:
                    if (i < flags.Length - 1)
                    {
                        try
                        {
                            modelViewer.SaveTplFile(flags[i + 1]);
                            WriteCommandSuccess(flag);
                        }
                        catch (Exception ex)
                        {
                            WriteCommandError(flag, "Error saving the TPL file->" + ex.Message);
                        }
                        finally
                        {
                            // Skip the command argument
                            i++;
                        }
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case EXPORT_GMA_FLAG:
                    if (i < flags.Length - 1)
                    {
                        try
                        {
                            modelViewer.SaveGmaFile(flags[i + 1]);
                            WriteCommandSuccess(flag);
                        }
                        catch (Exception ex)
                        {
                            WriteCommandError(flag, "Error saving the GMA file->" + ex.Message);
                        }
                        finally
                        {
                            // Skip the command argument
                            i++;
                        }
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case EXPORT_PNG_FLAG:
                    if (i < flags.Length - 1)
                    {
                        try
                        {
                            modelViewer.SavePngFiles(flags[i + 1]);
                            WriteCommandSuccess(flag);
                        }
                        catch (Exception ex)
                        {
                            WriteCommandError(flag, "Error saving the PNG files->" + ex.Message);
                        }
                        finally
                        {
                            // Skip the command argument
                            i++;
                        }
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                case SET_ALL_MIPMAPS:
                    if (i < flags.Length - 1)
                    {
                        int  value;
                        bool validInt = int.TryParse(flags[i + 1], out value);
                        if (validInt && value >= 0)
                        {
                            try
                            {
                                modelViewer.setAllMipmaps(value);
                                WriteCommandSuccess(flag);
                            }
                            catch (Exception ex)
                            {
                                WriteCommandError(flag, "Error setting mipmap values->" + ex.Message);
                            }
                        }
                        else
                        {
                            WriteCommandError(flag, "Value is not a valid (positive/zero) int->" + flags[i + 1]);
                        }
                        i++;
                    }
                    else
                    {
                        WriteCommandError(flag, "Not enough args for command");
                    }
                    break;

                default:
                    WriteCommandError(flag, "Unknown command");
                    break;
                }
            }

            // Interactive mode returns false to continue reading, true to quit
            if (isInteractive)
            {
                return(true);
            }
            return(startInteractive);
        }