99namespace ImperatorToCK3 . CommonUtils . Map ;
1010
1111internal sealed class ProvinceDefinitions : IdObjectCollection < ulong , ProvinceDefinition > {
12- public Dictionary < Rgb24 , ulong > ColorToProvinceDict { get ; } = [ ] ;
13- public Dictionary < ulong , Rgb24 > ProvinceToColorDict { get ; } = [ ] ;
12+ internal Dictionary < Rgb24 , ulong > ColorToProvinceDict { get ; } = [ ] ;
13+ internal Dictionary < ulong , Rgb24 > ProvinceToColorDict { get ; } = [ ] ;
1414
15- public void LoadDefinitions ( string definitionsFilename , ModFilesystem modFS ) {
15+ internal void LoadDefinitions ( string definitionsFilename , ModFilesystem modFS ) {
1616 var relativePath = Path . Combine ( "map_data" , definitionsFilename ) ;
17- var definitionsFilePath = modFS . GetActualFileLocation ( relativePath ) ;
17+ string ? definitionsFilePath = modFS . GetActualFileLocation ( relativePath ) ;
1818 if ( definitionsFilePath is null ) {
1919 Logger . Warn ( $ "Province definitions file { definitionsFilename } not found!") ;
2020 return ;
@@ -36,14 +36,46 @@ public void LoadDefinitions(string definitionsFilename, ModFilesystem modFS) {
3636 }
3737
3838 try {
39- var columns = line . Split ( ';' ) ;
39+ var span = line . AsSpan ( ) ;
40+ int pos = 0 ;
4041
41- var id = ulong . Parse ( columns [ 0 ] ) ;
42+ // id
43+ var idEnd = span . IndexOf ( ';' ) ;
44+ if ( idEnd < 0 ) throw new FormatException ( "Missing separators" ) ;
45+ var idSpan = span [ pos ..idEnd ] ;
46+ pos = idEnd + 1 ;
47+ if ( ! ulong . TryParse ( idSpan , out var id ) ) {
48+ throw new FormatException ( $ "Invalid id: { idSpan } ") ;
49+ }
4250 AddOrReplace ( new ProvinceDefinition ( id ) ) ;
4351
44- var r = byte . Parse ( columns [ 1 ] ) ;
45- var g = byte . Parse ( columns [ 2 ] ) ;
46- var b = byte . Parse ( columns [ 3 ] ) ;
52+ // r
53+ var rEnd = span [ pos ..] . IndexOf ( ';' ) ;
54+ if ( rEnd < 0 ) throw new FormatException ( "Missing separators" ) ;
55+ var rSpan = span [ pos ..( pos + rEnd ) ] ;
56+ pos += rEnd + 1 ;
57+ if ( ! byte . TryParse ( rSpan , out var r ) ) {
58+ throw new FormatException ( $ "Invalid r: { rSpan } ") ;
59+ }
60+
61+ // g
62+ var gEnd = span [ pos ..] . IndexOf ( ';' ) ;
63+ if ( gEnd < 0 ) throw new FormatException ( "Missing separators" ) ;
64+ var gSpan = span [ pos ..( pos + gEnd ) ] ;
65+ pos += gEnd + 1 ;
66+ if ( ! byte . TryParse ( gSpan , out var g ) ) {
67+ throw new FormatException ( $ "Invalid g: { gSpan } ") ;
68+ }
69+
70+ // b
71+ var bEnd = span [ pos ..] . IndexOf ( ';' ) ;
72+ if ( bEnd < 0 ) throw new FormatException ( "Missing separators" ) ;
73+ var bSpan = span [ pos ..( pos + bEnd ) ] ;
74+ pos += bEnd + 1 ;
75+ if ( ! byte . TryParse ( bSpan , out var b ) ) {
76+ throw new FormatException ( $ "Invalid b: { bSpan } ") ;
77+ }
78+
4779 var color = new Rgb24 ( r , g , b ) ;
4880 ProvinceToColorDict . Add ( id , color ) ;
4981 ColorToProvinceDict [ color ] = id ;
0 commit comments