diff --git a/src/client/houses.cpp b/src/client/houses.cpp index 36d22a3c..36d76a45 100644 --- a/src/client/houses.cpp +++ b/src/client/houses.cpp @@ -159,6 +159,7 @@ void HouseManager::load(const std::string& fileName) } catch(std::exception& e) { g_logger.error(stdext::format("Failed to load '%s': %s", fileName, e.what())); } + sort(); } 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; }); } +void HouseManager::sort() +{ + m_houses.sort([] (const HousePtr& lhs, const HousePtr& rhs) { return lhs->getName() < rhs->getName(); }); +} + /* vim: set ts=4 sw=4 et: */ diff --git a/src/client/houses.h b/src/client/houses.h index 2e32c291..4cb01312 100644 --- a/src/client/houses.h +++ b/src/client/houses.h @@ -96,6 +96,7 @@ public: void load(const std::string& fileName); void save(const std::string& fileName); + void sort(); void clear() { m_houses.clear(); } HouseList getHouseList() { return m_houses; } HouseList filterHouses(uint32 townId); diff --git a/src/client/luafunctions.cpp b/src/client/luafunctions.cpp index eec2e751..155edc23 100644 --- a/src/client/luafunctions.cpp +++ b/src/client/luafunctions.cpp @@ -82,13 +82,15 @@ void Client::registerLuaFunctions() 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", "filterHouses", &HouseManager::filterHouses, &g_houses); + g_lua.bindSingletonFunction("g_houses", "sort", &HouseManager::sort, &g_houses); g_lua.registerSingletonClass("g_towns"); g_lua.bindSingletonFunction("g_towns", "getTown", &TownManager::getTown, &g_towns); g_lua.bindSingletonFunction("g_towns", "getTownByName",&TownManager::getTownByName,&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", "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.bindSingletonFunction("g_sprites", "loadSpr", &SpriteManager::loadSpr, &g_sprites); diff --git a/src/client/mapio.cpp b/src/client/mapio.cpp index eeddf130..9e451a9f 100644 --- a/src/client/mapio.cpp +++ b/src/client/mapio.cpp @@ -202,6 +202,7 @@ void Map::loadOtbm(const std::string& fileName) if(!(town = g_towns.getTown(townId))) g_towns.addTown(TownPtr(new Town(townId, townName, townCoords))); } + g_towns.sort(); } else if(mapDataType == OTBM_WAYPOINTS && headerVersion > 1) { for(const BinaryTreePtr &nodeWaypoint : nodeMapData->getChildren()) { if(nodeWaypoint->getU8() != OTBM_WAYPOINT) diff --git a/src/client/towns.cpp b/src/client/towns.cpp index 2a78ee41..a717a667 100644 --- a/src/client/towns.cpp +++ b/src/client/towns.cpp @@ -72,3 +72,9 @@ TownList::iterator TownManager::findTown(uint32 townId) return std::find_if(m_towns.begin(), m_towns.end(), [=] (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(); }); +} + diff --git a/src/client/towns.h b/src/client/towns.h index 0e962381..ecae856b 100644 --- a/src/client/towns.h +++ b/src/client/towns.h @@ -56,6 +56,7 @@ public: const TownPtr& getTown(uint32 townId); const TownPtr& getTownByName(std::string name); + void sort(); TownList getTowns() { return m_towns; } void clear() { m_towns.clear(); m_nullTown = nullptr; }