-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmugenscriptparser.cpp
69 lines (56 loc) · 1.7 KB
/
mugenscriptparser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "prism/mugenscriptparser.h"
#include "prism/memoryhandler.h"
#include "prism/log.h"
#include "prism/system.h"
namespace prism {
typedef struct {
int(*mIsFunc)(MugenDefScriptGroup*);
void(*mHandleFunc)(MugenDefScriptGroup*);
} ScriptParseElement;
static struct {
int mIsActive;
Vector mParseElements;
} gPrismMugenScriptParserData;
static void clearMugenScriptParser() {
delete_vector(&gPrismMugenScriptParserData.mParseElements);
gPrismMugenScriptParserData.mIsActive = 0;
}
void resetMugenScriptParser()
{
if (gPrismMugenScriptParserData.mIsActive) {
clearMugenScriptParser();
}
gPrismMugenScriptParserData.mParseElements = new_vector();
gPrismMugenScriptParserData.mIsActive = 1;
}
void addMugenScriptParseFunction(int(*tIsFunc)(MugenDefScriptGroup*), void(*tHandleFunc)(MugenDefScriptGroup*))
{
ScriptParseElement* e = (ScriptParseElement*)allocMemory(sizeof(ScriptParseElement));
e->mIsFunc = tIsFunc;
e->mHandleFunc = tHandleFunc;
vector_push_back_owned(&gPrismMugenScriptParserData.mParseElements, e);
}
void parseMugenScript(MugenDefScript* tScript)
{
MugenDefScriptGroup* current = tScript->mFirstGroup;
while (current != NULL) {
int hasFound = 0;
int i;
for (i = 0; i < vector_size(&gPrismMugenScriptParserData.mParseElements); i++) {
ScriptParseElement* e = (ScriptParseElement*)vector_get(&gPrismMugenScriptParserData.mParseElements, i);
if (e->mIsFunc(current)) {
e->mHandleFunc(current);
hasFound = 1;
break;
}
}
if (!hasFound) {
logError("Unable to find script group.");
logErrorString(current->mName.data());
recoverFromError();
}
current = current->mNext;
}
clearMugenScriptParser();
}
}