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
23 #include "video/drawing_context.h"
24 #include "app/setup.h"
25 #include "app/globals.h"
26 #include "utils/lispreader.h"
28 #include "tile_manager.h"
31 TileManager* TileManager::instance_ = 0;
33 TileManager::TileManager()
35 std::string filename = datadir + "/images/tilesets/supertux.stgt";
36 load_tileset(filename);
39 TileManager::~TileManager()
41 for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i)
45 void TileManager::load_tileset(std::string filename)
47 if(filename == current_tileset)
51 for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i)
55 lisp_object_t* root_obj = lisp_read_from_file(filename);
58 Termination::abort("Couldn't load file", filename);
60 if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-tiles") != 0)
63 lisp_object_t* cur = lisp_cdr(root_obj);
66 while(!lisp_nil_p(cur)) {
67 lisp_object_t* element = lisp_car(cur);
69 if (strcmp(lisp_symbol(lisp_car(element)), "tile") == 0)
71 LispReader reader(lisp_cdr(element));
73 Tile* tile = new Tile;
76 while(tile->id >= tiles.size()) {
79 tiles[tile->id] = tile;
81 else if (strcmp(lisp_symbol(lisp_car(element)), "tileset") == 0)
83 LispReader reader(lisp_cdr(element));
85 reader.read_string("file", filename);
86 filename = datadir + "/images/tilesets/" + filename;
87 load_tileset(filename);
89 else if (strcmp(lisp_symbol(lisp_car(element)), "tilegroup") == 0)
92 LispReader reader(lisp_cdr(element));
93 reader.read_string("name", new_.name);
94 reader.read_int_vector("tiles", new_.tiles);
95 tilegroups.insert(new_).first;
97 else if (strcmp(lisp_symbol(lisp_car(element)), "properties") == 0)
99 LispReader reader(lisp_cdr(element));
100 reader.read_int("id", tileset_id);
105 std::cerr << "Unknown symbol: " <<
106 lisp_symbol(lisp_car(element)) << "\n";
113 current_tileset = filename;