Sort town/house names
This commit is contained in:
parent
3750a85c5f
commit
6f467d5a1b
|
@ -159,6 +159,7 @@ void HouseManager::load(const std::string& fileName)
|
||||||
} catch(std::exception& e) {
|
} catch(std::exception& e) {
|
||||||
g_logger.error(stdext::format("Failed to load '%s': %s", fileName, e.what()));
|
g_logger.error(stdext::format("Failed to load '%s': %s", fileName, e.what()));
|
||||||
}
|
}
|
||||||
|
sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HouseManager::save(const std::string& fileName)
|
void HouseManager::save(const std::string& fileName)
|
||||||
|
@ -201,4 +202,9 @@ HouseList::iterator HouseManager::findHouse(uint32 houseId)
|
||||||
[=] (const HousePtr& house) -> bool { return house->getId() == houseId; });
|
[=] (const HousePtr& house) -> bool { return house->getId() == houseId; });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HouseManager::sort()
|
||||||
|
{
|
||||||
|
m_houses.sort([] (const HousePtr& lhs, const HousePtr& rhs) { return lhs->getName() < rhs->getName(); });
|
||||||
|
}
|
||||||
|
|
||||||
/* vim: set ts=4 sw=4 et: */
|
/* vim: set ts=4 sw=4 et: */
|
||||||
|
|
|
@ -96,6 +96,7 @@ public:
|
||||||
void load(const std::string& fileName);
|
void load(const std::string& fileName);
|
||||||
void save(const std::string& fileName);
|
void save(const std::string& fileName);
|
||||||
|
|
||||||
|
void sort();
|
||||||
void clear() { m_houses.clear(); }
|
void clear() { m_houses.clear(); }
|
||||||
HouseList getHouseList() { return m_houses; }
|
HouseList getHouseList() { return m_houses; }
|
||||||
HouseList filterHouses(uint32 townId);
|
HouseList filterHouses(uint32 townId);
|
||||||
|
|
|
@ -82,6 +82,7 @@ void Client::registerLuaFunctions()
|
||||||
g_lua.bindSingletonFunction("g_houses", "removeHouse", &HouseManager::removeHouse, &g_houses);
|
g_lua.bindSingletonFunction("g_houses", "removeHouse", &HouseManager::removeHouse, &g_houses);
|
||||||
g_lua.bindSingletonFunction("g_houses", "getHouseList", &HouseManager::getHouseList, &g_houses);
|
g_lua.bindSingletonFunction("g_houses", "getHouseList", &HouseManager::getHouseList, &g_houses);
|
||||||
g_lua.bindSingletonFunction("g_houses", "filterHouses", &HouseManager::filterHouses, &g_houses);
|
g_lua.bindSingletonFunction("g_houses", "filterHouses", &HouseManager::filterHouses, &g_houses);
|
||||||
|
g_lua.bindSingletonFunction("g_houses", "sort", &HouseManager::sort, &g_houses);
|
||||||
|
|
||||||
g_lua.registerSingletonClass("g_towns");
|
g_lua.registerSingletonClass("g_towns");
|
||||||
g_lua.bindSingletonFunction("g_towns", "getTown", &TownManager::getTown, &g_towns);
|
g_lua.bindSingletonFunction("g_towns", "getTown", &TownManager::getTown, &g_towns);
|
||||||
|
@ -89,6 +90,7 @@ void Client::registerLuaFunctions()
|
||||||
g_lua.bindSingletonFunction("g_towns", "addTown", &TownManager::addTown, &g_towns);
|
g_lua.bindSingletonFunction("g_towns", "addTown", &TownManager::addTown, &g_towns);
|
||||||
g_lua.bindSingletonFunction("g_towns", "removeTown", &TownManager::removeTown, &g_towns);
|
g_lua.bindSingletonFunction("g_towns", "removeTown", &TownManager::removeTown, &g_towns);
|
||||||
g_lua.bindSingletonFunction("g_towns", "getTowns", &TownManager::getTowns, &g_towns);
|
g_lua.bindSingletonFunction("g_towns", "getTowns", &TownManager::getTowns, &g_towns);
|
||||||
|
g_lua.bindSingletonFunction("g_towns", "sort", &TownManager::sort, &g_towns);
|
||||||
|
|
||||||
g_lua.registerSingletonClass("g_sprites");
|
g_lua.registerSingletonClass("g_sprites");
|
||||||
g_lua.bindSingletonFunction("g_sprites", "loadSpr", &SpriteManager::loadSpr, &g_sprites);
|
g_lua.bindSingletonFunction("g_sprites", "loadSpr", &SpriteManager::loadSpr, &g_sprites);
|
||||||
|
|
|
@ -202,6 +202,7 @@ void Map::loadOtbm(const std::string& fileName)
|
||||||
if(!(town = g_towns.getTown(townId)))
|
if(!(town = g_towns.getTown(townId)))
|
||||||
g_towns.addTown(TownPtr(new Town(townId, townName, townCoords)));
|
g_towns.addTown(TownPtr(new Town(townId, townName, townCoords)));
|
||||||
}
|
}
|
||||||
|
g_towns.sort();
|
||||||
} else if(mapDataType == OTBM_WAYPOINTS && headerVersion > 1) {
|
} else if(mapDataType == OTBM_WAYPOINTS && headerVersion > 1) {
|
||||||
for(const BinaryTreePtr &nodeWaypoint : nodeMapData->getChildren()) {
|
for(const BinaryTreePtr &nodeWaypoint : nodeMapData->getChildren()) {
|
||||||
if(nodeWaypoint->getU8() != OTBM_WAYPOINT)
|
if(nodeWaypoint->getU8() != OTBM_WAYPOINT)
|
||||||
|
|
|
@ -72,3 +72,9 @@ TownList::iterator TownManager::findTown(uint32 townId)
|
||||||
return std::find_if(m_towns.begin(), m_towns.end(),
|
return std::find_if(m_towns.begin(), m_towns.end(),
|
||||||
[=] (const TownPtr& town) -> bool { return town->getId() == townId; });
|
[=] (const TownPtr& town) -> bool { return town->getId() == townId; });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TownManager::sort()
|
||||||
|
{
|
||||||
|
m_towns.sort([] (const TownPtr& lhs, const TownPtr& rhs) { return lhs->getName() < rhs->getName(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ public:
|
||||||
const TownPtr& getTown(uint32 townId);
|
const TownPtr& getTown(uint32 townId);
|
||||||
const TownPtr& getTownByName(std::string name);
|
const TownPtr& getTownByName(std::string name);
|
||||||
|
|
||||||
|
void sort();
|
||||||
TownList getTowns() { return m_towns; }
|
TownList getTowns() { return m_towns; }
|
||||||
void clear() { m_towns.clear(); m_nullTown = nullptr; }
|
void clear() { m_towns.clear(); m_nullTown = nullptr; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue