import { ChangeDetectionStrategy , Component , Input } from '@angular/core' ; import { AchievementProgress } from '../../models/achievement/achievement-progress' ; import { ConstructedState } from '../../models/constructed/constructed-state' ; import { groupByFunction } from '../../services/utils' ; import { EffectiveProgress } from './effective-progress' ; @ Component ( { selector : 'in-game-achievements-recap' , styleUrls : [ `../../../css/global/components-global.scss` , `../../../css/component/constructed/in-game-achievements-recap.component.scss` , ] , template : `
		<div class="in-game-achievements-recap">
			<div class="achievements" scrollable>
				<in-game-achievement-recap
					*ngFor="let progress of effectiveProgress; trackBy: trackById"
					class="recap"
					[progress]="progress"
				></in-game-achievement-recap>
			</div>
		</div>
	` , changeDetection : ChangeDetectionStrategy . OnPush , } ) export class InGameAchievementsRecapComponent { @ Input ( ) set state ( value ) { this . _state = value ; this . updateInfo ( ) ; } _state : ConstructedState ; effectiveProgress : readonly EffectiveProgress [ ] ; trackById ( index , progress ) { return progress . id ; } private updateInfo ( ) { if ( ! this . _state ?. currentAchievementsProgress ?. achievements ?. length ) { return ; } const nonCompletedAchievements = this . _state . initialAchievementsProgress . achievements . filter ( ( initial ) => ! initial . completed ) ; const groupedByType = groupByFunction ( ( progress ) => progress . type ) ( nonCompletedAchievements ) ; const firstSteps = Object . values ( groupedByType ) . map ( ( progresses ) => progresses . sort ( ( a , b ) => a . step - b . step ) [ 0 ] ) ; this . effectiveProgress = firstSteps . map ( ( initial ) => { const current = this . _state . currentAchievementsProgress . achievements . find ( ( ach ) => ach . id === initial . id ) ; return { id : initial . id , name : initial . name , text : initial . text , initialProgress : initial . progress , currentProgress : initial . progress , progressThisMatch : current . progress - initial . progress , quota : initial . quota , completed : current . completed , } ; } ) . sort ( ( a , b ) => a . progressThisMatch - b . progressThisMatch ) . sort ( ( a , b ) => ( a . completed ? 1 : 0 ) - ( b . completed ? 1 : 0 ) ) . reverse ( ) ; } }