More cleanups

Also, bind map descriptions auxiliar functions
This commit is contained in:
Ahmed Samy 2013-08-23 01:55:15 +02:00
parent 3b2d8a2b5e
commit 5df3ec8cf2
5 changed files with 308 additions and 296 deletions

View File

@ -260,7 +260,7 @@ void CreatureManager::saveSpawns(const std::string& fileName)
root->LinkEndChild(elem);
}
std::string savePath = g_resources.getRealDir(fileName) + "/" + fileName;
std::string savePath = g_resources.getRealPath(fileName);
if(!doc.SaveFile(savePath))
stdext::throw_exception(stdext::format("failed to save spawns XML %s: %s", savePath, doc.ErrorDesc()));
}

View File

@ -173,7 +173,7 @@ void HouseManager::save(const std::string& fileName)
root->LinkEndChild(elem);
}
std::string savePath = g_resources.getRealDir(fileName) + "/" + fileName;
std::string savePath = g_resources.getRealPath(fileName);
if(!doc.SaveFile(savePath))
stdext::throw_exception(stdext::format("failed to save houses XML %s: %s", savePath, doc.ErrorDesc()));
}

View File

@ -123,6 +123,9 @@ void Client::registerLuaFunctions()
g_lua.bindSingletonFunction("g_map", "setSpawnFile", &Map::setSpawnFile, &g_map);
g_lua.bindSingletonFunction("g_map", "createTile", &Map::createTile, &g_map);
g_lua.bindSingletonFunction("g_map", "getSize", &Map::getSize, &g_map);
g_lua.bindSingletonFunction("g_map", "setDescription", &Map::setDescription, &g_map);
g_lua.bindSingletonFunction("g_map", "getDescriptions", &Map::getDescriptions, &g_map);
g_lua.bindSingletonFunction("g_map", "clearDescriptions", &Map::clearDescriptions, &g_map);
g_lua.bindSingletonFunction("g_map", "setShowZone", &Map::setShowZone, &g_map);
g_lua.bindSingletonFunction("g_map", "setShowZones", &Map::setShowZones, &g_map);
g_lua.bindSingletonFunction("g_map", "setZoneColor", &Map::setZoneColor, &g_map);

View File

@ -151,6 +151,7 @@ public:
void setHouseFile(const std::string& file) { m_attribs.set(OTBM_ATTR_HOUSE_FILE, file); }
void setSpawnFile(const std::string& file) { m_attribs.set(OTBM_ATTR_SPAWN_FILE, file); }
void setDescription(const std::string& desc) { m_attribs.set(OTBM_ATTR_DESCRIPTION, desc); }
void clearDescriptions() { m_attribs.remove(OTBM_ATTR_DESCRIPTION); }
void setWidth(uint16 w) { m_attribs.set(OTBM_ATTR_WIDTH, w); }
void setHeight(uint16 h) { m_attribs.set(OTBM_ATTR_HEIGHT, h); }

View File

@ -34,6 +34,7 @@
void Map::loadOtbm(const std::string& fileName)
{
try {
FileStreamPtr fin = g_resources.openFile(fileName);
if(!fin)
stdext::throw_exception(stdext::format("Unable to load map '%s'", fileName));
@ -195,10 +196,8 @@ void Map::loadOtbm(const std::string& fileName)
townCoords.y = nodeTown->getU16();
townCoords.z = nodeTown->getU8();
if(!(town = g_towns.getTown(townId))) {
town = TownPtr(new Town(townId, townName, townCoords));
g_towns.addTown(town);
}
if(!(town = g_towns.getTown(townId)))
g_towns.addTown(TownPtr(new Town(townId, townName, townCoords)));
}
} else if(mapDataType == OTBM_WAYPOINTS && headerVersion > 1) {
for(const BinaryTreePtr &nodeWaypoint : nodeMapData->getChildren()) {
@ -220,10 +219,14 @@ void Map::loadOtbm(const std::string& fileName)
}
fin->close();
} catch(std::exception& e) {
g_logger.error(stdext::format("Failed to load '%s': %s", fileName, e.what()));
}
}
void Map::saveOtbm(const std::string& fileName)
{
try {
FileStreamPtr fin = g_resources.createFile(fileName);
if(!fin)
stdext::throw_exception(stdext::format("failed to open file '%s' for write", fileName));
@ -391,6 +394,9 @@ void Map::saveOtbm(const std::string& fileName)
fin->flush();
fin->close();
} catch(std::exception& e) {
g_logger.error(stdext::format("Failed to save '%s': %s", fileName, e.what()));
}
}
bool Map::loadOtcm(const std::string& fileName)
@ -538,3 +544,5 @@ void Map::saveOtcm(const std::string& fileName)
g_logger.error(stdext::format("failed to save OTCM map: %s", e.what()));
}
}
/* vim: set ts=4 sw=4 et: */