X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Ftrigger%2Fscripttrigger.cpp;h=cc330a237872ecb31b1b9fe59906fb3a8eddadf9;hb=3e89eb527d5f3bca2cb8cd219784048764a148f5;hp=5c8ecd70b64745b4edf4385ad4ba3b66193606f8;hpb=f9c3f3511d175a61d912be13297f6dd96dbbfe35;p=supertux.git diff --git a/src/trigger/scripttrigger.cpp b/src/trigger/scripttrigger.cpp index 5c8ecd70b..cc330a237 100644 --- a/src/trigger/scripttrigger.cpp +++ b/src/trigger/scripttrigger.cpp @@ -1,7 +1,7 @@ // $Id$ -// +// // SuperTux -// Copyright (C) 2005 Matthias Braun +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -12,36 +12,39 @@ // 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. -// +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + #include #include +#include +#include -#include "scripttrigger.h" -#include "game_session.h" -#include "lisp/lisp.h" -#include "lisp/writer.h" -#include "object_factory.h" -#include "scripting/script_interpreter.h" -#include "sector.h" +#include "scripttrigger.hpp" +#include "game_session.hpp" +#include "lisp/lisp.hpp" +#include "lisp/writer.hpp" +#include "object_factory.hpp" +#include "sector.hpp" ScriptTrigger::ScriptTrigger(const lisp::Lisp& reader) { - bool must_activate; + bool must_activate = false; reader.get("x", bbox.p1.x); reader.get("y", bbox.p1.y); - float w, h; + float w = 0, h = 0; reader.get("width", w); reader.get("height", h); bbox.set_size(w, h); reader.get("script", script); reader.get("button", must_activate); + if(script == "") { + throw std::runtime_error("Need to specify a script for trigger object"); + } if (must_activate) triggerevent = EVENT_ACTIVATE; @@ -79,30 +82,11 @@ ScriptTrigger::write(lisp::Writer& writer) void ScriptTrigger::event(Player& , EventType type) { - if(type == triggerevent) - { - if (script != "") - { - try - { - ScriptInterpreter* interpreter - = new ScriptInterpreter(GameSession::current()->get_working_directory()); - interpreter->register_sector(Sector::current()); - std::istringstream in(script); - interpreter->load_script(in, "trigger-script"); - interpreter->start_script(); - Sector::current()->add_object(interpreter); - } - catch(std::exception& e) - { - std::cerr << "Couldn't execute trigger script: " << e.what() << "\n"; - } - } - else - { - std::cerr << "Couldn't find trigger script.\n"; - } - } + if(type != triggerevent) + return; + + std::istringstream stream(script); + Sector::current()->run_script(stream, "ScriptTrigger"); } IMPLEMENT_FACTORY(ScriptTrigger, "scripttrigger");