Skip to content

Commit

Permalink
Define the datasets that can be fetched by the API
Browse files Browse the repository at this point in the history
Define the data structures of the various API endpoints.
  • Loading branch information
Gigabyte5671 committed Jan 15, 2023
1 parent 659cd70 commit d832c4e
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 0 deletions.
31 changes: 31 additions & 0 deletions datasets/AccountData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { EnumTree, Region, UnlockableItem } from '../interfaces/index.js';

/**
* Account data for the authenticated TA account.
*/
export class AccountData {
id = undefined as number | undefined;
name = undefined as string | undefined;
clanTag = undefined as string | undefined;
rank = undefined as number | undefined;
rankProgress = undefined as number | undefined;
xp = undefined as number | undefined;
gold = undefined as number | undefined;
region = undefined as Region | undefined;
items = undefined as UnlockableItem[] | undefined;

constructor (data: EnumTree) {
if (!('003D' in data)) {
return;
}

this.id = data['003D']['0348'];
this.name = data['003D']['034A'];
this.clanTag = data['003D']['06DE'];
this.rank = data['003D']['0296'];
this.rankProgress = data['003D']['05DC'];
this.xp = data['003D']['04CB'];
this.gold = data['003D']['05D3'];
this.region = data['003D']['0448'];
}
}
55 changes: 55 additions & 0 deletions datasets/GameServerInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { EnumTree, Map, Region } from '../interfaces/index.js';
import { Player } from './Player.js';

export class GameServerInfo {
id = undefined as number | undefined;
name = undefined as string | undefined;
messageOfTheDay = undefined as string | undefined;
passwordRequired = undefined as boolean | undefined;
map = undefined as Map | undefined;
timeRemaining = undefined as number | undefined;
scores = {
bloodEagle: undefined as number | undefined,
diamondSword: undefined as number | undefined
};
numberOfPlayers = undefined as number | undefined;
maxNumberOfPlayers = undefined as number | undefined;
officialRules = undefined as boolean | undefined;
region = undefined as Region | undefined;
rankRequirement = {
min: undefined as number | undefined,
max: undefined as number | undefined,
limit: undefined as number | undefined
};
ip = undefined as string | undefined;
players = [] as Player[];

constructor (data: EnumTree) {
let subData = data;

if ('01C6' in data && '00E9' in data['01C6']) {
subData = data['01C6']['00E9'][0];
}

this.id = subData['02C7'];
this.name = subData['0300'];
this.messageOfTheDay = subData['01A4'];
this.passwordRequired = subData['069C'];
this.map = subData['02B2'];
this.timeRemaining = subData['02F4'];
this.numberOfPlayers = subData['0343'];
this.maxNumberOfPlayers = subData['02D6'];
this.officialRules = subData['0703'];
this.region = subData['0448'];
this.rankRequirement.min = subData['0299'];
this.rankRequirement.max = subData['0298'];
this.rankRequirement.limit = subData['06BF'];
this.ip = subData['0246'];

if ('0132' in subData) {
(subData['0132'] as EnumTree[]).forEach((player) => {
this.players.push(new Player(player));
});
}
}
}
22 changes: 22 additions & 0 deletions datasets/Player.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { EnumTree, Region } from '../interfaces/index.js';

/**
* Account data for the authenticated TA account.
*/
export class Player {
id = undefined as number | undefined;
name = undefined as string | undefined;
clanTag = undefined as string | undefined;
rank = undefined as number | undefined;
region = undefined as Region | undefined;
team = undefined as number | undefined;

constructor (data: EnumTree) {
this.id = data['0348'];
this.name = data['034A'];
this.clanTag = data['003D'];
this.rank = data['0296'];
this.region = data['003D'];
this.team = data['0452'];
}
}
19 changes: 19 additions & 0 deletions datasets/WatchNowItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { EnumTree, WatchNowSection } from '../interfaces/index.js';

export class WatchNowItem {
id = undefined as number | undefined;
section = undefined as WatchNowSection | undefined;
name = undefined as string | undefined;
link = undefined as string | undefined;
featured = undefined as boolean | undefined;
official = undefined as boolean | undefined;

constructor (data: EnumTree) {
this.id = data['06B7'];
this.section = data['06B9'];
this.name = data['02FE'];
this.link = data['06B8'];
this.featured = data['06BA'];
this.official = data['0013'];
}
}
33 changes: 33 additions & 0 deletions datasets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { AccountData } from './AccountData.js';
export { AccountData } from './AccountData.js';
import { Player } from './Player.js';
export { Player } from './Player.js';
import { GameServerInfo } from './GameServerInfo.js';
export { GameServerInfo } from './GameServerInfo.js';
import { WatchNowItem } from './WatchNowItem.js';
export { WatchNowItem } from './WatchNowItem.js';

export type FetchableDataset =
'AccountData'
| 'OnlinePlayerList'
| 'OnlinePlayerNumber'
| 'GameServerList'
| 'GameServerInfo'
| 'WatchNowList';

export type FetchType<T> =
T extends 'AccountData' ? AccountData :
T extends 'OnlinePlayerList' ? Player[] :
T extends 'OnlinePlayerNumber' ? number :
T extends 'GameServerInfo' ? GameServerInfo :
T extends 'GameServerList' ? GameServerInfo[] :
T extends 'WatchNowList' ? WatchNowItem[] :
never;

export type ListenableDatasets = 'PlayerOnlineNotification';

export interface PlayerOnlineNotification {
id: number,
name: string,
rank: number
}

0 comments on commit d832c4e

Please sign in to comment.