Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 23, 2012, 4:24:24 PM (12 years ago)
Author:
huttemat
Message:

test2

File:
1 edited

Legend:

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

    r9045 r9057  
    112112        this->tagsUpdated();
    113113    }
     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();
     128    }
    114129
    115130    /**
     
    138153    /**
    139154    @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->tags_.insert(ship).second;
     166        if(update && success)
     167            this->tagsUpdated();
     168        return success;
     169    }
     170
     171
     172    /**
     173    @brief
    140174        Updates the comma-seperated string of all tags, if the set of tags has changed.
    141175    */
     
    156190    }
    157191
     192    /**
     193    @brief
     194        Updates the comma-seperated string of all ships, if the set of tags has changed.
     195    */
     196    void LevelInfoItem::shipsUpdated(void)
     197    {
     198        std::stringstream stream;
     199        std::set<std::string>::iterator temp;
     200        for(std::set<std::string>::iterator it = this->ships_.begin(); it != this->ships_.end(); )
     201        {
     202            temp = it;
     203            if(++it == this->ships_.end()) // If this is the last ship we don't add a comma.
     204                stream << *temp;
     205            else
     206                stream << *temp << ", ";
     207        }
     208
     209        this->startingShipsString_ = std::string(stream.str());
     210    }
    158211    // LevelInfo
    159212
     
    193246        XMLPortParam(LevelInfo, "screenshot", setScreenshot, getScreenshot, xmlelement, mode);
    194247        XMLPortParam(LevelInfo, "tags", setTags, getTags, xmlelement, mode);
     248        XMLPortParam(LevelInfo, "startingships", setShips, getShips, xmlelement, mode);
    195249    }
    196250
     
    208262        info->setScreenshot(this->getScreenshot());
    209263        info->setTags(this->getTags());
     264        info->setShips(this->getShips());
    210265        return info;
    211266    }
Note: See TracChangeset for help on using the changeset viewer.