// $Id$\r
-// \r
+//\r
// SuperTux\r
-// Copyright (C) 2005 Matthias Braun <matze@braunis.de>\r
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>\r
//\r
// This program is free software; you can redistribute it and/or\r
// modify it under the terms of the GNU General Public License\r
// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
// GNU General Public License for more details.\r
-// \r
+//\r
// You should have received a copy of the GNU General Public License\r
// along with this program; if not, write to the Free Software\r
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA\r
-// 02111-1307, USA.\r
-//\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+\r
#include <config.h>\r
\r
#include <sstream>\r
+#include <stdexcept>\r
+#include <memory>\r
\r
-#include "scripttrigger.h"\r
-#include "game_session.h"\r
-#include "lisp/lisp.h"\r
-#include "lisp/writer.h"\r
-#include "object_factory.h"\r
-#include "scripting/script_interpreter.h"\r
-#include "sector.h"\r
+#include "scripttrigger.hpp"\r
+#include "game_session.hpp"\r
+#include "lisp/lisp.hpp"\r
+#include "lisp/writer.hpp"\r
+#include "object_factory.hpp"\r
+#include "sector.hpp"\r
\r
ScriptTrigger::ScriptTrigger(const lisp::Lisp& reader)\r
{\r
- bool must_activate;\r
+ bool must_activate = false;\r
\r
reader.get("x", bbox.p1.x);\r
reader.get("y", bbox.p1.y);\r
- float w, h;\r
+ float w = 0, h = 0;\r
reader.get("width", w);\r
reader.get("height", h);\r
bbox.set_size(w, h);\r
reader.get("script", script);\r
reader.get("button", must_activate);\r
+ if(script == "") {\r
+ throw std::runtime_error("Need to specify a script for trigger object");\r
+ }\r
\r
if (must_activate)\r
triggerevent = EVENT_ACTIVATE;\r
void\r
ScriptTrigger::event(Player& , EventType type)\r
{\r
- if(type == triggerevent)\r
- {\r
- if (script != "")\r
- {\r
- try\r
- {\r
- ScriptInterpreter* interpreter \r
- = new ScriptInterpreter(GameSession::current()->get_working_directory());\r
- interpreter->register_sector(Sector::current());\r
- std::istringstream in(script);\r
- interpreter->load_script(in, "trigger-script");\r
- interpreter->start_script();\r
- Sector::current()->add_object(interpreter);\r
- }\r
- catch(std::exception& e)\r
- {\r
- std::cerr << "Couldn't execute trigger script: " << e.what() << "\n";\r
- }\r
- }\r
- else\r
- {\r
- std::cerr << "... and where's the trigger script I'm supposed to run?\n";\r
- }\r
- }\r
+ if(type != triggerevent)\r
+ return;\r
+\r
+ std::istringstream stream(script);\r
+ Sector::current()->run_script(stream, "ScriptTrigger");\r
}\r
\r
IMPLEMENT_FACTORY(ScriptTrigger, "scripttrigger");\r