Skip to content

Commit

Permalink
Minor refactoring in the map list code
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatyas committed Sep 13, 2024
1 parent 0a6169e commit 3c0399c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
17 changes: 8 additions & 9 deletions src/common/MapList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -118,7 +117,7 @@ class MapList

std::multimap<std::string, MapListNode*>::iterator outercurrent;

short iFilteredMapCount;
size_t iFilteredMapCount;

std::multimap<std::string, MapListNode*>::iterator * mlnFilteredMaps;
std::multimap<std::string, MapListNode*>::iterator * mlnMaps;
Expand Down
8 changes: 4 additions & 4 deletions src/leveleditor/leveleditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1088,15 +1088,15 @@ int editor_edit()
if (key == SDLK_PAGEUP) {
do {
maplist->prev(false);
} while (!maplist->GetValid());
} while (!maplist->isValid());

loadcurrentmap();
}

if (key == SDLK_PAGEDOWN) {
do {
maplist->next(false);
} while (!maplist->GetValid());
} while (!maplist->isValid());

loadcurrentmap();

Expand Down Expand Up @@ -1521,7 +1521,7 @@ int editor_edit()

}

if (maplist->GetValid()) {
if (maplist->isValid()) {
drawmap(false, TILESIZE);
} else {
SDL_FillRect(screen, NULL, 0x0);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/smw/GSMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ void MenuState::update()
//Write out all the map thumbnails for the map browser and filter editor
std::map<std::string, MapListNode*>::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);
Expand Down
2 changes: 1 addition & 1 deletion src/smw/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
}

Expand Down
4 changes: 2 additions & 2 deletions src/smw/ui/MI_MapBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3c0399c

Please sign in to comment.