diff --git a/src/sagotmx/tmx_struct.h b/src/sagotmx/tmx_struct.h index 4382843..a9a9052 100644 --- a/src/sagotmx/tmx_struct.h +++ b/src/sagotmx/tmx_struct.h @@ -576,13 +576,13 @@ inline bool tileInBound(const TileMap& tm, int x, int y) { * @param m The TileMap to look at. Required because the total size are located here * @param l The layer to look at * @param x The X coordinate - * @param y The Y coordiante + * @param y The Y coordinate * @return The gid number of the given tile. Provided that X and Y are within the map limits */ inline uint32_t getTileFromLayer(const TileMap& m, const TileLayer& l, int x, int y) { size_t tile_index = (m.height*y+x)*sizeof(uint32_t); if (tile_index > l.data.payload.size()-sizeof(uint32_t) ) { - throw SagoTiledException("ERROR: getTileFromLayer called with coordiantes out-of-bound. Called with (%d, %d). Limit (%d, %d). Or the layer is corrupt. " + throw SagoTiledException("ERROR: getTileFromLayer called with coordinates out-of-bound. Called with (%d, %d). Limit (%d, %d). Or the layer is corrupt. " "Reported number of tiles in layer: %ld", x, y, m.width-1, m.height-1, l.data.payload.size()/sizeof(uint32_t)); } const unsigned char *data = reinterpret_cast(l.data.payload.data()); @@ -597,7 +597,7 @@ inline void setTileOnLayerNumber(TileMap& m, int layer_number, int x, int y, uin size_t tile_index = (m.height*y+x)*sizeof(uint32_t); TileLayer& l = m.layers.at(layer_number); if (tile_index > l.data.payload.size()-sizeof(uint32_t) ) { - throw SagoTiledException("ERROR: setTileOnLayerNumber called with coordiantes out-of-bound. Called with (%d, %d). Limit (%d, %d). Or the layer is corrupt. " + throw SagoTiledException("ERROR: setTileOnLayerNumber called with coordinates out-of-bound. Called with (%d, %d). Limit (%d, %d). Or the layer is corrupt. " "Reported number of tiles in layer: %ld", x, y, m.width-1, m.height-1, l.data.payload.size()/sizeof(uint32_t)); } std::string& data = l.data.payload; diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 2670694..656ef3f 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp @@ -160,7 +160,7 @@ void Game::Draw(SDL_Renderer* target) { SDL_Texture* texture = globalData.spriteHolder->GetDataHolder().getTexturePtr("terrain"); DrawOuterBorder(target, texture, data->gameRegion.world.tm, data->topx, data->topy, data->gameRegion.outerTile); for (size_t i = 0; i < data->gameRegion.world.tm.layers.size(); ++i) { - DrawLayer(target, texture, data->gameRegion.world.tm, i, data->topx, data->topy); + DrawLayer(target, globalData.spriteHolder.get(), data->gameRegion.world.tm, i, data->topx, data->topy); } for (size_t i = 0; i < data->gameRegion.world.tm.object_groups.size(); ++i) { DrawOjbectGroup(target, data->gameRegion.world.tm, i, data->topx, data->topy); diff --git a/src/saland/GameDraw.cpp b/src/saland/GameDraw.cpp index ead0cf0..d3a7832 100644 --- a/src/saland/GameDraw.cpp +++ b/src/saland/GameDraw.cpp @@ -54,7 +54,7 @@ void DrawOuterBorder(SDL_Renderer* renderer, SDL_Texture* texture, const sago::t } } -void DrawLayer(SDL_Renderer* renderer, SDL_Texture* texture, const sago::tiled::TileMap& tm, size_t layer, int topx, int topy) { +void DrawLayer(SDL_Renderer* renderer, sago::SagoSpriteHolder* sHolder, const sago::tiled::TileMap& tm, size_t layer, int topx, int topy) { for (int i = 0; i < tm.height; ++i) { for (int j = 0; j < tm.width; ++j) { uint32_t gid = sago::tiled::getTileFromLayer(tm, tm.layers.at(layer), i, j); @@ -62,7 +62,11 @@ void DrawLayer(SDL_Renderer* renderer, SDL_Texture* texture, const sago::tiled:: continue; } SDL_Rect part{}; - getTextureLocationFromGid(tm, gid, nullptr, &part.x, &part.y, &part.w, &part.h); + std::string imageFile; + getTextureLocationFromGid(tm, gid, &imageFile, &part.x, &part.y, &part.w, &part.h); + imageFile = imageFile.substr(12); + imageFile = imageFile.substr(0,imageFile.length()-4); + SDL_Texture* texture = sHolder->GetDataHolder().getTexturePtr(imageFile); Draw(renderer, texture, 32 * i - topx, 32 * j - topy, part); } } diff --git a/src/saland/GameDraw.hpp b/src/saland/GameDraw.hpp index d0077bf..f594b24 100644 --- a/src/saland/GameDraw.hpp +++ b/src/saland/GameDraw.hpp @@ -30,7 +30,7 @@ https://github.com/sago007/saland #include "SDL.h" void DrawOuterBorder(SDL_Renderer* renderer, SDL_Texture* texture, const sago::tiled::TileMap& tm, int topx, int topy, uint32 outerTile); -void DrawLayer(SDL_Renderer* renderer, SDL_Texture* texture, const sago::tiled::TileMap& tm, size_t layer, int topx, int topy); +void DrawLayer(SDL_Renderer* renderer, sago::SagoSpriteHolder* sHolder, const sago::tiled::TileMap& tm, size_t layer, int topx, int topy); void DrawOjbectGroup(SDL_Renderer* renderer, const sago::tiled::TileMap& tm, size_t object_group, int topx, int topy); void DrawMiscEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const MiscItem *entity, float time, int offsetX, int offsetY, bool drawCollision);