- added translation table for the old format
[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               int id = 0;
42               std::vector<std::string> filenames;
43
44               Tile* tile = new Tile;             
45               tile->solid = false;
46               tile->brick = false;
47               tile->ice = false;          
48               tile->fullbox = false;          
49               tile->alpha = 0;
50               tile->distro = 0;
51               tile->data  = 0;
52               tile->anim_speed = 25;
53   
54               LispReader reader(lisp_cdr(element));
55               reader.read_int("id",  &id);
56               reader.read_bool("solid", &tile->solid);
57               reader.read_bool("brick", &tile->brick);
58               reader.read_bool("ice", &tile->ice);         
59               reader.read_bool("fullbox", &tile->fullbox);
60               reader.read_bool("distro", &tile->distro);
61               reader.read_int("data",  (int*)&tile->data);
62               reader.read_int("alpha",  (int*)&tile->alpha);
63               reader.read_int("anim-speed",  &tile->anim_speed);
64               reader.read_string_vector("images",  &filenames);
65
66               for(std::vector<std::string>::iterator it = filenames.begin(); it != filenames.end(); ++it)
67                 {
68                   texture_type cur_image;
69                   tile->images.push_back(cur_image);
70                   texture_load(&tile->images[tile->images.size()-1], 
71                                datadir +  "images/tilesets/" + (*it), 
72                                USE_ALPHA);
73                 }
74
75               if (id+tileset_id >= int(tiles.size()))
76                 tiles.resize(id+tileset_id+1);
77
78               tiles[id+tileset_id] = tile;
79             }
80           else if (strcmp(lisp_symbol(lisp_car(element)), "tileset") == 0)
81             {
82               LispReader reader(lisp_cdr(element));
83               std::string filename;
84               reader.read_string("file",  &filename);
85               filename = datadir + "images/tilesets/" + filename; 
86               load_tileset(filename);
87             }
88           else if (strcmp(lisp_symbol(lisp_car(element)), "properties") == 0)
89             {
90               LispReader reader(lisp_cdr(element));
91               reader.read_int("id",  &tileset_id);
92               tileset_id *= 1000;
93             }
94           else
95             {
96               puts("Unhandled symbol");
97             }
98
99           cur = lisp_cdr(cur);
100         }
101     }
102   else
103     {
104       assert(0);
105     }
106 }
107
108 // EOF //
109