From 9c91e9d5fd43406f940cbe345dc6ccc58378b6ec Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 3 Oct 2013 21:29:11 +1000 Subject: [PATCH] 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. --- editor/region.cpp | 8 ++++---- editor/region.hpp | 14 ++++++-------- editor/tile.hpp | 5 ++--- editor/tile_sheet.cpp | 2 ++ editor/tile_sheet.hpp | 5 +++++ 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/editor/region.cpp b/editor/region.cpp index 7f11de3..f5bec4d 100644 --- a/editor/region.cpp +++ b/editor/region.cpp @@ -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")); } diff --git a/editor/region.hpp b/editor/region.hpp index f03faff..eac450f 100644 --- a/editor/region.hpp +++ b/editor/region.hpp @@ -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 }); } diff --git a/editor/tile.hpp b/editor/tile.hpp index 0a2de58..6e74942 100644 --- a/editor/tile.hpp +++ b/editor/tile.hpp @@ -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; } }; diff --git a/editor/tile_sheet.cpp b/editor/tile_sheet.cpp index da5e377..46cf8a3 100644 --- a/editor/tile_sheet.cpp +++ b/editor/tile_sheet.cpp @@ -25,6 +25,8 @@ #include +int TileSheet::rangeEnd = 0; + SDL_Surface* TileSheet::LoadSurface(std::string fname, Uint16 w, Uint16 h) { //setup the image image.LoadSurface(fname); diff --git a/editor/tile_sheet.hpp b/editor/tile_sheet.hpp index 47d777c..bcb47f1 100644 --- a/editor/tile_sheet.hpp +++ b/editor/tile_sheet.hpp @@ -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;