ScriptTrigger Class Reference

#include <scripttrigger.hpp>

Inherits TriggerBase.

List of all members.

Public Member Functions

 ScriptTrigger (const Reader &reader)
 ScriptTrigger (const Vector &pos, const std::string &script)
 ~ScriptTrigger ()
void write (Writer &writer)
void event (Player &player, EventType type)
 Receive trigger events.

Private Attributes

EventType triggerevent
std::string script


Detailed Description

Definition at line 22 of file scripttrigger.hpp.


Constructor & Destructor Documentation

ScriptTrigger::ScriptTrigger ( const Reader reader  ) 

Definition at line 26 of file scripttrigger.cpp.

References MovingObject::bbox, TriggerBase::EVENT_ACTIVATE, TriggerBase::EVENT_TOUCH, lisp::Lisp::get(), Rectf::p1, script, Rectf::set_size(), triggerevent, Vector::x, and Vector::y.

00026                                                  :
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 }

ScriptTrigger::ScriptTrigger ( const Vector pos,
const std::string &  script 
)

Definition at line 50 of file scripttrigger.cpp.

References MovingObject::bbox, TriggerBase::EVENT_TOUCH, Rectf::set_pos(), Rectf::set_size(), and triggerevent.

00050                                                                        :
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 }

ScriptTrigger::~ScriptTrigger (  ) 

Definition at line 60 of file scripttrigger.cpp.

00061 {
00062 }


Member Function Documentation

void ScriptTrigger::write ( Writer writer  ) 

void ScriptTrigger::event ( Player player,
EventType  type 
) [virtual]

Receive trigger events.

Implements TriggerBase.

Definition at line 65 of file scripttrigger.cpp.

References Sector::current(), Sector::run_script(), script, and triggerevent.

00066 {
00067   if(type != triggerevent)
00068     return;
00069 
00070   std::istringstream stream(script);
00071   Sector::current()->run_script(stream, "ScriptTrigger");
00072 }


Member Data Documentation

EventType ScriptTrigger::triggerevent [private]

Definition at line 33 of file scripttrigger.hpp.

Referenced by event(), and ScriptTrigger().

std::string ScriptTrigger::script [private]

Definition at line 34 of file scripttrigger.hpp.

Referenced by event(), and ScriptTrigger().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:34 2014 for SuperTux by  doxygen 1.5.1