import { join } from 'path' ; import { category } from '../util/category' ; import { directories } from '../util/directories' ; import { write } from '../util/write' ; import { width } from '../util/width' ; const amount = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; const tierKeys = amount . map ( ( number ) => `tier${ number }` ) ; const rewardKeys = amount . map ( ( number ) => `tier${ number }Reward` ) ; const nounKeys = amount . map ( ( number ) => `tier${ number }Noun` ) ; const modifierKeys = amount . map ( ( number ) => `tier${ number }Modifier` ) ; const achievements = category ( 'Achievements' , directories . sanitized ) ; for ( const achievement of achievements ) { const container = ( achievement . tiers = { } ) ; const tiers = tierKeys . map ( ( key ) => achievement [ key ] ) . filter ( ( value ) => value !== null ) ; const rewards = rewardKeys . map ( ( key ) => achievement [ key ] ) . filter ( ( value ) => value !== null ) ; const nouns = nounKeys . map ( ( key ) => achievement [ key ] ) . filter ( ( value ) => value !== null ) ; const modifiers = modifierKeys . map ( ( key ) => achievement [ key ] ) . filter ( ( value ) => value !== null ) ; for ( const i in tiers ) { container [ Number ( i ) + 1 ] = { required : tiers [ i ] , reward : rewards [ i ] , nouns : nouns [ i ] , modifier : modifiers [ i ] } ; } for ( const key of [ ... tierKeys , ... rewardKeys , ... nounKeys , ... modifierKeys ] ) { delete achievement [ key ] ; } } write ( join ( directories . sanitized , `Achievements.json` ) , achievements , width ( 'Achievements' ) ) ;