@@ -17,15 +17,15 @@ public static async Task OutputProvinces(
17
17
Title . LandedTitles titles
18
18
) {
19
19
Logger . Info ( "Writing provinces..." ) ;
20
-
20
+
21
21
FrozenSet < ulong > countyCapitalProvinceIds = titles . Counties . AsValueEnumerable ( )
22
22
. Select ( title => title . CapitalBaronyProvinceId )
23
23
. Where ( id => id is not null )
24
24
. Select ( id => id ! . Value )
25
25
. ToFrozenSet ( ) ;
26
26
27
27
// Output provinces to files named after their de jure kingdoms.
28
- var alreadyOutputtedProvinces = new ConcurrentHashSet < ulong > ( ) ;
28
+ var alreadyOutputtedProvIds = new ConcurrentHashSet < ulong > ( ) ;
29
29
30
30
var deJureKingdoms = titles . GetDeJureKingdoms ( ) ;
31
31
Parallel . ForEach ( deJureKingdoms , kingdom => {
@@ -36,60 +36,63 @@ Title.LandedTitles titles
36
36
}
37
37
38
38
ProvinceOutputter . WriteProvince ( sb , province , countyCapitalProvinceIds . Contains ( province . Id ) ) ;
39
- alreadyOutputtedProvinces . Add ( province . Id ) ;
39
+ alreadyOutputtedProvIds . Add ( province . Id ) ;
40
40
}
41
41
42
42
var filePath = $ "{ outputModPath } /history/provinces/{ kingdom . Id } .txt";
43
43
using var historyOutput = new StreamWriter ( filePath ) ;
44
44
historyOutput . Write ( sb . ToString ( ) ) ;
45
45
} ) ;
46
46
47
- if ( alreadyOutputtedProvinces . Count != provinces . Count ) {
47
+ if ( alreadyOutputtedProvIds . Count != provinces . Count ) {
48
48
var filePath = $ "{ outputModPath } /history/provinces/onlyDeJureDuchy.txt";
49
49
await using var historyOutput = TextWriter . Synchronized ( new StreamWriter ( filePath ) ) ;
50
50
var deJureDuchies = titles . GetDeJureDuchies ( ) ;
51
- Parallel . ForEach ( deJureDuchies , duchy => {
51
+ foreach ( var duchy in deJureDuchies ) {
52
52
var sb = new System . Text . StringBuilder ( ) ;
53
53
54
54
foreach ( var province in provinces ) {
55
- if ( alreadyOutputtedProvinces . Contains ( province . Id ) ) {
55
+ if ( alreadyOutputtedProvIds . Contains ( province . Id ) ) {
56
56
continue ;
57
57
}
58
58
59
59
if ( duchy . DuchyContainsProvince ( province . Id ) ) {
60
60
sb . AppendLine ( $ "# { duchy . Id } ") ;
61
61
ProvinceOutputter . WriteProvince ( sb , province , countyCapitalProvinceIds . Contains ( province . Id ) ) ;
62
- alreadyOutputtedProvinces . Add ( province . Id ) ;
62
+ alreadyOutputtedProvIds . Add ( province . Id ) ;
63
63
}
64
64
}
65
65
66
66
if ( sb . Length > 0 ) {
67
- historyOutput . Write ( sb . ToString ( ) ) ;
67
+ await historyOutput . WriteAsync ( sb . ToString ( ) ) ;
68
68
}
69
- } ) ;
69
+ }
70
70
}
71
71
72
- // Create province mapping file.
73
- if ( alreadyOutputtedProvinces . Count != provinces . Count ) {
74
- var mappingsPath = $ "{ outputModPath } /history/province_mapping/province_mapping.txt";
75
- await using var mappingsWriter = FileHelper . OpenWriteWithRetries ( mappingsPath , System . Text . Encoding . UTF8 ) ;
76
- await using var threadSafeWriter = TextWriter . Synchronized ( mappingsWriter ) ;
72
+ if ( alreadyOutputtedProvIds . Count != provinces . Count ) {
73
+ await CreateProvinceMappingFile ( outputModPath , provinces , alreadyOutputtedProvIds ) ;
74
+ }
77
75
78
- foreach ( var province in provinces ) {
79
- if ( alreadyOutputtedProvinces . Contains ( province . Id ) ) {
80
- continue ;
81
- }
76
+ Logger . IncrementProgress ( ) ;
77
+ }
82
78
83
- var baseProvId = province . BaseProvinceId ;
84
- if ( baseProvId is null ) {
85
- continue ;
86
- }
79
+ private static async Task CreateProvinceMappingFile ( string outputModPath , ProvinceCollection provinces , ConcurrentHashSet < ulong > alreadyOutputtedProvinceIds ) {
80
+ var mappingsPath = $ " { outputModPath } /history/province_mapping/province_mapping.txt" ;
81
+ await using var mappingsWriter = FileHelper . OpenWriteWithRetries ( mappingsPath , System . Text . Encoding . UTF8 ) ;
82
+ await using var threadSafeWriter = TextWriter . Synchronized ( mappingsWriter ) ;
87
83
88
- await threadSafeWriter . WriteLineAsync ( $ "{ province . Id } = { baseProvId } ") ;
89
- alreadyOutputtedProvinces . Add ( province . Id ) ;
84
+ foreach ( var province in provinces ) {
85
+ if ( alreadyOutputtedProvinceIds . Contains ( province . Id ) ) {
86
+ continue ;
90
87
}
91
- }
92
88
93
- Logger . IncrementProgress ( ) ;
89
+ var baseProvId = province . BaseProvinceId ;
90
+ if ( baseProvId is null ) {
91
+ continue ;
92
+ }
93
+
94
+ await threadSafeWriter . WriteLineAsync ( $ "{ province . Id } = { baseProvId } ") ;
95
+ alreadyOutputtedProvinceIds . Add ( province . Id ) ;
96
+ }
94
97
}
95
98
}
0 commit comments