feat: extended player profile
This commit is contained in:
parent
7102eece1f
commit
4b0dbabf02
|
@ -67,7 +67,7 @@ export class DialogTable<T> {
|
|||
page >= maxPage ? ' disabled' : ''
|
||||
}>></button>
|
||||
</div>
|
||||
<table class="vis">
|
||||
<table style="width: 100%" class="vis">
|
||||
<tbody>
|
||||
<tr>
|
||||
${this.columns.map((col) => `<th>${col.header}</th>`).join('')}
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
TWHelpClient,
|
||||
} from './lib/client';
|
||||
import { DialogTable } from './common/DialogTable';
|
||||
import { buildURL } from './lib/twstats';
|
||||
|
||||
const SCREEN = 'info_player';
|
||||
const MODE = null;
|
||||
|
@ -19,6 +20,7 @@ const translations: Record<string, Record<string, string>> = {
|
|||
'Best rank': 'Najlepszy ranking',
|
||||
'Most points': 'Najwięcej punktów',
|
||||
'Most villages': 'Najwięcej wiosek',
|
||||
'Show other servers': 'Pokaż inne światy',
|
||||
'Show tribe changes': 'Pokaż zmiany plemion',
|
||||
'Show history': 'Pokaż historię',
|
||||
'Show ennoblements': 'Pokaż przejęcia',
|
||||
|
@ -31,6 +33,10 @@ const translations: Record<string, Record<string, string>> = {
|
|||
Points: 'Punkty',
|
||||
Barbarian: 'Barbarzyńska',
|
||||
Unknown: 'Nieznany',
|
||||
Server: 'Serwer',
|
||||
Deleted: 'Usunięty',
|
||||
Yes: 'Tak',
|
||||
No: 'Nie',
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -68,6 +74,7 @@ class TWHelpConnector {
|
|||
}
|
||||
|
||||
enum DialogId {
|
||||
OTHER_SERVERS = 'kichiyaki_other_servers',
|
||||
TRIBE_CHANGES = 'kichiyaki_tribe_changes',
|
||||
ENNOBLEMENTS = 'kichiyaki_ennoblements',
|
||||
}
|
||||
|
@ -142,6 +149,10 @@ class UI {
|
|||
}
|
||||
|
||||
[
|
||||
{
|
||||
name: t('Show other servers'),
|
||||
handler: this.showOtherServers.bind(this),
|
||||
},
|
||||
{
|
||||
name: t('Show tribe changes'),
|
||||
handler: this.showTribeChanges.bind(this),
|
||||
|
@ -166,6 +177,39 @@ class UI {
|
|||
});
|
||||
}
|
||||
|
||||
private async showOtherServers(e: Event) {
|
||||
e.preventDefault();
|
||||
|
||||
await new DialogTable(
|
||||
DialogId.OTHER_SERVERS,
|
||||
[
|
||||
{
|
||||
header: t('Server'),
|
||||
accessor: (s) =>
|
||||
`<a href="${buildURL({
|
||||
entity: 'player',
|
||||
server: s.key,
|
||||
id: this.player.id,
|
||||
})}">${s.key}</a>`,
|
||||
},
|
||||
{
|
||||
header: t('Deleted'),
|
||||
accessor: (s) =>
|
||||
s.deletedAt
|
||||
? `${t('Yes')} (${new Date(s.deletedAt).toLocaleString()})`
|
||||
: t('No'),
|
||||
},
|
||||
],
|
||||
this.player.otherServers.length,
|
||||
() => {
|
||||
return Promise.resolve({
|
||||
data: this.player.otherServers,
|
||||
total: this.player.otherServers.length,
|
||||
});
|
||||
}
|
||||
).render();
|
||||
}
|
||||
|
||||
private async showTribeChanges(e: Event) {
|
||||
e.preventDefault();
|
||||
|
||||
|
|
|
@ -10,6 +10,11 @@ export type Version = {
|
|||
timezone: string;
|
||||
};
|
||||
|
||||
export type PlayerServer = {
|
||||
key: string;
|
||||
deletedAt: string | null;
|
||||
};
|
||||
|
||||
export type Player = {
|
||||
id: number;
|
||||
bestRank: number;
|
||||
|
@ -20,6 +25,7 @@ export type Player = {
|
|||
mostVillagesAt: string;
|
||||
lastActivityAt: string;
|
||||
createdAt: string;
|
||||
otherServers: PlayerServer[];
|
||||
};
|
||||
|
||||
export type TribeMeta = {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
export type BuildURLParams = {
|
||||
entity: 'player';
|
||||
id: number;
|
||||
server: string;
|
||||
};
|
||||
|
||||
export const buildURL = (params: BuildURLParams) => {
|
||||
switch (params.entity) {
|
||||
case 'player':
|
||||
return `https://www.twstats.com/in/${params.server}/player/${params.id}`;
|
||||
default:
|
||||
throw new Error(`Unknown entity: ${params.entity}`);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue