1
1
forked from 0ad/0ad
0ad/source/scripting/GameEvents.h
janwas a69ac0dee9 - fix w4 warnings
- add convenience macros for config_db(CFG_GET_SYS_VAL)
- VFSUtil::EnumDirEnts now uses flags instead of bool recursive
- UNUSED() for params, UNUSED2 (<- need better name) for variables
- config.h defines must be tested with #if (always defined) -> allows
detecting misspellings thanks to compiler warnings
- replace debug_assert(0) with debug_warn (its sole purpose)
- replace ScriptingHost::ValueToInt et al with ToPrimitive
- use nommgr.h to disable both mmgr and VC debug heap

This was SVN commit r2585.
2005-08-09 15:55:44 +00:00

81 lines
2.3 KiB
C++

// GameEvents.h
// Defines a singleton class, g_JSGameEvents that fires certain events on
// request (Fire*). This serves to notify scripts of important game events.
// The CScriptEvent-derived events are declared here as well,
// with their type set to one of EventTypes.h's EEventType.
#ifndef GAME_EVENTS_INCLUDED
#define GAME_EVENTS_INCLUDED
#include "DOMEvent.h"
#include "EventTypes.h"
#include "ps/Singleton.h"
class CGameEvents : public IEventTarget, public Singleton<CGameEvents>
{
// Game events don't really run on an object
JSObject* GetScriptExecContext( IEventTarget* UNUSED(target) ) { return( g_ScriptingHost.GetGlobalObject() ); }
// Some events
class CEventSelectionChanged : public CScriptEvent
{
bool m_CausedByPlayer;
public:
CEventSelectionChanged(bool CausedByPlayer):
CScriptEvent( L"selectionChanged", EVENT_SELECTION_CHANGED, false ),
m_CausedByPlayer(CausedByPlayer)
{
AddLocalProperty( L"byPlayer", &m_CausedByPlayer, true );
}
};
class CEventWorldClick: public CScriptEvent
{
int m_Button;
int m_Clicks;
int m_Command;
int m_SecondaryCommand;
CEntity *m_Entity;
uint m_X, m_Y;
public:
CEventWorldClick(int button, int clicks, int command, int secCommand, CEntity *ent, uint x, uint y):
CScriptEvent(L"worldClick", EVENT_WORLD_CLICK, false),
m_Button(button),
m_Clicks(clicks),
m_Command(command),
m_SecondaryCommand(secCommand),
m_Entity(ent),
m_X(x),
m_Y(y)
{
AddLocalProperty(L"button", &m_Button);
AddLocalProperty(L"clicks", &m_Clicks);
AddLocalProperty(L"command", &m_Command);
AddLocalProperty(L"secondaryCommand", &m_SecondaryCommand);
if (ent)
AddLocalProperty(L"entity", &m_Entity);
else
AddProperty(L"entity", JSVAL_NULL);
AddLocalProperty(L"x", &m_X);
AddLocalProperty(L"y", &m_Y);
}
};
public:
void FireSelectionChanged( bool CausedByPlayer )
{
CEventSelectionChanged evt( CausedByPlayer );
DispatchEvent( &evt );
}
void FireWorldClick(int button, int clicks, int command, int secCommand, CEntity *ent, uint x, uint y)
{
CEventWorldClick evt(button, clicks, command, secCommand, ent, x, y);
DispatchEvent(&evt);
}
};
#define g_JSGameEvents CGameEvents::GetSingleton()
#endif