00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <memory>
00018 #include <sstream>
00019 #include <stdexcept>
00020
00021 #include "supertux/object_factory.hpp"
00022 #include "supertux/sector.hpp"
00023 #include "trigger/scripttrigger.hpp"
00024 #include "util/reader.hpp"
00025
00026 ScriptTrigger::ScriptTrigger(const Reader& reader) :
00027 triggerevent(),
00028 script()
00029 {
00030 bool must_activate = false;
00031
00032 reader.get("x", bbox.p1.x);
00033 reader.get("y", bbox.p1.y);
00034 float w = 0, h = 0;
00035 reader.get("width", w);
00036 reader.get("height", h);
00037 bbox.set_size(w, h);
00038 reader.get("script", script);
00039 reader.get("button", must_activate);
00040 if(script == "") {
00041 throw std::runtime_error("Need to specify a script for trigger object");
00042 }
00043
00044 if (must_activate)
00045 triggerevent = EVENT_ACTIVATE;
00046 else
00047 triggerevent = EVENT_TOUCH;
00048 }
00049
00050 ScriptTrigger::ScriptTrigger(const Vector& pos, const std::string& script) :
00051 triggerevent(),
00052 script()
00053 {
00054 bbox.set_pos(pos);
00055 bbox.set_size(32, 32);
00056 this->script = script;
00057 triggerevent = EVENT_TOUCH;
00058 }
00059
00060 ScriptTrigger::~ScriptTrigger()
00061 {
00062 }
00063
00064 void
00065 ScriptTrigger::event(Player& , EventType type)
00066 {
00067 if(type != triggerevent)
00068 return;
00069
00070 std::istringstream stream(script);
00071 Sector::current()->run_script(stream, "ScriptTrigger");
00072 }
00073
00074