From 0e0a2925fc673cde72378aefedbbaec5c1a8332f Mon Sep 17 00:00:00 2001 From: florianf Date: Sat, 30 Jan 2010 11:53:43 +0000 Subject: [PATCH] Bug 565: Support "editor-images" within "tiles". Resolves #565. git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6295 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/supertux/tile_set_parser.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/supertux/tile_set_parser.cpp b/src/supertux/tile_set_parser.cpp index a4cbd3d3f..42080a966 100644 --- a/src/supertux/tile_set_parser.cpp +++ b/src/supertux/tile_set_parser.cpp @@ -210,6 +210,8 @@ TileSetParser::parse_tiles(const Reader& reader) std::vector images; //List of frames that the editor tiles come in std::vector editor_images; + // Name used to report errors. + std::string image_name; // width and height of the image in tile units, this is used for two // purposes: @@ -228,15 +230,24 @@ TileSetParser::parse_tiles(const Reader& reader) reader.get("image", images) || reader.get("images", images); reader.get("editor-images", editor_images); + if (images.size() > 0) + image_name = images[0]; + else + image_name = "(no image)"; + reader.get("width", width); reader.get("height", height); float fps = 10; reader.get("fps", fps); - if (images.size() <= 0) + if (width <= 0) + { + throw std::runtime_error("Width is zero."); + } + else if (height <= 0) { - throw std::runtime_error("No images in tile."); + throw std::runtime_error("Height is zero."); } else if (fps < 0) { @@ -245,22 +256,23 @@ TileSetParser::parse_tiles(const Reader& reader) else if (ids.size() != width*height) { std::ostringstream err; - err << "Number of ids (" << ids.size() << ") and size of image (" << width*height - << ") mismatch for image '" << images[0] << "', but must be equal"; + err << "Number of ids (" << ids.size() << ") and " + "dimensions of image (" << width << "x" << height << " = " << width*height << ") " + "differ for image " << image_name; throw std::runtime_error(err.str()); } - else if (has_attributes && ids.size() != attributes.size()) + else if (has_attributes && (ids.size() != attributes.size())) { std::ostringstream err; err << "Number of ids (" << ids.size() << ") and attributes (" << attributes.size() - << ") mismatch for image '" << images[0] << "', but must be equal"; + << ") mismatch for image '" << image_name << "', but must be equal"; throw std::runtime_error(err.str()); } else if (has_datas && ids.size() != datas.size()) { std::ostringstream err; err << "Number of ids (" << ids.size() << ") and datas (" << datas.size() - << ") mismatch for image '" << images[0] << "', but must be equal"; + << ") mismatch for image '" << image_name << "', but must be equal"; throw std::runtime_error(err.str()); } else -- 2.11.0