Skip to content

Commit 82095d3

Browse files
committed
docs: adjust collectibles store for aviator
1 parent e4d0134 commit 82095d3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

apps/kitchen-sink/src/app/misc/aviator/collectible/collectibles.store.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import { DestroyRef, Directive, effect, inject, input, model, signal, WritableSignal } from '@angular/core';
1+
import { DestroyRef, Directive, effect, inject, input, model, signal, untracked, WritableSignal } from '@angular/core';
22
import { injectStore } from 'angular-three';
33
import { Object3D } from 'three';
44
import { COLLECTIBLES_SPEED, PLANE_AMP_HEIGHT, PLANE_DEFAULT_HEIGHT, SEA_RADIUS } from '../constants';
55
import { GameStore } from '../game.store';
66

7+
export type CollectibleState = 'spawned' | 'collected' | 'skipped';
8+
79
@Directive()
810
export class Collectible {
911
initialAngle = input(0);
1012
initialDistance = input(0);
1113
positionX = input(0);
1214
positionY = input(0);
13-
state = model.required<'spawned' | 'collected' | 'skipped'>();
15+
state = model.required<CollectibleState>();
1416

1517
protected angle = 0;
1618
protected distance = 0;
@@ -56,7 +58,7 @@ export class CollectiblesStore {
5658
coins = signal<
5759
Array<{
5860
key: number;
59-
state: WritableSignal<'spawned' | 'collected' | 'skipped'>;
61+
state: WritableSignal<CollectibleState>;
6062
angle: number;
6163
distance: number;
6264
positionY: number;
@@ -70,14 +72,15 @@ export class CollectiblesStore {
7072
const amplitude = 10 + Math.round(Math.random() * 10);
7173

7274
this.coins.update((prev) => [
73-
...prev,
75+
// NOTE: we filter out all the coins that are already collected or skipped
76+
...prev.filter((coin) => untracked(coin.state) === 'spawned'),
7477
...Array.from({ length: nCoins }).map((_, index) => {
7578
const angle = -(index * 0.02);
7679
const distance = d + Math.cos(index * 0.5) * amplitude;
7780

7881
return {
7982
key: this.gameStore.statistics.coinsSpawned + index,
80-
state: signal<'spawned' | 'collected' | 'skipped'>('spawned'),
83+
state: signal<CollectibleState>('spawned'),
8184
angle,
8285
distance,
8386
positionY: -SEA_RADIUS + Math.sin(angle) * distance,

0 commit comments

Comments
 (0)