Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 31, 2010, 3:37:40 AM (14 years ago)
Author:
landauf
Message:

merged consolecommands3 branch back to trunk.

note: the console command interface has changed completely, but the documentation is not yet up to date. just copy an existing command and change it to your needs, it's pretty self-explanatory. also the include files related to console commands are now located in core/command/. in the game it should work exactly like before, except for some changes in the auto-completion.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/ConfigFileManager.cc

    r7163 r7284  
    3434#include "util/Math.h"
    3535#include "util/StringUtils.h"
    36 #include "ConsoleCommand.h"
    3736#include "ConfigValueContainer.h"
    3837#include "PathConfig.h"
     38#include "command/ConsoleCommand.h"
    3939
    4040namespace orxonox
     
    277277                            if (commentposition == std::string::npos)
    278278                            {
    279                                 value = removeTrailingWhitespaces(line.substr(pos1 + 1));
     279                                value = line.substr(pos1 + 1);
    280280                            }
    281281                            else
    282282                            {
    283                                 value = removeTrailingWhitespaces(line.substr(pos1 + 1, commentposition - pos1 - 1));
     283                                value = line.substr(pos1 + 1, commentposition - pos1 - 1);
    284284                                comment = removeTrailingWhitespaces(line.substr(commentposition));
    285285                            }
     286
     287                            value = removeTrailingWhitespaces(value);
     288                            value = removeSlashes(value);
    286289
    287290                            if (pos2 != std::string::npos && pos3 != std::string::npos && pos3 > pos2 + 1)
     
    425428    ////////////////////////
    426429
     430    static const std::string __CC_load_name = "reloadSettings";
     431    static const std::string __CC_setFilename_name = "setSettingsFile";
     432    static const std::string __CC_config_name = "config";
     433    static const std::string __CC_tconfig_name = "tconfig";
     434    static const std::string __CC_getConfig_name = "getConfig";
     435
     436    SetConsoleCommand(__CC_load_name,            &ConfigFile::load);
     437    SetConsoleCommand(__CC_setFilename_name,     &SettingsConfigFile::setFilename);
     438    SetConsoleCommand(__CC_config_name,          &SettingsConfigFile::config).argumentCompleter(0, autocompletion::settingssections()).argumentCompleter(1, autocompletion::settingsentries()).argumentCompleter(2, autocompletion::settingsvalue());
     439    SetConsoleCommand(__CC_tconfig_name,         &SettingsConfigFile::tconfig).argumentCompleter(0, autocompletion::settingssections()).argumentCompleter(1, autocompletion::settingsentries()).argumentCompleter(2, autocompletion::settingsvalue());
     440    SetConsoleCommand(__CC_getConfig_name,       &SettingsConfigFile::getConfig).argumentCompleter(0, autocompletion::settingssections()).argumentCompleter(1, autocompletion::settingsentries());
     441
    427442    SettingsConfigFile* SettingsConfigFile::singletonPtr_s = 0;
    428443
     
    430445        : ConfigFile(filename)
    431446    {
    432         ConsoleCommand* command = createConsoleCommand(createFunctor(&ConfigFile::load, this), "reloadSettings");
    433         CommandExecutor::addConsoleCommandShortcut(command);
    434         command = createConsoleCommand(createFunctor(&SettingsConfigFile::setFilename, this), "setSettingsFile");
    435         CommandExecutor::addConsoleCommandShortcut(command);
    436         command = createConsoleCommand(createFunctor(&SettingsConfigFile::config, this), "config");
    437         CommandExecutor::addConsoleCommandShortcut(command).argumentCompleter(0, autocompletion::settingssections()).argumentCompleter(1, autocompletion::settingsentries()).argumentCompleter(2, autocompletion::settingsvalue());
    438         command = createConsoleCommand(createFunctor(&SettingsConfigFile::tconfig, this), "tconfig");
    439         CommandExecutor::addConsoleCommandShortcut(command).argumentCompleter(0, autocompletion::settingssections()).argumentCompleter(1, autocompletion::settingsentries()).argumentCompleter(2, autocompletion::settingsvalue());
    440         command = createConsoleCommand(createFunctor(&SettingsConfigFile::getConfig, this), "getConfig");
    441         CommandExecutor::addConsoleCommandShortcut(command).argumentCompleter(0, autocompletion::settingssections()).argumentCompleter(1, autocompletion::settingsentries());
     447        ModifyConsoleCommand(__CC_load_name).setObject(this);
     448        ModifyConsoleCommand(__CC_setFilename_name).setObject(this);
     449        ModifyConsoleCommand(__CC_config_name).setObject(this);
     450        ModifyConsoleCommand(__CC_tconfig_name).setObject(this);
     451        ModifyConsoleCommand(__CC_getConfig_name).setObject(this);
    442452    }
    443453
    444454    SettingsConfigFile::~SettingsConfigFile()
    445455    {
     456        ModifyConsoleCommand(__CC_load_name).setObject(0);
     457        ModifyConsoleCommand(__CC_setFilename_name).setObject(0);
     458        ModifyConsoleCommand(__CC_config_name).setObject(0);
     459        ModifyConsoleCommand(__CC_tconfig_name).setObject(0);
     460        ModifyConsoleCommand(__CC_getConfig_name).setObject(0);
    446461    }
    447462
     
    543558    }
    544559
    545     bool SettingsConfigFile::config(const std::string& section, const std::string& entry, const std::string& value)
    546     {
    547         return this->configImpl(section, entry, value, &ConfigValueContainer::set);
    548     }
    549 
    550     bool SettingsConfigFile::tconfig(const std::string& section, const std::string& entry, const std::string& value)
    551     {
    552         return this->configImpl(section, entry, value, &ConfigValueContainer::tset);
     560    void SettingsConfigFile::config(const std::string& section, const std::string& entry, const std::string& value)
     561    {
     562        if (!this->configImpl(section, entry, value, &ConfigValueContainer::set))
     563            COUT(1) << "Error: Config value \"" << entry << "\" in section \"" << section << "\" doesn't exist." << std::endl;
     564    }
     565
     566    void SettingsConfigFile::tconfig(const std::string& section, const std::string& entry, const std::string& value)
     567    {
     568        if (!this->configImpl(section, entry, value, &ConfigValueContainer::tset))
     569            COUT(1) << "Error: Config value \"" << entry << "\" in section \"" << section << "\" doesn't exist." << std::endl;
    553570    }
    554571
Note: See TracChangeset for help on using the changeset viewer.