@@ -3,19 +3,19 @@ import Updater from './core/CacheUpdater';
33import { Ships } from './core/api/api_ship' ;
44import { Equipments } from './core/api/api_equipment' ;
55import { Barrages } from './core/api/api_barrage' ;
6- import API from './core/api/api' ;
7- import { Equipment } from './types/equipment' ;
8- import { Chapter } from './types/chapter' ;
9- import { Voiceline } from './types/voiceline' ;
10- import { Barrage } from './types/barrage' ;
6+ import { Chapters } from './core/api/api_chapter' ;
7+ import { Voicelines } from './core/api/api_voiceline' ;
8+ import * as Hiei from './core/api/hiei' ;
119import { datatype } from './core/Data' ;
1210
1311export type Source = 'uncached' | 'local' | 'hiei'
1412
1513export interface CacheOptions {
16- source ?: Source ;
17- autoupdate ?: boolean ;
18- rate ?: number ;
14+ source ?: Source ;
15+ autoupdate ?: boolean ;
16+ rate ?: number ;
17+ hieiUrl ?: string ;
18+ hieiAuth ?: string ;
1919}
2020
2121export let instance : AzurAPI ;
@@ -24,49 +24,70 @@ export let instance: AzurAPI;
2424 * The main AzurAPI class
2525 */
2626export class AzurAPI extends EventEmitter {
27- public options : CacheOptions ;
28- public source : string ;
29- public autoupdate : boolean ;
30- public rate : number ;
31- public updater : Updater ;
32- public ships = new Ships ( this ) ;
33- public equipments = new Equipments ( this ) ;
34- public chapters = new API < Chapter > ( this ) ;
35- public voicelines = new API < Voiceline > ( this ) ;
36- public barrages = new Barrages ( this ) ;
37- public apis = {
27+ public options : CacheOptions ;
28+ public source : string ;
29+ public autoupdate : boolean ;
30+ public rate : number ;
31+ public updater : Updater ;
32+ public ships : Ships | Hiei . Ships /* = new Ships(this)*/ ;
33+ public equipments : Equipments | Hiei . Equipments /* = new Equipments(this)*/ ;
34+ public chapters : Chapters | Hiei . Chapters /* = new Chapters(this)*/ ;
35+ public voicelines : Voicelines | Hiei . Voicelines /* = new Voicelines(this)*/ ;
36+ public barrages : Barrages | Hiei . Barrages /* = new Barrages(this)*/ ;
37+ public apis : object /* = {
38+ ships: this.ships,
39+ equipments: this.equipments,
40+ chapters: this.chapters,
41+ voicelines: this.voicelines,
42+ barrages: this.barrages
43+ }*/ ;
44+
45+ /**
46+ * Cache client
47+ * @param options options for the cache
48+ */
49+ constructor ( options ?: CacheOptions ) {
50+ super ( ) ;
51+ this . options = options ? options : { source : 'local' , autoupdate : true , rate : 3600000 } ;
52+ this . source = this . options . source ? this . options . source : 'local' ;
53+ this . autoupdate = this . options . autoupdate ? this . options . autoupdate : true ;
54+ this . rate = this . options . rate ? this . options . rate : 3600000 ;
55+ if ( this . source === 'hiei' && ! this . options . hieiUrl ) throw new Error ( 'Option "hieiUrl" cannot be undefined when "source" is set to "hiei"' ) ;
56+ if ( this . source === 'hiei' ) {
57+ this . ships = new Hiei . Ships ( this ) ;
58+ this . equipments = new Hiei . Equipments ( this ) ;
59+ this . chapters = new Hiei . Chapters ( this ) ;
60+ this . voicelines = new Hiei . Voicelines ( this ) ;
61+ this . barrages = new Hiei . Barrages ( this ) ;
62+ } else {
63+ this . ships = new Ships ( this ) ;
64+ this . equipments = new Equipments ( this ) ;
65+ this . chapters = new Chapters ( this ) ;
66+ this . voicelines = new Voicelines ( this ) ;
67+ this . barrages = new Barrages ( this ) ;
68+ }
69+ this . apis = {
3870 ships : this . ships ,
3971 equipments : this . equipments ,
4072 chapters : this . chapters ,
4173 voicelines : this . voicelines ,
4274 barrages : this . barrages
4375 } ;
76+ this . updater = new Updater ( this ) ;
77+ this . updater . init ( ) ;
78+ if ( this . autoupdate && this . source === 'local' ) this . updater . start ( ) ;
79+ instance = this ;
80+ }
4481
45- /**
46- * Cache client
47- * @param options options for the cache
48- */
49- constructor ( options ?: CacheOptions ) {
50- super ( ) ;
51- this . options = options ? options : { source : 'local' , autoupdate : true , rate : 3600000 } ;
52- this . source = this . options . source ? this . options . source : 'local' ;
53- this . autoupdate = this . options . autoupdate ? this . options . autoupdate : true ;
54- this . rate = this . options . rate ? this . options . rate : 3600000 ;
55- this . updater = new Updater ( this ) ;
56- this . updater . init ( ) ;
57- if ( this . autoupdate ) this . updater . start ( ) ;
58- instance = this ;
59- }
60-
61- /**
62- * Set data in cache
63- * @param type A type of data (ship, equipment, voiceline, chapter, or barrage)
64- * @param raw Raw data in array
65- */
66- set ( type : datatype , raw : any [ ] ) {
67- if ( ! raw ) return ;
68- let api = this . apis [ type ] ;
69- if ( api ) api . setData ( raw ) ;
70- return api ;
71- }
82+ /**
83+ * Set data in cache
84+ * @param type A type of data (ship, equipment, voiceline, chapter, or barrage)
85+ * @param raw Raw data in array
86+ */
87+ set ( type : datatype , raw : any [ ] ) {
88+ if ( ! raw ) return ;
89+ let api = this . apis [ type ] ;
90+ if ( api ) api . setData ( raw ) ;
91+ return api ;
92+ }
7293}
0 commit comments