- removed next_tile2, which isn't needed
[supertux.git] / src / tile.cpp
1 //
2 // C++ Implementation: tile
3 //
4 // Description: 
5 //
6 //
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 #include "tile.h"
13 #include "assert.h"
14
15 TileManager* TileManager::instance_  = 0;
16
17 TileManager::TileManager()
18 {
19   std::string filename = datadir +  "images/tilesets/supertux.stgt"; 
20   load_tileset(filename);
21 }
22
23 void TileManager::load_tileset(std::string filename)
24 {
25   lisp_object_t* root_obj = lisp_read_from_file(filename);
26   
27   if (!root_obj)
28     st_abort("Couldn't load file", filename);
29
30   if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-tiles") == 0)
31     {
32       lisp_object_t* cur = lisp_cdr(root_obj);
33       int tileset_id = 0;
34
35       while(!lisp_nil_p(cur))
36         {
37           lisp_object_t* element = lisp_car(cur);
38
39           if (strcmp(lisp_symbol(lisp_car(element)), "tile") == 0)
40             {
41               Tile* tile = new Tile;
42               tile->id      = -1;
43               tile->solid   = false;
44               tile->brick   = false;
45               tile->ice     = false;      
46               tile->fullbox = false;          
47               tile->distro  = false;
48               tile->data    = 0;
49               tile->alpha   = 0;
50               tile->next_tile  = 0;
51               tile->anim_speed = 25;
52   
53               LispReader reader(lisp_cdr(element));
54               assert(reader.read_int("id",  &tile->id));
55               reader.read_bool("solid",     &tile->solid);
56               reader.read_bool("brick",     &tile->brick);
57               reader.read_bool("ice",       &tile->ice);           
58               reader.read_bool("fullbox",   &tile->fullbox);
59               reader.read_bool("distro",    &tile->distro);
60               reader.read_int("data",       (int*)&tile->data);
61               reader.read_int("alpha",      (int*)&tile->alpha);
62               reader.read_int("anim-speed", &tile->anim_speed);
63               reader.read_int("next-tile",  &tile->next_tile);
64               reader.read_string_vector("images",  &tile->filenames);
65
66               for(std::vector<std::string>::iterator it = tile->filenames.begin();
67                   it != tile->filenames.end();
68                   ++it)
69                 {
70                   texture_type cur_image;
71                   tile->images.push_back(cur_image);
72                   texture_load(&tile->images[tile->images.size()-1], 
73                                datadir +  "images/tilesets/" + (*it), 
74                                USE_ALPHA);
75                 }
76
77               if (tile->id + tileset_id >= int(tiles.size()))
78                 tiles.resize(tile->id + tileset_id+1);
79
80               tiles[tile->id + tileset_id] = tile;
81             }
82           else if (strcmp(lisp_symbol(lisp_car(element)), "tileset") == 0)
83             {
84               LispReader reader(lisp_cdr(element));
85               std::string filename;
86               reader.read_string("file",  &filename);
87               filename = datadir + "images/tilesets/" + filename; 
88               load_tileset(filename);
89             }
90           else if (strcmp(lisp_symbol(lisp_car(element)), "properties") == 0)
91             {
92               LispReader reader(lisp_cdr(element));
93               reader.read_int("id",  &tileset_id);
94               tileset_id *= 1000;
95             }
96           else
97             {
98               puts("Unhandled symbol");
99             }
100
101           cur = lisp_cdr(cur);
102         }
103     }
104   else
105     {
106       assert(0);
107     }
108 }
109
110 // EOF //
111