Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7412 in orxonox.OLD


Ignore:
Timestamp:
Apr 28, 2006, 12:03:54 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: Another CompletionMode is working

Location:
trunk/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell_command.cc

    r7411 r7412  
    295295  }
    296296
     297  ShellCommand* ShellCommand::completionPlugin(unsigned int parameter, const CompletorPlugin& completorPlugin)
     298  {
     299    if (this == NULL || this->executor == NULL)
     300      return NULL;
     301
     302    if (parameter >= this->executor->getParamCount())
     303    {
     304      PRINTF(1)("Parameter %d not inside of valid ParameterCount %d of Command %s::%s\n",
     305    parameter, this->executor->getParamCount(), this->getName(), this->shellClass->getName());
     306    }
     307    else
     308    {
     309      delete this->completors[parameter];
     310      this->completors[parameter] = completorPlugin.clone();
     311    }
     312    return this;
     313  }
     314
     315
    297316  /**
    298317   * @brief prints out nice information about the Shells Commands
     
    331350
    332351
     352
     353  ///////////
     354  // ALIAS //
     355  ///////////
     356
    333357  /**
    334358   * @param aliasName the name of the Alias
  • trunk/src/lib/shell/shell_command.h

    r7411 r7412  
    6262    friend class ShellCommandClass;
    6363  public:
    64     //! an enumerator for different types the Shell parses.
    65     typedef enum {
    66       NullRecognition         = 0,
    67       ClassRecognition              = 1,
    68       ObjectRecognition             = 2,
    69       FunctionRecognition           = 4,
    70       AliasRecognition              = 8,
    71       ParameterRecognition          = 16,
    72     } RecognitionType;
    73 
    7464    static bool execute (const std::string& executionString);
    7565
     
    7969                                const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL,
    8070                                const MultiType& value4 = MT_NULL);
     71    ShellCommand* completionPlugin(unsigned int parameter, const CompletorPlugin& completorPlugin);
    8172
    8273    static ShellCommand* registerCommand(const std::string& commandName, const std::string& className, const Executor& executor);
  • trunk/src/lib/shell/shell_completion.cc

    r7409 r7412  
    114114      if (sc != NULL)
    115115      {
    116         std::vector<std::string> test;
    117         sc->getCompletorPlugin(0)->addToCompleteList(test, inputSplits[inputSplits.size()-1]);
     116        std::vector<std::string> completed;
     117        sc->getCompletorPlugin(0)->addToCompleteList(completed, inputSplits[inputSplits.size()-1]);
     118        for (unsigned int i = 0; i < completed.size(); i++)
     119          this->completionList.push_back(CompletionElement(completed[i], ParamCompletion));
    118120      }
    119121    }
     
    256258          !nocaseCmp(*string, completionBegin, searchLength))
    257259      {
    258         CompletionElement newElem;
    259         newElem.name = (*string);
    260         newElem.type = type;
    261         this->completionList.push_back(newElem);
     260        this->completionList.push_back(CompletionElement (*string, type));
    262261      }
    263262    }
     
    282281          !nocaseCmp((*bo)->getName(), completionBegin, searchLength))
    283282      {
    284         CompletionElement newElem;
    285         newElem.name = (*bo)->getName();
    286         newElem.type = type;
    287         this->completionList.push_back(newElem);
     283        this->completionList.push_back(CompletionElement((*bo)->getName(), type));
    288284      }
    289285    }
     
    316312      case AliasCompletion:
    317313        return typeNames[4];
     314      case ParamCompletion:
     315        return typeNames[5];
    318316    }
    319317  }
     
    326324      "object",
    327325      "function",
    328       "alias"
     326      "alias",
     327      "parameter",
    329328    };
    330329
  • trunk/src/lib/shell/shell_completion.h

    r7406 r7412  
    2929        FunctionCompletion     = 4,
    3030        AliasCompletion        = 8,
     31        ParamCompletion        = 16,
    3132    } CompletionType;
    3233
     
    3435      struct CompletionElement
    3536      {
     37        CompletionElement(std::string name, CompletionType type) : name(name), type(type) {}
    3638        std::string     name;     //!< the Name of the Element to be completed.
    3739        CompletionType  type;     //!< the type of the Element
  • trunk/src/lib/shell/shell_completion_plugin.cc

    r7409 r7412  
    4747  void CompletorStringArray::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
    4848  {
     49    printf("TEST\n");
    4950    unsigned int inputLen = completionBegin.size();
    5051    for (unsigned int i = 0; i < this->_size; ++i)
     52    {
     53      printf("%s\n", this->_stringArray[i].c_str());
    5154      if (!nocaseCmp(this->_stringArray[i], completionBegin, inputLen))
    5255        completionList.push_back(this->_stringArray[i]);
     56    }
    5357  }
    5458
  • trunk/src/lib/util/helper_functions.cc

    r7371 r7412  
    146146int nocaseCmp(const std::string& s1, const std::string& s2, unsigned int len)
    147147{
     148  if (len == 0)
     149    return 0;
    148150  std::string::const_iterator it1=s1.begin();
    149151  std::string::const_iterator it2=s2.begin();
  • trunk/src/story_entities/game_world.cc

    r7391 r7412  
    6262
    6363
    64 SHELL_COMMAND(speed, GameWorld, setSpeed);
    65 SHELL_COMMAND(playmode, GameWorld, setPlaymode);
     64SHELL_COMMAND(speed, GameWorld, setSpeed) ->describe("set the Speed of the Level");
     65SHELL_COMMAND(playmode, GameWorld, setPlaymode)
     66    ->describe("Set the Playmode of the current Level")
     67    ->completionPlugin(0, OrxShell::CompletorStringArray(Playable::playmodeNames, Playable::PlaymodeCount));
     68
    6669SHELL_COMMAND_STATIC(togglePNodeVisibility, GameWorld, GameWorld::togglePNodeVisibility);
    6770SHELL_COMMAND_STATIC(toggleBVVisibility, GameWorld, GameWorld::toggleBVVisibility);
     
    292295      this->dataTank->localPlayer->getPlayable()->setPlaymode(playmode))
    293296  {
    294     PRINTF(3)("Set Playmode to %d:%s\n", playmode, Playable::playmodeToString(playmode));
     297    PRINTF(3)("Set Playmode to %d:%s\n", playmode, Playable::playmodeToString(playmode).c_str());
    295298  }
    296299  else
    297300  {
    298     PRINTF(1)("Unable to set Playmode %d:%s\n", playmode, Playable::playmodeToString(playmode));
     301    PRINTF(1)("Unable to set Playmode %d:%s\n", playmode, Playable::playmodeToString(playmode).c_str());
    299302  }
    300303}
  • trunk/src/world_entities/playable.cc

    r7356 r7412  
    563563Playable::Playmode Playable::stringToPlaymode(const std::string& playmode)
    564564{
    565   if (playmode == "Vertical")
     565  if (playmode == Playable::playmodeNames[0])
    566566    return Playable::Vertical;
    567   if (playmode == "Horizontal")
     567  if (playmode == Playable::playmodeNames[1])
    568568    return Playable::Horizontal;
    569   if (playmode == "FromBehind")
     569  if (playmode == Playable::playmodeNames[2])
    570570    return Playable::FromBehind;
    571   if (playmode == "Full3D")
     571  if (playmode == Playable::playmodeNames[3])
    572572    return Playable::Full3D;
    573573
     
    581581 * @returns the String.
    582582 */
    583 const char* Playable::playmodeToString(Playable::Playmode playmode)
     583const std::string& Playable::playmodeToString(Playable::Playmode playmode)
    584584{
    585585  switch(playmode)
    586586  {
    587587    case Playable::Vertical:
    588       return "Vertical";
     588      return Playable::playmodeNames[0];
    589589    case Playable::Horizontal:
    590       return "Horizontal";
     590      return Playable::playmodeNames[1];
    591591    case Playable::FromBehind:
    592       return "FromBehind";
     592      return Playable::playmodeNames[2];
    593593    case Playable::Full3D:
    594       return "Full3D";
     594      return Playable::playmodeNames[3];
    595595
    596596    default:
    597       return "Full3D";
    598   }
    599 
    600 }
     597      return Playable::playmodeNames[3];
     598  }
     599}
     600
     601/**
     602 * @brief PlaymodeNames
     603 */
     604const std::string Playable::playmodeNames[] =
     605{
     606  "Vertical",
     607  "Horizontal",
     608  "FromBehind",
     609  "Full3D"
     610};
  • trunk/src/world_entities/playable.h

    r7351 r7412  
    3333    FromBehind       = 4,       //!< Seen from behind (move in z-y)
    3434    Full3D           = 8,       //!< Full featured 3D-mode. (move in all directions x-y-z)
     35
     36    PlaymodeCount    = 4,
    3537  } Playmode;
    3638
     
    8789  // Transformations:
    8890  static Playable::Playmode stringToPlaymode(const std::string& playmode);
    89   static const char* playmodeToString(Playable::Playmode playmode);
     91  static const std::string& playmodeToString(Playable::Playmode playmode);
     92  static const std::string playmodeNames[];
     93
    9094protected:
    9195  Playable();
Note: See TracChangeset for help on using the changeset viewer.