summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-01-27 13:29:38 +0300
committerAndrei Karas <akaras@inbox.ru>2013-01-27 13:29:38 +0300
commit6897c86f62c6f5ed59ad0dade2c81946844fa5dd (patch)
tree8cd49605f6f7aab10aea2882d7b69c3bbfe5eab8 /src
parente0415e24477d07ecd90ec17667fba127deed91bd (diff)
downloadmanaverse-6897c86f62c6f5ed59ad0dade2c81946844fa5dd.tar.gz
manaverse-6897c86f62c6f5ed59ad0dade2c81946844fa5dd.tar.bz2
manaverse-6897c86f62c6f5ed59ad0dade2c81946844fa5dd.tar.xz
manaverse-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')
-rw-r--r--src/resources/mapreader.cpp16
-rw-r--r--src/resources/mapreader.h2
2 files changed, 17 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);
+}
diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h
index 9168206c3..26e47a74c 100644
--- a/src/resources/mapreader.h
+++ b/src/resources/mapreader.h
@@ -75,6 +75,8 @@ class MapReader final
*/
static Tileset *readTileset(XmlNodePtr node, const std::string &path,
Map *const map) A_WARN_UNUSED;
+
+ static void updateMusic(Map *const map);
};
#endif