4 // Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 #include "video/drawing_context.h"
26 #include "app/setup.h"
27 #include "app/globals.h"
28 #include "lisp/lisp.h"
29 #include "lisp/parser.h"
30 #include "lisp/list_iterator.h"
32 #include "tile_manager.h"
33 #include "resources.h"
35 TileManager::TileManager(const std::string& filename)
37 load_tileset(filename);
40 TileManager::~TileManager()
42 for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i)
46 void TileManager::load_tileset(std::string filename)
49 for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i)
53 std::string::size_type t = filename.rfind('/');
54 if(t == std::string::npos) {
57 tiles_path = filename.substr(0, t+1);
61 std::auto_ptr<lisp::Lisp> root (parser.parse(
62 get_resource_filename(filename)));
64 const lisp::Lisp* tiles_lisp = root->get_lisp("supertux-tiles");
66 throw std::runtime_error("file is not a supertux tiles file.");
68 lisp::ListIterator iter(tiles_lisp);
70 if(iter.item() == "tile") {
71 Tile* tile = new Tile();
72 tile->parse(*(iter.lisp()));
73 while(tile->id >= tiles.size()) {
76 tiles[tile->id] = tile;
77 } else if(iter.item() == "tilegroup") {
79 const lisp::Lisp* tilegroup_lisp = iter.lisp();
80 tilegroup_lisp->get("name", tilegroup.name);
81 tilegroup_lisp->get_vector("tiles", tilegroup.tiles);
82 tilegroups.insert(tilegroup);
83 } else if(iter.item() == "properties") {
86 std::cerr << "Unknown symbol '" << iter.item() << "'.\n";