// SuperTux
// Copyright (C) 2008 Matthias Braun <matze@braunis.de>
-// Ingo Ruhnke <grumbel@gmx.de>
+// Ingo Ruhnke <grumbel@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
m_tileset(tileset),
m_filename(filename),
m_tiles_path()
-{
+{
}
void
m_tiles_path = FileSystem::dirname(m_filename);
m_tileset.tiles.resize(1, 0);
- m_tileset.tiles[0] = new Tile(m_tileset);
+ m_tileset.tiles[0] = new Tile();
lisp::Parser parser;
const lisp::Lisp* root = parser.parse(m_filename);
throw std::runtime_error("file is not a supertux tiles file.");
lisp::ListIterator iter(tiles_lisp);
- while(iter.next())
+ while(iter.next())
{
- if (iter.item() == "tile")
+ if (iter.item() == "tile")
{
parse_tile(*iter.lisp());
- }
- else if (iter.item() == "tilegroup")
+ }
+ else if (iter.item() == "tilegroup")
{
/* tilegroups are only interesting for the editor */
- }
- else if (iter.item() == "tiles")
+ }
+ else if (iter.item() == "tiles")
{
parse_tiles(*iter.lisp());
}
- else
+ else
{
log_warning << "Unknown symbol '" << iter.item() << "' in tileset file" << std::endl;
}
TileSetParser::parse_tile(const Reader& reader)
{
uint32_t id;
- if (!reader.get("id", id))
+ if (!reader.get("id", id))
{
throw std::runtime_error("Missing tile-id.");
}
uint32_t attributes = 0;
- uint32_t data = 0;
- std::vector<Tile::ImageSpec> imagespecs;
-
- float anim_fps = 10;
bool value = false;
if(reader.get("solid", value) && value)
if(reader.get("goal", value) && value)
attributes |= Tile::GOAL;
+ uint32_t data = 0;
+
if(reader.get("north", value) && value)
data |= Tile::WORLDMAP_NORTH;
if(reader.get("south", value) && value)
data |= Tile::WORLDMAP_STOP;
reader.get("data", data);
- reader.get("anim-fps", anim_fps);
- uint32_t throwaway_data;
- if(reader.get("slope-type", throwaway_data))
+ float fps = 10;
+ reader.get("fps", fps);
+
+ if(reader.get("slope-type", data))
{
attributes |= Tile::SOLID | Tile::SLOPE;
}
+ std::vector<Tile::ImageSpec> editor_imagespecs;
+ const lisp::Lisp* editor_images;
+ editor_images = reader.get_lisp("editor-images");
+ if(editor_images)
+ editor_imagespecs = parse_tile_images(*editor_images);
+
+ std::vector<Tile::ImageSpec> imagespecs;
const lisp::Lisp* images;
-#ifndef NDEBUG
- images = reader.get_lisp("editor-images");
+ images = reader.get_lisp("images");
if(images)
- imagespecs = parse_tile_images(*images);
- else {
-#endif
- images = reader.get_lisp("images");
- if(images)
imagespecs = parse_tile_images(*images);
-#ifndef NDEBUG
- }
-#endif
- std::auto_ptr<Tile> tile(new Tile(m_tileset, imagespecs, attributes, data, anim_fps));
+ std::unique_ptr<Tile> tile(new Tile(imagespecs, editor_imagespecs, attributes, data, fps));
if (id >= m_tileset.tiles.size())
m_tileset.tiles.resize(id+1, 0);
- if (m_tileset.tiles[id] != 0)
+ if (m_tileset.tiles[id] != 0)
{
log_warning << "Tile with ID " << id << " redefined" << std::endl;
- }
- else
+ }
+ else
{
m_tileset.tiles[id] = tile.release();
}
std::vector<Tile::ImageSpec> imagespecs;
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);
- imagespecs.push_back(Tile::ImageSpec(m_tiles_path + file, Rect(0, 0, 0, 0)));
+ imagespecs.push_back(Tile::ImageSpec(m_tiles_path + file, Rectf(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")
+ cur->get_car()->get_symbol() == "region")
{
const lisp::Lisp* ptr = cur->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);
- imagespecs.push_back(Tile::ImageSpec(m_tiles_path + file, Rect(x, y, x+w, y+h)));
- }
- else
+ imagespecs.push_back(Tile::ImageSpec(m_tiles_path + file, Rectf(x, y, x+w, y+h)));
+ }
+ else
{
log_warning << "Expected string or list in images tag" << std::endl;
}
std::vector<uint32_t> datas;
//List of frames that the tiles come in
std::vector<std::string> images;
+ //List of frames that the editor tiles come in
+ std::vector<std::string> 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:
bool has_attributes = reader.get("attributes", attributes);
bool has_datas = reader.get("datas", datas);
- if (!reader.get("image", images))
- {
- reader.get("images", images);
- }
+ 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 animfps = 10;
- reader.get("anim-fps", animfps);
+ float fps = 10;
+ reader.get("fps", fps);
- if (images.size() <= 0)
+ if (width == 0)
{
- throw std::runtime_error("No images in tile.");
+ throw std::runtime_error("Width is zero.");
}
- else if (animfps < 0)
+ else if (height == 0)
+ {
+ throw std::runtime_error("Height is zero.");
+ }
+ else if (fps < 0)
{
throw std::runtime_error("Negative fps.");
}
- else if (ids.size() != width*height)
+ 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())
- {
+ 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
{
- for(std::vector<uint32_t>::size_type i = 0; i < ids.size() && i < width*height; ++i)
+ for(std::vector<uint32_t>::size_type i = 0; i < ids.size() && i < width*height; ++i)
{
if (ids[i] != 0)
{
int y = 32*(i / width);
std::vector<Tile::ImageSpec> imagespecs;
- for(std::vector<std::string>::const_iterator j = images.begin(); j != images.end(); ++j)
+ for(std::vector<std::string>::const_iterator j = images.begin(); j != images.end(); ++j)
+ {
+ imagespecs.push_back(Tile::ImageSpec(m_tiles_path + *j, Rectf(x, y, x + 32, y + 32)));
+ }
+
+ std::vector<Tile::ImageSpec> editor_imagespecs;
+ for(std::vector<std::string>::const_iterator j = editor_images.begin(); j != editor_images.end(); ++j)
{
- imagespecs.push_back(Tile::ImageSpec(m_tiles_path + *j, Rect(x, y, x + 32, y + 32)));
+ editor_imagespecs.push_back(Tile::ImageSpec(m_tiles_path + *j, Rectf(x, y, x + 32, y + 32)));
}
- std::auto_ptr<Tile> tile(new Tile(m_tileset, imagespecs,
- (has_attributes ? attributes[i] : 0), (has_datas ? datas[i] : 0), animfps));
+ std::unique_ptr<Tile> tile(new Tile(imagespecs, editor_imagespecs,
+ (has_attributes ? attributes[i] : 0), (has_datas ? datas[i] : 0), fps));
if (m_tileset.tiles[ids[i]] == 0) {
m_tileset.tiles[ids[i]] = tile.release();
} else {
}
}
}
- }
+ }
}
/* EOF */