2 // Copyright (C) 2004 Ricardo Cruz <rick2@aeiou.pt>
3 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "lisp/parser.hpp"
22 #include "math/vector.hpp"
23 #include "util/reader.hpp"
24 #include "supertux/object_factory.hpp"
26 GameObject* create_object(const std::string& name, const Reader& reader)
28 Factory::Factories::iterator i = Factory::get_factories().find(name);
29 if(i == Factory::get_factories().end()) {
30 std::stringstream msg;
31 msg << "No factory for object '" << name << "' found.";
32 throw std::runtime_error(msg.str());
35 return i->second->create_object(reader);
38 GameObject* create_object(const std::string& name, const Vector& pos, const Direction dir)
40 std::stringstream lisptext;
41 lisptext << "((x " << pos.x << ")"
42 << " (y " << pos.y << ")";
44 lisptext << " (direction " << dir << "))";
47 const lisp::Lisp* lisp = parser.parse(lisptext, "create_object");
48 GameObject* object = create_object(name, *(lisp->get_car()));