// $Id: button_factory.cpp 3059 2007-09-02 03:48:52Z grumbel $ // // Pingus - A free Lemmings clone // Copyright (C) 2000 Ingo Ruhnke // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include "../file_reader.hpp" #include "../pingus_error.hpp" #include "button_factory.hpp" #include "buttons/double_button.hpp" #include "buttons/joystick_button.hpp" #include "buttons/key_button.hpp" #include "buttons/mouse_button.hpp" #include "buttons/multiple_button.hpp" #include "buttons/triple_button.hpp" namespace Input { using namespace Buttons; Button* ButtonFactory::create(FileReader reader) { if (reader.get_name() == "double-button") return double_button(reader); else if (reader.get_name() == "joystick-button") return joystick_button(reader); else if (reader.get_name() == "key-button") return key_button(reader); else if (reader.get_name() == "mouse-button") return mouse_button(reader); else if (reader.get_name() == "multiple-button") return multiple_button(reader); else if (reader.get_name() == "triple-button") return triple_button(reader); else PingusError::raise(std::string("Unknown button type: ") + reader.get_name()); return 0; // never reached } Button* ButtonFactory::double_button(FileReader reader) { const std::vector& sections = reader.get_sections(); if (sections.size() != 2) PingusError::raise("DoubleButton isn't