Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
TextConv.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Text;
3using NPOI.SS.UserModel;
4using UnityEngine;
5
6public class TextConv : ExcelData
7{
8 public class Item
9 {
10 public static string[] DefaultSuffix = "、,。,!,?,…,ー".Split(',');
11
12 public string[] strs;
13
14 public string[] suffix;
15
16 public string[] keys;
17
18 public int probab;
19
20 public int gender;
21
22 public bool additive;
23
24 public Item(IRow row, string c0, string c1, string c2, int c4)
25 {
26 ICell cell = row.GetCell(3);
27 keys = c0.Split(',');
28 strs = c1.Split(',');
29 if (cell == null)
30 {
32 }
33 else
34 {
35 string text = cell.ToString();
36 if (text == "*")
37 {
38 suffix = null;
39 }
40 else
41 {
42 suffix = text.Split(',');
43 }
44 }
45 probab = c4;
47 gender = ((c2 == "F") ? 1 : ((c2 == "M") ? 2 : 0));
48 }
49 }
50
51 public string[] I_M;
52
53 public string[] I_F;
54
55 public string[] you_M;
56
57 public string[] you_F;
58
59 public string[] tags;
60
61 public int p_I_M;
62
63 public int p_I_F;
64
65 public int p_you_M;
66
67 public int p_you_F;
68
69 public List<Item> items = new List<Item>();
70
71 public StringBuilder Apply(ref string text, int gender)
72 {
73 BuildMap(null);
74 StringBuilder stringBuilder = new StringBuilder();
75 string text2 = null;
76 Item item = null;
77 int num = 0;
78 if (gender == 0)
79 {
80 gender = ((Rand.rnd(3) != 0) ? 1 : 2);
81 }
82 while (num < text.Length)
83 {
84 bool flag = false;
85 foreach (Item item2 in items)
86 {
87 if ((item2.probab != 0 && Rand.Range(0, 100) >= item2.probab) || (item2.gender != 0 && gender != item2.gender))
88 {
89 continue;
90 }
91 string[] keys = item2.keys;
92 foreach (string text3 in keys)
93 {
94 flag = true;
95 for (int j = 0; j < text3.Length; j++)
96 {
97 if (num + j >= text.Length || text[num + j] != text3[j])
98 {
99 flag = false;
100 break;
101 }
102 }
103 if (flag && item2.suffix != null)
104 {
105 flag = false;
106 if (num + text3.Length >= text.Length)
107 {
108 continue;
109 }
110 string[] suffix = item2.suffix;
111 foreach (string text4 in suffix)
112 {
113 if (text[num + text3.Length] == text4[0])
114 {
115 flag = true;
116 break;
117 }
118 }
119 }
120 if (flag)
121 {
122 item = item2;
123 text2 = text3;
124 break;
125 }
126 }
127 if (flag)
128 {
129 break;
130 }
131 }
132 if (flag && text2.Length > 0)
133 {
134 stringBuilder.Append((item.additive ? text2 : "") + item.strs[Rand.Range(0, item.strs.Length)]);
135 num += text2.Length;
136 }
137 else
138 {
139 stringBuilder.Append(text[num]);
140 num++;
141 }
142 }
143 stringBuilder.Replace("…ー", "ー…");
144 return stringBuilder;
145 }
146
147 public override void BuildMap(string sheetName = null)
148 {
149 LoadBook();
150 ISheet sheetAt = book.GetSheetAt(0);
151 if (sheetAt.LastRowNum <= 3)
152 {
153 return;
154 }
155 for (int i = 3; i <= sheetAt.LastRowNum; i++)
156 {
157 IRow row = sheetAt.GetRow(i);
158 if (row.Cells.Count == 0)
159 {
160 Debug.LogWarning(path + "/" + book?.ToString() + "/" + sheetName + "/" + sheetAt.LastRowNum + "/" + i);
161 continue;
162 }
163 string text = row.GetCell(0).ToString();
164 if (text.IsEmpty())
165 {
166 Debug.LogWarning(path + "/" + book?.ToString() + "/" + sheetName + "/" + sheetAt.LastRowNum + "/" + i);
167 continue;
168 }
169 string text2 = row.GetCell(1).ToString();
170 string text3 = row.GetCell(2)?.ToString() ?? "";
171 int @int = ExcelParser.GetInt(4, row);
172 if (text[0] == '$')
173 {
174 switch (text + "_" + text3)
175 {
176 case "$I_":
177 I_M = (I_F = text2.Split(','));
178 p_I_M = (p_I_F = @int);
179 break;
180 case "$you_":
181 you_M = (you_F = text2.Split(','));
182 p_you_M = (p_you_F = @int);
183 break;
184 case "$I_M":
185 I_M = text2.Split(',');
186 p_I_M = @int;
187 break;
188 case "$you_M":
189 you_M = text2.Split(',');
190 p_you_M = @int;
191 break;
192 case "$I_F":
193 I_F = text2.Split(',');
194 p_I_F = @int;
195 break;
196 case "$you_F":
197 you_F = text2.Split(',');
198 p_you_F = @int;
199 break;
200 case "$tag":
201 tags = text2.Split(',');
202 break;
203 }
204 }
205 items.Add(new Item(row, text, text2, text3, @int));
206 }
207 }
208}
void LoadBook()
Definition: ExcelData.cs:49
XSSFWorkbook book
Definition: ExcelData.cs:21
string path
Definition: ExcelData.cs:27
static bool GetBool(int id)
Definition: ExcelParser.cs:34
static int GetInt(int id)
Definition: ExcelParser.cs:19
Definition: Rand.cs:4
static int Range(int min, int max)
Definition: Rand.cs:42
static int rnd(int max)
Definition: Rand.cs:52
static string[] DefaultSuffix
Definition: TextConv.cs:10
Item(IRow row, string c0, string c1, string c2, int c4)
Definition: TextConv.cs:24
string[] keys
Definition: TextConv.cs:16
string[] strs
Definition: TextConv.cs:12
bool additive
Definition: TextConv.cs:22
string[] suffix
Definition: TextConv.cs:14
string[] I_F
Definition: TextConv.cs:53
int p_I_F
Definition: TextConv.cs:63
int p_you_F
Definition: TextConv.cs:67
List< Item > items
Definition: TextConv.cs:69
int p_you_M
Definition: TextConv.cs:65
StringBuilder Apply(ref string text, int gender)
Definition: TextConv.cs:71
string[] tags
Definition: TextConv.cs:59
string[] you_M
Definition: TextConv.cs:55
string[] you_F
Definition: TextConv.cs:57
int p_I_M
Definition: TextConv.cs:61
string[] I_M
Definition: TextConv.cs:51
override void BuildMap(string sheetName=null)
Definition: TextConv.cs:147