Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 953


Ignore:
Timestamp:
Mar 29, 2008, 3:38:10 PM (16 years ago)
Author:
landauf
Message:
  • added some functions to CommandEvaluation
  • added possibility of additional parameters to CommandEvaluator and CommandExecutor
Location:
code/branches/core2/src/orxonox/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core2/src/orxonox/core/CommandExecutor.cc

    r952 r953  
    4545    ConsoleCommandShortcutGeneric(keyword3, createExecutor((FunctorStatic*)0, "bind", AccessLevel::User));
    4646
     47
     48    ///////////////////////
     49    // CommandEvaluation //
     50    ///////////////////////
     51    KeybindMode CommandEvaluation::getKeybindMode()
     52    {
     53        if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
     54        {
     55//            if (this->shortcut_ != 0)
     56//                return this->shortcut_->getKeybindMode();
     57        }
     58        else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
     59        {
     60//            if (this->function_ != 0)
     61//                return this->function_->getKeybindMode();
     62        }
     63        else if (this->state_ == CS_ConfigValueType || this->state_ == CS_ConfigValueFinished)
     64        {
     65//            return KeybindMode::onPress;
     66        }
     67        else if (this->state_ == CS_KeybindCommand || this->state_ == CS_KeybindFinished)
     68        {
     69//            return KeybindMode::onPress;
     70        }
     71        else
     72        {
     73//            return KeybindMode::onPress;
     74        }
     75    }
     76
     77    void CommandEvaluation::setAdditionalParameter(const std::string& param)
     78    {
     79        this->additionalParameter_ = param;
     80    }
     81
     82    bool CommandEvaluation::isValid() const
     83    {
     84        if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
     85        {
     86            return (this->shortcut_ != 0);
     87        }
     88        else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
     89        {
     90            return ((this->functionclass_ != 0) && (this->function_ != 0));
     91        }
     92        else if (this->state_ == CS_ConfigValueType || this->state_ == CS_ConfigValueFinished)
     93        {
     94            return ((this->configvalueclass_ != 0) && (this->configvalue_ != 0));
     95        }
     96        else if (this->state_ == CS_KeybindCommand || this->state_ == CS_KeybindFinished)
     97        {
     98            return (this->key_ != 0);
     99        }
     100        else
     101        {
     102            return false;
     103        }
     104    }
     105
     106
     107    /////////////////////
     108    // CommandExecutor //
     109    /////////////////////
    47110    CommandExecutor& CommandExecutor::getInstance()
    48111    {
     
    111174                break;
    112175            case CS_Shortcut_Params:
    113                 // not enough parameters
     176                // not enough parameters but lets hope there are some additional parameters
     177                if (evaluation.shortcut_ != 0)
     178                    return evaluation.shortcut_->parse(tokens.subSet(1).join() + " " + evaluation.additionalParameter_);
    114179                break;
    115180            case CS_Shortcut_Finished:
    116181                // call the shortcut
    117182                if (evaluation.shortcut_ != 0)
    118                     return evaluation.shortcut_->parse(tokens.subSet(1).join());
     183                    return evaluation.shortcut_->parse(tokens.subSet(1).join() + " " + evaluation.additionalParameter_);
    119184                break;
    120185            case CS_Function:
    121186                break;
    122187            case CS_Function_Params:
    123                 // not enough parameters
     188                // not enough parameters but lets hope there are some additional parameters
     189                if (evaluation.function_ != 0)
     190                    return evaluation.function_->parse(tokens.subSet(2).join() + " " + evaluation.additionalParameter_);
    124191                break;
    125192            case CS_Function_Finished:
    126193                // call the shortcut
    127194                if (evaluation.function_ != 0)
    128                     return evaluation.function_->parse(tokens.subSet(2).join());
     195                    return evaluation.function_->parse(tokens.subSet(2).join() + " " + evaluation.additionalParameter_);
    129196                break;
    130197            case CS_ConfigValueClass:
     
    133200                break;
    134201            case CS_ConfigValueType:
    135                 // not enough parameters
     202                // not enough parameters but lets hope there are some additional parameters
     203                if (evaluation.configvalue_ != 0)
     204                    return evaluation.configvalue_->parseString(tokens.subSet(3).join() + " " + evaluation.additionalParameter_);
    136205                break;
    137206            case CS_ConfigValueFinished:
    138207                // set the config value
    139208                if (evaluation.configvalue_ != 0)
    140                     return evaluation.configvalue_->parseString(tokens.subSet(3).join());
     209                    return evaluation.configvalue_->parseString(tokens.subSet(3).join() + " " + evaluation.additionalParameter_);
    141210                break;
    142211            case CS_KeybindKey:
    143212                break;
    144213            case CS_KeybindCommand:
    145                 // not enough parameters
     214                // not enough parameters but lets hope there are some additional parameters
    146215                break;
    147216            case CS_KeybindFinished:
     
    296365    }
    297366
    298     const CommandEvaluation& CommandExecutor::evaluate(const std::string& command)
     367    CommandEvaluation CommandExecutor::evaluate(const std::string& command)
    299368    {
    300369        CommandExecutor::parse(command, true);
     
    308377
    309378        if (bInitialize)
    310             CommandExecutor::initialize();
     379            CommandExecutor::initialize(command);
    311380
    312381        switch (CommandExecutor::getEvaluation().state_)
     
    654723    }
    655724
    656     void CommandExecutor::initialize()
    657     {
     725    void CommandExecutor::initialize(const std::string& command)
     726    {
     727        CommandExecutor::getEvaluation().processedCommand_ = command;
     728        CommandExecutor::getEvaluation().additionalParameter_ = "";
     729
    658730        CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.clear();
    659731        CommandExecutor::getEvaluation().listOfPossibleShortcuts_.clear();
  • code/branches/core2/src/orxonox/core/CommandExecutor.h

    r952 r953  
    5959    };
    6060
     61    enum KeybindMode {}; // temporary
     62
     63    ///////////////////////
     64    // CommandEvaluation //
     65    ///////////////////////
    6166    class _CoreExport CommandEvaluation
    6267    {
    6368        public:
     69            KeybindMode getKeybindMode();
     70            void setAdditionalParameter(const std::string& param);
     71            bool isValid() const;
     72
    6473            std::string processedCommand_;
    6574            SubString tokens_;
     75            std::string additionalParameter_;
     76
    6677            std::list<const std::string*> listOfPossibleFunctionClasses_;
    6778            std::list<const std::string*> listOfPossibleShortcuts_;
     
    8293    };
    8394
     95    /////////////////////
     96    // CommandExecutor //
     97    /////////////////////
    8498    class _CoreExport CommandExecutor
    8599    {
     
    94108            static std::string hint(const CommandEvaluation& evaluation);
    95109
    96             static const CommandEvaluation& evaluate(const std::string& command);
     110            static CommandEvaluation evaluate(const std::string& command);
    97111
    98112            static bool addConsoleCommandShortcut(ExecutorStatic* executor);
     
    123137
    124138            static void parse(const std::string& command, bool bInitialize = true);
    125             static void initialize();
     139            static void initialize(const std::string& command);
    126140
    127141            static bool argumentsGiven(unsigned int num);
Note: See TracChangeset for help on using the changeset viewer.