Skip to content

Commit 2919843

Browse files
committed
Unlabelled timers/triggers/aliases now send internal name to script
1 parent b3d6361 commit 2919843

File tree

9 files changed

+129
-28
lines changed

9 files changed

+129
-28
lines changed

MUSHclient.dsp

Lines changed: 13 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OtherTypes.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ typedef CTypedPtrMap <CMapStringToPtr, CString, CAlias*> CAliasMap;
445445
typedef CTypedPtrArray <CPtrArray, CAlias*> CAliasArray;
446446
// list for alias evaluation
447447
typedef CTypedPtrList <CPtrList, CAlias*> CAliasList;
448+
// map for lookup name from pointer
449+
typedef map <CAlias*, string> CAliasRevMap;
448450

449451
/////////////////////////////////////////////////////////////////////////////
450452
// CTrigger
@@ -577,6 +579,8 @@ typedef CTypedPtrMap <CMapStringToPtr, CString, CTrigger*> CTriggerMap;
577579
typedef CTypedPtrArray <CPtrArray, CTrigger*> CTriggerArray;
578580
// list for trigger evaluation
579581
typedef CTypedPtrList <CPtrList, CTrigger*> CTriggerList;
582+
// map for lookup name from pointer
583+
typedef map <CTrigger*, string> CTriggerRevMap;
580584

581585
/////////////////////////////////////////////////////////////////////////////
582586
// CTimer
@@ -684,6 +688,8 @@ class CTimer : public CObject
684688
};
685689

686690
typedef CTypedPtrMap <CMapStringToPtr, CString, CTimer*> CTimerMap;
691+
// map for lookup name from pointer
692+
typedef map <CTimer*, string> CTimerRevMap;
687693

688694

689695
/////////////////////////////////////////////////////////////////////////////
@@ -925,9 +931,12 @@ class CPlugin :public CObject
925931

926932
CAliasMap m_AliasMap; // aliases
927933
CAliasArray m_AliasArray; // array of aliases for sequencing
934+
CAliasRevMap m_AliasRevMap; // for getting name back from pointer
928935
CTriggerMap m_TriggerMap; // triggers
929936
CTriggerArray m_TriggerArray; // array of triggers for sequencing
937+
CTriggerRevMap m_TriggerRevMap; // for getting name back from pointer
930938
CTimerMap m_TimerMap; // timers
939+
CTimerRevMap m_TimerRevMap; // for getting name back from pointer
931940
CVariableMap m_VariableMap; // variables
932941
tStringMapOfMaps m_Arrays; // map of arrays (for scripting)
933942

dialogs/world_prefs/prefspropertypages.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6079,6 +6079,8 @@ void CPrefsP16::OnAddTimer()
60796079
dlg.m_pDoc = m_doc;
60806080

60816081
OnAddItem (dlg);
6082+
m_doc->SortTimers ();
6083+
60826084
} // end of CPrefsP16::OnAddTimer
60836085

60846086
void CPrefsP16::OnChangeTimer()
@@ -6093,11 +6095,15 @@ void CPrefsP16::OnChangeTimer()
60936095
dlg.m_pDoc = m_doc;
60946096

60956097
OnChangeItem (dlg);
6098+
m_doc->SortTimers ();
6099+
60966100
} // end of CPrefsP16::OnChangeTimer
60976101

60986102
void CPrefsP16::OnDeleteTimer()
60996103
{
6100-
OnDeleteItem ();
6104+
OnDeleteItem ();
6105+
m_doc->SortTimers ();
6106+
61016107
} // end of CPrefsP16::OnDeleteTimer
61026108

61036109
void CPrefsP16::OnDblclkTimersList(NMHDR* pNMHDR, LRESULT* pResult)

doc.cpp

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,11 +2538,16 @@ void CMUSHclientDoc::ExecuteTriggerScript (CTrigger * trigger_item,
25382538
CString strReason = TFormat ("processing trigger \"%s\"",
25392539
(LPCTSTR) trigger_item->strLabel);
25402540

2541+
// get unlabelled trigger's internal name
2542+
const char * pLabel = trigger_item->strLabel;
2543+
if (pLabel [0] == 0)
2544+
pLabel = GetTriggerRevMap () [trigger_item].c_str ();
2545+
25412546
if (GetScriptEngine () && GetScriptEngine ()->IsLua ())
25422547
{
25432548
list<double> nparams;
25442549
list<string> sparams;
2545-
sparams.push_back ((LPCTSTR) trigger_item->strLabel);
2550+
sparams.push_back (pLabel);
25462551
sparams.push_back ((LPCTSTR) strCurrentLine);
25472552
trigger_item->bExecutingScript = true; // cannot be deleted now
25482553
GetScriptEngine ()->ExecuteLua (trigger_item->dispid,
@@ -2583,7 +2588,7 @@ long i = 1;
25832588

25842589
// ::AfxMessageBox (trigger_item->trigger);
25852590

2586-
args [eTriggerName] = trigger_item->strLabel;
2591+
args [eTriggerName] = pLabel;
25872592
args [eCurrentLine] = strCurrentLine;
25882593

25892594
// --------------- set up wildcards array ---------------------------
@@ -4537,11 +4542,16 @@ double t = (tNow.m_dt - ((int) tNow.m_dt) ) * 86400.0;
45374542
CString strReason = TFormat ("processing timer \"%s\"",
45384543
(LPCTSTR) timer_item->strLabel);
45394544

4545+
// get unlabelled timer's internal name
4546+
const char * pLabel = timer_item->strLabel;
4547+
if (pLabel [0] == 0)
4548+
pLabel = GetTimerRevMap () [timer_item].c_str ();
4549+
45404550
if (GetScriptEngine () && GetScriptEngine ()->IsLua ())
45414551
{
45424552
list<double> nparams;
45434553
list<string> sparams;
4544-
sparams.push_back ((LPCTSTR) timer_item->strLabel);
4554+
sparams.push_back (pLabel);
45454555
timer_item->bExecutingScript = true; // cannot be deleted now
45464556
bool bResult = GetScriptEngine ()->ExecuteLua (timer_item->dispid,
45474557
timer_item->strProcedure,
@@ -4573,7 +4583,7 @@ double t = (tNow.m_dt - ((int) tNow.m_dt) ) * 86400.0;
45734583
DISPPARAMS params = { args, NULL, eArgCount, 0 };
45744584

45754585
// args [eTimerName] = strTimerName;
4576-
args [eTimerName] = timer_item->strLabel;
4586+
args [eTimerName] = pLabel;
45774587
timer_item->bExecutingScript = true; // cannot be deleted now
45784588
bool bResult = ExecuteScript (timer_item->dispid,
45794589
timer_item->strProcedure,
@@ -4606,6 +4616,7 @@ double t = (tNow.m_dt - ((int) tNow.m_dt) ) * 86400.0;
46064616
{
46074617
TimerMap.RemoveKey (strTimerName);
46084618
delete timer_item;
4619+
SortTimers ();
46094620
}
46104621
} // end of processing each timer
46114622

@@ -6354,12 +6365,14 @@ CTrigger * pTrigger;
63546365
POSITION pos;
63556366

63566367
GetTriggerArray ().SetSize (iCount);
6368+
CTriggerRevMap ().empty ();
63576369

63586370
// extract pointers into a simple array
63596371
for (i = 0, pos = GetTriggerMap ().GetStartPosition(); pos; i++)
63606372
{
63616373
GetTriggerMap ().GetNextAssoc (pos, strTriggerName, pTrigger);
6362-
GetTriggerArray ().SetAt (i, pTrigger);
6374+
GetTriggerArray ().SetAt (i, pTrigger);
6375+
GetTriggerRevMap () [pTrigger] = strTriggerName;
63636376
}
63646377

63656378

@@ -6404,12 +6417,14 @@ CAlias * pAlias;
64046417
POSITION pos;
64056418

64066419
GetAliasArray ().SetSize (iCount);
6420+
CAliasRevMap ().empty ();
64076421

64086422
// extract pointers into a simple array
64096423
for (i = 0, pos = GetAliasMap ().GetStartPosition(); pos; i++)
64106424
{
64116425
GetAliasMap ().GetNextAssoc (pos, strAliasName, pAlias);
64126426
GetAliasArray ().SetAt (i, pAlias);
6427+
GetAliasRevMap () [pAlias] = strAliasName;
64136428
}
64146429

64156430

@@ -6422,6 +6437,28 @@ POSITION pos;
64226437
} // end of CMUSHclientDoc::SortAliases
64236438

64246439

6440+
void CMUSHclientDoc::SortTimers (void)
6441+
{
6442+
6443+
int iCount = GetTimerMap ().GetCount ();
6444+
int i;
6445+
CString strTimerName;
6446+
CTimer * pTimer;
6447+
POSITION pos;
6448+
6449+
CTimerRevMap ().empty ();
6450+
6451+
// extract pointers into a simple array
6452+
for (i = 0, pos = GetTimerMap ().GetStartPosition(); pos; i++)
6453+
{
6454+
GetTimerMap ().GetNextAssoc (pos, strTimerName, pTimer);
6455+
GetTimerRevMap () [pTimer] = strTimerName;
6456+
}
6457+
6458+
} // end of CMUSHclientDoc::SortTimers
6459+
6460+
6461+
64256462

64266463
// CTime:Format only allows for a total field size of 128 bytes
64276464
CString CMUSHclientDoc::FormatTime (const CTime theTime,

doc.h

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,10 +645,14 @@ class CMUSHclientDoc : public CDocument
645645
CString m_connect_text;
646646

647647
CAliasMap m_AliasMap;
648-
CAliasArray m_AliasArray; // array of aliases for sequencing
649-
CTriggerMap m_TriggerMap;
648+
CAliasArray m_AliasArray; // array of aliases for sequencing
649+
CAliasRevMap m_AliasRevMap; // for getting name back from pointer
650+
CTriggerMap m_TriggerMap;
650651
CTriggerArray m_TriggerArray; // array of triggers for sequencing
652+
CTriggerRevMap m_TriggerRevMap; // for getting name back from pointer
651653
CTimerMap m_TimerMap;
654+
CTimerRevMap m_TimerRevMap; // for getting name back from pointer
655+
652656

653657
// new in version 7
654658

@@ -1635,6 +1639,8 @@ class CMUSHclientDoc : public CDocument
16351639
void SortTriggers (void);
16361640
// set up alias array after adding an alias or two
16371641
void SortAliases (void);
1642+
// set up timer reverse map after adding timers
1643+
void SortTimers (void);
16381644

16391645

16401646
BOOL Load_Set (const int set_type,
@@ -1975,6 +1981,14 @@ class CMUSHclientDoc : public CDocument
19751981
return m_TriggerArray;
19761982
};
19771983

1984+
CTriggerRevMap & GetTriggerRevMap (void)
1985+
{
1986+
if (m_CurrentPlugin)
1987+
return m_CurrentPlugin->m_TriggerRevMap;
1988+
else
1989+
return m_TriggerRevMap;
1990+
};
1991+
19781992
CAliasMap & GetAliasMap (void)
19791993
{
19801994
if (m_CurrentPlugin)
@@ -1991,6 +2005,14 @@ class CMUSHclientDoc : public CDocument
19912005
return m_AliasArray;
19922006
};
19932007

2008+
CAliasRevMap & GetAliasRevMap (void)
2009+
{
2010+
if (m_CurrentPlugin)
2011+
return m_CurrentPlugin->m_AliasRevMap;
2012+
else
2013+
return m_AliasRevMap;
2014+
};
2015+
19942016
CTimerMap & GetTimerMap (void)
19952017
{
19962018
if (m_CurrentPlugin)
@@ -1999,6 +2021,14 @@ class CMUSHclientDoc : public CDocument
19992021
return m_TimerMap;
20002022
};
20012023

2024+
CTimerRevMap & GetTimerRevMap (void)
2025+
{
2026+
if (m_CurrentPlugin)
2027+
return m_CurrentPlugin->m_TimerRevMap;
2028+
else
2029+
return m_TimerRevMap;
2030+
};
2031+
20022032
CVariableMap & GetVariableMap (void)
20032033
{
20042034
if (m_CurrentPlugin)

evaluate.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,11 +933,16 @@ bool CMUSHclientDoc::ExecuteAliasScript (CAlias * alias_item,
933933
CString strReason = TFormat ("processing alias \"%s\"",
934934
(LPCTSTR) alias_item->strLabel);
935935

936+
// get unlabelled alias's internal name
937+
const char * pLabel = alias_item->strLabel;
938+
if (pLabel [0] == 0)
939+
pLabel = GetAliasRevMap () [alias_item].c_str ();
940+
936941
if (GetScriptEngine () && GetScriptEngine ()->IsLua ())
937942
{
938943
list<double> nparams;
939944
list<string> sparams;
940-
sparams.push_back ((LPCTSTR) alias_item->strLabel);
945+
sparams.push_back (pLabel);
941946
sparams.push_back ((LPCTSTR) strCurrentLine);
942947
alias_item->bExecutingScript = true; // cannot be deleted now
943948
GetScriptEngine ()->ExecuteLua (alias_item->dispid,
@@ -972,7 +977,7 @@ bool CMUSHclientDoc::ExecuteAliasScript (CAlias * alias_item,
972977
COleVariant args [eArgCount];
973978
DISPPARAMS params = { args, NULL, eArgCount, 0 };
974979

975-
args [eAliasName] = alias_item->strLabel;
980+
args [eAliasName] = pLabel;
976981
args [eInputLine] = strCurrentLine;
977982

978983
// --------------- set up wildcards array ---------------------------

plugins.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,11 @@ void CMUSHclientDoc::OnFilePluginwizard()
11711171

11721172
// show document modified
11731173
if (iCount)
1174+
{
1175+
m_CurrentPlugin = NULL;
1176+
SortTimers ();
11741177
SetModifiedFlag (TRUE); // document has changed
1178+
}
11751179

11761180
} // end of doing all Timers
11771181

0 commit comments

Comments
 (0)