Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 13, 2008, 1:36:45 AM (17 years ago)
Author:
landauf
Message:

added CoreSettings, a class containing all settings of core classes (at the moment it's only debuglevel and language)

removed DebugLevel
removed OrxonoxClass inheritance of Language and LanguageEntry

File:
1 edited

Legend:

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

    r1031 r1036  
    2828/**
    2929    @file Language.cc
    30     @brief Implementation of the Language and the LanguageEntry class.
     30    @brief Implementation of the Language and the LanguageEntry classes.
    3131*/
    3232
    3333#include <fstream>
    3434
    35 #include "CoreIncludes.h"
    3635#include "Language.h"
    37 #include "ConfigValueIncludes.h"
     36#include "CoreSettings.h"
    3837
    3938namespace orxonox
     
    4847    LanguageEntry::LanguageEntry(const std::string& fallbackEntry)
    4948    {
    50         RegisterRootObject(LanguageEntry);
    51 
    5249        this->fallbackEntry_ = fallbackEntry;
    5350        this->localisedEntry_ = fallbackEntry; // Set the localisation to the fallback entry, for the case that no translation gets assigned
     
    9289    Language::Language()
    9390    {
    94         RegisterRootObject(Language);
    95 
    9691        this->defaultLanguage_ = "default";
    9792        this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!";
     
    10297
    10398    /**
    104         @brief Function to collect the SetConfigValue-macro calls.
    105     */
    106     void Language::setConfigValues()
    107     {
    108         SetConfigValue(language_, this->defaultLanguage_).description("The language of the ingame text");
    109 
    110         // Read the translation file after the language was configured
    111         this->readTranslatedLanguageFile();
    112     }
    113 
    114     /**
    11599        @brief Returns a reference to the only existing instance of the Language class and calls the setConfigValues() function.
    116100        @return The reference to the only existing instance
     
    118102    Language& Language::getLanguage()
    119103    {
    120         // Use static variables to avoid conflicts while executing this code before main()
    121         static Language theOnlyLanguageObject = Language();
    122         static bool bCreatingTheOnlyLanguageObject = true;
    123 
    124         // This workaround is used to set a description of the own config value without creating an infinite recursion
    125         if (bCreatingTheOnlyLanguageObject)
    126         {
    127             bCreatingTheOnlyLanguageObject = false;
    128             theOnlyLanguageObject.setConfigValues();
    129         }
    130 
    131         return theOnlyLanguageObject;
     104        static Language instance = Language();
     105        return instance;
    132106    }
    133107
     
    267241    void Language::readTranslatedLanguageFile()
    268242    {
    269         COUT(4) << "Read translated language file (" << this->language_ << ")." << std::endl;
     243        COUT(4) << "Read translated language file (" << CoreSettings::getLanguage() << ")." << std::endl;
    270244
    271245        // Open the file
    272246        std::ifstream file;
    273         file.open(getFileName(this->language_).c_str(), std::fstream::in);
     247        file.open(getFileName(CoreSettings::getLanguage()).c_str(), std::fstream::in);
    274248
    275249        if (!file.is_open())
    276250        {
    277251            COUT(1) << "An error occurred in Language.cc:" << std::endl;
    278             COUT(1) << "Error: Couldn't open file " << getFileName(this->language_) << " to read the translated language entries!" << std::endl;
    279             ResetConfigValue(language_);
     252            COUT(1) << "Error: Couldn't open file " << getFileName(CoreSettings::getLanguage()) << " to read the translated language entries!" << std::endl;
     253            CoreSettings::resetLanguage();
    280254            COUT(3) << "Info: Reset language to " << this->defaultLanguage_ << "." << std::endl;
    281255            return;
     
    308282                else
    309283                {
    310                     COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFileName(this->language_) << std::endl;
     284                    COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFileName(CoreSettings::getLanguage()) << std::endl;
    311285                }
    312286            }
     
    335309
    336310        // Iterate through the list an write the lines into the file
    337         for (Iterator<LanguageEntry> it = ObjectList<LanguageEntry>::start(); it; ++it)
    338         {
    339             file << it->getLabel() << "=" << it->getDefault() << std::endl;
     311        for (std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.begin(); it != this->languageEntries_.end(); ++it)
     312        {
     313            file << (*it).second->getLabel() << "=" << (*it).second->getDefault() << std::endl;
    340314        }
    341315
Note: See TracChangeset for help on using the changeset viewer.