2006-11-24 20:45:04 +01:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
#include "TriggerManager.h"
|
|
|
|
#include "scripting/ScriptingHost.h"
|
|
|
|
#include "ps/XML/Xeromyces.h"
|
|
|
|
#include "ps/XML/XeroXMB.h"
|
|
|
|
#include "ps/CLogger.h"
|
|
|
|
|
|
|
|
#define LOG_CATEGORY "Triggers"
|
|
|
|
|
|
|
|
|
|
|
|
CTrigger::CTrigger()
|
|
|
|
{
|
|
|
|
m_timeLeft = m_timeDelay = m_maxRunCount = m_runCount = m_active = 0;
|
|
|
|
}
|
|
|
|
CTrigger::~CTrigger()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
CTrigger::CTrigger(const CStrW& name, bool active, float delay, int maxRuns, const CStrW& condFunc,
|
2007-05-02 14:07:08 +02:00
|
|
|
const CStrW& effectFunc)
|
2006-11-24 20:45:04 +01:00
|
|
|
{
|
|
|
|
m_name = name;
|
|
|
|
m_active = active;
|
|
|
|
m_timeLeft = m_timeDelay = delay;
|
|
|
|
m_runCount = 0;
|
|
|
|
m_maxRunCount = maxRuns;
|
|
|
|
|
2007-01-17 00:22:25 +01:00
|
|
|
CStrW validName = name;
|
|
|
|
validName.Replace(L" ", L"_");
|
|
|
|
|
2006-11-24 20:45:04 +01:00
|
|
|
m_conditionFuncString = condFunc;
|
|
|
|
m_effectFuncString = effectFunc;
|
2007-01-17 00:22:25 +01:00
|
|
|
m_conditionFunction.Compile( L"TriggerCondition_" + validName, condFunc );
|
|
|
|
m_effectFunction.Compile( L"TriggerEffect_" + validName, effectFunc );
|
2006-11-24 20:45:04 +01:00
|
|
|
}
|
|
|
|
CTrigger::CTrigger(const CStrW& name, bool active, float delay, int maxRuns,
|
|
|
|
CScriptObject& condFunc, CScriptObject& effectFunc)
|
|
|
|
{
|
|
|
|
m_name = name;
|
|
|
|
m_active = active;
|
|
|
|
m_timeLeft = m_timeDelay = delay;
|
|
|
|
m_runCount = 0;
|
|
|
|
m_maxRunCount = maxRuns;
|
|
|
|
m_conditionFunction = condFunc;
|
|
|
|
m_effectFunction = effectFunc;
|
|
|
|
}
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
JSBool CTrigger::Construct( JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* rval )
|
2006-11-24 20:45:04 +01:00
|
|
|
{
|
|
|
|
JSU_REQUIRE_PARAMS_CPP(6);
|
|
|
|
|
|
|
|
CScriptObject condFunc( JS_ValueToFunction(cx, argv[4]) );
|
|
|
|
CScriptObject effectFunc( JS_ValueToFunction(cx, argv[5]) );
|
|
|
|
CTrigger* newTrigger = new CTrigger( ToPrimitive<CStr>( argv[0] ),
|
|
|
|
ToPrimitive<bool>( argv[1] ),
|
2007-04-27 05:05:26 +02:00
|
|
|
ToPrimitive<float>( argv[2] ),
|
|
|
|
ToPrimitive<int>( argv[3]),
|
2006-11-24 20:45:04 +01:00
|
|
|
condFunc, effectFunc );
|
|
|
|
|
|
|
|
g_TriggerManager.AddTrigger(newTrigger);
|
|
|
|
*rval = OBJECT_TO_JSVAL( newTrigger->GetScript() );
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CTrigger& CTrigger::operator= (const CTrigger& trigger)
|
|
|
|
{
|
|
|
|
m_name = trigger.m_name;
|
|
|
|
m_active = trigger.m_active;
|
|
|
|
m_timeLeft = trigger.m_timeLeft;
|
|
|
|
m_timeDelay = trigger.m_timeDelay;
|
|
|
|
m_maxRunCount = trigger.m_maxRunCount;
|
|
|
|
m_conditionFunction = trigger.m_conditionFunction;
|
|
|
|
m_effectFunction = trigger.m_effectFunction;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTrigger::ScriptingInit()
|
|
|
|
{
|
|
|
|
AddProperty<int>(L"runCount", &CTrigger::m_runCount, true);
|
|
|
|
AddProperty(L"name", &CTrigger::m_name, true);
|
|
|
|
AddProperty<int>(L"maxRunCount", &CTrigger::m_maxRunCount);
|
|
|
|
AddProperty<float>(L"timeDelay", &CTrigger::m_timeDelay);
|
|
|
|
|
2007-05-29 21:01:21 +02:00
|
|
|
AddMethod<void, &CTrigger::Activate>( "activate", 0 );
|
|
|
|
AddMethod<void, &CTrigger::Deactivate>( "deactivate", 0 );
|
2006-11-24 20:45:04 +01:00
|
|
|
|
|
|
|
CJSObject<CTrigger>::ScriptingInit("Trigger", CTrigger::Construct, 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CTrigger::ShouldFire()
|
|
|
|
{
|
|
|
|
if ( !m_active )
|
|
|
|
return false;
|
|
|
|
return m_conditionFunction.Run( this->GetScript() );
|
|
|
|
}
|
|
|
|
bool CTrigger::Fire()
|
|
|
|
{
|
|
|
|
m_effectFunction.Run( this->GetScript() );
|
|
|
|
++m_runCount;
|
|
|
|
m_timeLeft = m_timeDelay;
|
|
|
|
return (m_runCount < m_maxRunCount);
|
|
|
|
}
|
|
|
|
|
2008-07-04 13:16:30 +02:00
|
|
|
void CTrigger::Activate(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
|
2006-11-24 20:45:04 +01:00
|
|
|
{
|
|
|
|
m_active = true;
|
|
|
|
}
|
2008-07-04 13:16:30 +02:00
|
|
|
void CTrigger::Deactivate(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
|
2006-11-24 20:45:04 +01:00
|
|
|
{
|
|
|
|
m_active = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TriggerParameter::SetWindowData(const CStrW& _windowType, CStrW& windowPosition, CStrW& windowSize)
|
|
|
|
{
|
2007-12-20 20:57:41 +01:00
|
|
|
windowPosition.Remove( CStrW(L" ") );
|
|
|
|
windowSize.Remove( CStrW(L" ") );
|
2006-11-24 20:45:04 +01:00
|
|
|
|
|
|
|
xPos = windowPosition.BeforeFirst( CStrW(L",") ).ToInt();
|
|
|
|
yPos = windowPosition.AfterFirst( CStrW(L",") ).ToInt();
|
|
|
|
xSize = windowSize.BeforeFirst( CStrW(L",") ).ToInt();
|
|
|
|
ySize = windowSize.AfterFirst( CStrW(L",") ).ToInt();
|
|
|
|
windowType = _windowType;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TriggerParameter::operator< ( const TriggerParameter& rhs ) const
|
|
|
|
{
|
|
|
|
if ( row < rhs.row )
|
|
|
|
return true;
|
|
|
|
else if ( row == rhs.row)
|
|
|
|
return ( column < rhs.column );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//===========Trigger Manager===========
|
|
|
|
|
2007-02-02 03:17:15 +01:00
|
|
|
CTriggerManager::CTriggerManager() : m_UpdateRate(.20f), m_UpdateTime(.20f)
|
2006-11-24 20:45:04 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CTriggerManager::~CTriggerManager()
|
|
|
|
{
|
|
|
|
DestroyEngineTriggers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTriggerManager::DestroyEngineTriggers()
|
|
|
|
{
|
|
|
|
for ( TriggerIter it = m_TriggerMap.begin(); it != m_TriggerMap.end(); ++it )
|
|
|
|
{
|
|
|
|
SAFE_DELETE(it->second);
|
|
|
|
}
|
|
|
|
m_TriggerMap.clear();
|
|
|
|
}
|
2007-01-17 00:22:25 +01:00
|
|
|
|
2006-11-24 20:45:04 +01:00
|
|
|
std::vector<std::wstring> CTriggerManager::GetTriggerChoices(const std::wstring& name)
|
|
|
|
{
|
|
|
|
return m_TriggerChoices[name];
|
|
|
|
}
|
2007-01-17 00:22:25 +01:00
|
|
|
std::vector<std::wstring> CTriggerManager::GetTriggerTranslations(const std::wstring& name)
|
|
|
|
{
|
|
|
|
return m_TriggerTranslations[name];
|
|
|
|
}
|
2006-11-24 20:45:04 +01:00
|
|
|
|
2007-02-02 03:17:15 +01:00
|
|
|
void CTriggerManager::Update(float delta_ms)
|
2006-11-24 20:45:04 +01:00
|
|
|
{
|
2007-02-02 03:17:15 +01:00
|
|
|
float delta = delta_ms / 1000.f;
|
2007-01-17 00:22:25 +01:00
|
|
|
m_UpdateTime -= delta;
|
|
|
|
if ( m_UpdateTime < 0 )
|
2007-02-02 03:17:15 +01:00
|
|
|
m_UpdateTime += m_UpdateRate;
|
2007-01-17 00:22:25 +01:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
2006-11-24 20:45:04 +01:00
|
|
|
std::list<TriggerIter> expired;
|
|
|
|
for ( TriggerIter it = m_TriggerMap.begin(); it != m_TriggerMap.end(); ++it )
|
|
|
|
{
|
|
|
|
if ( it->second->ShouldFire() )
|
|
|
|
{
|
2007-02-02 03:17:15 +01:00
|
|
|
it->second->m_timeLeft -= m_UpdateRate;
|
2006-11-24 20:45:04 +01:00
|
|
|
if ( it->second->m_timeLeft < 0 )
|
|
|
|
{
|
|
|
|
if ( !it->second->Fire() )
|
|
|
|
expired.push_back(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Remove all expired triggers
|
|
|
|
for ( std::list<TriggerIter>::iterator it = expired.begin(); it != expired.end(); ++it )
|
|
|
|
{
|
2007-04-27 05:05:26 +02:00
|
|
|
delete (*it)->second;
|
2006-11-24 20:45:04 +01:00
|
|
|
m_TriggerMap.erase(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTriggerManager::AddTrigger(CTrigger* trigger)
|
|
|
|
{
|
|
|
|
m_TriggerMap[trigger->GetName()] = trigger;
|
|
|
|
}
|
|
|
|
void CTriggerManager::AddGroup(const MapTriggerGroup& group)
|
|
|
|
{
|
|
|
|
m_GroupList.push_back(group);
|
|
|
|
}
|
|
|
|
void CTriggerManager::SetAllGroups(const std::list<MapTriggerGroup>& groups)
|
|
|
|
{
|
|
|
|
m_GroupList = groups;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTriggerManager::AddTrigger(MapTriggerGroup& group, const MapTrigger& trigger)
|
|
|
|
{
|
2007-01-29 23:21:25 +01:00
|
|
|
CStrW conditionBody;
|
2006-11-24 20:45:04 +01:00
|
|
|
CStrW linkLogic[] = { CStrW(L""), CStrW(L" && "), CStrW(L" || ") };
|
|
|
|
size_t i=0;
|
2007-01-17 00:22:25 +01:00
|
|
|
bool allParameters = true;
|
2006-11-24 20:45:04 +01:00
|
|
|
|
2007-01-29 23:21:25 +01:00
|
|
|
if(trigger.conditions.size() == 0) {
|
|
|
|
conditionBody = CStrW(L"return ( true );");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
conditionBody = CStrW(L"return ( ");
|
|
|
|
|
|
|
|
for ( std::list<MapTriggerCondition>::const_iterator it = trigger.conditions.begin();
|
|
|
|
it != trigger.conditions.end(); ++it, ++i )
|
2006-11-24 20:45:04 +01:00
|
|
|
{
|
2007-01-29 23:21:25 +01:00
|
|
|
//Opening parenthesis here?
|
|
|
|
std::set<MapTriggerLogicBlock>::const_iterator blockIt;
|
|
|
|
if ( ( blockIt = trigger.logicBlocks.find(MapTriggerLogicBlock(i)) ) != trigger.logicBlocks.end() )
|
|
|
|
{
|
|
|
|
if ( blockIt->negated )
|
|
|
|
conditionBody += CStrW(L"!");
|
|
|
|
conditionBody += CStrW(L" (");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( it->negated )
|
2006-11-24 20:45:04 +01:00
|
|
|
conditionBody += CStrW(L"!");
|
2007-01-29 23:21:25 +01:00
|
|
|
conditionBody += it->functionName;
|
|
|
|
conditionBody += CStrW(L"(");
|
2007-01-17 00:22:25 +01:00
|
|
|
|
2007-01-29 23:21:25 +01:00
|
|
|
for ( std::list<CStrW>::const_iterator it2 = it->parameters.begin(); it2 !=
|
|
|
|
it->parameters.end(); ++it2 )
|
2007-01-17 00:22:25 +01:00
|
|
|
{
|
2007-01-29 23:21:25 +01:00
|
|
|
size_t params = (size_t)std::find(m_ConditionSpecs.begin(), m_ConditionSpecs.end(), it->displayName)->funcParameters;
|
|
|
|
size_t distance = std::distance(it->parameters.begin(), it2);
|
|
|
|
|
|
|
|
//Parameters end here, additional "parameters" are used directly as script
|
|
|
|
if ( distance == params )
|
|
|
|
{
|
|
|
|
conditionBody += CStrW(L") ");
|
|
|
|
allParameters = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Take display parameter and translate into JS usable code...evilness
|
|
|
|
CTriggerSpec spec = *std::find( m_ConditionSpecs.begin(), m_ConditionSpecs.end(), it->displayName );
|
|
|
|
const std::set<TriggerParameter>& specParameters = spec.GetParameters();
|
|
|
|
|
|
|
|
//Don't use specialized find, since we're searching for a different member
|
|
|
|
std::set<TriggerParameter>::const_iterator specParam = std::find(
|
|
|
|
specParameters.begin(), specParameters.end(), (int)distance);
|
|
|
|
std::wstring combined = std::wstring( it->functionName + specParam->name );
|
|
|
|
size_t translatedIndex = std::distance( m_TriggerChoices[combined].begin(),
|
|
|
|
std::find(m_TriggerChoices[combined].begin(), m_TriggerChoices[combined].end(), std::wstring(*it2)) );
|
|
|
|
|
|
|
|
if ( m_TriggerTranslations[combined].empty() )
|
|
|
|
conditionBody += *it2;
|
|
|
|
else
|
|
|
|
conditionBody += m_TriggerTranslations[combined][translatedIndex];
|
|
|
|
|
|
|
|
if ( distance + 1 < params )
|
|
|
|
conditionBody += CStrW(L", ");
|
2007-01-17 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
2007-01-29 23:21:25 +01:00
|
|
|
if ( allParameters ) //Otherwise, closed inside loop
|
|
|
|
conditionBody += CStrW(L")");
|
|
|
|
if ( trigger.logicBlockEnds.find(i) != trigger.logicBlockEnds.end() )
|
|
|
|
conditionBody += CStrW(L" )");
|
2007-01-17 00:22:25 +01:00
|
|
|
|
2007-01-29 23:21:25 +01:00
|
|
|
if ( std::distance(it, trigger.conditions.end()) != 1 )
|
|
|
|
conditionBody += linkLogic[it->linkLogic];
|
2006-11-24 20:45:04 +01:00
|
|
|
}
|
2007-01-29 23:21:25 +01:00
|
|
|
|
|
|
|
conditionBody += CStrW(L" );");
|
2006-11-24 20:45:04 +01:00
|
|
|
}
|
2007-01-17 00:22:25 +01:00
|
|
|
|
2006-11-24 20:45:04 +01:00
|
|
|
CStrW effectBody;
|
|
|
|
|
|
|
|
for ( std::list<MapTriggerEffect>::const_iterator it = trigger.effects.begin();
|
|
|
|
it != trigger.effects.end(); ++it )
|
|
|
|
{
|
|
|
|
effectBody += it->functionName;
|
|
|
|
effectBody += CStrW(L"(");
|
|
|
|
for ( std::list<CStrW>::const_iterator it2 = it->parameters.begin(); it2 !=
|
|
|
|
it->parameters.end(); ++it2 )
|
|
|
|
{
|
2007-01-17 00:22:25 +01:00
|
|
|
size_t distance = std::distance(it->parameters.begin(), it2);
|
|
|
|
//Take display parameter and translate into JS usable code...evilness
|
|
|
|
CTriggerSpec spec = *std::find( m_EffectSpecs.begin(), m_EffectSpecs.end(), it->displayName );
|
|
|
|
const std::set<TriggerParameter>& specParameters = spec.GetParameters();
|
|
|
|
|
|
|
|
//Don't use specialized find, since we're searching for a different member
|
|
|
|
std::set<TriggerParameter>::const_iterator specParam = std::find(
|
|
|
|
specParameters.begin(), specParameters.end(), (int)distance);
|
|
|
|
std::wstring combined = std::wstring( it->functionName + specParam->name );
|
|
|
|
size_t translatedIndex = std::distance( m_TriggerChoices[combined].begin(),
|
|
|
|
std::find(m_TriggerChoices[combined].begin(), m_TriggerChoices[combined].end(), std::wstring(*it2)) );
|
|
|
|
|
|
|
|
if ( m_TriggerTranslations[combined].empty() )
|
|
|
|
effectBody += *it2;
|
|
|
|
else
|
|
|
|
effectBody += m_TriggerTranslations[combined][translatedIndex];
|
2006-11-24 20:45:04 +01:00
|
|
|
std::list<CStrW>::const_iterator endIt = it->parameters.end();
|
|
|
|
if ( std::distance(it2, endIt) != 1 )
|
|
|
|
effectBody += CStrW(L", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
effectBody += CStrW(L");");
|
|
|
|
}
|
2007-01-17 00:22:25 +01:00
|
|
|
|
2006-11-24 20:45:04 +01:00
|
|
|
group.triggers.push_back(trigger);
|
|
|
|
CTrigger* newTrigger = new CTrigger(trigger.name, trigger.active, trigger.timeValue,
|
|
|
|
trigger.maxRunCount, conditionBody, effectBody);
|
|
|
|
AddTrigger(newTrigger);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//XML stuff
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
bool CTriggerManager::LoadXml( const CStr& filename )
|
2006-11-24 20:45:04 +01:00
|
|
|
{
|
|
|
|
CXeromyces XeroFile;
|
|
|
|
|
|
|
|
if ( XeroFile.Load( filename.c_str() ) != PSRETURN_OK )
|
|
|
|
return false;
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
#define EL(x) int el_##x = XeroFile.GetElementID(#x)
|
|
|
|
#define AT(x) int at_##x = XeroFile.GetAttributeID(#x)
|
2006-11-24 20:45:04 +01:00
|
|
|
|
|
|
|
EL(condition);
|
|
|
|
EL(effect);
|
|
|
|
EL(definitions);
|
|
|
|
|
|
|
|
#undef EL
|
|
|
|
#undef AT
|
|
|
|
|
|
|
|
//Return false on any error to be extra sure the point gets across (FIX IT)
|
2007-05-02 14:07:08 +02:00
|
|
|
XMBElement root = XeroFile.GetRoot();
|
2006-11-24 20:45:04 +01:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
if ( root.GetNodeName() != el_definitions )
|
2006-11-24 20:45:04 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
XERO_ITER_EL(root, rootChild)
|
|
|
|
{
|
2007-05-02 14:07:08 +02:00
|
|
|
int name = rootChild.GetNodeName();
|
2006-11-24 20:45:04 +01:00
|
|
|
if ( name == el_condition )
|
|
|
|
{
|
2007-05-02 14:07:08 +02:00
|
|
|
if ( !LoadTriggerSpec(rootChild, XeroFile, true) )
|
2006-11-24 20:45:04 +01:00
|
|
|
{
|
2007-12-29 17:22:23 +01:00
|
|
|
LOG(CLogger::Error, LOG_CATEGORY, "Error detected in Trigger XML <condition> tag. File: %s", filename.c_str());
|
2006-11-24 20:45:04 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( name == el_effect )
|
|
|
|
{
|
2007-05-02 14:07:08 +02:00
|
|
|
if ( !LoadTriggerSpec(rootChild, XeroFile, false) )
|
2006-11-24 20:45:04 +01:00
|
|
|
{
|
2007-12-29 17:22:23 +01:00
|
|
|
LOG(CLogger::Error, LOG_CATEGORY, "Error detected in Trigger XML <effect> tag. File: %s", filename.c_str());
|
2006-11-24 20:45:04 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-29 17:22:23 +01:00
|
|
|
LOG(CLogger::Error, LOG_CATEGORY, "Invalid tag in trigger XML. File: %s", filename.c_str());
|
2006-11-24 20:45:04 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
bool CTriggerManager::LoadTriggerSpec( XMBElement condition, CXeromyces& XeroFile, bool isCondition )
|
2006-11-24 20:45:04 +01:00
|
|
|
{
|
2007-05-02 14:07:08 +02:00
|
|
|
#define EL(x) int el_##x = XeroFile.GetElementID(#x)
|
|
|
|
#define AT(x) int at_##x = XeroFile.GetAttributeID(#x)
|
2006-11-24 20:45:04 +01:00
|
|
|
|
|
|
|
EL(parameter);
|
|
|
|
EL(window);
|
|
|
|
EL(inputtype);
|
|
|
|
EL(parameterorder);
|
|
|
|
EL(windowrow);
|
|
|
|
EL(choices);
|
2007-01-17 00:22:25 +01:00
|
|
|
EL(choicetranslation);
|
2006-11-24 20:45:04 +01:00
|
|
|
|
|
|
|
AT(type);
|
|
|
|
AT(position);
|
|
|
|
AT(name);
|
|
|
|
AT(size);
|
|
|
|
AT(function);
|
2007-01-17 00:22:25 +01:00
|
|
|
AT(funcParameters);
|
2006-11-24 20:45:04 +01:00
|
|
|
|
|
|
|
#undef EL
|
|
|
|
#undef AT
|
|
|
|
|
|
|
|
CTriggerSpec specStore;
|
2007-05-02 14:07:08 +02:00
|
|
|
specStore.functionName = CStrW( condition.GetAttributes().GetNamedItem(at_function) );
|
|
|
|
specStore.displayName = CStrW( condition.GetAttributes().GetNamedItem(at_name) );
|
|
|
|
specStore.funcParameters = CStr( condition.GetAttributes().GetNamedItem(at_funcParameters) ).ToInt();
|
2006-11-24 20:45:04 +01:00
|
|
|
int row = -1, column = -1;
|
|
|
|
|
|
|
|
XERO_ITER_EL(condition, child)
|
|
|
|
{
|
2007-05-02 14:07:08 +02:00
|
|
|
int childID = child.GetNodeName();
|
2006-11-24 20:45:04 +01:00
|
|
|
|
|
|
|
if ( childID == el_windowrow )
|
|
|
|
{
|
|
|
|
++row;
|
|
|
|
column = -1;
|
|
|
|
|
|
|
|
XERO_ITER_EL(child, windowChild)
|
|
|
|
{
|
|
|
|
++column;
|
|
|
|
TriggerParameter specParam(row, column);
|
2007-05-02 14:07:08 +02:00
|
|
|
specParam.name = windowChild.GetAttributes().GetNamedItem(at_name);
|
|
|
|
childID = windowChild.GetNodeName();
|
2006-11-24 20:45:04 +01:00
|
|
|
|
|
|
|
if ( childID != el_parameter)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
XERO_ITER_EL(windowChild, parameterChild)
|
|
|
|
{
|
2007-05-02 14:07:08 +02:00
|
|
|
childID = parameterChild.GetNodeName();
|
2006-11-24 20:45:04 +01:00
|
|
|
|
|
|
|
if ( childID == el_window )
|
|
|
|
{
|
2007-05-02 14:07:08 +02:00
|
|
|
CStrW type( parameterChild.GetAttributes().GetNamedItem(at_type) );
|
|
|
|
CStrW pos( parameterChild.GetAttributes().GetNamedItem(at_position) );
|
|
|
|
CStrW size( parameterChild.GetAttributes().GetNamedItem(at_size) );
|
2006-11-24 20:45:04 +01:00
|
|
|
specParam.SetWindowData(type, pos, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ( childID == el_inputtype )
|
2007-05-02 14:07:08 +02:00
|
|
|
specParam.inputType = CStrW( parameterChild.GetText() );
|
2006-11-24 20:45:04 +01:00
|
|
|
else if ( childID == el_parameterorder )
|
2007-05-02 14:07:08 +02:00
|
|
|
specParam.parameterOrder = CStrW( parameterChild.GetText() ).ToInt();
|
2006-11-24 20:45:04 +01:00
|
|
|
else if ( childID == el_choices )
|
|
|
|
{
|
|
|
|
std::vector<std::wstring> choices;
|
2007-05-02 14:07:08 +02:00
|
|
|
CStrW comma(L","), input(parameterChild.GetText());
|
2006-11-24 20:45:04 +01:00
|
|
|
CStrW substr;
|
|
|
|
while ( (substr = input.BeforeFirst(comma)) != input )
|
|
|
|
{
|
|
|
|
choices.push_back(substr);
|
|
|
|
input = input.AfterFirst(comma);
|
|
|
|
}
|
|
|
|
|
|
|
|
choices.push_back(substr); //Last element has no comma
|
|
|
|
m_TriggerChoices[specStore.functionName + specParam.name] = choices;
|
|
|
|
}
|
2007-01-17 00:22:25 +01:00
|
|
|
else if ( childID == el_choicetranslation )
|
|
|
|
{
|
|
|
|
std::vector<std::wstring> choices;
|
2007-05-02 14:07:08 +02:00
|
|
|
CStrW comma(L","), input(parameterChild.GetText());
|
2007-01-17 00:22:25 +01:00
|
|
|
CStrW substr;
|
|
|
|
while ( (substr = input.BeforeFirst(comma)) != input )
|
|
|
|
{
|
|
|
|
choices.push_back(substr);
|
|
|
|
input = input.AfterFirst(comma);
|
|
|
|
}
|
|
|
|
|
|
|
|
choices.push_back(substr); //Last element has no comma
|
|
|
|
m_TriggerTranslations[specStore.functionName + specParam.name] = choices;
|
|
|
|
}
|
2006-11-24 20:45:04 +01:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
specStore.AddParameter(specParam);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isCondition )
|
|
|
|
m_ConditionSpecs.push_back(specStore);
|
|
|
|
else
|
|
|
|
m_EffectSpecs.push_back(specStore);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|