59 lines
2.0 KiB
TypeScript
59 lines
2.0 KiB
TypeScript
import { ChangeDetectionStrategy, Component, computed, inject, signal } from '@angular/core';
|
|
import { RouterLink } from '@angular/router';
|
|
import { Store } from '@ngrx/store';
|
|
|
|
import { CityCatalogService } from '../../root/services/city-catalog.service';
|
|
import { Icon } from '../../shared/icon/icon';
|
|
import { selectCollectedIdSet, selectOpenedCount, selectProgress } from '../../state';
|
|
|
|
type CollectionFilter = 'all' | 'open' | 'closed';
|
|
|
|
@Component({
|
|
selector: 'app-collection-page',
|
|
imports: [Icon, RouterLink],
|
|
templateUrl: './collection-page.html',
|
|
styleUrl: './collection-page.scss',
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
})
|
|
export class CollectionPage {
|
|
private readonly catalog = inject(CityCatalogService);
|
|
private readonly store = inject(Store);
|
|
|
|
protected readonly city = this.catalog.city;
|
|
protected readonly filter = signal<CollectionFilter>('all');
|
|
protected readonly collectedIds = this.store.selectSignal(selectCollectedIdSet);
|
|
protected readonly openedCount = this.store.selectSignal(selectOpenedCount);
|
|
protected readonly progress = this.store.selectSignal(selectProgress);
|
|
protected readonly closedCount = computed(
|
|
() => this.city.objects.length - this.openedCount(),
|
|
);
|
|
protected readonly landmarks = computed(() => {
|
|
const items = this.city.objects;
|
|
const ids = this.collectedIds();
|
|
|
|
switch (this.filter()) {
|
|
case 'open':
|
|
return items.filter((item) => ids.has(item.id));
|
|
case 'closed':
|
|
return items.filter((item) => !ids.has(item.id));
|
|
default:
|
|
return items;
|
|
}
|
|
});
|
|
|
|
protected readonly rays = Array.from({ length: 16 }, (_, index) => {
|
|
const angle = (index / 16) * Math.PI * 2;
|
|
const inner = 30;
|
|
const outer = index % 2 === 0 ? 54 : 46;
|
|
const center = 56;
|
|
|
|
return {
|
|
x1: center + Math.cos(angle) * inner,
|
|
y1: center + Math.sin(angle) * inner,
|
|
x2: center + Math.cos(angle) * outer,
|
|
y2: center + Math.sin(angle) * outer,
|
|
strong: index % 2 === 0,
|
|
};
|
|
});
|
|
}
|