Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 18, 2012, 3:39:47 PM (12 years ago)
Author:
smerkli
Message:

merged branch shipSelection

Location:
code/branches/presentation2012
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2012

  • code/branches/presentation2012/src/orxonox/LevelInfo.cc

    r9016 r9208  
    9393            LevelInfoItem::possibleTags_s.insert("gametype");
    9494            LevelInfoItem::possibleTags_s.insert("minigame");
     95            LevelInfoItem::possibleTags_s.insert("shipselection");
    9596        }
    9697    }
     
    110111
    111112        this->tagsUpdated();
     113    }
     114    /**
     115    @brief
     116        Set the starting ship models of the level
     117    @param tags
     118        A comma-seperated string of all the allowed ship models for the shipselection.
     119    */
     120    void LevelInfoItem::setShips(const std::string& ships)
     121    {
     122        SubString substr = SubString(ships, ",", " "); // Split the string into tags.
     123        const std::vector<std::string>& strings = substr.getAllStrings();
     124        for(std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); it++)
     125            this->addShip(*it, false);
     126
     127        this->shipsUpdated();
    112128    }
    113129
     
    137153    /**
    138154    @brief
     155        Add a ship model to allowed models for the shipselection
     156    @param ship
     157        The ship model to be added.
     158    @param update
     159        Whether the comma-seperated string of all ship models should be updated. Default is true.
     160    @return
     161        Returns true if the ship was successfully added, if the ship was already present it returns false.
     162    */
     163    bool LevelInfoItem::addShip(const std::string& ship, bool update)
     164    {
     165        bool success = this->ships_.insert(ship).second;
     166        if(update && success)
     167            this->shipsUpdated();
     168           
     169        return success;
     170    }
     171
     172
     173    /**
     174    @brief
    139175        Updates the comma-seperated string of all tags, if the set of tags has changed.
    140176    */
     
    155191    }
    156192
     193    /**
     194    @brief
     195        Updates the comma-seperated string of all ships, if the set of tags has changed.
     196    */
     197    void LevelInfoItem::shipsUpdated(void)
     198    {
     199        std::stringstream stream;
     200        std::set<std::string>::iterator temp;
     201        for(std::set<std::string>::iterator it = this->ships_.begin(); it != this->ships_.end(); )
     202        {
     203            temp = it;
     204            if(++it == this->ships_.end()) // If this is the last ship we don't add a comma.
     205                stream << *temp;
     206            else
     207                stream << *temp << ", ";
     208        }
     209
     210        this->startingShipsString_ = std::string(stream.str());
     211    }
    157212    // LevelInfo
    158213
     
    192247        XMLPortParam(LevelInfo, "screenshot", setScreenshot, getScreenshot, xmlelement, mode);
    193248        XMLPortParam(LevelInfo, "tags", setTags, getTags, xmlelement, mode);
     249        XMLPortParam(LevelInfo, "startingships", setShips, getShips, xmlelement, mode);
    194250    }
    195251
     
    207263        info->setScreenshot(this->getScreenshot());
    208264        info->setTags(this->getTags());
     265        info->setShips(this->getShips());
    209266        return info;
    210267    }
Note: See TracChangeset for help on using the changeset viewer.