This repository has been archived by the owner on Apr 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
parser_dlg.cpp
66 lines (61 loc) · 1.46 KB
/
parser_dlg.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
/*
* Bermuda Syndrome engine rewrite
* Copyright (C) 2007-2011 Gregory Montoir
*/
#include "fs.h"
#include "file.h"
#include "game.h"
#include "str.h"
enum ParserToken {
kParserTokenGoto,
kParserTokenEnd,
kParserTokenThen,
kParserTokenEOS,
kParserTokenUnknown
};
static ParserToken _currentToken;
static ParserToken getNextToken(char **s) {
char *token = stringNextToken(s);
if (!token || !*token) {
return kParserTokenEOS;
} else if (strcmp(token, "Goto") == 0) {
return kParserTokenGoto;
} else if (strcmp(token, "End") == 0) {
return kParserTokenEnd;
} else if (strcmp(token, "->") == 0) {
return kParserTokenThen;
} else {
return kParserTokenUnknown;
}
}
void Game::parseDLG() {
_dialogueChoiceSize = 0;
for (char *s = _dialogueDescriptionBuffer; s; ) {
assert(_dialogueChoiceSize < NUM_DIALOG_ENTRIES);
DialogueChoice *dc = &_dialogueChoiceData[_dialogueChoiceSize];
dc->id = stringNextToken(&s);
if (!s) {
break;
}
_currentToken = getNextToken(&s);
switch (_currentToken) {
case kParserTokenGoto:
dc->gotoFlag = true;
break;
case kParserTokenEnd:
dc->gotoFlag = false;
break;
default:
error("Unexpected token %d", _currentToken);
break;
}
dc->nextId = stringNextToken(&s);
dc->speechSoundFile = stringNextToken(&s);
_currentToken = getNextToken(&s);
if (_currentToken != kParserTokenThen) {
error("Unexpected token %d", _currentToken);
}
dc->text = stringNextTokenEOL(&s);
++_dialogueChoiceSize;
}
}