You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.2 KiB
65 lines
2.2 KiB
import { Injectable, NgZone } from '@angular/core';
|
|
import { WorldArea } from '../_models/world-area';
|
|
import { invoke } from '@tauri-apps/api';
|
|
import { Observable, ReplaySubject, Subject, filter, from, map } from 'rxjs';
|
|
import naturalCompare from 'natural-compare';
|
|
import { Fuzzr } from '../fuzzr/fuzzr';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class WorldAreaService {
|
|
private worldAreas?: Map<string, WorldArea>;
|
|
public matcher?: Fuzzr;
|
|
|
|
private worldAreasSubject = new ReplaySubject<Map<string, WorldArea>>();
|
|
private fullWorldAreasSubject = new ReplaySubject<Map<string, WorldArea>>();
|
|
|
|
constructor(private zone: NgZone) {
|
|
from(invoke<Map<string, WorldArea>>('load_world_areas')).subscribe((data) => {
|
|
const entries = Object.entries(data).sort((a, b) => a[1].key_id - b[1].key_id);
|
|
this.worldAreas = new Map(entries);
|
|
this.zone.run(() => this.worldAreasSubject.next(this.worldAreas!));
|
|
this.matcher = new Fuzzr(this.worldAreas, {
|
|
toString: (e: [string, WorldArea]) => e[1].name
|
|
})
|
|
});
|
|
|
|
from(invoke<Map<string, WorldArea>>('load_full_world_areas')).subscribe((data) => {
|
|
const entries = Object.entries(data).sort((a, b) => a[1].key_id - b[1].key_id);
|
|
this.worldAreas = new Map(entries);
|
|
this.zone.run(() => this.fullWorldAreasSubject.next(this.worldAreas!));
|
|
});
|
|
}
|
|
|
|
getWorldAreas(): Observable<Map<string, WorldArea>> {
|
|
return this.worldAreasSubject.asObservable().pipe(
|
|
filter(worldAreas => !!worldAreas),
|
|
);
|
|
}
|
|
|
|
getFullWorldAreas(): Observable<Map<string, WorldArea>> {
|
|
return this.fullWorldAreasSubject.asObservable().pipe(
|
|
filter(worldAreas => !!worldAreas),
|
|
);
|
|
}
|
|
|
|
hasTrial(key: string): boolean {
|
|
switch (key) {
|
|
case "1_1_7_1": return true;
|
|
case "1_2_5_1": return true;
|
|
case "1_2_6_2": return true;
|
|
case "1_3_3_1": return true;
|
|
case "1_3_6": return true;
|
|
case "1_3_15": return true;
|
|
case "2_6_7_1": return true;
|
|
case "2_7_4": return true;
|
|
case "2_7_5_2": return true;
|
|
case "2_8_5": return true;
|
|
case "2_9_7": return true;
|
|
case "2_10_9": return true;
|
|
default: return false;
|
|
}
|
|
}
|
|
}
|