File tree Expand file tree Collapse file tree 1 file changed +25
-6
lines changed
Expand file tree Collapse file tree 1 file changed +25
-6
lines changed Original file line number Diff line number Diff line change 1- using SharedLib ;
1+ using Microsoft . Extensions . Logging ;
2+
3+ using SharedLib ;
24using SharedLib . Data ;
35
6+ using System ;
47using System . Collections . Frozen ;
58
69using static Newtonsoft . Json . JsonConvert ;
@@ -13,12 +16,28 @@ public sealed class FactionTemplateDB
1316{
1417 public FrozenDictionary < int , int > Factions { get ; }
1518
16- public FactionTemplateDB ( DataConfig dataConfig )
19+ public const string FileName = "factiontemplates.json" ;
20+
21+ public FactionTemplateDB ( ILogger < FactionTemplateDB > logger , DataConfig dataConfig )
1722 {
18- FactionTemplate [ ] data = DeserializeObject < FactionTemplate [ ] > (
19- ReadAllText ( Join ( dataConfig . ExpDbc , "factiontemplates.json" ) ) ) ! ;
23+ string path = Join ( dataConfig . ExpDbc , FileName ) ;
24+
25+ FactionTemplate [ ] data = [ ] ;
26+
27+ try
28+ {
29+ string json = ReadAllText ( path ) ;
30+ if ( ! string . IsNullOrWhiteSpace ( json ) )
31+ {
32+ data = DeserializeObject < FactionTemplate [ ] > ( json ) ?? [ ] ;
33+ }
34+ }
35+ catch ( Exception ex )
36+ {
37+ logger . LogWarning ( $ "Failed to load { FileName } : { ex . Message } ") ;
38+ logger . LogWarning ( "AdhocNPC profiles with 'Auto NPC Route' features will not work properly!" ) ;
39+ }
2040
21- Factions = data
22- . ToFrozenDictionary ( c => c . Id , c => c . FriendGroup ) ;
41+ Factions = data . ToFrozenDictionary ( c => c . Id , c => c . FriendGroup ) ;
2342 }
2443}
You can’t perform that action at this time.
0 commit comments