removed old data and contrib, new files will follow
[supertux.git] / src / tile_manager.h
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
5 //
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.
10 //
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.
15 // 
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
19 //  02111-1307, USA.
20
21 #ifndef HEADER_TILE_MANAGER_HXX
22 #define HEADER_TILE_MANAGER_HXX
23
24 #include <set>
25 #include <vector>
26 #include <string>
27 #include <map>
28 #include <stdint.h>
29 #include <assert.h>
30 #include "tile.h"
31
32 struct TileGroup
33 {
34   friend bool operator<(const TileGroup& lhs, const TileGroup& rhs)
35   { return lhs.name < rhs.name; };
36   friend bool operator>(const TileGroup& lhs, const TileGroup& rhs)
37   { return lhs.name > rhs.name; };
38
39   std::string name;
40   std::vector<int> tiles;
41 };
42
43 class TileManager
44 {
45 private:
46   typedef std::vector<Tile*> Tiles;
47   Tiles tiles;
48
49   static TileManager* instance_ ;
50   std::set<TileGroup> tilegroups;
51
52   std::string tiles_path;
53   
54   void load_tileset(std::string filename);
55
56 public:
57   TileManager(const std::string& filename);
58   ~TileManager();
59
60   const std::set<TileGroup>& get_tilegroups() const
61   {
62     return tilegroups;
63   }
64
65   const Tile* get(uint32_t id) const
66   {
67     //FIXME: Commenting out tiles in supertux.stgt makes tiles.size() fail - it's being set to the first tile commented out.
68     assert(id < tiles.size());
69     Tile* tile = tiles[id];
70     if(!tile) {
71       std::cout << "TileManager: Invalid tile: " << id << std::endl;
72       return tiles[0];
73     }
74
75     if(tile->images.size() == 0 && tile->imagespecs.size() != 0)
76       tile->load_images(tiles_path);
77     
78     return tile;
79   }
80
81   uint32_t get_max_tileid() const
82   {
83     return tiles.size();
84   }
85
86   int get_default_width() const
87   {
88     return 32;
89   }
90
91   int get_default_height() const
92   {
93     return 32;
94   }
95 };
96
97 #endif