diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-01-27 13:29:38 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-01-27 13:29:38 +0300 |
commit | 6897c86f62c6f5ed59ad0dade2c81946844fa5dd (patch) | |
tree | 8cd49605f6f7aab10aea2882d7b69c3bbfe5eab8 /src/resources/mapreader.cpp | |
parent | e0415e24477d07ecd90ec17667fba127deed91bd (diff) | |
download | manaplus-6897c86f62c6f5ed59ad0dade2c81946844fa5dd.tar.gz manaplus-6897c86f62c6f5ed59ad0dade2c81946844fa5dd.tar.bz2 manaplus-6897c86f62c6f5ed59ad0dade2c81946844fa5dd.tar.xz manaplus-6897c86f62c6f5ed59ad0dade2c81946844fa5dd.zip |
Add ability to maps to play music files with map name.
If music attribute missing, music can be played with name MAP.ogg
Diffstat (limited to 'src/resources/mapreader.cpp')
-rw-r--r-- | src/resources/mapreader.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index db3b31f25..a8388e5a9 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -244,6 +244,8 @@ Map *MapReader::readMap(const std::string &filename, map->setProperty("_realfilename", filename); } + if (map->getProperty("music").empty()) + updateMusic(map); return map; } @@ -274,10 +276,11 @@ Map *MapReader::readMap(XmlNodePtr node, const std::string &path) Map *const map = new Map(w, h, tilew, tileh); + const std::string fileName = path.substr(path.rfind("/") + 1); + map->setProperty("shortName", fileName); #ifdef USE_OPENGL if (graphicsManager.getUseAtlases()) { - const std::string fileName = path.substr(path.rfind("/") + 1); const MapDB::MapInfo *const info = MapDB::getMapAtlas(fileName); if (info) { @@ -843,6 +846,7 @@ Map *MapReader::createEmptyMap(const std::string &filename, Map *const map = new Map(300, 300, 32, 32); map->setProperty("_filename", realFilename); map->setProperty("_realfilename", filename); + updateMusic(map); map->setCustom(true); MapLayer *layer = new MapLayer(0, 0, 300, 300, false); map->addLayer(layer); @@ -851,3 +855,13 @@ Map *MapReader::createEmptyMap(const std::string &filename, return map; } + +void MapReader::updateMusic(Map *const map) +{ + std::string name = map->getProperty("shortName"); + const size_t p = name.rfind("."); + if (p != std::string::npos) + name = name.substr(0, p); + name += ".ogg"; + map->setProperty("music", name); +} |