Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 9, 2012, 3:51:51 PM (12 years ago)
Author:
landauf
Message:

small cleanup in ship selection:

  • renamed some functions
  • moved implementation of changeStartingShip() from header to source file
  • removed ShipManager which doesn't seem to be used nor compiled (and it's just a copy of LevelManager anyway)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2012merge/src/orxonox/LevelInfo.cc

    r9269 r9281  
    4242
    4343    // LevelInfoItem
    44    
     44
    4545    //! The list of allowed tags.
    4646    /*static*/ std::set<std::string> LevelInfoItem::possibleTags_s = std::set<std::string>();
     
    107107        SubString substr = SubString(tags, ",", " "); // Split the string into tags.
    108108        const std::vector<std::string>& strings = substr.getAllStrings();
    109         for(std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); it++)
     109        for (std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); it++)
    110110            this->addTag(*it, false);
    111111
     
    118118        A comma-seperated string of all the allowed ship models for the shipselection.
    119119    */
    120     void LevelInfoItem::setShips(const std::string& ships)
     120    void LevelInfoItem::setStartingShips(const std::string& ships)
    121121    {
    122122        SubString substr = SubString(ships, ",", " "); // Split the string into tags.
    123123        const std::vector<std::string>& strings = substr.getAllStrings();
    124124        for(std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); it++)
    125             this->addShip(*it, false);
    126 
    127         this->shipsUpdated();
     125            this->addStartingShip(*it, false);
     126
     127        this->startingshipsUpdated();
    128128    }
    129129
     
    161161        Returns true if the ship was successfully added, if the ship was already present it returns false.
    162162    */
    163     bool LevelInfoItem::addShip(const std::string& ship, bool update)
    164     {
    165         bool success = this->ships_.insert(ship).second;
     163    bool LevelInfoItem::addStartingShip(const std::string& ship, bool update)
     164    {
     165        bool success = this->startingShips_.insert(ship).second;
    166166        if(update && success)
    167             this->shipsUpdated();
    168            
     167            this->startingshipsUpdated();
     168
    169169        return success;
    170170    }
     
    195195        Updates the comma-seperated string of all ships, if the set of tags has changed.
    196196    */
    197     void LevelInfoItem::shipsUpdated(void)
     197    void LevelInfoItem::startingshipsUpdated(void)
    198198    {
    199199        std::stringstream stream;
    200200        std::set<std::string>::iterator temp;
    201         for(std::set<std::string>::iterator it = this->ships_.begin(); it != this->ships_.end(); )
     201        for(std::set<std::string>::iterator it = this->startingShips_.begin(); it != this->startingShips_.end(); )
    202202        {
    203203            temp = it;
    204             if(++it == this->ships_.end()) // If this is the last ship we don't add a comma.
     204            if(++it == this->startingShips_.end()) // If this is the last ship we don't add a comma.
    205205                stream << *temp;
    206206            else
     
    210210        this->startingShipsString_ = std::string(stream.str());
    211211    }
     212
     213    void LevelInfoItem::changeStartingShip(const std::string& model)
     214    {
     215        static std::string shipSelectionTag = "shipselection";
     216        //HACK: Read Level XML File, find "shipselection", replace with ship model
     217        std::string levelPath = "../levels/";
     218        levelPath.append(this->getXMLFilename());
     219        std::string tempPath = "../levels/";
     220        tempPath.append("_temp.oxw");
     221        orxout(user_status) << levelPath << endl;
     222        orxout(user_status) << tempPath << endl;
     223        std::ifstream myLevel (levelPath.c_str());
     224        std::ofstream tempLevel (tempPath.c_str());
     225        while(!myLevel.eof())
     226        {
     227            std::string buff;
     228            std::getline(myLevel, buff);
     229            std::string pawndesignString = "pawndesign=";
     230            size_t found = buff.find(pawndesignString.append(shipSelectionTag));
     231            if (found!= std::string::npos)
     232                buff = buff.substr(0, found + 11) + model + buff.substr(found+11+shipSelectionTag.length(), std::string::npos);
     233            tempLevel.write(buff.c_str(), buff.length());
     234            tempLevel << std::endl;
     235        }
     236        myLevel.close();
     237        tempLevel.close();
     238        orxout(user_status) << "done" << endl;
     239    }
     240
     241
    212242    // LevelInfo
    213243
     
    247277        XMLPortParam(LevelInfo, "screenshot", setScreenshot, getScreenshot, xmlelement, mode);
    248278        XMLPortParam(LevelInfo, "tags", setTags, getTags, xmlelement, mode);
    249         XMLPortParam(LevelInfo, "startingships", setShips, getShips, xmlelement, mode);
     279        XMLPortParam(LevelInfo, "startingships", setStartingShips, getStartingShips, xmlelement, mode);
    250280    }
    251281
     
    263293        info->setScreenshot(this->getScreenshot());
    264294        info->setTags(this->getTags());
    265         info->setShips(this->getShips());
     295        info->setStartingShips(this->getStartingShips());
    266296        return info;
    267297    }
Note: See TracChangeset for help on using the changeset viewer.