diff options
Diffstat (limited to 'src/control')
-rw-r--r-- | src/control/ImageLoader.cpp (renamed from src/control/TileLoader.cpp) | 10 | ||||
-rw-r--r-- | src/control/ImageLoader.hpp (renamed from src/control/TileLoader.hpp) | 4 | ||||
-rw-r--r-- | src/control/MapContext.cpp | 12 | ||||
-rw-r--r-- | src/control/MapContext.hpp | 11 |
4 files changed, 22 insertions, 15 deletions
diff --git a/src/control/TileLoader.cpp b/src/control/ImageLoader.cpp index 476ffa4..2e78087 100644 --- a/src/control/TileLoader.cpp +++ b/src/control/ImageLoader.cpp @@ -24,7 +24,7 @@ */ -#include "TileLoader.hpp" +#include "ImageLoader.hpp" #include <SDL_image.h> @@ -33,19 +33,19 @@ namespace RPGEdit { namespace Control { -std::unique_ptr<SDL_Surface, TileLoader::SDL_Surface_deleter> TileLoader::loadTile(const std::string &name) { - std::string filename = "../resources/tile/" + name + ".png"; +std::unique_ptr<SDL_Surface, ImageLoader::SDL_Surface_deleter> ImageLoader::load(const std::string &name) { + std::string filename = "../resources/" + name + ".png"; SDL_Surface *surface = IMG_Load(filename.c_str()); return std::unique_ptr<SDL_Surface, SDL_Surface_deleter>(surface, SDL_Surface_deleter()); } -SDL_Surface * TileLoader::get(const std::string &name) { +SDL_Surface * ImageLoader::get(const std::string &name) { std::unique_ptr<SDL_Surface, SDL_Surface_deleter> &surface = tiles[name]; if (!surface) - surface = loadTile(name); + surface = load(name); if (!surface) tiles.erase(tiles.find(name)); diff --git a/src/control/TileLoader.hpp b/src/control/ImageLoader.hpp index 9fc9dfa..36ae7cd 100644 --- a/src/control/TileLoader.hpp +++ b/src/control/ImageLoader.hpp @@ -36,7 +36,7 @@ namespace RPGEdit { namespace Control { -class TileLoader { +class ImageLoader { private: class SDL_Surface_deleter { public: @@ -47,7 +47,7 @@ private: std::unordered_map<std::string, std::unique_ptr<SDL_Surface, SDL_Surface_deleter>> tiles; - std::unique_ptr<SDL_Surface, SDL_Surface_deleter> loadTile(const std::string &name); + std::unique_ptr<SDL_Surface, SDL_Surface_deleter> load(const std::string &name); public: SDL_Surface * get(const std::string &name); diff --git a/src/control/MapContext.cpp b/src/control/MapContext.cpp index 4d3a4d7..5fda337 100644 --- a/src/control/MapContext.cpp +++ b/src/control/MapContext.cpp @@ -31,14 +31,18 @@ namespace RPGEdit { namespace Control { -MapContext::MapContext(TileLoader *tileLoader0, const std::shared_ptr<const Model::Map> &map0) - : tileLoader(tileLoader0), map(map0) { +MapContext::MapContext(ImageLoader *imageLoader0, const std::shared_ptr<const Model::Map> &map0) + : imageLoader(imageLoader0), map(map0) { const std::vector<std::string> &tileset = map->getTileset(); tiles.resize(tileset.size()); - for (size_t i = 0; i < tileset.size(); i++) - tiles[i] = tileLoader->get(tileset[i]); + tiles[i] = imageLoader->get("tile/" + tileset[i]); + + std::deque<std::shared_ptr<Model::Entity>> &mapEntities = map->getEntities(); + + for (const std::shared_ptr<Model::Entity> &entity : mapEntities) + entities[entity->getName()] = imageLoader->get("entity/" + entity->getName()); } } diff --git a/src/control/MapContext.hpp b/src/control/MapContext.hpp index 703a582..a98d818 100644 --- a/src/control/MapContext.hpp +++ b/src/control/MapContext.hpp @@ -26,10 +26,11 @@ #pragma once -#include "TileLoader.hpp" +#include "ImageLoader.hpp" #include "../model/Map.hpp" #include "../view/MapView.hpp" +#include <map> #include <memory> @@ -39,16 +40,18 @@ namespace Control { class MapContext { private: - TileLoader *const tileLoader; + ImageLoader *const imageLoader; std::shared_ptr<const Model::Map> map; + std::vector<SDL_Surface *> tiles; + std::map<std::string, SDL_Surface *> entities; public: - MapContext(TileLoader *tileLoader0, const std::shared_ptr<const Model::Map> &map0); + MapContext(ImageLoader *imageLoader0, const std::shared_ptr<const Model::Map> &map0); std::shared_ptr<View::MapView> initView(const std::shared_ptr<View::Window> &window) { - return std::make_shared<View::MapView>(window, map, tiles); + return std::make_shared<View::MapView>(window, map, tiles, entities); } }; |