-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventParser.cs
82 lines (72 loc) · 2.74 KB
/
EventParser.cs
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
70
71
72
73
74
75
76
77
78
79
80
81
82
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Linq;
using System;
using System.IO;
namespace PathOfThal
{
public class EventParser
{
public List<string> DialogText;
string currentDialogLine;
public string Type;
string eventData;
IEvent eventObject;
public enum Section{
TYPE,
TYPEDATA,
DATA,
DATADATA,
DONE,
NONE
}
public Section currentSection;
public EventParser(){
}
public IEvent ParseEvent(string iFileName){
//NOTE: Parse mapData to a 'Map' object
eventData = File.ReadAllText(iFileName);
if(eventData != string.Empty){
//Reset some vars because parser is declared once
currentSection = Section.TYPE;
DialogText = new List<string>();
Type = string.Empty;
currentDialogLine = String.Empty;
//Parse event
foreach(char c in eventData){
if(currentSection == Section.TYPE){
if(Utility.IsQuote(c)){
currentSection = Section.TYPEDATA;
}
}else if(currentSection == Section.TYPEDATA){
if(Utility.IsQuote(c)){
currentSection = Section.DATA;
}else if(Utility.IsChar(c)){
Type += c;
}
}else if(currentSection == Section.DATA){
if(Utility.IsDoubleQuote(c)){
currentSection = Section.DATADATA;
}else if(Utility.isStar(c)){
currentSection = Section.DONE;
eventObject = new Dialog(DialogText.ToArray());
}
}else if(currentSection == Section.DATADATA){
if(Utility.IsDoubleQuote(c)){
currentSection = Section.DATA;
DialogText.Add(currentDialogLine);
currentDialogLine = "";
}else if(Utility.IsChar(c) || Utility.isNum(c)){
currentDialogLine += c;
}
}else if(currentSection == Section.DONE){
Console.WriteLine("[EventParser] Parsed following event correctly");
Console.WriteLine(eventObject.ToString());
currentSection = Section.NONE;
}
}
}
return eventObject;
}
}
}