-
Notifications
You must be signed in to change notification settings - Fork 8
/
AtlasReader.cs
80 lines (74 loc) · 2.47 KB
/
AtlasReader.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
using System;
using System.IO;
using System.Collections.Generic;
namespace SpineBin2Json35
{
public class AtlasReader
{
TextReader reader;
public Dictionary<string, int[]> size = new Dictionary<string, int[]>();
string tupleName;
string[] tupleValues = new string[4];
int ReadTuple()
{
string line = reader.ReadLine();
int colon = line.IndexOf(':');
if (colon == -1) throw new System.Exception("Line dismatch: " + line);
tupleName = line.Substring(colon);
int count = 0, lastComma = colon+1;
for (count = 0; count < 3; ++count)
{
int comma = line.IndexOf(',', lastComma);
if (comma == -1) break;
tupleValues[count] = line.Substring(lastComma, comma - lastComma).Trim();
lastComma = comma + 1;
}
tupleValues[count] = line.Substring(lastComma).Trim();
return count + 1;
}
public AtlasReader(TextReader reader)
{
this.reader = reader;
Convert();
}
void Convert()
{
string line, pageFile = null;
while ((line = reader.ReadLine()) != null)
{
if (line.Trim().Length == 0)
{
pageFile = null;
continue;
}
if (pageFile == null)
{
pageFile = line;
if (ReadTuple() == 2) ReadTuple();//size, format
ReadTuple();//filter
ReadTuple();//repeat
}
else
{
ReadTuple();//rotate
ReadTuple();//xy
ReadTuple();//size
// Console.WriteLine(int.Parse(tupleValues[0]));
// Console.WriteLine(int.Parse(tupleValues[1]));
size[line] = new int[2] { int.Parse(tupleValues[0]), int.Parse(tupleValues[1]) };
if (ReadTuple() == 4)//origin size
{
//split
if (ReadTuple() == 4)
{
//pads
ReadTuple();
}
}
ReadTuple();//offset
ReadTuple();//index
}
}
}
}
}