-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define the datasets that can be fetched by the API
Define the data structures of the various API endpoints.
- Loading branch information
1 parent
659cd70
commit d832c4e
Showing
5 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |