Decoupled the TileSheet class from the Map class
I moved the rangeEnd variable into the TileSheet class, making it static. I also tweaked the return types for a few functions in Region, and removed the sheetIndex member from Tile.
This commit is contained in:
+4
-4
@@ -40,13 +40,13 @@ Region::Region(int _x, int _y, int _w, int _h):
|
||||
}
|
||||
}
|
||||
|
||||
bool Region::NewTileR(Tile const& tile) {
|
||||
int Region::NewTileR(Tile const& tile) {
|
||||
//return 1 for overwrite, 0 for insert
|
||||
if (!InBoundsR(tile.x, tile.y)) {
|
||||
throw(std::runtime_error("New tile location out of bounds"));
|
||||
}
|
||||
|
||||
bool ret = tiles.erase(tile);
|
||||
int ret = tiles.erase(tile);
|
||||
tiles.insert(tile);
|
||||
return ret;
|
||||
}
|
||||
@@ -77,10 +77,10 @@ Tile Region::GetTileR(int tx, int ty, int minDepth) {
|
||||
}
|
||||
|
||||
//a tileIndex of -1 is an error code, the rest is for show
|
||||
return {0,0,0,-1,-1,-1,-1};
|
||||
return {0,0,0,-1,-1,-1};
|
||||
}
|
||||
|
||||
bool Region::DeleteTileR(Tile const& tile) {
|
||||
int Region::DeleteTileR(Tile const& tile) {
|
||||
if (!InBoundsR(tile.x, tile.y)) {
|
||||
throw(std::runtime_error("Deleted tile location out of bounds"));
|
||||
}
|
||||
|
||||
+6
-8
@@ -38,8 +38,8 @@ public:
|
||||
~Region() = default;
|
||||
|
||||
//create and insert a new tile, overwriting an existing tile at that location
|
||||
bool NewTileR(Tile const& tile);
|
||||
bool NewTileA(Tile const& tile) {
|
||||
int NewTileR(Tile const& tile);
|
||||
int NewTileA(Tile const& tile) {
|
||||
//these can change, if the Tile class is changed
|
||||
return NewTileR({
|
||||
tile.x - x,
|
||||
@@ -47,7 +47,6 @@ public:
|
||||
tile.depth,
|
||||
tile.width,
|
||||
tile.height,
|
||||
tile.sheetIndex,
|
||||
tile.tileIndex
|
||||
});
|
||||
}
|
||||
@@ -59,17 +58,17 @@ public:
|
||||
}
|
||||
|
||||
//wrap the other delete functions
|
||||
bool DeleteTileR(int tx, int ty, int minDepth) {
|
||||
int DeleteTileR(int tx, int ty, int minDepth) {
|
||||
return DeleteTileR(GetTileR(tx, ty, minDepth));
|
||||
}
|
||||
bool DeleteTileA(int tx, int ty, int minDepth) {
|
||||
int DeleteTileA(int tx, int ty, int minDepth) {
|
||||
//explicitly skip one function call by adjusting from A to R
|
||||
return DeleteTileR(GetTileR(tx - x, ty - y, minDepth));
|
||||
}
|
||||
|
||||
//delete the specified tile
|
||||
bool DeleteTileR(Tile const& tile);
|
||||
bool DeleteTileA(Tile const& tile) {
|
||||
int DeleteTileR(Tile const& tile);
|
||||
int DeleteTileA(Tile const& tile) {
|
||||
//these can change, if the Tile class is changed
|
||||
return DeleteTileR({
|
||||
tile.x - x,
|
||||
@@ -77,7 +76,6 @@ public:
|
||||
tile.depth,
|
||||
tile.width,
|
||||
tile.height,
|
||||
tile.sheetIndex,
|
||||
tile.tileIndex
|
||||
});
|
||||
}
|
||||
|
||||
+2
-3
@@ -29,17 +29,16 @@ struct Tile {
|
||||
|
||||
//graphics
|
||||
int width, height;
|
||||
int sheetIndex, tileIndex;
|
||||
int tileIndex;
|
||||
|
||||
Tile() = default;
|
||||
Tile(int _x, int _y, int _depth, int _width, int _height, int _sheetIndex, int _tileIndex) {
|
||||
Tile(int _x, int _y, int _depth, int _width, int _height, int _tileIndex) {
|
||||
//The order of the arguments should be explicit
|
||||
x = _x;
|
||||
y = _y;
|
||||
depth = _depth;
|
||||
width = _width;
|
||||
height = _height;
|
||||
sheetIndex = _sheetIndex;
|
||||
tileIndex = _tileIndex;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
int TileSheet::rangeEnd = 0;
|
||||
|
||||
SDL_Surface* TileSheet::LoadSurface(std::string fname, Uint16 w, Uint16 h) {
|
||||
//setup the image
|
||||
image.LoadSurface(fname);
|
||||
|
||||
@@ -45,6 +45,9 @@ public:
|
||||
|
||||
bool InRange(int i) { return i >= begin && i < end; }
|
||||
|
||||
static int SetRangeEnd(int i) { return rangeEnd = i; }
|
||||
static int GetRangeEnd() { return rangeEnd; }
|
||||
|
||||
//accessors and mutators
|
||||
Image* GetImage() { return ℑ }
|
||||
|
||||
@@ -61,6 +64,8 @@ public:
|
||||
int GetBegin() const { return begin; }
|
||||
int GetEnd() const { return end; }
|
||||
private:
|
||||
static int rangeEnd;
|
||||
|
||||
Image image;
|
||||
std::string name;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user