diff --git a/common/mapsystem/tile_sheet.cpp b/common/mapsystem/tile_sheet.cpp index 9608a5e..434c259 100644 --- a/common/mapsystem/tile_sheet.cpp +++ b/common/mapsystem/tile_sheet.cpp @@ -33,6 +33,10 @@ SDL_Surface* TileSheet::LoadSurface(std::string fname, Uint16 w, Uint16 h) { xCount = image.GetSurface()->w / w; yCount = image.GetSurface()->h / h; totalCount = xCount * yCount; + + //set begin & end (usually temporary) + begin = 0; + end = totalCount; } SDL_Surface* TileSheet::GetSurface() { diff --git a/common/mapsystem/tile_sheet.hpp b/common/mapsystem/tile_sheet.hpp index 1dfa94b..c872b5f 100644 --- a/common/mapsystem/tile_sheet.hpp +++ b/common/mapsystem/tile_sheet.hpp @@ -36,6 +36,7 @@ public: //these load/set functions need to be followed by bookkeeping code //w & h are the width & height of individual tiles + //TODO: rename these SDL_Surface* LoadSurface(std::string fname, Uint16 w, Uint16 h); SDL_Surface* GetSurface(); void FreeSurface(); diff --git a/common/mapsystem/tile_sheet_manager.cpp b/common/mapsystem/tile_sheet_manager.cpp index 7f0275b..07e3bc8 100644 --- a/common/mapsystem/tile_sheet_manager.cpp +++ b/common/mapsystem/tile_sheet_manager.cpp @@ -29,11 +29,16 @@ TileSheet* TileSheetManager::LoadSheet(std::string fname, Uint16 w, Uint16 h) { //get the key std::string key = truncatePath(fname); - //override what's already here - sheetMap.erase(key); + //don't override what's already here + if (sheetMap.find(key) != sheetMap.end()) { + throw(std::runtime_error("Cannot load duplicate tile sheets")); + } + //load & setup the sheet object sheetMap[key].LoadSurface(fname, w, h); + sheetMap[key].SetBegin(rangeEnd); rangeEnd += sheetMap[key].GetTotalCount(); + sheetMap[key].SetEnd(rangeEnd); } void TileSheetManager::DrawTo(SDL_Surface* const dest, int x, int y, int tileIndex) { diff --git a/common/mapsystem/tile_Sheet_manager.hpp b/common/mapsystem/tile_sheet_manager.hpp similarity index 95% rename from common/mapsystem/tile_Sheet_manager.hpp rename to common/mapsystem/tile_sheet_manager.hpp index 2fea37c..954da94 100644 --- a/common/mapsystem/tile_Sheet_manager.hpp +++ b/common/mapsystem/tile_sheet_manager.hpp @@ -44,6 +44,8 @@ public: int SetRangeEnd(int i) { return rangeEnd += i; } int GetRangeEnd() const { return rangeEnd; } + + std::map* GetSheetMap() { return &sheetMap; } private: std::map sheetMap; int rangeEnd = 0;