@@ -88,7 +88,9 @@ public List<TraitDto> GetAllTraitDto()
8888 LocalizedName = GetLocalizationName ( trait ) ,
8989 Modifiers = string . Join ( '\n ' , GetModifiersDescription ( trait ) ) ,
9090 FileOrigin = fileOrigin ,
91- Type = trait . Type
91+ Type = trait . Type ,
92+ Position = trait . Position . ToDocumentRange ( ) ,
93+ FilePath = fileResource . Key
9294 } ;
9395
9496 if (
@@ -111,12 +113,7 @@ public IEnumerable<string> GetModifiersDescription(GeneralTrait trait)
111113
112114 foreach ( var modifierCollection in trait . ModifiersCollection )
113115 {
114- if (
115- modifierCollection . Key . Equals (
116- GeneralTrait . TraitXpFactor ,
117- StringComparison . OrdinalIgnoreCase
118- )
119- )
116+ if ( modifierCollection . Key . Equals ( GeneralTrait . TraitXpFactor , StringComparison . OrdinalIgnoreCase ) )
120117 {
121118 foreach ( var modifier in modifierCollection . Modifiers . OfType < LeafModifier > ( ) )
122119 {
@@ -200,60 +197,66 @@ private ReadOnlySpan<GeneralTrait> ParseTraitsNode(Node traitsNode)
200197 continue ;
201198 }
202199
203- string traitName = traitNode . Key ;
200+ traits . Add ( ParseTraitNode ( traitNode ) ) ;
201+ }
204202
205- var modifiers = new List < ModifierCollection > ( 4 ) ;
206- var skillModifiers = new List < LeafModifier > ( ) ;
207- var customModifiersTooltip = new List < LeafModifier > ( ) ;
208- var traitType = TraitType . None ;
209- foreach ( var traitAttribute in traitNode . AllArray )
203+ return CollectionsMarshal . AsSpan ( traits ) ;
204+ }
205+
206+ private GeneralTrait ParseTraitNode ( Node traitNode )
207+ {
208+ string traitName = traitNode . Key ;
209+
210+ var modifiers = new List < ModifierCollection > ( 4 ) ;
211+ var skillModifiers = new List < LeafModifier > ( ) ;
212+ var customModifiersTooltip = new List < LeafModifier > ( ) ;
213+ var traitType = TraitType . None ;
214+ foreach ( var traitAttribute in traitNode . AllArray )
215+ {
216+ string ? key = traitAttribute . GetKeyOrNull ( ) ;
217+ // type 可以为 Leaf 或 Node
218+ if ( StringComparer . OrdinalIgnoreCase . Equals ( key , "type" ) )
210219 {
211- string ? key = traitAttribute . GetKeyOrNull ( ) ;
212- // type 可以为 Leaf 或 Node
213- if ( StringComparer . OrdinalIgnoreCase . Equals ( key , "type" ) )
214- {
215- traitType = GetTraitType ( traitAttribute ) ;
216- }
217- else if (
218- traitAttribute . TryGetNode ( out var node )
219- && (
220- Array . Exists (
221- ModifierNodeKeys ,
222- keyword => StringComparer . OrdinalIgnoreCase . Equals ( keyword , key )
223- ) || StringComparer . OrdinalIgnoreCase . Equals ( key , GeneralTrait . TraitXpFactor )
224- )
225- )
226- {
227- modifiers . Add ( ParseModifier ( node ) ) ;
228- }
229- else if (
230- traitAttribute . TryGetLeaf ( out var leaf )
231- && StringComparer . OrdinalIgnoreCase . Equals ( LeafModifier . CustomEffectTooltipKey , key )
220+ traitType = GetTraitType ( traitAttribute ) ;
221+ }
222+ else if (
223+ traitAttribute . TryGetNode ( out var node )
224+ && (
225+ Array . Exists (
226+ ModifierNodeKeys ,
227+ keyword => StringComparer . OrdinalIgnoreCase . Equals ( keyword , key )
228+ ) || StringComparer . OrdinalIgnoreCase . Equals ( key , GeneralTrait . TraitXpFactor )
232229 )
233- {
234- customModifiersTooltip . Add ( LeafModifier . FromLeaf ( leaf ) ) ;
235- }
236- else if ( IsSkillModifier ( traitAttribute , out leaf ) )
237- {
238- skillModifiers . Add ( LeafModifier . FromLeaf ( leaf ) ) ;
239- }
230+ )
231+ {
232+ modifiers . Add ( ParseModifier ( node ) ) ;
240233 }
241-
242- if ( skillModifiers . Count != 0 )
234+ else if (
235+ traitAttribute . TryGetLeaf ( out var leaf )
236+ && StringComparer . OrdinalIgnoreCase . Equals ( LeafModifier . CustomEffectTooltipKey , key )
237+ )
243238 {
244- modifiers . Add ( new ModifierCollection ( GeneralTrait . TraitSkillModifiersKey , skillModifiers ) ) ;
239+ customModifiersTooltip . Add ( LeafModifier . FromLeaf ( leaf ) ) ;
245240 }
246-
247- if ( customModifiersTooltip . Count != 0 )
241+ else if ( IsSkillModifier ( traitAttribute , out leaf ) )
248242 {
249- modifiers . Add (
250- new ModifierCollection ( LeafModifier . CustomEffectTooltipKey , customModifiersTooltip )
251- ) ;
243+ skillModifiers . Add ( LeafModifier . FromLeaf ( leaf ) ) ;
252244 }
253- traits . Add ( new GeneralTrait ( traitName , traitType , modifiers ) ) ;
254245 }
255246
256- return CollectionsMarshal . AsSpan ( traits ) ;
247+ if ( skillModifiers . Count != 0 )
248+ {
249+ modifiers . Add ( new ModifierCollection ( GeneralTrait . TraitSkillModifiersKey , skillModifiers ) ) ;
250+ }
251+
252+ if ( customModifiersTooltip . Count != 0 )
253+ {
254+ modifiers . Add (
255+ new ModifierCollection ( LeafModifier . CustomEffectTooltipKey , customModifiersTooltip )
256+ ) ;
257+ }
258+
259+ return new GeneralTrait ( traitName , traitType , modifiers , traitNode . Position ) ;
257260 }
258261
259262 private TraitType GetTraitType ( Child traitAttribute )
0 commit comments