summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-03-13 21:23:33 +0200
committerAndrei Karas <akaras@inbox.ru>2011-03-13 21:59:10 +0200
commitbf32ca896ccf51385eb67812088ba5861ca2ede2 (patch)
tree02cc6a7f8de3ef48b6092668368f3b5ba8f35683 /src/resources
parent774e86e8d2f8d787fb3b3a865cd500f166153c96 (diff)
downloadmanaplus-bf32ca896ccf51385eb67812088ba5861ca2ede2.tar.gz
manaplus-bf32ca896ccf51385eb67812088ba5861ca2ede2.tar.bz2
manaplus-bf32ca896ccf51385eb67812088ba5861ca2ede2.tar.xz
manaplus-bf32ca896ccf51385eb67812088ba5861ca2ede2.zip
Add ability to remap maps to different files.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/mapdb.cpp88
-rw-r--r--src/resources/mapdb.h50
-rw-r--r--src/resources/mapreader.cpp30
-rw-r--r--src/resources/mapreader.h3
4 files changed, 156 insertions, 15 deletions
diff --git a/src/resources/mapdb.cpp b/src/resources/mapdb.cpp
new file mode 100644
index 000000000..37b127c02
--- /dev/null
+++ b/src/resources/mapdb.cpp
@@ -0,0 +1,88 @@
+/*
+ * Color database
+ * Copyright (C) 2008 Aethyra Development Team
+ * Copyright (C) 2011 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "resources/mapdb.h"
+
+#include "configuration.h"
+#include "client.h"
+#include "log.h"
+
+#include "utils/xml.h"
+
+#include <libxml/tree.h>
+
+namespace
+{
+ bool mLoaded = false;
+ MapDB::Maps mMaps;
+}
+
+void MapDB::load()
+{
+ if (mLoaded)
+ unload();
+
+ XML::Document *doc = new XML::Document(
+ paths.getStringValue("maps") + "remap.xml");
+
+ xmlNodePtr root = doc->rootNode();
+ if (!root)
+ return;
+
+ for_each_xml_child_node(node, root)
+ {
+ if (xmlStrEqual(node->name, BAD_CAST "map"))
+ {
+ std::string name = XML::getProperty(node, "name", "");
+ if (name.empty())
+ continue;
+
+ std::string value = XML::getProperty(node, "value", "");
+ if (value.empty())
+ continue;
+
+ mMaps[name] = value;
+ }
+ }
+
+ delete doc;
+
+ mLoaded = true;
+}
+
+
+void MapDB::unload()
+{
+ logger->log1("Unloading map database...");
+
+ mMaps.clear();
+ mLoaded = false;
+}
+
+std::string MapDB::getMapName(std::string name)
+{
+ MapIterator it = mMaps.find(name);
+ logger->log("map: " + name);
+
+ if (it != mMaps.end())
+ return it->second;
+ return name;
+}
diff --git a/src/resources/mapdb.h b/src/resources/mapdb.h
new file mode 100644
index 000000000..2ba084297
--- /dev/null
+++ b/src/resources/mapdb.h
@@ -0,0 +1,50 @@
+/*
+ * Color database
+ * Copyright (C) 2008 Aethyra Development Team
+ * Copyright (C) 2011 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAPDB_H
+#define MAPDB_H
+
+#include <map>
+#include <string>
+
+/**
+ * Color information database.
+ */
+namespace MapDB
+{
+ /**
+ * Loads the map remap data from <code>maps\remap.xml</code>.
+ */
+ void load();
+
+ /**
+ * Clear the remap data
+ */
+ void unload();
+
+ std::string getMapName(std::string name);
+
+ // Maps DB
+ typedef std::map<std::string, std::string> Maps;
+ typedef Maps::iterator MapIterator;
+}
+
+#endif
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 5a635a8c2..d3cd22988 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -29,6 +29,7 @@
#include "resources/animation.h"
#include "resources/image.h"
+#include "resources/mapdb.h"
#include "resources/resourcemanager.h"
#include "utils/base64.h"
@@ -177,25 +178,26 @@ int inflateMemory(unsigned char *in, unsigned int inLength,
return outLength;
}
-Map *MapReader::readMap(const std::string &filename)
+Map *MapReader::readMap(const std::string &filename,
+ const std::string &realFilename)
{
- logger->log("Attempting to read map %s", filename.c_str());
+ logger->log("Attempting to read map %s", realFilename.c_str());
// Load the file through resource manager
ResourceManager *resman = ResourceManager::getInstance();
int fileSize;
- void *buffer = resman->loadFile(filename, fileSize);
+ void *buffer = resman->loadFile(realFilename, fileSize);
Map *map = NULL;
if (buffer == NULL)
{
- logger->log("Map file not found (%s)", filename.c_str());
+ logger->log("Map file not found (%s)", realFilename.c_str());
return NULL;
}
unsigned char *inflated;
unsigned int inflatedSize;
- if (filename.find(".gz", filename.length() - 3) != std::string::npos)
+ if (realFilename.find(".gz", realFilename.length() - 3) != std::string::npos)
{
// Inflate the gzipped map data
inflatedSize =
@@ -205,7 +207,7 @@ Map *MapReader::readMap(const std::string &filename)
if (inflated == NULL)
{
logger->log("Could not decompress map file (%s)",
- filename.c_str());
+ realFilename.c_str());
return NULL;
}
}
@@ -224,20 +226,20 @@ Map *MapReader::readMap(const std::string &filename)
if (node)
{
if (!xmlStrEqual(node->name, BAD_CAST "map"))
- {
- logger->log("Error: Not a map file (%s)!", filename.c_str());
- }
+ logger->log("Error: Not a map file (%s)!", realFilename.c_str());
else
- {
- map = readMap(node, filename);
- }
+ map = readMap(node, realFilename);
}
else
{
- logger->log("Error while parsing map file (%s)!", filename.c_str());
+ logger->log("Error while parsing map file (%s)!", realFilename.c_str());
}
- if (map) map->setProperty("_filename", filename);
+ if (map)
+ {
+ map->setProperty("_filename", realFilename);
+ map->setProperty("_realfilename", filename);
+ }
return map;
}
diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h
index 6995aaf8e..927b76173 100644
--- a/src/resources/mapreader.h
+++ b/src/resources/mapreader.h
@@ -46,7 +46,8 @@ class MapReader
/**
* Read an XML map from a file.
*/
- static Map *readMap(const std::string &filename);
+ static Map *readMap(const std::string &filename,
+ const std::string &realFilename);
/**
* Read an XML map from a parsed XML tree. The path is used to find the