import { ChangeDetectionStrategy , Component , NgZone , OnDestroy , OnInit } from '@angular/core' ; import { EventSubscription } from '@app/event' ; import { FeatureSettingsService } from '@app/feature/feature-settings.service' ; import { TradeHighlightWindowData , TradeHighlightWindowService } from '@modules/trade/service' ; import { TradeFeatureSettings } from '@modules/trade/trade-feature-settings' ; import { StashService } from '@shared/module/poe/stash' ; import { BehaviorSubject } from 'rxjs' ; enum TradeStashFactor { Normal = 1 , Quad = 0.5 } @ Component ( { selector : 'app-trade-highlight-window' , templateUrl : './trade-highlight-window.component.html' , styleUrls : [ './trade-highlight-window.component.scss' ] , changeDetection : ChangeDetectionStrategy . OnPush } ) export class TradeHighlightWindowComponent implements OnInit , OnDestroy { private subscription : EventSubscription ; public data$ = new BehaviorSubject < TradeHighlightWindowData > ( null ) ; public factor = TradeStashFactor . Normal ; public folder = false ; constructor ( private readonly window , private readonly settings , private readonly stash , private readonly ngZone ) { } public ngOnInit ( ) { this . updateData ( this . window . data$ . get ( ) ) ; this . subscription = this . window . data$ . on ( data => { this . ngZone . run ( ( ) => { this . updateData ( data ) ; } ) ; } ) ; } public ngOnDestroy ( ) { this . subscription ?. unsubscribe ( ) ; } public onSearch ( item ) { this . stash . highlight ( item ) ; } public onFolderChange ( stash ? ) { this . folder = ! this . folder ; if ( stash ) { this . settings . update ( ( settings ) => { settings . tradeStashFolder [ stash ] = this . folder ; } ) . subscribe ( ) ; } } public onFactorChange ( stash ? ) { this . factor = this . factor === TradeStashFactor . Quad ? TradeStashFactor . Normal : TradeStashFactor . Quad ; if ( stash ) { this . settings . update ( ( settings ) => { settings . tradeStashFactor [ stash ] = this . factor ; } ) . subscribe ( ) ; } } private updateData ( data ) { this . settings . get ( ) . subscribe ( ( settings ) => { this . folder = ! ! settings . tradeStashFolder [ data . stash ] ; const factor = settings . tradeStashFactor [ data . stash ] ; if ( factor ) { this . factor = factor ; } else { this . factor = data . left > 13 || data . top > 13 ? TradeStashFactor . Quad : TradeStashFactor . Normal ; } this . data$ . next ( data ) ; } ) ; } }