@@ -40,28 +40,25 @@ internal static void
40
40
private static ( string LangClassName , List < NamedDictionary > Dict )
41
41
ReadSource ( string file )
42
42
{
43
- var retDict = new List < NamedDictionary > ( ) ;
44
-
45
- var classInstanceDict = new Dictionary < string , string > ( ) ;
46
-
47
43
string code = File . ReadAllText ( file ) ;
48
44
var tree = ParseTextFast ( code ) ;
49
45
50
46
var ( markedMember , _) = GetAttrMarkedItem ( tree , SyntaxKind . ClassDeclaration , GenAttributes . FenGenLocalizationSourceClass ) ;
51
- var LTextClass = ( ClassDeclarationSyntax ) markedMember ;
47
+ var lTextClass = ( ClassDeclarationSyntax ) markedMember ;
52
48
53
- var childNodes = LTextClass . ChildNodes ( ) . ToArray ( ) ;
49
+ var childNodes = lTextClass . ChildNodes ( ) . ToArray ( ) ;
54
50
51
+ var classInstanceDict = new Dictionary < string , string > ( ) ;
55
52
// Once through first to get the instance types and names
56
53
for ( int i = 0 ; i < childNodes . Length ; i ++ )
57
54
{
58
55
if ( childNodes [ i ] is FieldDeclarationSyntax field )
59
56
{
60
- classInstanceDict . Add ( field . Declaration . Type . ToString ( ) ,
61
- field . Declaration . Variables [ 0 ] . Identifier . Text ) ;
57
+ classInstanceDict . Add ( field . Declaration . Type . ToString ( ) , field . Declaration . Variables [ 0 ] . Identifier . Text ) ;
62
58
}
63
59
}
64
60
61
+ var retDict = new List < NamedDictionary > ( ) ;
65
62
// Now through again to get the language string names from the nested classes
66
63
foreach ( SyntaxNode cn in childNodes )
67
64
{
@@ -85,8 +82,6 @@ private static (string LangClassName, List<NamedDictionary> Dict)
85
82
}
86
83
87
84
var member = ( MemberDeclarationSyntax ) m ;
88
-
89
- string fName , fValue = "" ;
90
85
foreach ( AttributeListSyntax attrList in member . AttributeLists )
91
86
{
92
87
foreach ( AttributeSyntax attr in attrList . Attributes )
@@ -98,6 +93,7 @@ private static (string LangClassName, List<NamedDictionary> Dict)
98
93
var argList = attr . ArgumentList ;
99
94
if ( argList != null )
100
95
{
96
+ string fValue = "" ;
101
97
var args = argList . Arguments ;
102
98
for ( int i = 0 ; i < args . Count ; i ++ )
103
99
{
@@ -126,6 +122,7 @@ private static (string LangClassName, List<NamedDictionary> Dict)
126
122
}
127
123
}
128
124
125
+ string fName ;
129
126
EqualsValueClauseSyntax ? initializer ;
130
127
if ( m . IsKind ( SyntaxKind . FieldDeclaration ) )
131
128
{
@@ -143,18 +140,16 @@ private static (string LangClassName, List<NamedDictionary> Dict)
143
140
if ( initializer == null )
144
141
{
145
142
string type = m . IsKind ( SyntaxKind . FieldDeclaration ) ? "field" : "property" ;
146
- ThrowErrorAndTerminate ( nameof ( Language ) + ":\r \n " +
147
- "Found a " + type + " without an initializer in " + file ) ;
143
+ ThrowErrorAndTerminate ( nameof ( Language ) + ":\r \n " + "Found a " + type + " without an initializer in " + file ) ;
148
144
}
149
145
150
- fValue = ( ( LiteralExpressionSyntax ) initializer ! . Value ) . Token . ValueText ;
151
- dict . Add ( new IniItem { Key = fName , Value = fValue } ) ;
146
+ dict . Add ( new IniItem { Key = fName , Value = ( ( LiteralExpressionSyntax ) initializer ! . Value ) . Token . ValueText } ) ;
152
147
}
153
148
154
149
retDict . Add ( dict ) ;
155
150
}
156
151
157
- string lTextClassId = LTextClass . Identifier . ToString ( ) ;
152
+ string lTextClassId = lTextClass . Identifier . ToString ( ) ;
158
153
return ( lTextClassId , retDict ) ;
159
154
}
160
155
@@ -248,42 +243,31 @@ private static void WriteDest(string langClassName, List<NamedDictionary> dictLi
248
243
private static void WriteIniFile ( string langIniFile , List < NamedDictionary > dictList , bool test = false )
249
244
{
250
245
var sb = new StringBuilder ( ) ;
251
-
252
- string testPrefix = test ? "█" : "" ;
253
-
254
246
sb . AppendLine ( "; This is an AngelLoader language file." ) ;
255
247
sb . AppendLine ( "; This file MUST be saved with UTF8 encoding in order to guarantee correct display of strings." ) ;
256
248
sb . AppendLine ( ) ;
257
249
250
+ string testPrefix = test ? "█" : "" ;
258
251
for ( int i = 0 ; i < dictList . Count ; i ++ )
259
252
{
260
253
var dict = dictList [ i ] ;
261
254
262
255
sb . AppendLine ( "[" + dict . Name + "]" ) ;
263
256
foreach ( IniItem item in dict )
264
257
{
265
- if ( item . IsComment )
258
+ if ( item . Key . IsEmpty ( ) && item . Value . IsEmpty ( ) )
266
259
{
267
- if ( ! item . Value . IsEmpty ( ) )
268
- {
269
- string [ ] comments = item . Value . Split ( new [ ] { "\r \n " , "\r " , "\n " } , StringSplitOptions . None ) ;
270
- foreach ( string c in comments ) sb . AppendLine ( "; " + c ) ;
271
- }
260
+ sb . AppendLine ( ) ;
272
261
}
273
- else if ( item . Key . IsEmpty ( ) && item . Value . IsEmpty ( ) )
262
+ else if ( item . IsComment && ! item . Value . IsEmpty ( ) )
274
263
{
275
- sb . AppendLine ( ) ;
264
+ string [ ] comments = item . Value . Split ( new [ ] { "\r \n " , "\r " , "\n " } , StringSplitOptions . None ) ;
265
+ foreach ( string c in comments ) sb . AppendLine ( "; " + c ) ;
276
266
}
277
267
else
278
268
{
279
- if ( test && item . Key == "TranslatedLanguageName" )
280
- {
281
- sb . AppendLine ( item . Key + "=" + "TéstLang" ) ;
282
- }
283
- else
284
- {
285
- sb . AppendLine ( item . Key + "=" + testPrefix + item . Value ) ;
286
- }
269
+ string val = test && item . Key == "TranslatedLanguageName" ? "TéstLang" : testPrefix + item . Value ;
270
+ sb . AppendLine ( item . Key + "=" + val ) ;
287
271
}
288
272
}
289
273
if ( i < dictList . Count - 1 ) sb . AppendLine ( ) ;
0 commit comments