From: Ingo Ruhnke Date: Sun, 6 Dec 2009 01:32:11 +0000 (+0000) Subject: Removed tile_path from tileset, instead give fully qualified path to the Tile X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ab14b1de1b9f6a5a691a70e618f590b048e3f2e0;p=supertux.git Removed tile_path from tileset, instead give fully qualified path to the Tile SVN-Revision: 6175 --- diff --git a/src/supertux/tile.cpp b/src/supertux/tile.cpp index 419de8e4f..516102057 100644 --- a/src/supertux/tile.cpp +++ b/src/supertux/tile.cpp @@ -58,18 +58,19 @@ Tile::load_images() { if(images.size() == 0 && imagespecs.size() != 0) { - const std::string& tiles_path = tileset.tiles_path; - assert(images.size() == 0); - for(std::vector::iterator i = imagespecs.begin(); i != - imagespecs.end(); ++i) { + for(std::vector::iterator i = imagespecs.begin(); i != imagespecs.end(); ++i) + { const ImageSpec& spec = *i; + Surface* surface; - std::string file = tiles_path + spec.file; - if(spec.rect.get_width() <= 0) { - surface = new Surface(file); - } else { - surface = new Surface(file, + if(spec.rect.get_width() <= 0) + { + surface = new Surface(spec.file); + } + else + { + surface = new Surface(spec.file, (int) spec.rect.p1.x, (int) spec.rect.p1.y, (int) spec.rect.get_width(), diff --git a/src/supertux/tile_set.cpp b/src/supertux/tile_set.cpp index 42a48ec87..475f4a441 100644 --- a/src/supertux/tile_set.cpp +++ b/src/supertux/tile_set.cpp @@ -20,7 +20,6 @@ TileSet::TileSet() : tiles(), - tiles_path(), tiles_loaded(false) { tiles.resize(1, 0); @@ -29,7 +28,6 @@ TileSet::TileSet() : TileSet::TileSet(const std::string& filename) : tiles(), - tiles_path(), tiles_loaded(true) { TileSetParser parser(*this, filename); diff --git a/src/supertux/tile_set.hpp b/src/supertux/tile_set.hpp index a5085c526..cc303d253 100644 --- a/src/supertux/tile_set.hpp +++ b/src/supertux/tile_set.hpp @@ -30,7 +30,6 @@ private: typedef std::vector Tiles; Tiles tiles; - std::string tiles_path; bool tiles_loaded; friend class TileManager; diff --git a/src/supertux/tile_set_parser.cpp b/src/supertux/tile_set_parser.cpp index 68c4d37a3..e3fe52e5f 100644 --- a/src/supertux/tile_set_parser.cpp +++ b/src/supertux/tile_set_parser.cpp @@ -27,14 +27,15 @@ TileSetParser::TileSetParser(TileSet& tileset, const std::string& filename) : m_tileset(tileset), - m_filename(filename) + m_filename(filename), + m_tiles_path() { } void TileSetParser::parse() { - m_tileset.tiles_path = FileSystem::dirname(m_filename); + m_tiles_path = FileSystem::dirname(m_filename); m_tileset.tiles.resize(1, 0); m_tileset.tiles[0] = new Tile(m_tileset); @@ -86,8 +87,16 @@ TileSetParser::parse() bool has_attributes = iter.lisp()->get("attributes", attributes); bool has_datas = iter.lisp()->get("datas", datas); - if(!iter.lisp()->get("image", images)) + if (!iter.lisp()->get("image", images)) + { iter.lisp()->get( "images", images); + } + + // make the image path absolute + for(std::vector::iterator i = images.begin(); i != images.end(); ++i) + { + *i = m_tiles_path + *i; + } iter.lisp()->get("width", width); iter.lisp()->get("height", height); @@ -199,12 +208,12 @@ TileSetParser::parse_tile(Tile& tile, const Reader& reader) #ifndef NDEBUG images = reader.get_lisp("editor-images"); if(images) - parse_images(tile, *images); + parse_tile_images(tile, *images); else { #endif images = reader.get_lisp("images"); if(images) - parse_images(tile, *images); + parse_tile_images(tile, *images); #ifndef NDEBUG } #endif @@ -215,31 +224,40 @@ TileSetParser::parse_tile(Tile& tile, const Reader& reader) } void -TileSetParser::parse_images(Tile& tile, const Reader& images_lisp) +TileSetParser::parse_tile_images(Tile& tile, const Reader& images_lisp) { const lisp::Lisp* list = &images_lisp; - while(list) { + while(list) + { const lisp::Lisp* cur = list->get_car(); - if(cur->get_type() == lisp::Lisp::TYPE_STRING) { + + if(cur->get_type() == lisp::Lisp::TYPE_STRING) + { std::string file; cur->get(file); - tile.imagespecs.push_back(Tile::ImageSpec(file, Rect(0, 0, 0, 0))); - } else if(cur->get_type() == lisp::Lisp::TYPE_CONS && - cur->get_car()->get_type() == lisp::Lisp::TYPE_SYMBOL && - cur->get_car()->get_symbol() == "region") { + tile.imagespecs.push_back(Tile::ImageSpec(m_tiles_path + file, Rect(0, 0, 0, 0))); + } + else if(cur->get_type() == lisp::Lisp::TYPE_CONS && + cur->get_car()->get_type() == lisp::Lisp::TYPE_SYMBOL && + cur->get_car()->get_symbol() == "region") + { const lisp::Lisp* ptr = cur->get_cdr(); std::string file; - float x = 0, y = 0, w = 0, h = 0; + float x = 0; + float y = 0; + float w = 0; + float h = 0; ptr->get_car()->get(file); ptr = ptr->get_cdr(); ptr->get_car()->get(x); ptr = ptr->get_cdr(); ptr->get_car()->get(y); ptr = ptr->get_cdr(); ptr->get_car()->get(w); ptr = ptr->get_cdr(); ptr->get_car()->get(h); - tile.imagespecs.push_back(Tile::ImageSpec(file, Rect(x, y, x+w, y+h))); - } else { + tile.imagespecs.push_back(Tile::ImageSpec(m_tiles_path + file, Rect(x, y, x+w, y+h))); + } + else + { log_warning << "Expected string or list in images tag" << std::endl; - continue; } list = list->get_cdr(); diff --git a/src/supertux/tile_set_parser.hpp b/src/supertux/tile_set_parser.hpp index 04adbda9b..88c7ea536 100644 --- a/src/supertux/tile_set_parser.hpp +++ b/src/supertux/tile_set_parser.hpp @@ -31,6 +31,7 @@ class TileSetParser private: TileSet& m_tileset; std::string m_filename; + std::string m_tiles_path; public: TileSetParser(TileSet& tileset, const std::string& filename); @@ -39,7 +40,7 @@ public: private: uint32_t parse_tile(Tile& tile, const Reader& reader); - void parse_images(Tile& tile, const Reader& cur); + void parse_tile_images(Tile& tile, const Reader& cur); private: TileSetParser(const TileSetParser&);