void
Tile::load_images()
{
- const std::string& tiles_path = tileset->tiles_path;
-
- assert(images.size() == 0);
- for(std::vector<ImageSpec>::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,
- (int) spec.rect.p1.x,
- (int) spec.rect.p1.y,
- (int) spec.rect.get_width(),
- (int) spec.rect.get_height());
+ if(images.size() == 0 && imagespecs.size() != 0)
+ {
+ const std::string& tiles_path = tileset->tiles_path;
+
+ assert(images.size() == 0);
+ for(std::vector<ImageSpec>::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,
+ (int) spec.rect.p1.x,
+ (int) spec.rect.p1.y,
+ (int) spec.rect.get_width(),
+ (int) spec.rect.get_height());
+ }
+ images.push_back(surface);
}
- images.push_back(surface);
}
}
}
}
-void Tile::correct_attributes()
+void
+Tile::correct_attributes()
{
//Fix little oddities in attributes (not many, currently...)
if(!(attributes & SOLID) && (attributes & SLOPE || attributes & UNISOLID)) {
}
}
+void
+Tile::print_debug(int id) const
+{
+ log_debug << " Tile: id " << id << ", data " << getData() << ", attributes " << getAttributes() << ":" << std::endl;
+ for(std::vector<Tile::ImageSpec>::const_iterator im = imagespecs.begin(); im != imagespecs.end(); ++im)
+ {
+ log_debug << " Imagespec: file " << im->file << "; rect " << im->rect << std::endl;
+ }
+}
+
/* EOF */
float anim_fps;
public:
+ Tile(const TileSet* tileset);
+ Tile(const TileSet* tileset, std::vector<std::string> images, Rect rect,
+ uint32_t attributes, uint32_t data, float animfps);
~Tile();
+ /** load Surfaces, if not already loaded */
+ void load_images();
+
/** Draw a tile on the screen */
void draw(DrawingContext& context, const Vector& pos, int z_pos) const;
int getWidth() const
{
if(!images.size())
+ {
return 0;
- return (int) images[0]->get_width();
+ }
+ else
+ {
+ return (int) images[0]->get_width();
+ }
}
/// returns the height of the tiles in pixels
int getHeight() const
{
if(!images.size())
+ {
return 0;
- return (int) images[0]->get_height();
+ }
+ else
+ {
+ return (int) images[0]->get_height();
+ }
}
-protected:
- friend class TileSet;
- Tile(const TileSet *tileset);
- Tile(const TileSet *tileset, std::vector<std::string> images, Rect rect,
- uint32_t attributes = 0, uint32_t data = 0, float animfps = 1.0);
-
- void load_images();
-
/// parses the tile and returns it's id number
uint32_t parse(const Reader& reader);
+
+ void print_debug(int id) const;
+
+private:
void parse_images(const Reader& cur);
//Correct small oddities in attributes that naive people
log_debug << "Tileset in " << filename << std::endl;
for(int i = 0; i < int(tiles.size()); ++i)
{
- if(tiles[i] == 0)
- continue;
- Tile* t = tiles[i];
- log_debug << " Tile: id " << i << ", data " << t->data << ", attributes " << t->attributes << ":" << std::endl;
- for(std::vector<Tile::ImageSpec>::iterator im = t->imagespecs.begin(); im !=
- t->imagespecs.end(); ++im) {
- log_debug << " Imagespec: file " << im->file << "; rect " << im->rect << std::endl;
+ if(tiles[i] != 0)
+ {
+ tiles[i]->print_debug(i);
}
}
}