Skip to content

Commit 8d6811f

Browse files
committed
Add very not optimised untested hiei stuff
1 parent 700c9cd commit 8d6811f

9 files changed

Lines changed: 395 additions & 198 deletions

File tree

package-lock.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azurapi/azurapi",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Open Source Azur Lane Local Database",
55
"main": "./build/index.js",
66
"types": "./build/index.d.ts",
@@ -42,7 +42,7 @@
4242
"devDependencies": {
4343
"@augu/eslint-config": "^1.8.2",
4444
"@types/jest": "^26.0.14",
45-
"@types/node": "^14.11.2",
45+
"@types/node": "^14.14.45",
4646
"@typescript-eslint/eslint-plugin": "^4.2.0",
4747
"@typescript-eslint/parser": "^4.2.0",
4848
"eslint": "^7.17.0",

src/Client.ts

Lines changed: 67 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import Updater from './core/CacheUpdater';
33
import { Ships } from './core/api/api_ship';
44
import { Equipments } from './core/api/api_equipment';
55
import { 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';
119
import { datatype } from './core/Data';
1210

1311
export type Source = 'uncached' | 'local' | 'hiei'
1412

1513
export 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

2121
export let instance: AzurAPI;
@@ -24,49 +24,70 @@ export let instance: AzurAPI;
2424
* The main AzurAPI class
2525
*/
2626
export 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

Comments
 (0)