File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed
libs/resources/src/transformers Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -342,14 +342,21 @@ export function transformFaction(faction: unknown): FACTION | null {
342342 return null ;
343343 }
344344
345- // @todo faction type is set to { type?: string | null; name?: string | null; } in some cases
345+ const factionObject = faction as { type ?: string | null ; name ?: string | null ; } ;
346346
347- const hasFactionTypeWithoutName = faction . type && faction . name === null ;
347+ const hasFactionTypeWithoutName = factionObject . type && factionObject . name === null ;
348348 if ( hasFactionTypeWithoutName ) {
349- const factionTypeStartsWithA = faction . type . toString ( ) . startsWith ( 'A' ) ;
350- summary . faction = factionTypeStartsWithA ? FACTION . A : FACTION . H ;
351- } else {
352- summary . faction = faction . name ;
349+ const typeUpper = factionObject . type . toString ( ) . toUpperCase ( ) ;
350+ const validFactions = Object . values ( FACTION ) . filter ( f => f !== FACTION . ANY ) ;
351+ const matchedFaction = validFactions . find ( f => f . toString ( ) . toUpperCase ( ) === typeUpper ) ;
352+ return matchedFaction || null ;
353+ }
354+
355+ if ( factionObject . name ) {
356+ const nameUpper = factionObject . name . toUpperCase ( ) ;
357+ const validFactions = Object . values ( FACTION ) . filter ( f => f !== FACTION . ANY ) ;
358+ const matchedFaction = validFactions . find ( f => f . toString ( ) . toUpperCase ( ) === nameUpper ) ;
359+ return matchedFaction || null ;
353360 }
354361
355362 return null
You can’t perform that action at this time.
0 commit comments