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
24 #include "video/drawing_context.h"
25 #include "app/setup.h"
26 #include "app/globals.h"
27 #include "utils/lispreader.h"
29 #include "tile_manager.h"
32 TileManager* TileManager::instance_ = 0;
34 TileManager::TileManager()
36 std::string filename = datadir + "/images/tilesets/supertux.stgt";
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)
48 if(filename == current_tileset)
52 for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i)
56 lisp_object_t* root_obj = lisp_read_from_file(filename);
59 Termination::abort("Couldn't load file", filename);
61 if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-tiles") != 0)
64 lisp_object_t* cur = lisp_cdr(root_obj);
67 while(!lisp_nil_p(cur)) {
68 lisp_object_t* element = lisp_car(cur);
70 if (strcmp(lisp_symbol(lisp_car(element)), "tile") == 0)
72 LispReader reader(lisp_cdr(element));
74 Tile* tile = new Tile;
77 while(tile->id >= tiles.size()) {
80 tiles[tile->id] = tile;
82 else if (strcmp(lisp_symbol(lisp_car(element)), "tileset") == 0)
84 LispReader reader(lisp_cdr(element));
86 reader.read_string("file", filename);
87 filename = datadir + "/images/tilesets/" + filename;
88 load_tileset(filename);
90 else if (strcmp(lisp_symbol(lisp_car(element)), "tilegroup") == 0)
93 LispReader reader(lisp_cdr(element));
94 reader.read_string("name", new_.name);
95 reader.read_int_vector("tiles", new_.tiles);
96 tilegroups.insert(new_).first;
98 else if (strcmp(lisp_symbol(lisp_car(element)), "properties") == 0)
100 LispReader reader(lisp_cdr(element));
101 reader.read_int("id", tileset_id);
106 std::cerr << "Unknown symbol: " <<
107 lisp_symbol(lisp_car(element)) << "\n";
114 current_tileset = filename;