66using ParadoxPower . CSharpExtensions ;
77using ParadoxPower . Process ;
88using VModer . Core . Extensions ;
9+ using VModer . Core . Infrastructure ;
910using VModer . Core . Models . Character ;
1011using VModer . Core . Models . Modifiers ;
1112using VModer . Core . Services . GameResource . Base ;
@@ -16,9 +17,9 @@ namespace VModer.Core.Services.GameResource;
1617public sealed class GeneralTraitsService
1718 : CommonResourcesService < GeneralTraitsService , FrozenDictionary < string , CharacterTrait > >
1819{
19- public IEnumerable < CharacterTrait > GetAllTraits ( ) => _allTraitsLazy . Value ;
20+ public IReadOnlyCollection < CharacterTrait > GetAllTraits ( ) => _allTraitsLazy . Value ;
2021
21- private Lazy < IEnumerable < CharacterTrait > > _allTraitsLazy ;
22+ private readonly ResetLazy < CharacterTrait [ ] > _allTraitsLazy ;
2223 private readonly LocalizationService _localizationService ;
2324 private Dictionary < string , FrozenDictionary < string , CharacterTrait > > . ValueCollection Traits =>
2425 Resources . Values ;
@@ -62,13 +63,12 @@ public GeneralTraitsService(LocalizationService localizationService)
6263 {
6364 _localizationService = localizationService ;
6465
65- _allTraitsLazy = GetAllTraitsLazy ( ) ;
66- OnResourceChanged += ( _ , _ ) => _allTraitsLazy = GetAllTraitsLazy ( ) ;
66+ _allTraitsLazy = new ResetLazy < CharacterTrait [ ] > (
67+ ( ) => Traits . SelectMany ( trait => trait . Values ) . ToArray ( )
68+ ) ;
69+ OnResourceChanged += ( _ , _ ) => _allTraitsLazy . Reset ( ) ;
6770 }
6871
69- private Lazy < IEnumerable < CharacterTrait > > GetAllTraitsLazy ( ) =>
70- new ( ( ) => Traits . SelectMany ( trait => trait . Values ) . ToArray ( ) ) ;
71-
7272 public bool TryGetTrait ( string name , [ NotNullWhen ( true ) ] out CharacterTrait ? trait )
7373 {
7474 foreach ( var traitMap in Traits )
0 commit comments