Slight refactoring
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
SDL_Surface* TileSheet::LoadSurface(std::string fname, Uint16 w, Uint16 h) {
|
||||
void TileSheet::Load(std::string fname, Uint16 w, Uint16 h) {
|
||||
//setup the image
|
||||
image.LoadSurface(fname);
|
||||
image.SetClipW(w);
|
||||
@@ -39,11 +39,7 @@ SDL_Surface* TileSheet::LoadSurface(std::string fname, Uint16 w, Uint16 h) {
|
||||
end = totalCount;
|
||||
}
|
||||
|
||||
SDL_Surface* TileSheet::GetSurface() {
|
||||
return image.GetSurface();
|
||||
}
|
||||
|
||||
void TileSheet::FreeSurface() {
|
||||
void TileSheet::Unload() {
|
||||
image.FreeSurface();
|
||||
totalCount = xCount = yCount = 0;
|
||||
begin = end = -1;
|
||||
|
||||
@@ -37,9 +37,8 @@ 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();
|
||||
void Load(std::string fname, Uint16 w, Uint16 h);
|
||||
void Unload();
|
||||
|
||||
void DrawTo(SDL_Surface* const dest, int x, int y, int tileIndex);
|
||||
|
||||
@@ -48,6 +47,9 @@ public:
|
||||
//accessors and mutators
|
||||
Image* GetImage() { return ℑ }
|
||||
|
||||
int GetTileW() const { return image.GetClipW(); }
|
||||
int GetTileH() const { return image.GetClipH(); }
|
||||
|
||||
int GetTotalCount() const { return totalCount; }
|
||||
int GetXCount() const { return xCount; }
|
||||
int GetYCount() const { return yCount; }
|
||||
|
||||
@@ -35,10 +35,30 @@ TileSheet* TileSheetManager::LoadSheet(std::string fname, Uint16 w, Uint16 h) {
|
||||
}
|
||||
|
||||
//load & setup the sheet object
|
||||
sheetMap[key].LoadSurface(fname, w, h);
|
||||
sheetMap[key].Load(fname, w, h);
|
||||
sheetMap[key].SetBegin(rangeEnd);
|
||||
rangeEnd += sheetMap[key].GetTotalCount();
|
||||
sheetMap[key].SetEnd(rangeEnd);
|
||||
|
||||
//you can modify the object, say, during the save & load routines...
|
||||
return &sheetMap[key];
|
||||
}
|
||||
|
||||
TileSheet* TileSheetManager::GetSheet(std::string name) {
|
||||
return &sheetMap.at(name);
|
||||
}
|
||||
|
||||
TileSheet* TileSheetManager::GetSheetByIndex(int tileIndex) {
|
||||
for (auto& it : sheetMap) {
|
||||
if (it.second.InRange(tileIndex)) {
|
||||
return &it.second;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TileSheetManager::UnloadSheet(std::string name) {
|
||||
sheetMap.erase(name);
|
||||
}
|
||||
|
||||
void TileSheetManager::DrawTo(SDL_Surface* const dest, int x, int y, int tileIndex) {
|
||||
|
||||
@@ -33,12 +33,9 @@ public:
|
||||
~TileSheetManager() = default;
|
||||
|
||||
TileSheet* LoadSheet(std::string fname, Uint16 w, Uint16 h);
|
||||
TileSheet* GetSheet(std::string name) {
|
||||
return &sheetMap.at(name);
|
||||
}
|
||||
void UnloadSheet(std::string name) {
|
||||
sheetMap.erase(name);
|
||||
}
|
||||
TileSheet* GetSheet(std::string name);
|
||||
TileSheet* GetSheetByIndex(int tileIndex);
|
||||
void UnloadSheet(std::string name);
|
||||
|
||||
void DrawTo(SDL_Surface* const, int x, int y, int tileIndex);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user