4 // Copyright (C) 2004 Ingo Ruhnke <grumbel@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 02111-1307, USA.
25 #include "utils/lispreader.h"
26 #include "sprite_manager.h"
27 #include "sprite_data.h"
33 SpriteManager::SpriteManager(const std::string& filename)
35 load_resfile(filename);
38 SpriteManager::~SpriteManager()
40 for(Sprites::iterator i = sprites.begin(); i != sprites.end(); ++i) {
46 SpriteManager::load_resfile(const std::string& filename)
48 lisp_object_t* root_obj = lisp_read_from_file(filename);
51 std::cout << "SpriteManager: Couldn't load: " << filename << std::endl;
55 lisp_object_t* cur = root_obj;
57 if (strcmp(lisp_symbol(lisp_car(cur)), "supertux-resources") != 0)
62 lisp_object_t* el = lisp_car(cur);
64 if (strcmp(lisp_symbol(lisp_car(el)), "sprite") == 0) {
65 SpriteData* spritedata = new SpriteData(lisp_cdr(el));
67 Sprites::iterator i = sprites.find(spritedata->get_name());
68 if (i == sprites.end()) {
69 sprites[spritedata->get_name()] = spritedata;
72 i->second = spritedata;
73 std::cout << "Warning: dulpicate entry: '" << spritedata->get_name()
74 << "' in spritefile." << std::endl;
77 std::cout << "SpriteManager: Unknown tag in spritefile.\n";
87 SpriteManager::create(const std::string& name)
89 Sprites::iterator i = sprites.find(name);
90 if(i == sprites.end()) {
91 std::stringstream msg;
92 msg << "Sprite '" << name << "' not found.";
93 throw std::runtime_error(msg.str());
95 return new Sprite(*i->second);