X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Ftrigger%2Fscripttrigger.cpp;h=439ec11308ee98035d34a4ed98da506fb72eda2e;hb=5240d812e12e6b53dc3c36bf313361d2d457382a;hp=07939924eb9e0d9e34c1590800f638a1d0ae64e2;hpb=267c14b530f86b58090e6e054a0a775076729061;p=supertux.git diff --git a/src/trigger/scripttrigger.cpp b/src/trigger/scripttrigger.cpp index 07939924e..439ec1130 100644 --- a/src/trigger/scripttrigger.cpp +++ b/src/trigger/scripttrigger.cpp @@ -1,95 +1,74 @@ -// $Id$ -// -// SuperTux -// Copyright (C) 2005 Matthias Braun -// -// 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 -#include -#include - -#include "scripttrigger.hpp" -#include "game_session.hpp" -#include "lisp/lisp.hpp" -#include "lisp/writer.hpp" -#include "object_factory.hpp" -#include "scripting/script_interpreter.hpp" -#include "sector.hpp" - -ScriptTrigger::ScriptTrigger(const lisp::Lisp& reader) -{ - bool must_activate = false; - - reader.get("x", bbox.p1.x); - reader.get("y", bbox.p1.y); - 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; - else - triggerevent = EVENT_TOUCH; -} - -ScriptTrigger::ScriptTrigger(const Vector& pos, const std::string& script) -{ - bbox.set_pos(pos); - bbox.set_size(32, 32); - this->script = script; - triggerevent = EVENT_TOUCH; -} - -ScriptTrigger::~ScriptTrigger() -{ -} - -void -ScriptTrigger::write(lisp::Writer& writer) -{ - writer.start_list("scripttrigger"); - - writer.write_float("x", bbox.p1.x); - writer.write_float("y", bbox.p1.y); - writer.write_float("width", bbox.get_width()); - writer.write_float("height", bbox.get_height()); - writer.write_string("script", script); - writer.write_bool("button", (triggerevent == EVENT_ACTIVATE) ? true : false); - - writer.end_list("scripttrigger"); -} - -void -ScriptTrigger::event(Player& , EventType type) -{ - if(type != triggerevent) - return; - - ScriptInterpreter::add_script_object(Sector::current(), "trigger - scritp", - script); -} - -IMPLEMENT_FACTORY(ScriptTrigger, "scripttrigger"); - +// SuperTux +// 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 as published by +// the Free Software Foundation, either version 3 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, see . + +#include +#include +#include + +#include "supertux/object_factory.hpp" +#include "supertux/sector.hpp" +#include "trigger/scripttrigger.hpp" +#include "util/reader.hpp" + +ScriptTrigger::ScriptTrigger(const Reader& reader) : + triggerevent(), + script() +{ + bool must_activate = false; + + reader.get("x", bbox.p1.x); + reader.get("y", bbox.p1.y); + 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; + else + triggerevent = EVENT_TOUCH; +} + +ScriptTrigger::ScriptTrigger(const Vector& pos, const std::string& script_) : + triggerevent(), + script() +{ + bbox.set_pos(pos); + bbox.set_size(32, 32); + this->script = script_; + triggerevent = EVENT_TOUCH; +} + +ScriptTrigger::~ScriptTrigger() +{ +} + +void +ScriptTrigger::event(Player& , EventType type) +{ + if(type != triggerevent) + return; + + std::istringstream stream(script); + Sector::current()->run_script(stream, "ScriptTrigger"); +} + +/* EOF */