-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClipTransformer.cs
365 lines (361 loc) · 12.8 KB
/
ClipTransformer.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
//建立元件转换类
class ClipTransformer
{
//创建cr实例
ClipReader cr = new ClipReader();
//创建ta实例
TransformAction ta = new TransformAction();
//预置ca数组以记录所有元件名称(包括被引用的)
public ArrayList ca = new ArrayList();
//预置cca数组以记录所有元件名称(包括被引用的)
public ArrayList cca = new ArrayList();
//预置元件类型表示
public int icca = 0;
//预置about
public string about = null;
//预置json名称及属性
public string oname, jname, j1, j2, j3, j4, j5, o1, o2, o3, o4, o5;
//判断元件类型20240402添加
int graphic = 0;
//生成序号重写选择部分
public int NumRewrite()
{
int num = 0;
Console.WriteLine("是否进行元件序号重写?重写输入1或者y,不重写输入0或n(不输入按回车默认重写)");
//选项收录
string s = Console.ReadLine();
if (s == "" || s == "/n/n" || s == "1" || s == "y")
{
num = 1;
}
else if(s == "0" || s == "n")
{
num = 0;
}
else
{
Console.WriteLine("输入错误,执行默认重选操作");
num=NumRewrite();
}
return num;
}
//生成元件类型选择部分20240402添加
public int NumGraphic()
{
int num = 0;
Console.WriteLine("请选择元件类型(不输入按回车默认图形元件)\n1.图形元件\n2.影片剪辑");
//选项收录
string s = Console.ReadLine();
if (s == "" || s == "/n/n" || s == "1")
{
num = 1;
}
else if (s == "2")
{
num = 0;
}
else
{
Console.WriteLine("输入错误,执行默认重选操作");
num = NumGraphic();
}
return num;
}
//生成选择部分
public void Select(ArrayList cca)
{
try
{
//预定义元件前缀
string aa = null, ii = null, ma = null;
Console.WriteLine("请根据以下需求输入相应序号并按回车键(不输入按回车默认转太極的xfl)\n1.转SPC-Util的xfl\n2.转太極的xfl\n3.转TwinKles-ToolKit的xfl(因数据结构问题停止支持)\n4.转PopStudio的xfl(因数据结构问题停止支持)\n5.转SPCUtil的xfl(Android)\n6.转太極的xfl(Android)\n注:请务必按照说明书严格执行规范操作!!!");
//选项收录
string s = Console.ReadLine();
//判定是否直接回车,直接回车则执行2,1为转SPC-Util的xfl,2为转太極的xfl,3为转TwinKles-ToolKit的xfl,4为转PopStudio的xfl,5为转SPCUtil的xfl(Android),6为转太極的xfl(Android)
if (s == "1")
{
//前缀赋值
aa = "A_";
ii = "M_";
ma = "A_Main";
about = "This XFL is convert from PAM file, By SPC-Util.";
jname = "OtherInfo.json";
j1 = "UnK";
j2 = "Origin";
j3 = "ImageSize";
j4 = "ImageMapper";
j5 = "SubAnimMapper";
//转换数组
ArrayListTransform(cca, aa, ii, ma);
}
else if (s == "" || s == "/n/n" || s == "2")
{
//前缀赋值
aa = "a";
ii = "i";
ma = "main";
about = "this XFL is convert from Popcap-AniMation file , by TaiJi .";
jname = "extra.json";
j1 = "unk";
j2 = "origin";
j3 = "imgSz";
j4 = "imgMapper";
j5 = "animMapper";
//转换数组
ArrayListTransform(cca, aa, ii, ma);
}
else if (s == "3")
{
//前缀赋值
aa = "animation_";
ii = "sprite_";
ma = "main_animation";
jname = "extra.json";
j1 = "unknown";
j2 = "origin";
j3 = "imgSz";
j4 = "imgMapper";
j5 = "animMapper";
//停止支持//转换数组
//停止支持///ArrayListTransform(cca, aa, ii, ma);
Console.WriteLine("功能因数据结构停止支持,执行默认重选操作");
Select(cca);
}
else if (s == "4")
{
//前缀赋值
aa = "animation_";
ii = "sprite_";
ma = "main_animation";
jname = "extra.json";
j1 = "unknown";
j2 = "origin";
j3 = "imgSz";
j4 = "imgMapper";
j5 = "animMapper";
//停止支持//转换数组
//停止支持///ArrayListTransform(cca, aa, ii, ma);
Console.WriteLine("功能因数据结构停止支持,执行默认重选操作");
Select(cca);
}
else if (s == "5")
{
//前缀赋值
aa = "A_";
ii = "M_";
ma = "A_Main";
about = "This XFL is convert from PAM file, By SPC-Util.";
jname = "OtherInfo.json";
j1 = "UnK";
j2 = "Origin";
j3 = "ImageSize";
j4 = "ImageMapper";
j5 = "SubAnimMapper";
//转换数组
ArrayListTransform(cca, aa, ii, ma);
}
else if (s == "6")
{
//前缀赋值
aa = "a";
ii = "i";
ma = "main";
about = "this XFL is convert from Popcap-AniMation file , by TaiJi .";
jname = "extra.json";
j1 = "unk";
j2 = "origin";
j3 = "imgSz";
j4 = "imgMapper";
j5 = "animMapper";
//转换数组
ArrayListTransform(cca, aa, ii, ma);
}
else
{
Console.WriteLine("输入数字错误,执行默认重选操作");
Select(cca);
}
}
catch
{
Console.WriteLine("Select ERROR");
//提示按任意键继续
Console.WriteLine("Press any key to continue...");
//输入任意键退出
Console.ReadLine();
}
}
//生成数组转换部分
public void ArrayListTransform(ArrayList cca,string aa,string ii,string ma)
{
try
{
//判断是否重写元件序号
int num = NumRewrite(), aj = 0, ij = 0;
//判断元件类型20240402添加
graphic=NumGraphic();
if (num == 1)
{
Console.WriteLine("元件序号重写中......");
}
else { }
if (cca.Contains("A_Main"))
{
icca = 1;
oname = "OtherInfo.json";
o1 = "UnK";
o2 = "Origin";
o3 = "ImageSize";
o4 = "ImageMapper";
o5 = "SubAnimMapper";
}
else if (cca.Contains("main"))
{
icca = 2;
oname = "extra.json";
o1 = "unk";
o2 = "origin";
o3 = "imgSz";
o4 = "imgMapper";
o5 = "animMapper";
}
else if (cca.Contains("main_animation"))
{
icca = 0;
oname = "extra.json";
o1 = "unknown";
o2 = "origin";
o3 = j3;
o4 = j4;
o5 = j5;
Console.WriteLine("数据结构不支持,不予转换");
}
else
{
Console.WriteLine("缺少核心元件或数据结构不支持,不予转换");
}
for (int i = 0; i < cca.Count; i++)
{
if (icca == 1)
{
cca[i] = cca[i].ToString().Replace("A_Main", ma);
if (cca[i].ToString()!=ma)
{
cca[i] = cca[i].ToString().Replace("A_", aa);
if(Regex.Replace(cca[i].ToString(), @"[\d]", "") == aa&&num==1)
{
cca[i] = Regex.Replace(cca[i].ToString(), @"[\d]", "") + aj.ToString();
aj++;
}
else { }
cca[i] = cca[i].ToString().Replace("M_", ii);
if (Regex.Replace(cca[i].ToString(), @"[\d]", "") == ii&&num==1)
{
cca[i] = Regex.Replace(cca[i].ToString(), @"[\d]", "") + ij.ToString();
ij++;
}
else { }
}
else { }
}
else if (icca == 2)
{
cca[i] = cca[i].ToString().Replace("main", ma);
if (cca[i].ToString() != ma)
{
cca[i] = cca[i].ToString().Replace("a", aa);
if (Regex.Replace(cca[i].ToString(), @"[\d]", "") == aa && num == 1)
{
cca[i] = Regex.Replace(cca[i].ToString(), @"[\d]", "") + aj.ToString();
aj++;
}
else { }
cca[i] = cca[i].ToString().Replace("i", ii);
if (Regex.Replace(cca[i].ToString(), @"[\d]", "") == ii && num == 1)
{
cca[i] = Regex.Replace(cca[i].ToString(), @"[\d]", "") + ij.ToString();
ij++;
}
else { }
}
else { }
}
else if (icca == 3)
{
cca[i] = cca[i].ToString().Replace("main_animation", ma);
if (cca[i].ToString() != ma)
{
cca[i] = cca[i].ToString().Replace("animation_", aa);
if (Regex.Replace(cca[i].ToString(), @"[\d]", "") == aa && num == 1)
{
cca[i] = Regex.Replace(cca[i].ToString(), @"[\d]", "") + aj.ToString();
aj++;
}
else { }
cca[i] = cca[i].ToString().Replace("sprite_", ii);
if (Regex.Replace(cca[i].ToString(), @"[\d]", "") == ii && num == 1)
{
cca[i] = Regex.Replace(cca[i].ToString(), @"[\d]", "") + ij.ToString();
ij++;
}
else { }
}
else { }
}
else { }
}
if (num == 1)
{
Console.WriteLine("元件序号重写完成");
}
else { }
}
catch
{
Console.WriteLine("ArrayListTransform ERROR");
//提示按任意键继续
Console.WriteLine("Press any key to continue...");
//输入任意键退出
Console.ReadLine();
}
}
//生成元件转换部分
public void ClipTransform(string Fpath)
{
try
{
//生成元件数组
cr.ClipRead(Fpath);
//得到检测的元件数组
ca.AddRange(cr.ca);
//复制数组
cca.AddRange(ca);
//选择转换形式
Select(cca);
if (icca != 0)
{
//转换行为
ta.ClipTransform(Fpath + "\\LIBRARY", ca, cca,graphic);
//DOMDocument重写
ta.DOMDocumentTransform(Fpath + "\\DOMDocument.xml", about, ca, cca,graphic);
//json重写
ta.JsonRewrite(Fpath, oname, jname, j1, j2, j3, j4, j5, o1, o2, o3, o4, o5, icca, ca, cca);
}
else { }
}
catch
{
Console.WriteLine("ClipTransform ERROR");
//提示按任意键继续
Console.WriteLine("Press any key to continue...");
//输入任意键退出
Console.ReadLine();
}
}
}