+ const lisp::Lisp* images = reader.get_lisp("images");
+ if(images)
+ parse_images(*images);
+ reader.get("editor-images", editor_imagefile);
+}
+
+void
+Tile::parse_images(const lisp::Lisp& images_lisp)
+{
+ const lisp::Lisp* list = &images_lisp;
+ while(list) {
+ const lisp::Lisp* cur = list->get_car();
+ if(cur->get_type() == lisp::Lisp::TYPE_STRING) {
+ std::string file;
+ cur->get(file);
+ imagespecs.push_back(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) {
+ const lisp::Lisp* ptr = cur->get_cdr();
+
+ std::string file;
+ float x, y, w, h;
+ 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);
+ imagespecs.push_back(ImageSpec(file, Rect(x, y, x+w, y+h)));
+ } else {
+ std::cerr << "Expected string or list in images tag.\n";
+ continue;
+ }
+
+ list = list->get_cdr();
+ }
+}
+
+void
+Tile::load_images(const std::string& tilesetpath)
+{
+ 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
+ = get_resource_filename(tilesetpath + spec.file);
+ if(spec.rect.get_width() <= 0) {
+ surface = new Surface(file, true);
+ } 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(), true);
+ }
+ images.push_back(surface);
+ }
+ if(editor_imagefile != "") {
+ editor_image = new Surface(
+ get_resource_filename(
+ std::string("images/tilesets/") + editor_imagefile), true);
+ }
+}
+
+Surface*
+Tile::get_editor_image() const
+{
+ if(editor_image)
+ return editor_image;
+ if(images.size() > 0)
+ return images[0];
+
+ return 0;