-
Notifications
You must be signed in to change notification settings - Fork 1
/
FontInfo.cs
182 lines (145 loc) · 3.9 KB
/
FontInfo.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
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
namespace LegalityChecker
{
public class FontChar : IEntity
{
private ushort m_PokeChar;
private ushort m_Unicode;
public ushort PokeChar{ get{ return m_PokeChar; } set{ m_PokeChar = value; } }
public ushort Unicode{ get{ return m_Unicode; } set{ m_Unicode = value; } }
public bool IsTerminator{ get{ return m_PokeChar == 0xFFFF; } }
ushort IEntity.ID{ get{ return m_PokeChar; } set{ m_PokeChar = value; } }
public FontChar( ushort pokechar, ushort unicode )
{
m_PokeChar = pokechar;
m_Unicode = unicode;
}
public FontChar()
{
}
public void Deserialize( GenericReader reader )
{
m_PokeChar = reader.ReadUShort();
m_Unicode = reader.ReadUShort();
}
public void Serialize( GenericWriter writer )
{
writer.Write( m_PokeChar );
writer.Write( m_Unicode );
}
}
public abstract class PokeString
{
private ushort[] m_PokeChars;
public ushort[] ToArray(){ return m_PokeChars; }
public bool IsTerminatedAt(int number){ return m_PokeChars[number] == 0xFFFF; }
public abstract int Length{ get; }
public abstract bool HasTrash{ get; }
public PokeString( GenericReader reader )
{
m_PokeChars = new ushort[Length];
for ( int i = 0; i < Length; i++ )
{
m_PokeChars[i] = reader.ReadUShort();
if ( !HasTrash && IsTerminatedAt( i ) )
break;
}
}
public PokeString( ushort[] chars )
{
m_PokeChars = chars;
}
public PokeString( string chars, int size )
{
m_PokeChars = new ushort[size];
for ( int i = 0; i < chars.Length && i < size; i++ )
m_PokeChars[i] = PokeData.FindPokeChar( chars[i] );
if ( chars.Length < size )
m_PokeChars[chars.Length] = 0xFFFF; //ushort terminator
}
public override string ToString()
{
StringBuilder builder = new StringBuilder();
for ( int i = 0; i < m_PokeChars.Length; i++ )
{
if ( IsTerminatedAt( i ) )
break;
else
{
//Console.WriteLine( "Char: {0:X}", m_PokeChars[i] );
if ( m_PokeChars[i] > 0 )
builder.Append( (char)PokeData.FindUniChar( m_PokeChars[i] ) );
}
}
return builder.ToString();
}
public virtual void Serialize( GenericWriter writer )
{
for ( int i = 0; i < Length; i++ )
{
writer.Write( (ushort)m_PokeChars[i] );
if ( !HasTrash && IsTerminatedAt( i ) )
break;
}
}
}
public class PokeString10Info : PokeString //Pokemon Names in database
{
public override int Length{ get{ return 11; } }
public override bool HasTrash{ get{ return false; } }
public PokeString10Info( GenericReader reader ) : base( reader )
{
}
public PokeString10Info( ushort[] chars ) : base( chars )
{
}
public PokeString10Info( string chars, int size ) : base( chars, size )
{
}
}
public class PokeString10 : PokeString //Pokemon Names
{
public override int Length{ get{ return 11; } }
public override bool HasTrash{ get{ return true; } }
public PokeString10( GenericReader reader ) : base( reader )
{
}
public PokeString10( ushort[] chars ) : base( chars )
{
}
public PokeString10( string chars, int size ) : base( chars, size )
{
}
}
public class PokeString7 : PokeString //Original Trainer Name
{
public override int Length{ get{ return 8; } }
public override bool HasTrash{ get{ return true; } }
public PokeString7( GenericReader reader ) : base( reader )
{
}
public PokeString7( ushort[] chars ) : base( chars )
{
}
public PokeString7( string chars, int size ) : base( chars, size )
{
}
}
public class PokeString8Info : PokeString //Box Names
{
public override int Length{ get{ return 9; } }
public override bool HasTrash{ get{ return false; } }
public PokeString8Info( GenericReader reader ) : base( reader )
{
}
public PokeString8Info( ushort[] chars ) : base( chars )
{
}
public PokeString8Info( string chars, int size ) : base( chars, size )
{
}
}
}