From 3c0399c3aad7fb089d865eeff3e709ac592caf7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Mustoha?= Date: Fri, 13 Sep 2024 19:22:18 +0200 Subject: [PATCH] Minor refactoring in the map list code --- src/common/MapList.h | 17 ++++++++--------- src/leveleditor/leveleditor.cpp | 8 ++++---- src/smw/GSMenu.cpp | 2 +- src/smw/main.cpp | 2 +- src/smw/ui/MI_MapBrowser.cpp | 4 ++-- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/common/MapList.h b/src/common/MapList.h index 7d1748ee..c730fb77 100644 --- a/src/common/MapList.h +++ b/src/common/MapList.h @@ -53,23 +53,22 @@ class MapList std::string randomFilename() const; - //Sets/Gets if a map at the current map node is valid and can be loaded - void SetValid(bool fValid) { + /// Sets whether the current map is valid and can be loaded + void setValid(bool fValid) { (*current).second->fValid = fValid; } - bool GetValid() { + /// The current map is valid and can be loaded + bool isValid() const { return (*current).second->fValid; } - //TODO: use size? - bool IsEmpty() { + bool isEmpty() const { return maps.empty(); } - - int GetFilteredCount() { + size_t filteredCount() const { return iFilteredMapCount; } - int GetCount() { + size_t count() const { return maps.size(); } @@ -118,7 +117,7 @@ class MapList std::multimap::iterator outercurrent; - short iFilteredMapCount; + size_t iFilteredMapCount; std::multimap::iterator * mlnFilteredMaps; std::multimap::iterator * mlnMaps; diff --git a/src/leveleditor/leveleditor.cpp b/src/leveleditor/leveleditor.cpp index 1502eee0..b5d341c1 100644 --- a/src/leveleditor/leveleditor.cpp +++ b/src/leveleditor/leveleditor.cpp @@ -1088,7 +1088,7 @@ int editor_edit() if (key == SDLK_PAGEUP) { do { maplist->prev(false); - } while (!maplist->GetValid()); + } while (!maplist->isValid()); loadcurrentmap(); } @@ -1096,7 +1096,7 @@ int editor_edit() if (key == SDLK_PAGEDOWN) { do { maplist->next(false); - } while (!maplist->GetValid()); + } while (!maplist->isValid()); loadcurrentmap(); @@ -1521,7 +1521,7 @@ int editor_edit() } - if (maplist->GetValid()) { + if (maplist->isValid()) { drawmap(false, TILESIZE); } else { SDL_FillRect(screen, NULL, 0x0); @@ -4804,7 +4804,7 @@ int clearMap() #ifdef _DEBUG void convertAll() { - for (int k = 0; k < maplist->GetCount(); k++) { + for (int k = 0; k < maplist->count(); k++) { //g_map->convertMap(); g_map->saveMap(maplist->currentFilename()); maplist->next(false); diff --git a/src/smw/GSMenu.cpp b/src/smw/GSMenu.cpp index 21baf5cd..100fa74a 100644 --- a/src/smw/GSMenu.cpp +++ b/src/smw/GSMenu.cpp @@ -1447,7 +1447,7 @@ void MenuState::update() //Write out all the map thumbnails for the map browser and filter editor std::map::iterator itr = maplist->GetIteratorAt(0, false); - short iMapCount = maplist->GetCount(); + short iMapCount = maplist->count(); for (short iMap = 0; iMap < iMapCount; iMap++) { std::string szThumbnail("maps/cache/"); szThumbnail += GetNameFromFileName(itr->second->filename); diff --git a/src/smw/main.cpp b/src/smw/main.cpp index 780bc863..2b478c53 100644 --- a/src/smw/main.cpp +++ b/src/smw/main.cpp @@ -176,7 +176,7 @@ void create_globals() maplist = new MapList(false); //TODO: add proper test via size - if (maplist->IsEmpty()) { + if (maplist->isEmpty()) { throw "Empty map directory!"; } diff --git a/src/smw/ui/MI_MapBrowser.cpp b/src/smw/ui/MI_MapBrowser.cpp index 731a01dc..c1e132b4 100644 --- a/src/smw/ui/MI_MapBrowser.cpp +++ b/src/smw/ui/MI_MapBrowser.cpp @@ -243,10 +243,10 @@ void MI_MapBrowser::Reset(short type) iFilterTagAnimationTimer = 0; iFilterTagAnimationFrame = 72; - iMapCount = maplist->GetCount(); + iMapCount = maplist->count(); } else { iSelectedIndex = maplist->GetCurrent()->second->iFilteredIndex; - iMapCount = maplist->GetFilteredCount(); + iMapCount = maplist->filteredCount(); } iSelectedRow = (iSelectedIndex / 3) % 3;