Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
ExcelData Class Reference
Inheritance diagram for ExcelData:
TextConv

Classes

class  Sheet
 

Public Member Functions

 ExcelData ()
 
 ExcelData (string _path, int _index)
 
 ExcelData (string _path)
 
void LoadBook ()
 
bool IsModified ()
 
virtual void BuildMap (string sheetName="_default")
 
List< Dictionary< string, string > > BuildList (string sheetName="_default")
 
void Override (Dictionary< string, SourceData > sources, bool canAddData=true)
 
string GetText (string id, string topic="text")
 

Public Attributes

int startIndex = 5
 
XSSFWorkbook book
 
IRow rowIndex
 
Dictionary< string, Sheetsheets = new Dictionary<string, Sheet>()
 
string path
 
int maxEmptyRows
 
DateTime lastModified
 

Detailed Description

Definition at line 10 of file ExcelData.cs.

Constructor & Destructor Documentation

◆ ExcelData() [1/3]

ExcelData.ExcelData ( )
inline

Definition at line 33 of file ExcelData.cs.

34 {
35 }

◆ ExcelData() [2/3]

ExcelData.ExcelData ( string  _path,
int  _index 
)
inline

Definition at line 37 of file ExcelData.cs.

38 {
39 path = _path;
40 startIndex = _index;
41 BuildMap();
42 }
int startIndex
Definition: ExcelData.cs:19
virtual void BuildMap(string sheetName="_default")
Definition: ExcelData.cs:77
string path
Definition: ExcelData.cs:27

References BuildMap(), path, and startIndex.

◆ ExcelData() [3/3]

ExcelData.ExcelData ( string  _path)
inline

Definition at line 44 of file ExcelData.cs.

45 {
46 path = _path;
47 }

References path.

Member Function Documentation

◆ BuildList()

List< Dictionary< string, string > > ExcelData.BuildList ( string  sheetName = "_default")
inline

Definition at line 92 of file ExcelData.cs.

93 {
94 LoadBook();
95 if (sheetName.IsEmpty())
96 {
97 sheetName = "_default";
98 }
99 Sheet sheet = sheets.TryGetValue(sheetName);
100 if (sheet == null)
101 {
102 sheet = new Sheet();
103 sheets[sheetName] = sheet;
104 }
105 if (sheet.list != null)
106 {
107 return sheet.list;
108 }
109 sheet.list = new List<Dictionary<string, string>>();
110 ISheet sheet2 = (string.IsNullOrEmpty(sheetName) ? book.GetSheetAt(0) : (book.GetSheet(sheetName) ?? book.GetSheetAt(0)));
111 rowIndex = sheet2.GetRow(0);
112 int num = 0;
113 for (int i = startIndex - 1; i <= sheet2.LastRowNum; i++)
114 {
115 IRow row = sheet2.GetRow(i);
116 if (row == null)
117 {
118 if (i >= 5)
119 {
120 num++;
121 if (num > maxEmptyRows)
122 {
123 break;
124 }
125 }
126 continue;
127 }
128 num = 0;
129 Dictionary<string, string> dictionary = new Dictionary<string, string>();
130 for (int j = 0; j < rowIndex.LastCellNum; j++)
131 {
132 ICell cell = row.GetCell(j);
133 string text = rowIndex.GetCell(j).ToString();
134 if (text.IsEmpty())
135 {
136 break;
137 }
138 try
139 {
140 dictionary.Add(text, (cell == null) ? "" : cell.ToString());
141 }
142 catch
143 {
144 }
145 }
146 sheet.list.Add(dictionary);
147 }
148 return sheet.list;
149 }
IRow rowIndex
Definition: ExcelData.cs:23
int maxEmptyRows
Definition: ExcelData.cs:29
Dictionary< string, Sheet > sheets
Definition: ExcelData.cs:25
void LoadBook()
Definition: ExcelData.cs:49
XSSFWorkbook book
Definition: ExcelData.cs:21

References book, ExcelData.Sheet.list, LoadBook(), maxEmptyRows, rowIndex, sheets, and startIndex.

Referenced by BuildMap(), Zone_SnowGrave.GenerateGrave(), Player.Flags.GetStoryExcelData(), DramaEventEndRoll.Init(), DramaManager.Load(), Zone_WindRest.OnGenerateMap(), and TraitStoryBook.OnRead().

◆ BuildMap()

virtual void ExcelData.BuildMap ( string  sheetName = "_default")
inlinevirtual

Reimplemented in TextConv.

Definition at line 77 of file ExcelData.cs.

78 {
79 BuildList(sheetName);
80 Sheet sheet = sheets[sheetName];
81 if (sheet.map != null)
82 {
83 return;
84 }
85 sheet.map = new Dictionary<string, Dictionary<string, string>>();
86 foreach (Dictionary<string, string> item in sheet.list)
87 {
88 sheet.map[item["id"]] = item;
89 }
90 }
List< Dictionary< string, string > > BuildList(string sheetName="_default")
Definition: ExcelData.cs:92

References BuildList(), item, ExcelData.Sheet.map, and sheets.

Referenced by ExcelData(), Lang.GetDialog(), GetText(), and DramaCustomSequence.HasTopic().

◆ GetText()

string ExcelData.GetText ( string  id,
string  topic = "text" 
)
inline

Definition at line 209 of file ExcelData.cs.

210 {
211 BuildMap();
212 return sheets["_default"].map.TryGetValue(topic)?[id];
213 }

References BuildMap(), and sheets.

Referenced by Religion.GetGodTalk().

◆ IsModified()

bool ExcelData.IsModified ( )
inline

Definition at line 72 of file ExcelData.cs.

73 {
74 return !lastModified.Equals(File.GetLastWriteTime(path));
75 }
DateTime lastModified
Definition: ExcelData.cs:31

References lastModified, and path.

Referenced by DramaManager.Load().

◆ LoadBook()

void ExcelData.LoadBook ( )
inline

Definition at line 49 of file ExcelData.cs.

50 {
51 if (book != null)
52 {
53 if (lastModified.Equals(File.GetLastWriteTime(path)))
54 {
55 return;
56 }
57 Debug.Log("Excel file modified:" + path);
58 sheets.Clear();
59 }
60 lastModified = File.GetLastWriteTime(path);
61 TextAsset textAsset = Resources.Load(path) as TextAsset;
62 if ((bool)textAsset)
63 {
64 Stream @is = new MemoryStream(textAsset.bytes);
65 book = new XSSFWorkbook(@is);
66 return;
67 }
68 using FileStream is2 = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
69 book = new XSSFWorkbook((Stream)is2);
70 }

References book, Debug, lastModified, path, and sheets.

Referenced by BuildList(), and TextConv.BuildMap().

◆ Override()

void ExcelData.Override ( Dictionary< string, SourceData sources,
bool  canAddData = true 
)
inline

Definition at line 151 of file ExcelData.cs.

152 {
153 using FileStream @is = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
154 book = new XSSFWorkbook((Stream)@is);
155 for (int i = 0; i < book.NumberOfSheets; i++)
156 {
157 ISheet sheetAt = book.GetSheetAt(i);
158 ExcelParser.rowDefault = sheetAt.GetRow(2);
159 SourceData value = null;
160 if (!sources.TryGetValue(sheetAt.SheetName, out value))
161 {
162 Debug.Log(sheetAt.SheetName + " does not exist in sourceMap.");
163 continue;
164 }
165 Type type = value.GetType();
166 IList list = type.GetField("rows").GetValue(value) as IList;
167 IDictionary dictionary = type.GetField("map").GetValue(value) as IDictionary;
168 Type type2 = list.GetType().GetGenericArguments()[0];
169 List<FieldInfo> list2 = new List<FieldInfo>();
170 List<ExcelIndex> index = ExcelIndex.GetIndex(sheetAt);
171 for (int j = 0; j < index.Count; j++)
172 {
173 list2.Add(type2.GetField(index[j].name));
174 }
175 for (int k = startIndex - 1; k <= sheetAt.LastRowNum; k++)
176 {
177 string stringCellValue = (ExcelParser.row = sheetAt.GetRow(k)).GetCell(0).StringCellValue;
178 bool flag = true;
179 object obj;
180 if (dictionary.Contains(stringCellValue))
181 {
182 obj = dictionary[stringCellValue];
183 flag = false;
184 }
185 else
186 {
187 if (!canAddData)
188 {
189 continue;
190 }
191 obj = Activator.CreateInstance(type2);
192 }
193 for (int l = 0; l < index.Count; l++)
194 {
195 string type3 = index[l].type;
196 if (type3 == "str" || type3 == "string")
197 {
198 list2[l].SetValue(obj, ExcelParser.GetString(l));
199 }
200 }
201 if (flag)
202 {
203 list.Add(obj);
204 }
205 }
206 }
207 }
static List< ExcelIndex > GetIndex(ISheet sheet)
Definition: ExcelIndex.cs:14
static string GetString(int id)
Definition: ExcelParser.cs:102

References book, Debug, ExcelIndex.GetIndex(), ExcelParser.GetString(), path, and startIndex.

Member Data Documentation

◆ book

XSSFWorkbook ExcelData.book

Definition at line 21 of file ExcelData.cs.

Referenced by BuildList(), TextConv.BuildMap(), LoadBook(), and Override().

◆ lastModified

DateTime ExcelData.lastModified

Definition at line 31 of file ExcelData.cs.

Referenced by IsModified(), and LoadBook().

◆ maxEmptyRows

int ExcelData.maxEmptyRows

Definition at line 29 of file ExcelData.cs.

Referenced by BuildList().

◆ path

string ExcelData.path

Definition at line 27 of file ExcelData.cs.

Referenced by TextConv.BuildMap(), ExcelData(), IsModified(), LoadBook(), and Override().

◆ rowIndex

IRow ExcelData.rowIndex

Definition at line 23 of file ExcelData.cs.

Referenced by BuildList().

◆ sheets

Dictionary<string, Sheet> ExcelData.sheets = new Dictionary<string, Sheet>()

◆ startIndex

int ExcelData.startIndex = 5

Definition at line 19 of file ExcelData.cs.

Referenced by BuildList(), ExcelData(), and Override().


The documentation for this class was generated from the following file: