mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
034429cd47 | ||
|
|
57867317cc | ||
|
|
c2e314b193 | ||
|
|
9d2af1de13 | ||
|
|
232823566b | ||
|
|
958f0f2a52 | ||
|
|
b34fef2147 | ||
|
|
fe661124fa | ||
|
|
457dcbcad5 | ||
|
|
c18ee70eba | ||
|
|
095ffc3d6a | ||
|
|
e8b91648b1 | ||
|
|
1b43f6ba99 | ||
|
|
fc5360363c | ||
|
|
47b3c3029e | ||
|
|
dea7f34ca3 | ||
|
|
1e5026ea4a | ||
|
|
98f568ff6a | ||
|
|
10a6f8371d | ||
|
|
0933aa6615 | ||
|
|
746592418d | ||
|
|
e2404b063c | ||
|
|
bae1301556 | ||
|
|
c2de4952ad | ||
|
|
cce61d8075 | ||
|
|
34a0388f45 | ||
|
|
9d62965fc3 | ||
|
|
892434e28f | ||
|
|
2597fe4bcd | ||
|
|
f85b4b36bd | ||
|
|
f777dafefc | ||
|
|
6ef65ccea3 | ||
|
|
974b27a313 | ||
|
|
5124d8abcd | ||
|
|
849bd356c0 | ||
|
|
6406486441 | ||
|
|
2993ada2e5 | ||
|
|
f083c18dd0 | ||
|
|
c7021c5689 | ||
|
|
815369805a | ||
|
|
d8feb5c3a8 | ||
|
|
cb101da8a8 | ||
|
|
71481f5971 | ||
|
|
817796ed3c | ||
|
|
ebb7618f2d | ||
|
|
9717f153cd | ||
|
|
afa0cfaeef | ||
|
|
298b89b227 | ||
|
|
3b94034767 | ||
|
|
444b4c21af | ||
|
|
3e9c828781 | ||
|
|
ca3a1fbe3f | ||
|
|
5f28b541e3 | ||
|
|
18edd349f2 | ||
|
|
f7c6a065c1 | ||
|
|
91d48eeadd | ||
|
|
21bafa1b7b | ||
|
|
38af2f2817 | ||
|
|
8faa1143e9 | ||
|
|
8f34ebbca4 | ||
|
|
1c03701e17 | ||
|
|
c8edd16eb3 | ||
|
|
b96ff2e239 | ||
|
|
a575da3005 | ||
|
|
3ca2dece3e | ||
|
|
191d6133b2 | ||
|
|
b15e73e3a8 | ||
|
|
9a6b8ab979 | ||
|
|
87786d41a7 | ||
|
|
ee7ffe7bc8 | ||
|
|
379a33375d | ||
|
|
bd3f5dea05 | ||
|
|
146d36234e | ||
|
|
f3edcb8077 | ||
|
|
9e492015ff | ||
|
|
d2977182d9 | ||
|
|
7d2d65bab8 | ||
|
|
415c3bd066 | ||
|
|
990ab1520c | ||
|
|
81cb1afeff | ||
|
|
dba5a0a2cd | ||
|
|
04cd205fee | ||
|
|
ec93d8e9ab | ||
|
|
56321d9e33 | ||
|
|
d39ab43e74 | ||
|
|
787d3ae6ea | ||
|
|
035f751bf1 | ||
|
|
43442ac829 | ||
|
|
da02a089b9 | ||
|
|
476d8e804a | ||
|
|
43e1d53d39 | ||
|
|
5372068830 | ||
|
|
025cec3687 | ||
|
|
c47c629a83 | ||
|
|
2b7907f8f7 | ||
|
|
903d4e4d95 | ||
|
|
8857b2baae | ||
|
|
f7bbb17f66 | ||
|
|
f407ffe4bb | ||
|
|
791a09daae | ||
|
|
9592c0b55f | ||
|
|
d9a34dc60e | ||
|
|
30e4e4e9b3 | ||
|
|
bd3ea9a8ec | ||
|
|
8131b69422 | ||
|
|
340d9c2666 | ||
|
|
2a169fac34 | ||
|
|
4819100ec6 | ||
|
|
f39a94cbe0 | ||
|
|
e61598f768 | ||
|
|
04ee3a0a44 | ||
|
|
8fa613f1e2 | ||
|
|
bdc240df08 | ||
|
|
7169e0d91a | ||
|
|
889ed7e191 | ||
|
|
1fb8dac805 | ||
|
|
9f71ac68b9 | ||
|
|
c1f3517a79 | ||
|
|
adb0af0f18 | ||
|
|
f79f1ffdc3 | ||
|
|
1c9b7463fc | ||
|
|
80741d66fc | ||
|
|
f02fb00e8c | ||
|
|
3d353cc3cf | ||
|
|
c54ceb944e | ||
|
|
37a2ba3566 | ||
|
|
caff7bb6d0 | ||
|
|
01c491aee0 | ||
|
|
fd408d6777 | ||
|
|
6d1ed1e56e | ||
|
|
46f9d605f7 | ||
|
|
a65ea42b81 | ||
|
|
40f8c6a915 | ||
|
|
4678359f36 | ||
|
|
f91bd63646 | ||
|
|
c1872262f5 | ||
|
|
082e112758 | ||
|
|
4cb7d50eb5 | ||
|
|
8c050add23 | ||
|
|
2610697d86 | ||
|
|
64f1de37ad | ||
|
|
58f6862279 | ||
|
|
b47f6fdb32 | ||
|
|
ce5a53d0ff | ||
|
|
6ee1fa13d3 | ||
|
|
196f780bb3 | ||
|
|
088d5a2941 | ||
|
|
47abdaed6f | ||
|
|
30f6055a69 | ||
|
|
9d4b750dfd | ||
|
|
d1308bc625 | ||
|
|
db40256bb4 | ||
|
|
70f1ebadfc | ||
|
|
43adaf85f5 | ||
|
|
8d5e78a510 | ||
|
|
9d6d893373 | ||
|
|
9840982aa2 | ||
|
|
8e216ebe46 | ||
|
|
889ae39e3b | ||
|
|
265eff98bf | ||
|
|
ef7d1dcfb3 | ||
|
|
607ebc0025 | ||
|
|
0f0bc9569d | ||
|
|
169e892678 | ||
|
|
fe249e2704 | ||
|
|
b8be5d5e38 | ||
|
|
77d6c93b90 | ||
|
|
4fedaf1cea | ||
|
|
b2220f885e | ||
|
|
3181f9c4e7 | ||
|
|
153d0d326d | ||
|
|
7f9b349de6 | ||
|
|
b3a50f2b27 | ||
|
|
fb49628375 | ||
|
|
394a74c3a0 | ||
|
|
370bf826c0 | ||
|
|
38ca1499e2 | ||
|
|
2deced699b | ||
|
|
6405af7ec7 | ||
|
|
fa2bdfca12 | ||
|
|
872e7ce704 | ||
|
|
110d3c1007 | ||
|
|
7a27b70c29 | ||
|
|
2ffe5a137c | ||
|
|
bf0246ec26 | ||
|
|
b71feca802 | ||
|
|
da1fbeeca4 | ||
|
|
53174db351 | ||
|
|
19d2ad4cb2 | ||
|
|
3325536bbc | ||
|
|
4220177b02 | ||
|
|
796aca21cf | ||
|
|
3510768786 | ||
|
|
6197642d5e | ||
|
|
b60f8bfd57 | ||
|
|
9437d16908 | ||
|
|
de9077e0d2 | ||
|
|
4a6e946809 | ||
|
|
935c578ef6 | ||
|
|
0e06ff52ba | ||
|
|
fa4590d8f6 | ||
|
|
5620b118f4 | ||
|
|
d53b31ca40 | ||
|
|
a4a5d53f66 | ||
|
|
9f4c8c9088 | ||
|
|
472172c504 | ||
|
|
bc08656806 | ||
|
|
bd6f1f3570 | ||
|
|
716b446272 | ||
|
|
96a9e5b938 | ||
|
|
83e31e6352 | ||
|
|
49d0dbe86d | ||
|
|
e141a7ca3f | ||
|
|
adad668157 | ||
|
|
267f23cad8 | ||
|
|
f605801555 | ||
|
|
19e81ff78a | ||
|
|
9232a95e00 | ||
|
|
6dcef6b199 | ||
|
|
e355bd10b1 | ||
|
|
ceb4ed52c0 | ||
|
|
227750efad | ||
|
|
8a76558f01 | ||
|
|
db7c865c76 | ||
|
|
8e35e0d6d9 | ||
|
|
c9d50f39b5 | ||
|
|
77ac893a7c | ||
|
|
ac60a436f1 | ||
|
|
2ba9f0f4c8 | ||
|
|
47c3aa4842 | ||
|
|
d2edf4b89d | ||
|
|
11a0c246dc | ||
|
|
cba93b3d55 | ||
|
|
fa9b6c6d97 | ||
|
|
bef48eca62 | ||
|
|
e42ff03c4b | ||
|
|
ec628e4a0d | ||
|
|
8865a48936 | ||
|
|
d3a9c3bd95 | ||
|
|
90bff59af3 | ||
|
|
9efe9860ae | ||
|
|
f6a418499b | ||
|
|
66740bcb8d | ||
|
|
035e257926 | ||
|
|
e63549158b | ||
|
|
7fb64e690f | ||
|
|
54798c30b1 | ||
|
|
4c0f7b61e4 | ||
|
|
206ac373d2 | ||
|
|
c626e84f7d | ||
|
|
90ec5fa80b | ||
|
|
d496b46b6f | ||
|
|
7af1fdcf6b | ||
|
|
199e156e53 | ||
|
|
f5578ee788 | ||
|
|
c0a3628b3b | ||
|
|
fa8922e0a6 | ||
|
|
bf6991ce06 | ||
|
|
7f49245f15 | ||
|
|
f55313e0cd | ||
|
|
69c388f243 | ||
|
|
35788657a8 | ||
|
|
d531698867 | ||
|
|
cc4177bf14 | ||
|
|
d377067441 | ||
|
|
b2f026c212 | ||
|
|
07cdb0788c | ||
|
|
01f919ddd3 | ||
|
|
4b1fda9680 | ||
|
|
79d03233ae | ||
|
|
522b40aff1 | ||
|
|
06c878dd2c | ||
|
|
f5c589373d | ||
|
|
2689568650 | ||
|
|
fabf649608 | ||
|
|
080af86e1b | ||
|
|
e5b58cd5ff | ||
|
|
3500389628 | ||
|
|
1129f0d60b | ||
|
|
b3a6a47a6a | ||
|
|
bdb3844bcc | ||
|
|
f0bb25efc1 |
No files matched your search
@@ -2,10 +2,10 @@ name: CD Build Assets
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: dev
|
branches: main
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
# schedule:
|
schedule:
|
||||||
# - cron: '0 0 * * *'
|
- cron: '0 2 * * *'
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
@@ -18,6 +18,9 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
token: ${{ secrets.GH_TOKEN }}
|
||||||
|
|
||||||
- name: Use node
|
- name: Use node
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
@@ -46,8 +49,17 @@ jobs:
|
|||||||
- name: Run DepotDownloader
|
- name: Run DepotDownloader
|
||||||
run: ./temp/depotDownloader/DepotDownloader.exe -app 444200 -username ${{ secrets.DEPOT_DOWNLOADER_USERNAME }} -password "${{ secrets.DEPOT_DOWNLOADER_PASSWORD }}"
|
run: ./temp/depotDownloader/DepotDownloader.exe -app 444200 -username ${{ secrets.DEPOT_DOWNLOADER_USERNAME }} -password "${{ secrets.DEPOT_DOWNLOADER_PASSWORD }}"
|
||||||
|
|
||||||
|
- name: Apply patches
|
||||||
|
run: |
|
||||||
|
$env:GH_TOKEN = "${{ secrets.GH_TOKEN }}"
|
||||||
|
$env:DISCORD_TOKEN = "${{ secrets.DISCORD_TOKEN }}"
|
||||||
|
$env:DISCORD_BLITZ_DB = "${{ secrets.DISCORD_BLITZ_DB }}"
|
||||||
|
$env:WOTB_DLC_CDN = "${{ secrets.WOTB_DLC_CDN }}"
|
||||||
|
yarn setup:patches --depot
|
||||||
|
|
||||||
- name: Build assets
|
- name: Build assets
|
||||||
run: |
|
run: |
|
||||||
$env:GH_TOKEN = "${{ secrets.GH_TOKEN }}"
|
$env:GH_TOKEN = "${{ secrets.GH_TOKEN }}"
|
||||||
$env:DISCORD_TOKEN = "${{ secrets.DISCORD_TOKEN }}"
|
$env:DISCORD_TOKEN = "${{ secrets.DISCORD_TOKEN }}"
|
||||||
|
$env:DISCORD_BLITZ_DB = "${{ secrets.DISCORD_BLITZ_DB }}"
|
||||||
yarn build:assets --all-targets --depot ${{ github.ref == 'refs/heads/main' && '--production' || '' }}
|
yarn build:assets --all-targets --depot ${{ github.ref == 'refs/heads/main' && '--production' || '' }}
|
||||||
@@ -18,10 +18,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Use node
|
- name: Use node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -54,7 +54,7 @@ jobs:
|
|||||||
uses: actions/deploy-pages@v1
|
uses: actions/deploy-pages@v1
|
||||||
|
|
||||||
- name: Archive build
|
- name: Archive build
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: dist
|
name: dist
|
||||||
path: docs/.vitepress/dist
|
path: docs/.vitepress/dist
|
||||||
@@ -6,6 +6,8 @@ on:
|
|||||||
schedule:
|
schedule:
|
||||||
- cron: '0 */5 * * *'
|
- cron: '0 */5 * * *'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
release:
|
||||||
|
types: [created, published, released, edited]
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
@@ -17,7 +19,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Use node
|
- name: Use node
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
name: CD Ratings Asia
|
name: CD Rating Asia
|
||||||
|
|
||||||
# latest: '0 0 * * *'
|
|
||||||
# asia midnight: '0 17 * * *'
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 0 * * *'
|
|
||||||
- cron: '0 17 * * *'
|
- cron: '0 17 * * *'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -14,10 +10,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Use node
|
- name: Use node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -35,4 +31,4 @@ jobs:
|
|||||||
run: yarn
|
run: yarn
|
||||||
|
|
||||||
- name: Generate leaderboard
|
- name: Generate leaderboard
|
||||||
run: GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} yarn publish:ratingsleaderboard --region=asia --target=${{ github.event.schedule == '0 0 * * *' && 'latest' || 'midnight' }}
|
run: GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} DISCORD_BLITZ_DB=${{ secrets.DISCORD_BLITZ_DB }} yarn publish:ratingleaderboard --region=asia --target=midnight --production
|
||||||
@@ -1,11 +1,7 @@
|
|||||||
name: CD Ratings Europe
|
name: CD Rating Europe
|
||||||
|
|
||||||
# latest: '0 0 * * *'
|
|
||||||
# eu midnight: '0 23 * * *'
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 0 * * *'
|
|
||||||
- cron: '0 23 * * *'
|
- cron: '0 23 * * *'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -14,10 +10,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Use node
|
- name: Use node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -35,4 +31,4 @@ jobs:
|
|||||||
run: yarn
|
run: yarn
|
||||||
|
|
||||||
- name: Generate leaderboard
|
- name: Generate leaderboard
|
||||||
run: GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} yarn publish:ratingsleaderboard --region=eu --target=${{ github.event.schedule == '0 0 * * *' && 'latest' || 'midnight' }}
|
run: GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} DISCORD_BLITZ_DB=${{ secrets.DISCORD_BLITZ_DB }} yarn publish:ratingleaderboard --region=eu --target=midnight --production
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
name: CI Version
|
name: CD Rating Latest
|
||||||
|
|
||||||
on: push
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * *'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
host:
|
host:
|
||||||
@@ -8,10 +10,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Use node
|
- name: Use node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -28,5 +30,5 @@ jobs:
|
|||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn
|
run: yarn
|
||||||
|
|
||||||
- name: Generate leaderboard
|
- name: Generate all leaderboards
|
||||||
run: yarn lint:version
|
run: GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} DISCORD_BLITZ_DB=${{ secrets.DISCORD_BLITZ_DB }} yarn publish:ratingleaderboard --region=na,asia,eu --target=latest --production
|
||||||
@@ -1,11 +1,7 @@
|
|||||||
name: CD Ratings North America
|
name: CD Rating North America
|
||||||
|
|
||||||
# latest: '0 0 * * *'
|
|
||||||
# na midnight: '0 5 * * *'
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 0 * * *'
|
|
||||||
- cron: '0 5 * * *'
|
- cron: '0 5 * * *'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -14,10 +10,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Use node
|
- name: Use node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -35,4 +31,4 @@ jobs:
|
|||||||
run: yarn
|
run: yarn
|
||||||
|
|
||||||
- name: Generate leaderboard
|
- name: Generate leaderboard
|
||||||
run: GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} yarn publish:ratingsleaderboard --region=na --target=${{ github.event.schedule == '0 0 * * *' && 'latest' || 'midnight' }}
|
run: GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} DISCORD_BLITZ_DB=${{ secrets.DISCORD_BLITZ_DB }} yarn publish:ratingleaderboard --region=na --target=midnight --production
|
||||||
@@ -13,10 +13,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Use node
|
- name: Use node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -34,10 +34,10 @@ jobs:
|
|||||||
run: yarn
|
run: yarn
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: yarn build:bot
|
run: yarn build:bot --production
|
||||||
|
|
||||||
- name: Archive build
|
- name: Archive build
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: bot
|
name: bot
|
||||||
path: dist/bot
|
path: dist/bot
|
||||||
@@ -13,10 +13,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Use node
|
- name: Use node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -37,7 +37,7 @@ jobs:
|
|||||||
run: yarn build:docs
|
run: yarn build:docs
|
||||||
|
|
||||||
- name: Archive build
|
- name: Archive build
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: docs
|
name: docs
|
||||||
path: dist/docs
|
path: dist/docs
|
||||||
@@ -13,10 +13,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Use node
|
- name: Use node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -37,7 +37,7 @@ jobs:
|
|||||||
run: yarn build:website
|
run: yarn build:website
|
||||||
|
|
||||||
- name: Archive build
|
- name: Archive build
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: website
|
name: website
|
||||||
path: dist/website
|
path: dist/website
|
||||||
+3
-1
@@ -8,7 +8,6 @@ dist/
|
|||||||
dist.*
|
dist.*
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
/test.*
|
/test.*
|
||||||
test.*
|
|
||||||
/docs/.vitepress/dist
|
/docs/.vitepress/dist
|
||||||
/docs/.vitepress/cache
|
/docs/.vitepress/cache
|
||||||
servers.csv
|
servers.csv
|
||||||
@@ -18,3 +17,6 @@ temp/
|
|||||||
/.yarn
|
/.yarn
|
||||||
/.VSCodeCounter
|
/.VSCodeCounter
|
||||||
/.yarn
|
/.yarn
|
||||||
|
depots
|
||||||
|
public/sitemap*.xml
|
||||||
|
public/robots.txt
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "submodules/closedkrieg"]
|
||||||
|
path = submodules/closedkrieg
|
||||||
|
url = https://github.com/tresabhi/closedkrieg
|
||||||
Vendored
+13
-3
@@ -5,7 +5,9 @@
|
|||||||
"accountinfo",
|
"accountinfo",
|
||||||
"aeson",
|
"aeson",
|
||||||
"alphatest",
|
"alphatest",
|
||||||
|
"APAC",
|
||||||
"apcr",
|
"apcr",
|
||||||
|
"applypatches",
|
||||||
"artefacts",
|
"artefacts",
|
||||||
"atgm",
|
"atgm",
|
||||||
"AYUV",
|
"AYUV",
|
||||||
@@ -14,12 +16,14 @@
|
|||||||
"betakrieg",
|
"betakrieg",
|
||||||
"BINORMAL",
|
"BINORMAL",
|
||||||
"Binormals",
|
"Binormals",
|
||||||
|
"BKRL",
|
||||||
"bkwd",
|
"bkwd",
|
||||||
"blitzstars",
|
"blitzstars",
|
||||||
"Camo",
|
"Camo",
|
||||||
"CDON",
|
"CDON",
|
||||||
"classname",
|
"classname",
|
||||||
"cleandist",
|
"cleandist",
|
||||||
|
"closedkrieg",
|
||||||
"cockroackdb",
|
"cockroackdb",
|
||||||
"Coef",
|
"Coef",
|
||||||
"cooldown",
|
"cooldown",
|
||||||
@@ -40,8 +44,10 @@
|
|||||||
"donotremove",
|
"donotremove",
|
||||||
"drei",
|
"drei",
|
||||||
"Droodles",
|
"Droodles",
|
||||||
|
"dvpd",
|
||||||
"dvpl",
|
"dvpl",
|
||||||
"DVPLCRC",
|
"DVPLCRC",
|
||||||
|
"dvpm",
|
||||||
"dxgi",
|
"dxgi",
|
||||||
"Everytime",
|
"Everytime",
|
||||||
"FASTNAME",
|
"FASTNAME",
|
||||||
@@ -54,6 +60,7 @@
|
|||||||
"glsl",
|
"glsl",
|
||||||
"GLTF",
|
"GLTF",
|
||||||
"haha",
|
"haha",
|
||||||
|
"highp",
|
||||||
"iife",
|
"iife",
|
||||||
"immer",
|
"immer",
|
||||||
"Inclusivity",
|
"Inclusivity",
|
||||||
@@ -69,6 +76,7 @@
|
|||||||
"lods",
|
"lods",
|
||||||
"metallicness",
|
"metallicness",
|
||||||
"minitelrose",
|
"minitelrose",
|
||||||
|
"Minotauro",
|
||||||
"MIPMAPCOUNT",
|
"MIPMAPCOUNT",
|
||||||
"modeltransform",
|
"modeltransform",
|
||||||
"MURICA",
|
"MURICA",
|
||||||
@@ -92,8 +100,7 @@
|
|||||||
"POSITIVEZ",
|
"POSITIVEZ",
|
||||||
"Promisable",
|
"Promisable",
|
||||||
"Pyogenics",
|
"Pyogenics",
|
||||||
"ratingsleaderboard",
|
"ratingleaderboard",
|
||||||
"ratingsplot",
|
|
||||||
"raycaster",
|
"raycaster",
|
||||||
"researchable",
|
"researchable",
|
||||||
"Resvg",
|
"Resvg",
|
||||||
@@ -128,6 +135,7 @@
|
|||||||
"TYPELESS",
|
"TYPELESS",
|
||||||
"ubjson",
|
"ubjson",
|
||||||
"Unicum",
|
"Unicum",
|
||||||
|
"UNLOCALIZED",
|
||||||
"UNORM",
|
"UNORM",
|
||||||
"Unregistering",
|
"Unregistering",
|
||||||
"vickers",
|
"vickers",
|
||||||
@@ -137,6 +145,7 @@
|
|||||||
"webp",
|
"webp",
|
||||||
"winrate",
|
"winrate",
|
||||||
"wireframe",
|
"wireframe",
|
||||||
|
"WOTB",
|
||||||
"wotblitz",
|
"wotblitz",
|
||||||
"xffn",
|
"xffn",
|
||||||
"xkdkw",
|
"xkdkw",
|
||||||
@@ -145,5 +154,6 @@
|
|||||||
"zustand"
|
"zustand"
|
||||||
],
|
],
|
||||||
"deno.enable": false,
|
"deno.enable": false,
|
||||||
"deno.unstable": false
|
"deno.unstable": false,
|
||||||
|
"cSpell.enableFiletypes": ["glsl"]
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
files:
|
||||||
|
- source: /src/lang/en-US.json
|
||||||
|
translation: /src/lang/%locale%.json
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# Blitzkrieg 1.16.1
|
||||||
|
|
||||||
|
Armor sandbox gains 25% rendering speed and 40% memory efficiency with added accuracy and features.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Multiple layers of spaced armors are now calculated properly by the visual armor highlighting
|
||||||
|
- Added opaque mode to view armor highlighting without any transparency
|
||||||
|
- Added breakdown on layers of armor penetrated
|
||||||
|
- Penetration of each layer is shown represented by a color and an index
|
||||||
|
- Green: penetration
|
||||||
|
- Red: blocked
|
||||||
|
- Yellow: ricochet
|
||||||
|
- This also shows layers encountered after a ricochet
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
|
||||||
|
- Accuracy now doesn't drop the further the shot is placed from the origin
|
||||||
|
- HE shells no longer loose penetration like how HEAT shells do when traveling between layers of armor
|
||||||
|
- Persistent settings are now merged in the correct order making them truly persistent now
|
||||||
|
- Enhanced armor and calibrated shells are now properly synced from the get go
|
||||||
|
|
||||||
|
## Technical Changes
|
||||||
|
|
||||||
|
- Spaced armor and external module scenes have been merged
|
||||||
|
- They now use additive blending
|
||||||
|
- Colors are now normalized by the penetration value instead of maximum armor plate thickness
|
||||||
|
- Shell normalization now doesn't violate arccosine's domain
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
# Blitzkrieg 1.16.2
|
||||||
|
|
||||||
|
¡Hola desde el mundo del español!
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Added translations for Spanish to the bot
|
||||||
|
- Your language will be inferred automatically from your Discord settings
|
||||||
|
- Any untranslated languages and words we forgot to translate will be left in English
|
||||||
|
- If you have your language set to Spanish and see English in any places, please let us know on [the official Discord server](https://discord.gg/nDt7AjGJQH)
|
||||||
|
- All `/about` commands except for `commands` remain in English
|
||||||
|
- Tank names are still in English
|
||||||
|
- The website remains unchanged
|
||||||
|
- The title bar (featured as the big text on top of most commands) has now been made more compact
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
- "Tank type" is now called "tank class"
|
||||||
|
- Removed `/player-achievements` and `search-tanks`
|
||||||
|
- They will be reintroduced in the future in a far better way
|
||||||
|
- Also removed a `SKLLD` server exclusive `/eligible` command
|
||||||
|
- This will be generalized for all clans in the future
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
|
||||||
|
- Fixed the red glowing floor underneath the tank sandbox
|
||||||
|
- This has been replaced with a static image
|
||||||
|
- The refresh button is now properly removed when lacking permissions
|
||||||
|
- Tank names that start with a number are now properly inferred from command inputs
|
||||||
|
|
||||||
|
## Technical Changes
|
||||||
|
|
||||||
|
- Command registration is now error tolerant meaning that if a single command fails to initiate, it will be discarded until the next restart
|
||||||
|
- We are currently looking into how we can allow the command to retry registration after a fixed amount of time
|
||||||
|
- Due to the implications of the code added which can be very easily exploited by hackers, a single file has been added to the repository as a closed source submodule and will remain closed unless a third party open-source implementation is made public
|
||||||
|
- Removed preview commands
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# Blitzkrieg 1.16.3
|
||||||
|
|
||||||
|
Further polishing and corrections for the Tankopedia.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Added a few more stats to view for the Tankopedia
|
||||||
|
- Added the count of shells in the magazine for auto-reloaders
|
||||||
|
- The optimal shell index was moved below this stats
|
||||||
|
- Shell reloads for auto-reloaders now abide crew stats
|
||||||
|
- Intra-clip is now also shown for auto-reloaders
|
||||||
|
- Added 1 more decimal place worth of precision when viewing and changing gun pitch and yaw
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
|
||||||
|
- "Inter-clip" is now correctly spelled as "intra-clip"
|
||||||
|
- Tanks with initial gun pitches (like the Minotauro) are now handled correctly
|
||||||
|
- The stats now reflect the fact that the gun is naturally pitched downwards
|
||||||
|
- The view model now compensates for the natural pitch
|
||||||
|
- Tanks with the improved vertical stabilizer equipment are now handled correctly
|
||||||
|
- The view model now allows you to pitch the gun further as intended when the equipment is on
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Blitzkrieg 1.16.4
|
||||||
|
|
||||||
|
A few issues here and there addressed for good measure.
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
- Armor layer penetration indices are now much more compact.
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
|
||||||
|
- Reverted splash mechanics changes from `1.16.1` as it made them less accurate.
|
||||||
|
- Auto-reloaders now report their DPM stats correctly with crew training.
|
||||||
|
|
||||||
|
## Technical Changes
|
||||||
|
|
||||||
|
- All files in the project were reviewed and constant exports were isolated.
|
||||||
|
- The downloaded game in the workflow now also includes the latest patches.
|
||||||
|
- Asset building now uses sharp under the hood which should in theory be faster.
|
||||||
|
- Fetching CDON LZ4 files now uses `no-store` instead of `no-cache`
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Blitzkrieg 1.17.0
|
||||||
|
|
||||||
|
A preview command and a touchup.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Added `/research` in preview only accessible in the official Discord server.
|
||||||
|
- More details will be posted when the command is made public.
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
- `/owned-tanks` now returns a simple text message listing all the tanks instead of an image.
|
||||||
|
- This is meant to improve the readability and ease of copying.
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Blitzkrieg 1.17.1
|
||||||
|
|
||||||
|
Some stability fixes.
|
||||||
|
|
||||||
|
## Technical Changes
|
||||||
|
|
||||||
|
- `sharp` is now included in the build instead of having being installed before runtime.
|
||||||
|
- Png converter cache is now more memory efficient.
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Blitzkrieg 1.17.2
|
||||||
|
|
||||||
|
Introducing the new `/research` command!
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Added the `/research` command
|
||||||
|
- Type in the name of a tech tree tank you desire to research and this command will list all the expenses in researching all tanks in that line
|
||||||
|
- The starting tank is inferred automatically by the tanks you own
|
||||||
|
- This may be a bit inaccurate because of the lack of accurate information Wargaming provides about owned tanks
|
||||||
|
- You are also manually provide a starting tank and a user to see the progress on a line for
|
||||||
|
- Replaced Vercel Analytics (which collapsed under the insane amount of traffic on the website) with Google Analytics
|
||||||
|
- Spaced armor can now be toggled in the Tankopedia armor sandbox
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Blitzkrieg 1.18.0
|
||||||
|
|
||||||
|
Introducing the new `/rating` command!
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- `/rating` command
|
||||||
|
- Features statistics on today's performance in ratings
|
||||||
|
- The included stats are battles, winrate, damage, survival, and kills
|
||||||
|
- This command also features the score, rank, and league you are at plus the reward you'll get if you are high enough on the leaderboard
|
||||||
|
- `/ratings`, the old leaderboard command, has been renamed `/rating-leaderboard`
|
||||||
|
- Reward icons have been removed from the leaderboard
|
||||||
|
|
||||||
|
## Technical Changes
|
||||||
|
|
||||||
|
- Rating leaderboards are now built in a more action-efficient manner.
|
||||||
|
- This version also introduces the BKRL (Blitzkrieg rating leaderboard) file format which is an efficient way to store entire leaderboards of regions to disk (1 MB per 40,000 users).
|
||||||
|
- Latest archival actions now build all regions at once in a single action.
|
||||||
|
- The sharp module is now included in the build.
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Blitzkrieg 1.18.1
|
||||||
|
|
||||||
|
HE gets more accurate and say goodbye to NaNaNaNaNaN.
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
|
||||||
|
- Armor highlighting now works on Apple MacBooks
|
||||||
|
- Applied equipments now persist after switching shells
|
||||||
|
- The bottom of the tank sandbox panel can now be interacted with as it was previously blocked by an invisible layer
|
||||||
|
- `/rating` now uses the midnight leaderboard instead of the absolute latest one
|
||||||
|
- 0-battle stats are now hidden
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# Blitzkrieg 1.18.2
|
||||||
|
|
||||||
|
Redefining how micro a micro-path is.
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
|
||||||
|
- The pitch and yaw controls, along with the quick equipment buttons, can once again be interacted with
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
# Blitzkrieg Rating Leaderboard
|
||||||
|
|
||||||
|
A straightforward way of storing the entire World of Tanks Blitz rating leaderboard to disk.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
primary BlitzkriegRatingLeaderboard {
|
||||||
|
utf8"BKRL" magic;
|
||||||
|
Header header;
|
||||||
|
primary Body<header> body;
|
||||||
|
}
|
||||||
|
|
||||||
|
Header {
|
||||||
|
uint16 version; // always 1
|
||||||
|
Format format;
|
||||||
|
uint32 count;
|
||||||
|
}
|
||||||
|
|
||||||
|
Format enum<uint8> {
|
||||||
|
Base,
|
||||||
|
Superset1,
|
||||||
|
}
|
||||||
|
|
||||||
|
Body<Header header> match<header.format> {
|
||||||
|
Base {
|
||||||
|
primary {
|
||||||
|
uint32 id;
|
||||||
|
uint16 score;
|
||||||
|
}[header.count] entries;
|
||||||
|
};
|
||||||
|
|
||||||
|
Superset1 {
|
||||||
|
primary {
|
||||||
|
uint32 id;
|
||||||
|
uint16 score;
|
||||||
|
|
||||||
|
uint32 battles;
|
||||||
|
uint32 wins;
|
||||||
|
uint32 survived;
|
||||||
|
|
||||||
|
uint32 damage;
|
||||||
|
uint32 kills;
|
||||||
|
}[header.count] entries;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
+1
-3
@@ -1,7 +1,5 @@
|
|||||||
# Cedilla Object Notation
|
# Cedilla Object Notation
|
||||||
|
|
||||||
This documentation uses an experimental binary notation syntax called "Buffer Up".
|
|
||||||
|
|
||||||
1. JSON compressed as CDON, written directly to disk (a direct 50% reduction).
|
1. JSON compressed as CDON, written directly to disk (a direct 50% reduction).
|
||||||
2. CDON further compressed with LZ4 (a clean 90% reduction).
|
2. CDON further compressed with LZ4 (a clean 90% reduction).
|
||||||
3. The raw JSON file as fetched from a random data source.
|
3. The raw JSON file as fetched from a random data source.
|
||||||
@@ -19,7 +17,7 @@ primary CedillaObjectNotation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Header {
|
Header {
|
||||||
uint16 version;
|
uint16 version; // always 1
|
||||||
FSFormat fsFormat;
|
FSFormat fsFormat;
|
||||||
StringTable<fsFormat> stringTable;
|
StringTable<fsFormat> stringTable;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,5 +18,5 @@ Blitzkrieg is available as a Discord bot and can be [installed very easily](/gui
|
|||||||
Provides a bunch of very helpful tools; https://blitz-krieg.vercel.app/
|
Provides a bunch of very helpful tools; https://blitz-krieg.vercel.app/
|
||||||
|
|
||||||
- Session tracker
|
- Session tracker
|
||||||
- Ratings leaderboard
|
- Rating leaderboard
|
||||||
- Way more to come
|
- Way more to come
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
/** @type {import('next-sitemap').IConfig} */
|
||||||
|
module.exports = {
|
||||||
|
siteUrl: process.env.SITE_URL || 'https://blitz-krieg.vercel.app',
|
||||||
|
generateRobotsTxt: true,
|
||||||
|
sourceDir: 'dist/website',
|
||||||
|
};
|
||||||
+11
-10
@@ -1,31 +1,32 @@
|
|||||||
{
|
{
|
||||||
"name": "blitzkrieg",
|
"name": "blitzkrieg",
|
||||||
"version": "1.16.0",
|
"version": "1.18.2",
|
||||||
"description": "🎉 Tools for everything World of Tanks Blitz",
|
"description": "🎉 Tools for everything World of Tanks Blitz",
|
||||||
"main": "src/server.ts",
|
"main": "src/server.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:bot": "vite-node --script scripts/build",
|
"build:bot": "vite-node --script scripts/build",
|
||||||
"build:website": "next build",
|
"build:website": "next build && next-sitemap --config next-sitemap.config.cjs",
|
||||||
"build:docs": "vitepress build docs",
|
"build:docs": "vitepress build docs",
|
||||||
"build:ratingsleaderboard": "vite-node --script scripts/buildRatingsLeaderboard",
|
"build:ratingleaderboard": "vite-node --script scripts/buildRatingLeaderboard",
|
||||||
"build:assets": "vite-node --max_old_space_size=16384 --script scripts/buildAssets/index",
|
"build:assets": "vite-node --max_old_space_size=16384 --script scripts/buildAssets/index",
|
||||||
"build:test": "vite-node --script scripts/buildTest",
|
"build:test": "vite-node --script scripts/buildTest",
|
||||||
"build:ratingsplot": "vite-node --script scripts/buildRatingsPlot",
|
"dev:bot": "vite-node --script scripts/build --production && yarn start:bot",
|
||||||
"dev:bot": "yarn build:bot && yarn start:bot",
|
|
||||||
"dev:docs": "vitepress dev docs",
|
"dev:docs": "vitepress dev docs",
|
||||||
"dev:website": "next dev",
|
"dev:website": "next dev",
|
||||||
"start:bot": "node --enable-source-maps dist/bot/index.cjs",
|
"start:bot": "node --enable-source-maps dist/bot/index.cjs",
|
||||||
"start:website": "next start",
|
"start:website": "next start",
|
||||||
"host:docs": "vitepress preview docs",
|
"host:docs": "vitepress preview docs",
|
||||||
"publish:ratingsleaderboard": "vite-node --script scripts/buildRatingsLeaderboard --publish",
|
"publish:ratingleaderboard": "vite-node --script scripts/buildRatingLeaderboard --publish",
|
||||||
|
"setup:patches": "vite-node --script scripts/applyPatches",
|
||||||
"lint": "npx tsc",
|
"lint": "npx tsc",
|
||||||
"lint:website": "next lint",
|
"lint:website": "next lint",
|
||||||
"format": "prettier --write \"**/*.@(json|js|jsx|css|md|ts|tsx|html|xml|yml|gltf)\"",
|
"format": "prettier --write \"**/*.@(json|js|jsx|css|md|ts|tsx|html|xml|yml|gltf)\"",
|
||||||
"lint:version": "vite-node --script scripts/checkVersionMissMatch",
|
"lint:version": "vite-node --script scripts/checkVersionMissMatch",
|
||||||
"knip": "knip",
|
"knip": "knip",
|
||||||
"update": "yarn upgrade --latest",
|
"update": "yarn upgrade --latest",
|
||||||
"setup:depotdownloader": "vite-node --script scripts/setupDepotDownloader"
|
"setup:depotdownloader": "vite-node --script scripts/setupDepotDownloader",
|
||||||
|
"tunnel": "cloudflared tunnel --url http://localhost:3000"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -33,7 +34,7 @@
|
|||||||
"@octokit/plugin-throttling": "^8.1.3",
|
"@octokit/plugin-throttling": "^8.1.3",
|
||||||
"@octokit/rest": "^20.0.1",
|
"@octokit/rest": "^20.0.1",
|
||||||
"@prisma/client": "^5.4.1",
|
"@prisma/client": "^5.4.1",
|
||||||
"@radix-ui/colors": "^3.0.0-rc.4",
|
"@radix-ui/colors": "^3.0.0",
|
||||||
"@radix-ui/react-icons": "^1.3.0",
|
"@radix-ui/react-icons": "^1.3.0",
|
||||||
"@radix-ui/themes": "^2.0.1",
|
"@radix-ui/themes": "^2.0.1",
|
||||||
"@react-three/drei": "^9.93.0",
|
"@react-three/drei": "^9.93.0",
|
||||||
@@ -41,7 +42,6 @@
|
|||||||
"@resvg/resvg-js": "^2.4.1",
|
"@resvg/resvg-js": "^2.4.1",
|
||||||
"@types/three": "^0.160.0",
|
"@types/three": "^0.160.0",
|
||||||
"@vanilla-extract/css": "^1.13.0",
|
"@vanilla-extract/css": "^1.13.0",
|
||||||
"@vercel/analytics": "^1.2.2",
|
|
||||||
"bepaint": "^0.1.0-beta.3",
|
"bepaint": "^0.1.0-beta.3",
|
||||||
"decompress": "^4.2.1",
|
"decompress": "^4.2.1",
|
||||||
"discord.js": "^14.13.0",
|
"discord.js": "^14.13.0",
|
||||||
@@ -56,6 +56,7 @@
|
|||||||
"lz4js": "^0.2.0",
|
"lz4js": "^0.2.0",
|
||||||
"markdown-escape": "^2.0.0",
|
"markdown-escape": "^2.0.0",
|
||||||
"next": "^14.1.0",
|
"next": "^14.1.0",
|
||||||
|
"next-sitemap": "^4.2.3",
|
||||||
"parse-dds": "^1.2.1",
|
"parse-dds": "^1.2.1",
|
||||||
"postprocessing": "^6.34.1",
|
"postprocessing": "^6.34.1",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
@@ -64,7 +65,7 @@
|
|||||||
"react-fuzzysort": "^1.0.1",
|
"react-fuzzysort": "^1.0.1",
|
||||||
"react-promise-suspense": "^0.3.4",
|
"react-promise-suspense": "^0.3.4",
|
||||||
"react-spinners": "^0.13.8",
|
"react-spinners": "^0.13.8",
|
||||||
"satori": "^0.10.8",
|
"satori": "^0.10.13",
|
||||||
"sharp": "0.33.1",
|
"sharp": "0.33.1",
|
||||||
"three": "0.159.0",
|
"three": "0.159.0",
|
||||||
"three-stdlib": "^2.29.4",
|
"three-stdlib": "^2.29.4",
|
||||||
|
|||||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,48 @@
|
|||||||
|
import { mkdir, writeFile } from 'fs/promises';
|
||||||
|
import { parse as parsePath } from 'path';
|
||||||
|
import { parse as parseYaml } from 'yaml';
|
||||||
|
import { readStringDVPL } from '../src/core/blitz/readStringDVPL';
|
||||||
|
import { writeDVPL } from '../src/core/blitz/writeDVPL';
|
||||||
|
import { secrets } from '../src/core/blitzkrieg/secrets';
|
||||||
|
import { dvp } from '../submodules/closedkrieg/src/dvp';
|
||||||
|
import { DATA } from './buildAssets/constants';
|
||||||
|
|
||||||
|
const versionTextFile = await readStringDVPL(`${DATA}/version.txt.dvpl`);
|
||||||
|
const currentVersion = versionTextFile
|
||||||
|
.split(' ')[0]
|
||||||
|
.split('.')
|
||||||
|
.slice(0, 3)
|
||||||
|
.join('.');
|
||||||
|
|
||||||
|
console.log(`Installing patches for ${currentVersion}...`);
|
||||||
|
|
||||||
|
let patchIndex = 1;
|
||||||
|
while (true) {
|
||||||
|
const response = await fetch(
|
||||||
|
`${secrets.WOTB_DLC_CDN}/dlc/s${currentVersion}_${patchIndex}.yaml`,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.status === 200) {
|
||||||
|
console.log(`Applying patch ${patchIndex}...`);
|
||||||
|
|
||||||
|
const data = parseYaml(await response.text());
|
||||||
|
const dvpm = await fetch(`${secrets.WOTB_DLC_CDN}/dlc/${data.dx11}`).then(
|
||||||
|
(response) => response.arrayBuffer(),
|
||||||
|
);
|
||||||
|
const dvpd = await fetch(
|
||||||
|
`${secrets.WOTB_DLC_CDN}/dlc/${data.dx11.replace('.dvpm', '.dvpd')}`,
|
||||||
|
).then((response) => response.arrayBuffer());
|
||||||
|
const files = await dvp(dvpm, dvpd);
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
files.map(async ({ path, data }) => {
|
||||||
|
const { dir } = parsePath(path);
|
||||||
|
|
||||||
|
await mkdir(`${DATA}/${dir}`, { recursive: true });
|
||||||
|
await writeFile(`${DATA}/${path}.dvpl`, writeDVPL(Buffer.from(data)));
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
patchIndex++;
|
||||||
|
} else break;
|
||||||
|
}
|
||||||
+20
-3
@@ -1,7 +1,13 @@
|
|||||||
|
import { exec } from 'child_process';
|
||||||
import { build } from 'esbuild';
|
import { build } from 'esbuild';
|
||||||
import { cp, readdir } from 'fs/promises';
|
import { cp, readdir } from 'fs/promises';
|
||||||
|
import { argv } from 'process';
|
||||||
|
import { promisify } from 'util';
|
||||||
|
|
||||||
readdir('src/workers').then((workers) => {
|
const execPromise = promisify(exec);
|
||||||
|
const isProduction = argv.includes('--production');
|
||||||
|
|
||||||
|
await readdir('src/workers').then((workers) => {
|
||||||
const files = [
|
const files = [
|
||||||
'bot',
|
'bot',
|
||||||
'index',
|
'index',
|
||||||
@@ -25,6 +31,7 @@ readdir('src/workers').then((workers) => {
|
|||||||
'.js': '.cjs',
|
'.js': '.cjs',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
external: ['sharp'],
|
||||||
bundle: true,
|
bundle: true,
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
minifyIdentifiers: false, // causes goofy errors
|
minifyIdentifiers: false, // causes goofy errors
|
||||||
@@ -36,9 +43,19 @@ readdir('src/workers').then((workers) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// copy schema.prisma
|
// copy schema.prisma
|
||||||
cp('prisma/schema.prisma', 'dist/bot/schema.prisma');
|
await cp('prisma/schema.prisma', 'dist/bot/schema.prisma');
|
||||||
readdir('node_modules/prisma').then((files) =>
|
await readdir('node_modules/prisma').then((files) =>
|
||||||
files
|
files
|
||||||
.filter((file) => file.endsWith('.node'))
|
.filter((file) => file.endsWith('.node'))
|
||||||
.map((file) => cp(`node_modules/prisma/${file}`, `dist/bot/${file}`)),
|
.map((file) => cp(`node_modules/prisma/${file}`, `dist/bot/${file}`)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (isProduction) {
|
||||||
|
// install fixed sharp
|
||||||
|
console.log('Installing fixed sharp...');
|
||||||
|
await execPromise('yarn init -y && yarn add [email protected] --ignore-engines', {
|
||||||
|
cwd: 'dist/bot',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Generated:', await readdir('dist/bot'));
|
||||||
@@ -2,10 +2,11 @@ import { readdir } from 'fs/promises';
|
|||||||
import { argv } from 'process';
|
import { argv } from 'process';
|
||||||
|
|
||||||
const isDepot = argv.includes('--depot');
|
const isDepot = argv.includes('--depot');
|
||||||
|
export const WOTB_WIN32_DEPOT = 444202;
|
||||||
export const DATA = isDepot
|
export const DATA = isDepot
|
||||||
? await (async () => {
|
? await (async () => {
|
||||||
const [installationVersion] = await readdir('depots/444202');
|
const [installationVersion] = await readdir(`depots/${WOTB_WIN32_DEPOT}`);
|
||||||
return `depots/444202/${installationVersion}/Data`;
|
return `depots/${WOTB_WIN32_DEPOT}/${installationVersion}/Data`;
|
||||||
})()
|
})()
|
||||||
: 'C:/Program Files (x86)/Steam/steamapps/common/World of Tanks Blitz/Data';
|
: 'C:/Program Files (x86)/Steam/steamapps/common/World of Tanks Blitz/Data';
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import sharp from 'sharp';
|
||||||
|
import { readDVPLFile } from '../../src/core/blitz/readDVPLFile';
|
||||||
|
import { commitAssets } from '../../src/core/blitzkrieg/commitAssets';
|
||||||
|
import { FileChange } from '../../src/core/blitzkrieg/commitMultipleFiles';
|
||||||
|
import { DATA } from './constants';
|
||||||
|
|
||||||
|
const ICONS = [
|
||||||
|
['currency_silver_m.packed.webp', 'silver'],
|
||||||
|
['currency_premium_xl.packed.webp', 'premium'],
|
||||||
|
['currency_gold_m.packed.webp', 'gold'],
|
||||||
|
['currency_free-xp_xl.packed.webp', 'free-xp'],
|
||||||
|
['currency_elite-xp_xl.packed.webp', 'elite-xp'],
|
||||||
|
['currency_crew-xp_xl.packed.webp', 'crew-xp'],
|
||||||
|
['currency_battle-xp_xl.packed.webp', 'xp'],
|
||||||
|
];
|
||||||
|
|
||||||
|
export async function currencies(production: boolean) {
|
||||||
|
console.log('Building currency icons...');
|
||||||
|
|
||||||
|
const changes = await Promise.all(
|
||||||
|
ICONS.map(async ([file, name]) => {
|
||||||
|
const content = (
|
||||||
|
await sharp(
|
||||||
|
await readDVPLFile(`${DATA}/Gfx/Lobby/currency/${file}.dvpl`),
|
||||||
|
)
|
||||||
|
.trim()
|
||||||
|
.toBuffer()
|
||||||
|
).toString('base64');
|
||||||
|
|
||||||
|
return {
|
||||||
|
content,
|
||||||
|
encoding: 'base64',
|
||||||
|
path: `icons/currencies/${name}.webp`,
|
||||||
|
} satisfies FileChange;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
await commitAssets('currency icons', changes, production);
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import { readdir } from 'fs/promises';
|
import { readdir, writeFile } from 'fs/promises';
|
||||||
import { parse as parsePath } from 'path';
|
import { parse as parsePath } from 'path';
|
||||||
import { Vector3Tuple } from 'three';
|
import { Vector3Tuple } from 'three';
|
||||||
import { parse as parseYaml } from 'yaml';
|
import { parse as parseYaml } from 'yaml';
|
||||||
import { TankType } from '../../src/components/Tanks';
|
import { TankClass } from '../../src/components/Tanks';
|
||||||
import { readXMLDVPL } from '../../src/core/blitz/readXMLDVPL';
|
import { readXMLDVPL } from '../../src/core/blitz/readXMLDVPL';
|
||||||
import { readYAMLDVPL } from '../../src/core/blitz/readYAMLDVPL';
|
import { readYAMLDVPL } from '../../src/core/blitz/readYAMLDVPL';
|
||||||
import { toUniqueId } from '../../src/core/blitz/toUniqueId';
|
import { toUniqueId } from '../../src/core/blitz/toUniqueId';
|
||||||
@@ -34,7 +34,6 @@ import {
|
|||||||
import { DATA, POI } from './constants';
|
import { DATA, POI } from './constants';
|
||||||
import { TankParameters } from './tankIcons';
|
import { TankParameters } from './tankIcons';
|
||||||
|
|
||||||
type BlitzTankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank';
|
|
||||||
interface Strings {
|
interface Strings {
|
||||||
[key: string]: string;
|
[key: string]: string;
|
||||||
}
|
}
|
||||||
@@ -80,6 +79,16 @@ type VehicleDefinitionArmor = Record<
|
|||||||
string,
|
string,
|
||||||
number | { vehicleDamageFactor: 0; '#text': number }
|
number | { vehicleDamageFactor: 0; '#text': number }
|
||||||
>;
|
>;
|
||||||
|
interface UnlocksInner {
|
||||||
|
cost: number;
|
||||||
|
'#text': number;
|
||||||
|
}
|
||||||
|
type Unlocks = {
|
||||||
|
[key in 'vehicle' | 'engine' | 'chassis' | 'turret' | 'gun']:
|
||||||
|
| UnlocksInner
|
||||||
|
| UnlocksInner[];
|
||||||
|
};
|
||||||
|
type UnlocksListing = Unlocks | undefined;
|
||||||
interface VehicleDefinitions {
|
interface VehicleDefinitions {
|
||||||
invisibility: {
|
invisibility: {
|
||||||
moving: number;
|
moving: number;
|
||||||
@@ -93,7 +102,7 @@ interface VehicleDefinitions {
|
|||||||
};
|
};
|
||||||
consumableSlots: number;
|
consumableSlots: number;
|
||||||
provisionSlots: number;
|
provisionSlots: number;
|
||||||
optDevicePreset: string;
|
optDevicePreset: string | string[];
|
||||||
hull: {
|
hull: {
|
||||||
armor: VehicleDefinitionArmor;
|
armor: VehicleDefinitionArmor;
|
||||||
turretPositions: { turret: string };
|
turretPositions: { turret: string };
|
||||||
@@ -103,6 +112,7 @@ interface VehicleDefinitions {
|
|||||||
};
|
};
|
||||||
chassis: {
|
chassis: {
|
||||||
[key: string]: {
|
[key: string]: {
|
||||||
|
unlocks: UnlocksListing;
|
||||||
weight: number;
|
weight: number;
|
||||||
terrainResistance: string;
|
terrainResistance: string;
|
||||||
rotationSpeed: number;
|
rotationSpeed: number;
|
||||||
@@ -131,10 +141,13 @@ interface VehicleDefinitions {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
engines: {
|
engines: {
|
||||||
[key: string]: unknown;
|
[key: string]: {
|
||||||
|
unlocks: UnlocksListing;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
turrets0: {
|
turrets0: {
|
||||||
[key: string]: {
|
[key: string]: {
|
||||||
|
unlocks: UnlocksListing;
|
||||||
rotationSpeed: number;
|
rotationSpeed: number;
|
||||||
weight: number;
|
weight: number;
|
||||||
circularVisionRadius: number;
|
circularVisionRadius: number;
|
||||||
@@ -150,6 +163,7 @@ interface VehicleDefinitions {
|
|||||||
};
|
};
|
||||||
guns: {
|
guns: {
|
||||||
[key: string]: {
|
[key: string]: {
|
||||||
|
unlocks: UnlocksListing;
|
||||||
armor: VehicleDefinitionArmor & {
|
armor: VehicleDefinitionArmor & {
|
||||||
gun?:
|
gun?:
|
||||||
| number
|
| number
|
||||||
@@ -306,19 +320,6 @@ type ConsumablesVehicleFilter =
|
|||||||
| { name: string }
|
| { name: string }
|
||||||
| { extendedTags: string };
|
| { extendedTags: string };
|
||||||
|
|
||||||
const consumableProvisionEffectSuffixes = [
|
|
||||||
'Increase',
|
|
||||||
'Factor',
|
|
||||||
'Bias',
|
|
||||||
'Coef',
|
|
||||||
'Percent',
|
|
||||||
];
|
|
||||||
const blitzTankTypeToBlitzkrieg: Record<BlitzTankType, TankType> = {
|
|
||||||
'AT-SPG': 'tankDestroyer',
|
|
||||||
lightTank: 'light',
|
|
||||||
mediumTank: 'medium',
|
|
||||||
heavyTank: 'heavy',
|
|
||||||
};
|
|
||||||
const blitzShellKindToBLitzkrieg: Record<ShellKind, ShellType> = {
|
const blitzShellKindToBLitzkrieg: Record<ShellKind, ShellType> = {
|
||||||
ARMOR_PIERCING: 'ap',
|
ARMOR_PIERCING: 'ap',
|
||||||
ARMOR_PIERCING_CR: 'ap_cr',
|
ARMOR_PIERCING_CR: 'ap_cr',
|
||||||
@@ -367,6 +368,8 @@ export async function definitions(production: boolean) {
|
|||||||
`${DATA}/${POI.provisionsCommon}.dvpl`,
|
`${DATA}/${POI.provisionsCommon}.dvpl`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const tankXps = new Map<number, number>();
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
nations.map(async (nation) => {
|
nations.map(async (nation) => {
|
||||||
const tankList = await readXMLDVPL<{ root: VehicleDefinitionList }>(
|
const tankList = await readXMLDVPL<{ root: VehicleDefinitionList }>(
|
||||||
@@ -399,6 +402,10 @@ export async function definitions(production: boolean) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
for (const tankKey in tankList.root) {
|
for (const tankKey in tankList.root) {
|
||||||
|
const gunXps = new Map<number, number>();
|
||||||
|
const turretXps = new Map<number, number>();
|
||||||
|
const engineXps = new Map<number, number>();
|
||||||
|
const trackXps = new Map<number, number>();
|
||||||
const tank = tankList.root[tankKey];
|
const tank = tankList.root[tankKey];
|
||||||
const tankPrice: TankDefinitionPrice =
|
const tankPrice: TankDefinitionPrice =
|
||||||
typeof tank.price === 'number'
|
typeof tank.price === 'number'
|
||||||
@@ -441,6 +448,7 @@ export async function definitions(production: boolean) {
|
|||||||
});
|
});
|
||||||
const crew: Crew[] = [];
|
const crew: Crew[] = [];
|
||||||
const fixedCamouflage = tankTags.includes('eventCamouflage_user');
|
const fixedCamouflage = tankTags.includes('eventCamouflage_user');
|
||||||
|
const totalUnlocks: UnlocksListing[] = [];
|
||||||
|
|
||||||
Object.entries(tankDefinition.root.crew).forEach(([key, value]) => {
|
Object.entries(tankDefinition.root.crew).forEach(([key, value]) => {
|
||||||
let entry: Crew;
|
let entry: Crew;
|
||||||
@@ -487,7 +495,8 @@ export async function definitions(production: boolean) {
|
|||||||
forwards: tankDefinition.root.speedLimits.forward,
|
forwards: tankDefinition.root.speedLimits.forward,
|
||||||
backwards: tankDefinition.root.speedLimits.backward,
|
backwards: tankDefinition.root.speedLimits.backward,
|
||||||
},
|
},
|
||||||
equipment,
|
equipment:
|
||||||
|
typeof equipment === 'string' ? equipment : equipment.at(-1)!,
|
||||||
consumables: tankDefinition.root.consumableSlots,
|
consumables: tankDefinition.root.consumableSlots,
|
||||||
provisions: tankDefinition.root.provisionSlots,
|
provisions: tankDefinition.root.provisionSlots,
|
||||||
name:
|
name:
|
||||||
@@ -502,7 +511,7 @@ export async function definitions(production: boolean) {
|
|||||||
? 'premium'
|
? 'premium'
|
||||||
: 'researchable',
|
: 'researchable',
|
||||||
tier: tank.level as Tier,
|
tier: tank.level as Tier,
|
||||||
type: blitzTankTypeToBlitzkrieg[tankTags[0] as BlitzTankType],
|
class: tankTags[0] as TankClass,
|
||||||
testing: tankTags.includes('testTank') ? true : undefined,
|
testing: tankTags.includes('testTank') ? true : undefined,
|
||||||
price: tankPrice,
|
price: tankPrice,
|
||||||
camouflage: {
|
camouflage: {
|
||||||
@@ -545,6 +554,7 @@ export async function definitions(production: boolean) {
|
|||||||
.split(' ')
|
.split(' ')
|
||||||
.map(Number) as Vector3Tuple;
|
.map(Number) as Vector3Tuple;
|
||||||
|
|
||||||
|
totalUnlocks.push(track.unlocks);
|
||||||
tankDefinitions[tankId].tracks.push({
|
tankDefinitions[tankId].tracks.push({
|
||||||
id: trackId,
|
id: trackId,
|
||||||
weight: track.weight,
|
weight: track.weight,
|
||||||
@@ -571,16 +581,18 @@ export async function definitions(production: boolean) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Object.keys(tankDefinition.root.engines).forEach((engineKey) => {
|
Object.keys(tankDefinition.root.engines).forEach((engineKey) => {
|
||||||
const engine = enginesList.root.shared[engineKey];
|
const engine = tankDefinition.root.engines[engineKey];
|
||||||
|
const engineListEntry = enginesList.root.shared[engineKey];
|
||||||
const engineId = toUniqueId(nation, enginesList.root.ids[engineKey]);
|
const engineId = toUniqueId(nation, enginesList.root.ids[engineKey]);
|
||||||
|
|
||||||
|
totalUnlocks.push(engine.unlocks);
|
||||||
tankDefinitions[tankId].engines.push({
|
tankDefinitions[tankId].engines.push({
|
||||||
id: engineId,
|
id: engineId,
|
||||||
name: strings[engine.userString],
|
name: strings[engineListEntry.userString],
|
||||||
fireChance: engine.fireStartingChance,
|
fireChance: engineListEntry.fireStartingChance,
|
||||||
tier: engine.level as Tier,
|
tier: engineListEntry.level as Tier,
|
||||||
weight: engine.weight,
|
weight: engineListEntry.weight,
|
||||||
power: engine.power,
|
power: engineListEntry.power,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -607,6 +619,7 @@ export async function definitions(production: boolean) {
|
|||||||
.map(Number) as Vector3Tuple;
|
.map(Number) as Vector3Tuple;
|
||||||
const turretArmor: ModelArmor = { thickness: {} };
|
const turretArmor: ModelArmor = { thickness: {} };
|
||||||
|
|
||||||
|
totalUnlocks.push(turret.unlocks);
|
||||||
Object.keys(turret.armor)
|
Object.keys(turret.armor)
|
||||||
.filter((name) => name.startsWith('armor_'))
|
.filter((name) => name.startsWith('armor_'))
|
||||||
.forEach((name) => {
|
.forEach((name) => {
|
||||||
@@ -659,11 +672,11 @@ export async function definitions(production: boolean) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Object.keys(turret.guns).forEach((gunKey, gunIndex) => {
|
Object.keys(turret.guns).forEach((gunKey, gunIndex) => {
|
||||||
const turretGunEntry = turret.guns[gunKey];
|
const gun = turret.guns[gunKey];
|
||||||
const gunId = toUniqueId(nation, gunList.root.ids[gunKey]);
|
const gunId = toUniqueId(nation, gunList.root.ids[gunKey]);
|
||||||
const gunListEntry = gunList.root.shared[gunKey];
|
const gunListEntry = gunList.root.shared[gunKey];
|
||||||
const pitchLimitsRaw =
|
const pitchLimitsRaw =
|
||||||
turretGunEntry.pitchLimits ?? gunListEntry.pitchLimits;
|
gun.pitchLimits ?? gunListEntry.pitchLimits;
|
||||||
const gunPitch = (
|
const gunPitch = (
|
||||||
typeof pitchLimitsRaw === 'string'
|
typeof pitchLimitsRaw === 'string'
|
||||||
? pitchLimitsRaw
|
? pitchLimitsRaw
|
||||||
@@ -672,43 +685,41 @@ export async function definitions(production: boolean) {
|
|||||||
.split(' ')
|
.split(' ')
|
||||||
.map(Number) as [number, number];
|
.map(Number) as [number, number];
|
||||||
const gunModel = Number(
|
const gunModel = Number(
|
||||||
parsePath(turretGunEntry.models.undamaged).name.split('_')[1],
|
parsePath(gun.models.undamaged).name.split('_')[1],
|
||||||
);
|
);
|
||||||
const gunName =
|
const gunName =
|
||||||
strings[gunListEntry.userString] ?? gunKey.replaceAll('_', ' ');
|
strings[gunListEntry.userString] ?? gunKey.replaceAll('_', ' ');
|
||||||
const gunType =
|
const gunType =
|
||||||
'clip' in turretGunEntry
|
'clip' in gun
|
||||||
? turretGunEntry.pumpGunMode
|
? gun.pumpGunMode
|
||||||
? 'autoReloader'
|
? 'autoReloader'
|
||||||
: 'autoLoader'
|
: 'autoLoader'
|
||||||
: 'regular';
|
: 'regular';
|
||||||
const gunReload =
|
const gunReload =
|
||||||
gunType === 'autoReloader'
|
gunType === 'autoReloader'
|
||||||
? turretGunEntry.pumpGunReloadTimes!.split(' ').map(Number)
|
? gun.pumpGunReloadTimes!.split(' ').map(Number)
|
||||||
: turretGunEntry.reloadTime;
|
: gun.reloadTime;
|
||||||
const gunClipCount =
|
const gunClipCount =
|
||||||
gunType === 'regular' ? undefined : turretGunEntry.clip!.count;
|
gunType === 'regular' ? undefined : gun.clip!.count;
|
||||||
const gunInterClip =
|
const gunIntraClip =
|
||||||
gunType === 'regular'
|
gunType === 'regular' ? undefined : 60 / gun.clip!.rate;
|
||||||
? undefined
|
const front = gun.extraPitchLimits?.front
|
||||||
: 60 / turretGunEntry.clip!.rate;
|
? gun.extraPitchLimits.front.split(' ').map(Number)
|
||||||
const front = turretGunEntry.extraPitchLimits?.front
|
|
||||||
? turretGunEntry.extraPitchLimits.front.split(' ').map(Number)
|
|
||||||
: undefined;
|
: undefined;
|
||||||
const back = turretGunEntry.extraPitchLimits?.back
|
const back = gun.extraPitchLimits?.back
|
||||||
? turretGunEntry.extraPitchLimits.back.split(' ').map(Number)
|
? gun.extraPitchLimits.back.split(' ').map(Number)
|
||||||
: undefined;
|
: undefined;
|
||||||
const transition = turretGunEntry.extraPitchLimits?.transition
|
const transition = gun.extraPitchLimits?.transition
|
||||||
? typeof turretGunEntry.extraPitchLimits.transition === 'number'
|
? typeof gun.extraPitchLimits.transition === 'number'
|
||||||
? turretGunEntry.extraPitchLimits.transition
|
? gun.extraPitchLimits.transition
|
||||||
: turretGunEntry.extraPitchLimits.transition.at(-1)!
|
: gun.extraPitchLimits.transition.at(-1)!
|
||||||
: undefined;
|
: undefined;
|
||||||
const gunArmor: ModelArmor = { thickness: {} };
|
const gunArmor: ModelArmor = { thickness: {} };
|
||||||
const shotDispersionFactors =
|
const shotDispersionFactors =
|
||||||
turretGunEntry.shotDispersionFactors ??
|
gun.shotDispersionFactors ?? gunListEntry.shotDispersionFactors;
|
||||||
gunListEntry.shotDispersionFactors;
|
|
||||||
|
|
||||||
Object.keys(turretGunEntry.armor)
|
totalUnlocks.push(gun.unlocks);
|
||||||
|
Object.keys(gun.armor)
|
||||||
.filter((name) => name.startsWith('armor_'))
|
.filter((name) => name.startsWith('armor_'))
|
||||||
.forEach((name) => {
|
.forEach((name) => {
|
||||||
const armorIdString = name.match(/armor_(\d+)/)?.[1];
|
const armorIdString = name.match(/armor_(\d+)/)?.[1];
|
||||||
@@ -716,7 +727,7 @@ export async function definitions(production: boolean) {
|
|||||||
throw new SyntaxError(`Invalid armor id: ${name}`);
|
throw new SyntaxError(`Invalid armor id: ${name}`);
|
||||||
}
|
}
|
||||||
const armorId = parseInt(armorIdString);
|
const armorId = parseInt(armorIdString);
|
||||||
const armorRaw = turretGunEntry.armor[name];
|
const armorRaw = gun.armor[name];
|
||||||
if (typeof armorRaw === 'number') {
|
if (typeof armorRaw === 'number') {
|
||||||
gunArmor.thickness[armorId] = armorRaw;
|
gunArmor.thickness[armorId] = armorRaw;
|
||||||
} else {
|
} else {
|
||||||
@@ -736,15 +747,15 @@ export async function definitions(production: boolean) {
|
|||||||
type: gunType,
|
type: gunType,
|
||||||
reload: gunReload,
|
reload: gunReload,
|
||||||
count: gunClipCount,
|
count: gunClipCount,
|
||||||
interClip: gunInterClip,
|
intraClip: gunIntraClip,
|
||||||
camouflageLoss:
|
camouflageLoss:
|
||||||
typeof turretGunEntry.invisibilityFactorAtShot === 'number'
|
typeof gun.invisibilityFactorAtShot === 'number'
|
||||||
? turretGunEntry.invisibilityFactorAtShot
|
? gun.invisibilityFactorAtShot
|
||||||
: turretGunEntry.invisibilityFactorAtShot.at(-1)!,
|
: gun.invisibilityFactorAtShot.at(-1)!,
|
||||||
aimTime: turretGunEntry.aimingTime ?? gunListEntry.aimingTime,
|
aimTime: gun.aimingTime ?? gunListEntry.aimingTime,
|
||||||
dispersion: {
|
dispersion: {
|
||||||
base:
|
base:
|
||||||
turretGunEntry.shotDispersionRadius ??
|
gun.shotDispersionRadius ??
|
||||||
gunListEntry.shotDispersionRadius,
|
gunListEntry.shotDispersionRadius,
|
||||||
damaged: shotDispersionFactors.whileGunDamaged,
|
damaged: shotDispersionFactors.whileGunDamaged,
|
||||||
shot: shotDispersionFactors.afterShot,
|
shot: shotDispersionFactors.afterShot,
|
||||||
@@ -756,11 +767,11 @@ export async function definitions(production: boolean) {
|
|||||||
armor: gunArmor,
|
armor: gunArmor,
|
||||||
model: gunModel,
|
model: gunModel,
|
||||||
thickness:
|
thickness:
|
||||||
turretGunEntry.armor.gun === undefined
|
gun.armor.gun === undefined
|
||||||
? 0
|
? 0
|
||||||
: typeof turretGunEntry.armor.gun === 'number'
|
: typeof gun.armor.gun === 'number'
|
||||||
? turretGunEntry.armor.gun
|
? gun.armor.gun
|
||||||
: turretGunEntry.armor.gun['#text'],
|
: gun.armor.gun['#text'],
|
||||||
pitch: {
|
pitch: {
|
||||||
min: gunPitch[0],
|
min: gunPitch[0],
|
||||||
max: gunPitch[1],
|
max: gunPitch[1],
|
||||||
@@ -822,10 +833,100 @@ export async function definitions(production: boolean) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
totalUnlocks.forEach((unlocks) => {
|
||||||
|
if (unlocks === undefined) return;
|
||||||
|
|
||||||
|
Object.entries(unlocks).forEach(([key, value]) => {
|
||||||
|
(Array.isArray(value) ? value : [value]).forEach((vehicle) => {
|
||||||
|
switch (key as keyof Unlocks) {
|
||||||
|
case 'vehicle': {
|
||||||
|
const tankListEntry = tankList.root[vehicle['#text']];
|
||||||
|
const currentTank = tankDefinitions[tankId];
|
||||||
|
const successorId = toUniqueId(nation, tankListEntry.id);
|
||||||
|
|
||||||
|
tankXps.set(successorId, vehicle.cost);
|
||||||
|
|
||||||
|
if (currentTank.successors === undefined) {
|
||||||
|
currentTank.successors = [];
|
||||||
|
}
|
||||||
|
if (!currentTank.successors!.includes(successorId)) {
|
||||||
|
currentTank.successors!.push(successorId);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'gun': {
|
||||||
|
gunXps.set(
|
||||||
|
toUniqueId(nation, gunList.root.ids[vehicle['#text']]),
|
||||||
|
vehicle.cost,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'turret': {
|
||||||
|
turretXps.set(
|
||||||
|
toUniqueId(nation, turretList.root.ids[vehicle['#text']]),
|
||||||
|
vehicle.cost,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'engine': {
|
||||||
|
engineXps.set(
|
||||||
|
toUniqueId(nation, enginesList.root.ids[vehicle['#text']]),
|
||||||
|
vehicle.cost,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'chassis': {
|
||||||
|
trackXps.set(
|
||||||
|
toUniqueId(nation, chassisList.root.ids[vehicle['#text']]),
|
||||||
|
vehicle.cost,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.values(tankDefinitions[tankId].turrets).forEach((turret) => {
|
||||||
|
turret.xp = turretXps.get(turret.id);
|
||||||
|
|
||||||
|
Object.values(turret.guns).forEach((gun) => {
|
||||||
|
gun.xp = gunXps.get(gun.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.values(tankDefinitions[tankId].engines).forEach((engine) => {
|
||||||
|
engine.xp = engineXps.get(engine.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.values(tankDefinitions[tankId].tracks).forEach((track) => {
|
||||||
|
track.xp = trackXps.get(track.id);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Object.values(tankDefinitions).forEach((tank) => {
|
||||||
|
tank.xp = tankXps.get(tank.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.values(tankDefinitions).forEach((tank) => {
|
||||||
|
tank.successors?.forEach((predecessorId) => {
|
||||||
|
if (tankDefinitions[predecessorId].ancestors === undefined) {
|
||||||
|
tankDefinitions[predecessorId].ancestors = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tankDefinitions[predecessorId].ancestors?.includes(tank.id)) {
|
||||||
|
tankDefinitions[predecessorId].ancestors?.push(tank.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
Object.entries(optionalDevices.root).forEach(
|
Object.entries(optionalDevices.root).forEach(
|
||||||
([optionalDeviceKey, optionalDeviceEntry]) => {
|
([optionalDeviceKey, optionalDeviceEntry]) => {
|
||||||
if (optionalDeviceKey === 'nextAvailableId') return;
|
if (optionalDeviceKey === 'nextAvailableId') return;
|
||||||
@@ -983,6 +1084,10 @@ export async function definitions(production: boolean) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
writeFile(
|
||||||
|
'test.tanks.cdon.lz4',
|
||||||
|
Buffer.from(superCompress(tankDefinitions), 'base64'),
|
||||||
|
);
|
||||||
await commitAssets(
|
await commitAssets(
|
||||||
'definitions',
|
'definitions',
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { boosterIcons } from './boosterIcons';
|
|||||||
import { camouflageIcons } from './camouflageIcons';
|
import { camouflageIcons } from './camouflageIcons';
|
||||||
import { circleFlags } from './circleFlags';
|
import { circleFlags } from './circleFlags';
|
||||||
import { consumableProvisionIcons } from './consumableProvisionIcons';
|
import { consumableProvisionIcons } from './consumableProvisionIcons';
|
||||||
|
import { currencies } from './currencies';
|
||||||
import { definitions } from './definitions';
|
import { definitions } from './definitions';
|
||||||
import { equipmentIcons } from './equipmentIcons';
|
import { equipmentIcons } from './equipmentIcons';
|
||||||
import { moduleIcons } from './moduleIcons';
|
import { moduleIcons } from './moduleIcons';
|
||||||
@@ -38,6 +39,7 @@ const methods = [
|
|||||||
boosterIcons,
|
boosterIcons,
|
||||||
tankArmors,
|
tankArmors,
|
||||||
tankModels,
|
tankModels,
|
||||||
|
currencies,
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const method of methods) {
|
for (const method of methods) {
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
import { NodeIO } from '@gltf-transform/core';
|
import { NodeIO } from '@gltf-transform/core';
|
||||||
import { readdir } from 'fs/promises';
|
import { readdir } from 'fs/promises';
|
||||||
import { Vector3Tuple } from 'three';
|
|
||||||
import { extractModel } from '../../src/core/blitz/extractModel';
|
import { extractModel } from '../../src/core/blitz/extractModel';
|
||||||
import { readXMLDVPL } from '../../src/core/blitz/readXMLDVPL';
|
import { readXMLDVPL } from '../../src/core/blitz/readXMLDVPL';
|
||||||
import { readYAMLDVPL } from '../../src/core/blitz/readYAMLDVPL';
|
import { readYAMLDVPL } from '../../src/core/blitz/readYAMLDVPL';
|
||||||
import { toUniqueId } from '../../src/core/blitz/toUniqueId';
|
import { toUniqueId } from '../../src/core/blitz/toUniqueId';
|
||||||
// import { AssetCommit } from '../../src/core/github/assetCommit';
|
|
||||||
import { commitAssets } from '../../src/core/blitzkrieg/commitAssets';
|
import { commitAssets } from '../../src/core/blitzkrieg/commitAssets';
|
||||||
import { FileChange } from '../../src/core/blitzkrieg/commitMultipleFiles';
|
import { FileChange } from '../../src/core/blitzkrieg/commitMultipleFiles';
|
||||||
import { DATA, POI } from './constants';
|
import { DATA, POI } from './constants';
|
||||||
import { VehicleDefinitionList } from './definitions';
|
import { VehicleDefinitionList } from './definitions';
|
||||||
import { TankParameters } from './tankIcons';
|
import { TankParameters } from './tankIcons';
|
||||||
|
|
||||||
interface VehicleCustomization {
|
|
||||||
armorColor: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function tankModels(production: boolean) {
|
export async function tankModels(production: boolean) {
|
||||||
console.log('Building tank models...');
|
console.log('Building tank models...');
|
||||||
|
|
||||||
@@ -27,18 +21,9 @@ export async function tankModels(production: boolean) {
|
|||||||
for (const nationIndex in nations) {
|
for (const nationIndex in nations) {
|
||||||
const nation = nations[nationIndex];
|
const nation = nations[nationIndex];
|
||||||
const changes: FileChange[] = [];
|
const changes: FileChange[] = [];
|
||||||
// const assetCommit = new AssetCommit(`tank models ${nation}`, production);
|
|
||||||
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
|
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
|
||||||
`${DATA}/${POI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
|
`${DATA}/${POI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
|
||||||
);
|
);
|
||||||
const customization = await readXMLDVPL<{ root: VehicleCustomization }>(
|
|
||||||
`${DATA}/${POI.vehicleDefinitions}/${nation}/customization.xml.dvpl`,
|
|
||||||
);
|
|
||||||
const baseColor = customization.root.armorColor
|
|
||||||
.split(' ')
|
|
||||||
.slice(0, 3)
|
|
||||||
.map(Number)
|
|
||||||
.map((channel) => channel / 255) as Vector3Tuple;
|
|
||||||
|
|
||||||
console.log(`Building models for ${nation}`);
|
console.log(`Building models for ${nation}`);
|
||||||
|
|
||||||
@@ -56,11 +41,8 @@ export async function tankModels(production: boolean) {
|
|||||||
const model = await extractModel(
|
const model = await extractModel(
|
||||||
DATA,
|
DATA,
|
||||||
parameters.resourcesPath.blitzModelPath.replace(/\.sc2$/, ''),
|
parameters.resourcesPath.blitzModelPath.replace(/\.sc2$/, ''),
|
||||||
baseColor,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// writeFile(`test.${tankKey}.glb`, await nodeIO.writeBinary(model));
|
|
||||||
|
|
||||||
changes.push({
|
changes.push({
|
||||||
path: `3d/tanks/models/${id}.glb`,
|
path: `3d/tanks/models/${id}.glb`,
|
||||||
content: Buffer.from(await nodeIO.writeBinary(model)).toString(
|
content: Buffer.from(await nodeIO.writeBinary(model)).toString(
|
||||||
@@ -71,7 +53,6 @@ export async function tankModels(production: boolean) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
// assetCommit.push();
|
|
||||||
await commitAssets(`tank models ${nation}`, changes, production);
|
await commitAssets(`tank models ${nation}`, changes, production);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,199 @@
|
|||||||
|
import { chunk } from 'lodash';
|
||||||
|
import { argv } from 'process';
|
||||||
|
import {
|
||||||
|
RatingInfo,
|
||||||
|
RatingNeighbors,
|
||||||
|
RatingPlayer,
|
||||||
|
} from '../src/commands/ratingLeaderboard';
|
||||||
|
import { RegionSubdomain } from '../src/constants/regions';
|
||||||
|
import { getAccountInfo } from '../src/core/blitz/getAccountInfo';
|
||||||
|
import regionSubdomainToRegion from '../src/core/blitz/regionSubdomainToRegion';
|
||||||
|
import { commitAssets } from '../src/core/blitzkrieg/commitAssets';
|
||||||
|
import { FileChange } from '../src/core/blitzkrieg/commitMultipleFiles.js';
|
||||||
|
import { patientFetchJSON } from '../src/core/blitzkrieg/patientFetchJSON';
|
||||||
|
import { superCompress } from '../src/core/blitzkrieg/superCompress';
|
||||||
|
import {
|
||||||
|
BkrlBaseEntry,
|
||||||
|
BkrlFormat,
|
||||||
|
BkrlSuperset1Entry,
|
||||||
|
BkrlWriteStream,
|
||||||
|
} from '../src/core/streams/bkrl';
|
||||||
|
import { CdonValue, CdonWriteStream } from '../src/core/streams/cdon';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Central North American Time (UTC-5): use 0 5 * * *.
|
||||||
|
* Central European Time (UTC+1): use 0 23 * * *.
|
||||||
|
* Central Asia Standard Time (UTC+7): use 0 17 * * *.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const production = argv.includes('--production');
|
||||||
|
const target = argv
|
||||||
|
.find((arg) => arg.startsWith('--target='))
|
||||||
|
?.split('=')[1] as 'midnight' | 'latest' | undefined;
|
||||||
|
const regionSubdomains = argv
|
||||||
|
.find((arg) => arg.startsWith('--region='))
|
||||||
|
?.split('=')[1];
|
||||||
|
|
||||||
|
if (!target) throw new Error('Target parameter not specified');
|
||||||
|
if (!regionSubdomains) throw new Error('Region parameter not specified');
|
||||||
|
|
||||||
|
regionSubdomains.split(',').forEach(async (regionSubdomain) => {
|
||||||
|
const region = regionSubdomainToRegion(regionSubdomain as RegionSubdomain);
|
||||||
|
|
||||||
|
console.log(`Building ${target} rating leaderboard for ${region}`);
|
||||||
|
|
||||||
|
const NEIGHBORS = 2 ** 8;
|
||||||
|
const PLAYERS = await patientFetchJSON<RatingInfo>(
|
||||||
|
`https://${regionSubdomain}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
||||||
|
).then((data) => (data.detail === undefined ? data.count : undefined));
|
||||||
|
|
||||||
|
if (PLAYERS === undefined) {
|
||||||
|
throw new Error('No current rating season running');
|
||||||
|
}
|
||||||
|
|
||||||
|
const players: Record<number, RatingPlayer> = {};
|
||||||
|
const leaderboard: BkrlBaseEntry[] = [];
|
||||||
|
let registered = 0;
|
||||||
|
|
||||||
|
async function branchFromPlayer(id: number) {
|
||||||
|
const { neighbors } = await patientFetchJSON<RatingNeighbors>(
|
||||||
|
`https://${regionSubdomain}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${NEIGHBORS}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const firstPlayer = neighbors[0];
|
||||||
|
const lastPlayer = neighbors[neighbors.length - 1];
|
||||||
|
|
||||||
|
const branches: Promise<void>[] = [];
|
||||||
|
if (!players[firstPlayer.number])
|
||||||
|
branches.push(branchFromPlayer(firstPlayer.spa_id));
|
||||||
|
if (!players[lastPlayer.number])
|
||||||
|
branches.push(branchFromPlayer(lastPlayer.spa_id));
|
||||||
|
|
||||||
|
neighbors.forEach((neighbor) => {
|
||||||
|
if (players[neighbor.number]) return;
|
||||||
|
|
||||||
|
players[neighbor.number] = neighbor;
|
||||||
|
registered++;
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Registered ${registered} / ${PLAYERS} (${(
|
||||||
|
(registered / PLAYERS!) *
|
||||||
|
100
|
||||||
|
).toFixed(2)}%)`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await Promise.all(branches);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function branchFromLeague(id: number) {
|
||||||
|
const { result } = await patientFetchJSON<{ result: RatingPlayer[] }>(
|
||||||
|
`https://${regionSubdomain}.wotblitz.com/en/api/rating-leaderboards/league/${id}/top/`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const firstPlayer = result[0];
|
||||||
|
const lastPlayer = result.at(-1)!;
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
branchFromPlayer(firstPlayer.spa_id),
|
||||||
|
branchFromPlayer(lastPlayer.spa_id),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Branching from leagues...');
|
||||||
|
await Promise.all([
|
||||||
|
branchFromLeague(0),
|
||||||
|
branchFromLeague(1),
|
||||||
|
branchFromLeague(2),
|
||||||
|
branchFromLeague(3),
|
||||||
|
branchFromLeague(4),
|
||||||
|
]);
|
||||||
|
|
||||||
|
console.log('Converting to an array...');
|
||||||
|
for (let index = 0; index < PLAYERS; index++) {
|
||||||
|
const listing = players[index + 1];
|
||||||
|
if (listing) {
|
||||||
|
leaderboard[index] = { id: listing.spa_id, score: listing.score };
|
||||||
|
} else {
|
||||||
|
console.warn(`Position ${index + 1} had no player`);
|
||||||
|
leaderboard[index] = { id: 0, score: 0 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Requesting further stats...');
|
||||||
|
const comprehensiveLeaderboard: BkrlSuperset1Entry[] = [];
|
||||||
|
let chunkIndex = 0;
|
||||||
|
for (const leaderboardChunk of chunk(leaderboard, 100)) {
|
||||||
|
console.log(
|
||||||
|
`Chunk ${chunkIndex + 1} of ${Math.ceil(leaderboard.length / 100)}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const stats = await getAccountInfo(
|
||||||
|
region,
|
||||||
|
leaderboardChunk.map(({ id }) => id),
|
||||||
|
['statistics.rating'],
|
||||||
|
);
|
||||||
|
|
||||||
|
stats.forEach((stat, index) => {
|
||||||
|
const trueIndex = chunkIndex * 100 + index;
|
||||||
|
comprehensiveLeaderboard[trueIndex] =
|
||||||
|
leaderboardChunk[index].id === 0 ||
|
||||||
|
stat?.statistics.rating === undefined
|
||||||
|
? {
|
||||||
|
battles: 0,
|
||||||
|
damage: 0,
|
||||||
|
id: 0,
|
||||||
|
kills: 0,
|
||||||
|
score: 0,
|
||||||
|
survived: 0,
|
||||||
|
wins: 0,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
id: leaderboardChunk[index].id,
|
||||||
|
score: leaderboardChunk[index].score,
|
||||||
|
battles: stat.statistics.rating.battles,
|
||||||
|
damage: stat.statistics.rating.damage_dealt,
|
||||||
|
kills: stat.statistics.rating.frags,
|
||||||
|
survived: stat.statistics.rating.survived_battles,
|
||||||
|
wins: stat.statistics.rating.wins,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
chunkIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
const info = await patientFetchJSON<RatingInfo & { detail: undefined }>(
|
||||||
|
`https://${regionSubdomain}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
||||||
|
);
|
||||||
|
const normalizedServer = regionSubdomain === 'na' ? 'com' : regionSubdomain;
|
||||||
|
const infoContent = new CdonWriteStream().cdon(
|
||||||
|
info as unknown as CdonValue,
|
||||||
|
).uint8Array;
|
||||||
|
const leaderboardWriteStream = new BkrlWriteStream();
|
||||||
|
|
||||||
|
leaderboardWriteStream.bkrl({
|
||||||
|
format: BkrlFormat.Superset1,
|
||||||
|
entries: comprehensiveLeaderboard,
|
||||||
|
});
|
||||||
|
|
||||||
|
const changes: FileChange[] = [
|
||||||
|
{
|
||||||
|
path: `regions/${normalizedServer}/rating/${info.current_season}/info.cdon.lz4`,
|
||||||
|
content: superCompress(infoContent),
|
||||||
|
encoding: 'base64',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: `regions/${normalizedServer}/rating/${info.current_season}/${target}.bkrl`,
|
||||||
|
content: Buffer.from(leaderboardWriteStream.uint8Array).toString(
|
||||||
|
'base64',
|
||||||
|
),
|
||||||
|
encoding: 'base64',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
commitAssets(
|
||||||
|
`rating leaderboard ${regionSubdomain} ${target}`,
|
||||||
|
changes,
|
||||||
|
production,
|
||||||
|
);
|
||||||
|
});
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
import { rm, writeFile } from 'fs/promises';
|
|
||||||
import { argv } from 'process';
|
|
||||||
import {
|
|
||||||
RatingsInfo,
|
|
||||||
RatingsNeighbors,
|
|
||||||
RatingsPlayer,
|
|
||||||
} from '../src/commands/ratings';
|
|
||||||
import commitMultipleFiles from '../src/core/blitzkrieg/commitMultipleFiles.js';
|
|
||||||
import { patientFetchJSON } from '../src/core/blitzkrieg/patientFetchJSON';
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Central North American Time (UTC-5): use 0 5 * * *.
|
|
||||||
* Central European Time (UTC+1): use 0 23 * * *.
|
|
||||||
* Central Asia Standard Time (UTC+7): use 0 17 * * *.
|
|
||||||
*
|
|
||||||
* [region]/ratings/[season]/info.json: season info like rewards, start & end time, etc.
|
|
||||||
* [region]/ratings/[season]/latest.json: the absolute latest leaderboard recorded at UTC+0 midnight
|
|
||||||
* [region]/ratings/[season]/midnight.json: last midnight's leaderboard relative to the region
|
|
||||||
*/
|
|
||||||
|
|
||||||
export type BlitzkriegRatingsLeaderboardEntry = { id: number; score: number };
|
|
||||||
export type BlitzkriegRatingsLeaderboard = BlitzkriegRatingsLeaderboardEntry[];
|
|
||||||
|
|
||||||
const publish = argv.includes('--publish');
|
|
||||||
const target = argv
|
|
||||||
.find((arg) => arg.startsWith('--target='))
|
|
||||||
?.split('=')[1] as 'midnight' | 'latest' | undefined;
|
|
||||||
const server = argv.find((arg) => arg.startsWith('--region='))?.split('=')[1];
|
|
||||||
|
|
||||||
if (!target) throw new Error('Target parameter not specified');
|
|
||||||
if (!server) throw new Error('Region parameter not specified');
|
|
||||||
|
|
||||||
const NEIGHBORS = 2 ** 8;
|
|
||||||
const PLAYERS = await patientFetchJSON<RatingsInfo>(
|
|
||||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
|
||||||
).then((data) => (data.detail === undefined ? data.count : undefined));
|
|
||||||
|
|
||||||
if (PLAYERS === undefined) {
|
|
||||||
throw new Error('No current ratings season running');
|
|
||||||
}
|
|
||||||
|
|
||||||
const players: Record<number, RatingsPlayer> = {};
|
|
||||||
const leaderboard: BlitzkriegRatingsLeaderboard = [];
|
|
||||||
let registered = 0;
|
|
||||||
|
|
||||||
async function branchFromPlayer(id: number) {
|
|
||||||
const { neighbors } = await patientFetchJSON<RatingsNeighbors>(
|
|
||||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${NEIGHBORS}`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const firstPlayer = neighbors[0];
|
|
||||||
const lastPlayer = neighbors[neighbors.length - 1];
|
|
||||||
|
|
||||||
const branches: Promise<void>[] = [];
|
|
||||||
if (!players[firstPlayer.number])
|
|
||||||
branches.push(branchFromPlayer(firstPlayer.spa_id));
|
|
||||||
if (!players[lastPlayer.number])
|
|
||||||
branches.push(branchFromPlayer(lastPlayer.spa_id));
|
|
||||||
|
|
||||||
neighbors.forEach((neighbor) => {
|
|
||||||
if (players[neighbor.number]) return;
|
|
||||||
|
|
||||||
players[neighbor.number] = neighbor;
|
|
||||||
registered++;
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Registered ${registered} / ${PLAYERS} (${(
|
|
||||||
(registered / PLAYERS!) *
|
|
||||||
100
|
|
||||||
).toFixed(2)}%)`,
|
|
||||||
);
|
|
||||||
|
|
||||||
await Promise.all(branches);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function branchFromLeague(id: number) {
|
|
||||||
const { result } = await patientFetchJSON<{ result: RatingsPlayer[] }>(
|
|
||||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/league/${id}/top/`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const firstPlayer = result[0];
|
|
||||||
const lastPlayer = result[result.length - 1];
|
|
||||||
|
|
||||||
await Promise.all([
|
|
||||||
branchFromPlayer(firstPlayer.spa_id),
|
|
||||||
branchFromPlayer(lastPlayer.spa_id),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Branching from leagues...');
|
|
||||||
await Promise.all([
|
|
||||||
branchFromLeague(0),
|
|
||||||
branchFromLeague(1),
|
|
||||||
branchFromLeague(2),
|
|
||||||
branchFromLeague(3),
|
|
||||||
branchFromLeague(4),
|
|
||||||
]);
|
|
||||||
|
|
||||||
console.log('Converting to an array...');
|
|
||||||
for (let index = 0; index < PLAYERS; index++) {
|
|
||||||
const listing = players[index + 1];
|
|
||||||
if (!listing) {
|
|
||||||
console.warn(`Position ${index + 1} had no player`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
leaderboard[index] = {
|
|
||||||
id: listing.spa_id,
|
|
||||||
score: listing.score,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const leaderboardJSON = JSON.stringify(leaderboard);
|
|
||||||
|
|
||||||
if (publish) {
|
|
||||||
const info = await patientFetchJSON<RatingsInfo & { detail: undefined }>(
|
|
||||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
|
||||||
);
|
|
||||||
const normalizedServer = server === 'na' ? 'com' : server;
|
|
||||||
const infoPath = `regions/${normalizedServer}/ratings/${info.current_season}/info.json`;
|
|
||||||
const leaderboardPath = `regions/${normalizedServer}/ratings/${info.current_season}/${target}.json`;
|
|
||||||
const infoJSON = JSON.stringify(info);
|
|
||||||
|
|
||||||
console.log(`Publishing to season ${info.current_season}...`);
|
|
||||||
commitMultipleFiles(
|
|
||||||
'tresabhi',
|
|
||||||
'blitzkrieg-assets',
|
|
||||||
'main',
|
|
||||||
new Date().toString(),
|
|
||||||
[
|
|
||||||
{ path: infoPath, content: infoJSON, encoding: 'utf-8' },
|
|
||||||
{ path: leaderboardPath, content: leaderboardJSON, encoding: 'utf-8' },
|
|
||||||
],
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.log('Writing to disk...');
|
|
||||||
await rm('dist.json', { force: true });
|
|
||||||
await writeFile('dist.json', leaderboardJSON);
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
import { writeFile } from 'fs/promises';
|
|
||||||
import { Region } from '../src/constants/regions';
|
|
||||||
import { getRatingsNeighbors } from '../src/core/blitz/getRatingsNeighbors';
|
|
||||||
|
|
||||||
const REGION: Region = 'com';
|
|
||||||
const PLAYER = 1041988373;
|
|
||||||
const ITERATIONS = 2 ** 4;
|
|
||||||
const MAX_NEIGHBORS = 2 ** 7;
|
|
||||||
const data: [number, number][] = [];
|
|
||||||
let finished = 0;
|
|
||||||
|
|
||||||
for (let index = 0; index < ITERATIONS; index++) {
|
|
||||||
const neighbors = Math.round((Math.random() * MAX_NEIGHBORS) / 2) * 2;
|
|
||||||
const start = Date.now();
|
|
||||||
|
|
||||||
console.log(`🟡 Iteration ${index} with ${neighbors} neighbors`);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await getRatingsNeighbors(REGION, PLAYER, neighbors);
|
|
||||||
|
|
||||||
finished++;
|
|
||||||
console.log(
|
|
||||||
`🟢 (${Math.round(
|
|
||||||
100 * (finished / ITERATIONS),
|
|
||||||
)}%) Iteration ${index} with ${neighbors} neighbors`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const end = Date.now();
|
|
||||||
const time = end - start;
|
|
||||||
|
|
||||||
data.push([neighbors, time]);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(
|
|
||||||
`🔴 Iteration ${index} with ${neighbors} neighbors\n\n${error}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('🟢 Done, sorting');
|
|
||||||
data.sort(([neighborsA], [neighborsB]) => neighborsA - neighborsB);
|
|
||||||
|
|
||||||
console.log('🟢 Writing');
|
|
||||||
writeFile(
|
|
||||||
'dist/ratingsPlot.csv',
|
|
||||||
data.map(([neighbors, time]) => `${neighbors},${time}`).join('\n'),
|
|
||||||
);
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ESNext",
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "Node",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"jsx": "preserve",
|
||||||
|
"lib": ["dom", "dom.iterable", "esnext"],
|
||||||
|
"allowJs": true,
|
||||||
|
"incremental": true,
|
||||||
|
"isolatedModules": true
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-2
@@ -1,10 +1,10 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { Region } from '../../../../../../constants/regions';
|
import { Region } from '../../../../../../constants/regions';
|
||||||
import getRatingsInfo from '../../../../../../core/blitz/getRatingsInfo';
|
import getRatingInfo from '../../../../../../core/blitz/getRatingInfo';
|
||||||
|
|
||||||
export async function GET(
|
export async function GET(
|
||||||
request: Request,
|
request: Request,
|
||||||
{ params }: { params: { region: Region } },
|
{ params }: { params: { region: Region } },
|
||||||
) {
|
) {
|
||||||
return NextResponse.json(await getRatingsInfo(params.region));
|
return NextResponse.json(await getRatingInfo(params.region));
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { Region } from '../../../../../../../constants/regions';
|
import { Region } from '../../../../../../../constants/regions';
|
||||||
import { getRatingsLeague } from '../../../../../../../core/blitz/getRatingsLeague';
|
import { getRatingLeague } from '../../../../../../../core/blitz/getRatingLeague';
|
||||||
|
|
||||||
export async function GET(
|
export async function GET(
|
||||||
request: Request,
|
request: Request,
|
||||||
{ params }: { params: { region: Region; league: number } },
|
{ params }: { params: { region: Region; league: number } },
|
||||||
) {
|
) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
await getRatingsLeague(params.region, params.league, true),
|
await getRatingLeague(params.region, params.league, true),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { Region } from '../../../../../../../constants/regions';
|
import { Region } from '../../../../../../../constants/regions';
|
||||||
import { searchCurrentRatingsPlayers } from '../../../../../../../core/blitz/searchCurrentRatingsPlayers';
|
import { searchCurrentRatingPlayers } from '../../../../../../../core/blitz/searchCurrentRatingPlayers';
|
||||||
|
|
||||||
export async function GET(
|
export async function GET(
|
||||||
request: Request,
|
request: Request,
|
||||||
{ params }: { params: { region: Region; username: string } },
|
{ params }: { params: { region: Region; username: string } },
|
||||||
) {
|
) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
await searchCurrentRatingsPlayers(params.region, params.username),
|
await searchCurrentRatingPlayers(params.region, params.username),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ import { useEffect, useState } from 'react';
|
|||||||
import * as Breakdown from '../../../components/Breakdown';
|
import * as Breakdown from '../../../components/Breakdown';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
|
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
|
||||||
import fetchBlitz from '../../../core/blitz/fetchBlitz';
|
import fetchBlitz from '../../../core/blitz/fetchBlitz';
|
||||||
|
import { resetSession } from '../../../core/blitzkrieg/resetSession';
|
||||||
import {
|
import {
|
||||||
TankDefinition,
|
TankDefinition,
|
||||||
tankDefinitions,
|
tankDefinitions,
|
||||||
@@ -13,10 +14,7 @@ import { tankAverages } from '../../../core/blitzstars/tankAverages';
|
|||||||
import calculateWN8 from '../../../core/statistics/calculateWN8';
|
import calculateWN8 from '../../../core/statistics/calculateWN8';
|
||||||
import { deltaTankStats } from '../../../core/statistics/deltaTankStats';
|
import { deltaTankStats } from '../../../core/statistics/deltaTankStats';
|
||||||
import getWN8Percentile from '../../../core/statistics/getWN8Percentile';
|
import getWN8Percentile from '../../../core/statistics/getWN8Percentile';
|
||||||
import mutateSession, {
|
import mutateSession, { useSession } from '../../../stores/session';
|
||||||
resetSession,
|
|
||||||
useSession,
|
|
||||||
} from '../../../stores/session';
|
|
||||||
import { IndividualTankStats, TanksStats } from '../../../types/tanksStats';
|
import { IndividualTankStats, TanksStats } from '../../../types/tanksStats';
|
||||||
import { CustomColumnDisplay } from '../../tools/session/components/CustomColumn';
|
import { CustomColumnDisplay } from '../../tools/session/components/CustomColumn';
|
||||||
import { Menu } from '../../tools/session/components/Menu';
|
import { Menu } from '../../tools/session/components/Menu';
|
||||||
@@ -311,7 +309,7 @@ export default function SessionPage({ naked = true }: SessionPageProps) {
|
|||||||
tankDefinitions?.name ?? `Unknown tank ${stats.tank_id}`
|
tankDefinitions?.name ?? `Unknown tank ${stats.tank_id}`
|
||||||
}
|
}
|
||||||
type="tank"
|
type="tank"
|
||||||
tankType={tankDefinitions?.type}
|
tankType={tankDefinitions?.class}
|
||||||
treeType={tankDefinitions?.treeType}
|
treeType={tankDefinitions?.treeType}
|
||||||
stats={session.customColumns.map((customColumn) => {
|
stats={session.customColumns.map((customColumn) => {
|
||||||
const rowStat = rowStats[customColumn.display];
|
const rowStat = rowStats[customColumn.display];
|
||||||
|
|||||||
+51
-49
@@ -3,12 +3,12 @@
|
|||||||
import { CaretRightIcon } from '@radix-ui/react-icons';
|
import { CaretRightIcon } from '@radix-ui/react-icons';
|
||||||
import { AlertDialog, Button, Flex, Text, Theme } from '@radix-ui/themes';
|
import { AlertDialog, Button, Flex, Text, Theme } from '@radix-ui/themes';
|
||||||
import '@radix-ui/themes/styles.css';
|
import '@radix-ui/themes/styles.css';
|
||||||
import { Analytics } from '@vercel/analytics/react';
|
|
||||||
import { config } from 'dotenv';
|
import { config } from 'dotenv';
|
||||||
import { Roboto_Flex } from 'next/font/google';
|
import { Roboto_Flex } from 'next/font/google';
|
||||||
import { usePathname } from 'next/navigation';
|
import { usePathname } from 'next/navigation';
|
||||||
import { ReactNode, useEffect, useState } from 'react';
|
import { ReactNode, useEffect, useState } from 'react';
|
||||||
import { SkyLine } from '../assets/art/SkyLine';
|
import { SkyLine } from '../assets/art/SkyLine';
|
||||||
|
import { Analytics } from '../components/Analytics';
|
||||||
import Navbar from '../components/Navbar';
|
import Navbar from '../components/Navbar';
|
||||||
import PageWrapper from '../components/PageWrapper';
|
import PageWrapper from '../components/PageWrapper';
|
||||||
import isDev from '../core/blitzkrieg/isDev';
|
import isDev from '../core/blitzkrieg/isDev';
|
||||||
@@ -51,16 +51,16 @@ export default function RootLayout({ children }: RootLayoutProps) {
|
|||||||
name="description"
|
name="description"
|
||||||
content="🎉 Tools for everything World of Tanks Blitz"
|
content="🎉 Tools for everything World of Tanks Blitz"
|
||||||
/>
|
/>
|
||||||
|
<Analytics />
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body
|
<body
|
||||||
style={{
|
style={{
|
||||||
margin: 0,
|
margin: 0,
|
||||||
paddingTop: isEmbed ? 0 : '3.25rem',
|
paddingTop: isEmbed ? 0 : '3.25rem',
|
||||||
|
backgroundColor: isEmbed ? 'transparent' : undefined,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Analytics />
|
|
||||||
|
|
||||||
<Theme
|
<Theme
|
||||||
appearance="dark"
|
appearance="dark"
|
||||||
panelBackground="translucent"
|
panelBackground="translucent"
|
||||||
@@ -100,59 +100,61 @@ export default function RootLayout({ children }: RootLayoutProps) {
|
|||||||
|
|
||||||
<Flex direction="column">{children}</Flex>
|
<Flex direction="column">{children}</Flex>
|
||||||
|
|
||||||
<PageWrapper>
|
{!isEmbed && (
|
||||||
<a
|
<PageWrapper>
|
||||||
target="_blank"
|
<a
|
||||||
href="https://ko-fi.com/tresabhi"
|
target="_blank"
|
||||||
style={{ textDecoration: 'none' }}
|
href="https://ko-fi.com/tresabhi"
|
||||||
>
|
style={{ textDecoration: 'none' }}
|
||||||
<Flex
|
|
||||||
align="center"
|
|
||||||
style={{
|
|
||||||
padding: 16,
|
|
||||||
borderRadius: 8,
|
|
||||||
backgroundColor: mintTheme.colors.componentInteractive,
|
|
||||||
position: 'relative',
|
|
||||||
overflow: 'hidden',
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Flex
|
<Flex
|
||||||
direction="column"
|
align="center"
|
||||||
gap="1"
|
|
||||||
style={{
|
style={{
|
||||||
flex: 1,
|
padding: 16,
|
||||||
zIndex: 1,
|
borderRadius: 8,
|
||||||
|
backgroundColor: mintTheme.colors.componentInteractive,
|
||||||
|
position: 'relative',
|
||||||
|
overflow: 'hidden',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Text size="4" color="mint">
|
<Flex
|
||||||
Blitzkrieg. Free forever. For everyone.
|
direction="column"
|
||||||
</Text>
|
gap="1"
|
||||||
<Text color="mint">
|
style={{
|
||||||
<b>Consider supporting today 🍀</b>
|
flex: 1,
|
||||||
</Text>
|
zIndex: 1,
|
||||||
</Flex>
|
}}
|
||||||
|
>
|
||||||
<Text
|
<Text size="4" color="mint">
|
||||||
color="mint"
|
Blitzkrieg. Free forever. For everyone.
|
||||||
style={{
|
</Text>
|
||||||
zIndex: 1,
|
<Text color="mint">
|
||||||
}}
|
<b>Consider supporting today 🍀</b>
|
||||||
>
|
</Text>
|
||||||
<Flex>
|
|
||||||
<CaretRightIcon width={32} height={32} />
|
|
||||||
</Flex>
|
</Flex>
|
||||||
</Text>
|
|
||||||
|
|
||||||
<SkyLine
|
<Text
|
||||||
style={{
|
color="mint"
|
||||||
position: 'absolute',
|
style={{
|
||||||
right: 'min(8vw, 15%)',
|
zIndex: 1,
|
||||||
top: '5%',
|
}}
|
||||||
}}
|
>
|
||||||
/>
|
<Flex>
|
||||||
</Flex>
|
<CaretRightIcon width={32} height={32} />
|
||||||
</a>
|
</Flex>
|
||||||
</PageWrapper>
|
</Text>
|
||||||
|
|
||||||
|
<SkyLine
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
right: 'min(8vw, 15%)',
|
||||||
|
top: '5%',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Flex>
|
||||||
|
</a>
|
||||||
|
</PageWrapper>
|
||||||
|
)}
|
||||||
</Theme>
|
</Theme>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
File renamed without changes.
File renamed without changes.
@@ -15,26 +15,30 @@ import { produce } from 'immer';
|
|||||||
import { debounce, range } from 'lodash';
|
import { debounce, range } from 'lodash';
|
||||||
import { ChangeEvent, useEffect, useRef, useState } from 'react';
|
import { ChangeEvent, useEffect, useRef, useState } from 'react';
|
||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
import { RatingsInfo, RatingsPlayer } from '../../../commands/ratings';
|
import { RatingInfo, RatingPlayer } from '../../../commands/ratingLeaderboard';
|
||||||
import PageWrapper from '../../../components/PageWrapper';
|
import PageWrapper from '../../../components/PageWrapper';
|
||||||
import { Skeleton } from '../../../components/Skeleton';
|
import { Skeleton } from '../../../components/Skeleton';
|
||||||
import { LEAGUES } from '../../../constants/leagues';
|
import { LEAGUES } from '../../../constants/leagues';
|
||||||
import { FIRST_ARCHIVED_RATINGS_SEASON } from '../../../constants/ratings';
|
import { FIRST_MINIMAL_ARCHIVED_RATING_SEASON } from '../../../constants/rating';
|
||||||
import { REGIONS, REGION_NAMES, Region } from '../../../constants/regions';
|
import {
|
||||||
|
REGIONS,
|
||||||
|
Region,
|
||||||
|
UNLOCALIZED_REGION_NAMES,
|
||||||
|
} from '../../../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
|
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
|
||||||
import fetchBlitz from '../../../core/blitz/fetchBlitz';
|
import fetchBlitz from '../../../core/blitz/fetchBlitz';
|
||||||
import { getClanAccountInfo } from '../../../core/blitz/getClanAccountInfo';
|
import { getClanAccountInfo } from '../../../core/blitz/getClanAccountInfo';
|
||||||
import getRatingsInfo from '../../../core/blitz/getRatingsInfo';
|
import getRatingInfo from '../../../core/blitz/getRatingInfo';
|
||||||
import { getRatingsLeague } from '../../../core/blitz/getRatingsLeague';
|
import { getRatingLeague } from '../../../core/blitz/getRatingLeague';
|
||||||
import { getRatingsNeighbors } from '../../../core/blitz/getRatingsNeighbors';
|
import { getRatingNeighbors } from '../../../core/blitz/getRatingNeighbors';
|
||||||
import { searchCurrentRatingsPlayers } from '../../../core/blitz/searchCurrentRatingsPlayers';
|
import { searchCurrentRatingPlayers } from '../../../core/blitz/searchCurrentRatingPlayers';
|
||||||
import {
|
import {
|
||||||
AccountList,
|
AccountList,
|
||||||
AccountListItem,
|
AccountListItem,
|
||||||
} from '../../../core/blitz/searchPlayersAcrossRegions';
|
} from '../../../core/blitz/searchPlayersAcrossRegions';
|
||||||
import { getArchivedLatestSeasonNumber } from '../../../core/blitzkrieg/getArchivedLatestSeasonNumber';
|
import { getArchivedLatestSeasonNumber } from '../../../core/blitzkrieg/getArchivedLatestSeasonNumber';
|
||||||
import getArchivedRatingsInfo from '../../../core/blitzkrieg/getArchivedRatingsInfo';
|
import getArchivedRatingInfo from '../../../core/blitzkrieg/getArchivedRatingInfo';
|
||||||
import { getArchivedRatingsLeaderboard } from '../../../core/blitzkrieg/getArchivedRatingsLeaderboard';
|
import { getArchivedRatingLeaderboard } from '../../../core/blitzkrieg/getArchivedRatingLeaderboard';
|
||||||
import { theme } from '../../../stitches.config';
|
import { theme } from '../../../stitches.config';
|
||||||
import { PageTurner } from './components/PageTurner';
|
import { PageTurner } from './components/PageTurner';
|
||||||
|
|
||||||
@@ -47,7 +51,7 @@ interface NameCacheEntry {
|
|||||||
}
|
}
|
||||||
type NameCache = Record<Region, Record<number, NameCacheEntry | null>>;
|
type NameCache = Record<Region, Record<number, NameCacheEntry | null>>;
|
||||||
type LeaderboardCache = Record<Region, Record<number, Record<number, number>>>;
|
type LeaderboardCache = Record<Region, Record<number, Record<number, number>>>;
|
||||||
type InfoCache = Record<Region, Record<number, RatingsInfo | undefined>>;
|
type InfoCache = Record<Region, Record<number, RatingInfo | undefined>>;
|
||||||
type ScoreCache = Record<Region, Record<number, Record<number, number>>>;
|
type ScoreCache = Record<Region, Record<number, Record<number, number>>>;
|
||||||
|
|
||||||
const useNameCache = create<NameCache>(() => ({
|
const useNameCache = create<NameCache>(() => ({
|
||||||
@@ -89,7 +93,7 @@ export default function Page() {
|
|||||||
{ type: 'id'; id: number } | { type: 'position'; position: number } | null
|
{ type: 'id'; id: number } | { type: 'position'; position: number } | null
|
||||||
>(null);
|
>(null);
|
||||||
|
|
||||||
const ratingsInfo = useInfoCache()[region][season];
|
const ratingInfo = useInfoCache()[region][season];
|
||||||
const [latestArchivedSeasonNumber, setLatestArchivedSeasonNumber] = useState<
|
const [latestArchivedSeasonNumber, setLatestArchivedSeasonNumber] = useState<
|
||||||
number | null
|
number | null
|
||||||
>(null);
|
>(null);
|
||||||
@@ -107,7 +111,7 @@ export default function Page() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const pages = Math.ceil(
|
const pages = Math.ceil(
|
||||||
(ratingsInfo && ratingsInfo.detail === undefined ? ratingsInfo?.count : 1) /
|
(ratingInfo && ratingInfo.detail === undefined ? ratingInfo?.count : 1) /
|
||||||
ROWS_PER_PAGE,
|
ROWS_PER_PAGE,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -118,8 +122,8 @@ export default function Page() {
|
|||||||
(async () => {
|
(async () => {
|
||||||
const newInfo =
|
const newInfo =
|
||||||
season === 0
|
season === 0
|
||||||
? await getRatingsInfo(region)
|
? await getRatingInfo(region)
|
||||||
: await getArchivedRatingsInfo(region, season);
|
: await getArchivedRatingInfo(region, season);
|
||||||
useInfoCache.setState(
|
useInfoCache.setState(
|
||||||
produce((draft: InfoCache) => {
|
produce((draft: InfoCache) => {
|
||||||
draft[region][season] = newInfo;
|
draft[region][season] = newInfo;
|
||||||
@@ -136,7 +140,7 @@ export default function Page() {
|
|||||||
const results = (
|
const results = (
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
range(0, 5).map(async (league: number) => {
|
range(0, 5).map(async (league: number) => {
|
||||||
const data = await getRatingsLeague(region, league);
|
const data = await getRatingLeague(region, league);
|
||||||
leaguePositionCache.current[region][league] = data[0].number - 1;
|
leaguePositionCache.current[region][league] = data[0].number - 1;
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@@ -174,12 +178,12 @@ export default function Page() {
|
|||||||
);
|
);
|
||||||
})();
|
})();
|
||||||
} else {
|
} else {
|
||||||
getArchivedRatingsLeaderboard(region, season).then((results) => {
|
getArchivedRatingLeaderboard(region, season).then((results) => {
|
||||||
useLeaderboardCache.setState(
|
useLeaderboardCache.setState(
|
||||||
produce((draft: LeaderboardCache) => {
|
produce((draft: LeaderboardCache) => {
|
||||||
if (!(season in draft[region])) draft[region][season] = {};
|
if (!(season in draft[region])) draft[region][season] = {};
|
||||||
|
|
||||||
results.forEach((result, index) => {
|
results.entries.forEach((result, index) => {
|
||||||
draft[region][season][index] = result.id;
|
draft[region][season][index] = result.id;
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
@@ -188,7 +192,7 @@ export default function Page() {
|
|||||||
produce((draft: ScoreCache) => {
|
produce((draft: ScoreCache) => {
|
||||||
if (!(season in draft[region])) draft[region][season] = {};
|
if (!(season in draft[region])) draft[region][season] = {};
|
||||||
|
|
||||||
results.forEach((result) => {
|
results.entries.forEach((result) => {
|
||||||
draft[region][season][result.id] = result.score;
|
draft[region][season][result.id] = result.score;
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
@@ -209,7 +213,7 @@ export default function Page() {
|
|||||||
}, [leaderboard[region]?.[season] && 0 in leaderboard[region][season]]);
|
}, [leaderboard[region]?.[season] && 0 in leaderboard[region][season]]);
|
||||||
// neighboring page caching for all seasons
|
// neighboring page caching for all seasons
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ratingsInfo || ratingsInfo?.detail) return;
|
if (!ratingInfo || ratingInfo?.detail) return;
|
||||||
|
|
||||||
if (season === 0) {
|
if (season === 0) {
|
||||||
const middleIndex = page * ROWS_PER_PAGE + ROWS_PER_PAGE / 2;
|
const middleIndex = page * ROWS_PER_PAGE + ROWS_PER_PAGE / 2;
|
||||||
@@ -232,7 +236,7 @@ export default function Page() {
|
|||||||
const ids = range(
|
const ids = range(
|
||||||
Math.max(0, (page - 1) * ROWS_PER_PAGE),
|
Math.max(0, (page - 1) * ROWS_PER_PAGE),
|
||||||
Math.min(
|
Math.min(
|
||||||
ratingsInfo.count - 1,
|
ratingInfo.count - 1,
|
||||||
(page + 1) * ROWS_PER_PAGE + ROWS_PER_PAGE,
|
(page + 1) * ROWS_PER_PAGE + ROWS_PER_PAGE,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -261,7 +265,7 @@ export default function Page() {
|
|||||||
page,
|
page,
|
||||||
region,
|
region,
|
||||||
season,
|
season,
|
||||||
ratingsInfo?.detail,
|
ratingInfo?.detail,
|
||||||
leaderboard[region][season] !== undefined &&
|
leaderboard[region][season] !== undefined &&
|
||||||
0 in leaderboard[region][season],
|
0 in leaderboard[region][season],
|
||||||
]);
|
]);
|
||||||
@@ -275,7 +279,7 @@ export default function Page() {
|
|||||||
async function cacheNeighbors(
|
async function cacheNeighbors(
|
||||||
id: number,
|
id: number,
|
||||||
size: number,
|
size: number,
|
||||||
): Promise<RatingsPlayer[] | null> {
|
): Promise<RatingPlayer[] | null> {
|
||||||
const radius = Math.round(size / 2);
|
const radius = Math.round(size / 2);
|
||||||
const targetPosition = Object.entries(leaderboard[region][season]).find(
|
const targetPosition = Object.entries(leaderboard[region][season]).find(
|
||||||
([, player]) => id === player,
|
([, player]) => id === player,
|
||||||
@@ -299,7 +303,7 @@ export default function Page() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { neighbors } = await getRatingsNeighbors(region, id, size, true);
|
const { neighbors } = await getRatingNeighbors(region, id, size, true);
|
||||||
|
|
||||||
useLeaderboardCache.setState(
|
useLeaderboardCache.setState(
|
||||||
produce((draft: LeaderboardCache) => {
|
produce((draft: LeaderboardCache) => {
|
||||||
@@ -337,11 +341,11 @@ export default function Page() {
|
|||||||
return neighbors;
|
return neighbors;
|
||||||
}
|
}
|
||||||
async function jumpToPosition(position: number) {
|
async function jumpToPosition(position: number) {
|
||||||
if (!ratingsInfo || ratingsInfo?.detail) return;
|
if (!ratingInfo || ratingInfo?.detail) return;
|
||||||
|
|
||||||
const targetPosition = Math.min(
|
const targetPosition = Math.min(
|
||||||
ratingsInfo.count - 1,
|
ratingInfo.count - 1,
|
||||||
Math.max(0, Math.min(position, ratingsInfo.count - 1)),
|
Math.max(0, Math.min(position, ratingInfo.count - 1)),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (season === 0) {
|
if (season === 0) {
|
||||||
@@ -374,7 +378,7 @@ export default function Page() {
|
|||||||
const loadingDirection = Math.sign(targetPosition - closestPosition);
|
const loadingDirection = Math.sign(targetPosition - closestPosition);
|
||||||
let seedingPlayer = closestPlayerId as number;
|
let seedingPlayer = closestPlayerId as number;
|
||||||
let targetPositionAcquired = false;
|
let targetPositionAcquired = false;
|
||||||
let neighbors: RatingsPlayer[] | null;
|
let neighbors: RatingPlayer[] | null;
|
||||||
|
|
||||||
setLoadingProgress([0, closestPositionDistance]);
|
setLoadingProgress([0, closestPositionDistance]);
|
||||||
|
|
||||||
@@ -419,7 +423,7 @@ export default function Page() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function jumpToScore() {
|
async function jumpToScore() {
|
||||||
if (!ratingsInfo || ratingsInfo?.detail) return;
|
if (!ratingInfo || ratingInfo?.detail) return;
|
||||||
|
|
||||||
const targetScore = scoreInput.current!.valueAsNumber;
|
const targetScore = scoreInput.current!.valueAsNumber;
|
||||||
|
|
||||||
@@ -518,7 +522,7 @@ export default function Page() {
|
|||||||
} else {
|
} else {
|
||||||
let playerIndex = -1;
|
let playerIndex = -1;
|
||||||
|
|
||||||
for (let index = ratingsInfo.count; index >= 0; index--) {
|
for (let index = ratingInfo.count; index >= 0; index--) {
|
||||||
if (!(index in leaderboard[region][season])) continue;
|
if (!(index in leaderboard[region][season])) continue;
|
||||||
|
|
||||||
if (scores[leaderboard[region][season][index]] >= targetScore) {
|
if (scores[leaderboard[region][season][index]] >= targetScore) {
|
||||||
@@ -541,7 +545,7 @@ export default function Page() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const totalPlayers =
|
const totalPlayers =
|
||||||
!ratingsInfo?.detail && ratingsInfo?.count ? ratingsInfo.count : undefined;
|
!ratingInfo?.detail && ratingInfo?.count ? ratingInfo.count : undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageWrapper color="orange">
|
<PageWrapper color="orange">
|
||||||
@@ -556,7 +560,7 @@ export default function Page() {
|
|||||||
<Select.Content>
|
<Select.Content>
|
||||||
{REGIONS.map((region) => (
|
{REGIONS.map((region) => (
|
||||||
<Select.Item key={region} value={region}>
|
<Select.Item key={region} value={region}>
|
||||||
{REGION_NAMES[region]}
|
{UNLOCALIZED_REGION_NAMES[region]}
|
||||||
</Select.Item>
|
</Select.Item>
|
||||||
))}
|
))}
|
||||||
</Select.Content>
|
</Select.Content>
|
||||||
@@ -569,7 +573,7 @@ export default function Page() {
|
|||||||
<Select.Trigger style={{ flex: 1 }} />
|
<Select.Trigger style={{ flex: 1 }} />
|
||||||
|
|
||||||
<Select.Content>
|
<Select.Content>
|
||||||
{ratingsInfo?.detail === undefined && (
|
{ratingInfo?.detail === undefined && (
|
||||||
<Select.Item value="0">Current season</Select.Item>
|
<Select.Item value="0">Current season</Select.Item>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -578,7 +582,7 @@ export default function Page() {
|
|||||||
|
|
||||||
{latestArchivedSeasonNumber &&
|
{latestArchivedSeasonNumber &&
|
||||||
range(
|
range(
|
||||||
FIRST_ARCHIVED_RATINGS_SEASON,
|
FIRST_MINIMAL_ARCHIVED_RATING_SEASON,
|
||||||
latestArchivedSeasonNumber + 1,
|
latestArchivedSeasonNumber + 1,
|
||||||
)
|
)
|
||||||
.map((season) => (
|
.map((season) => (
|
||||||
@@ -677,8 +681,8 @@ export default function Page() {
|
|||||||
<Select.Trigger />
|
<Select.Trigger />
|
||||||
|
|
||||||
<Select.Content>
|
<Select.Content>
|
||||||
{ratingsInfo?.detail === undefined &&
|
{ratingInfo?.detail === undefined &&
|
||||||
ratingsInfo?.leagues.map(({ index, title }) => (
|
ratingInfo?.leagues.map(({ index, title }) => (
|
||||||
<Select.Item key={index} value={`${index}`}>
|
<Select.Item key={index} value={`${index}`}>
|
||||||
{title}
|
{title}
|
||||||
</Select.Item>
|
</Select.Item>
|
||||||
@@ -710,11 +714,7 @@ export default function Page() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (
|
if (!ratingInfo || ratingInfo.detail || !leaderboard)
|
||||||
!ratingsInfo ||
|
|
||||||
ratingsInfo.detail ||
|
|
||||||
!leaderboard
|
|
||||||
)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const minScore =
|
const minScore =
|
||||||
@@ -723,7 +723,7 @@ export default function Page() {
|
|||||||
|
|
||||||
for (
|
for (
|
||||||
let index = 0;
|
let index = 0;
|
||||||
index < ratingsInfo.count;
|
index < ratingInfo.count;
|
||||||
index++
|
index++
|
||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
@@ -775,7 +775,7 @@ export default function Page() {
|
|||||||
setSearchLoading(true);
|
setSearchLoading(true);
|
||||||
|
|
||||||
const accountList =
|
const accountList =
|
||||||
await searchCurrentRatingsPlayers(
|
await searchCurrentRatingPlayers(
|
||||||
region,
|
region,
|
||||||
trimmedSearch,
|
trimmedSearch,
|
||||||
);
|
);
|
||||||
@@ -881,12 +881,12 @@ export default function Page() {
|
|||||||
id: player.account_id,
|
id: player.account_id,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (!ratingsInfo || ratingsInfo.detail) return;
|
if (!ratingInfo || ratingInfo.detail) return;
|
||||||
let playerIndex = -1;
|
let playerIndex = -1;
|
||||||
|
|
||||||
for (
|
for (
|
||||||
let index = 0;
|
let index = 0;
|
||||||
index < ratingsInfo.count;
|
index < ratingInfo.count;
|
||||||
index++
|
index++
|
||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
@@ -947,9 +947,7 @@ export default function Page() {
|
|||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
<PageTurner
|
<PageTurner
|
||||||
totalPlayers={
|
totalPlayers={(ratingInfo?.detail ? undefined : ratingInfo?.count) ?? 0}
|
||||||
(ratingsInfo?.detail ? undefined : ratingsInfo?.count) ?? 0
|
|
||||||
}
|
|
||||||
leaderboard={leaderboard[region][season] ?? {}}
|
leaderboard={leaderboard[region][season] ?? {}}
|
||||||
rowsPerPage={ROWS_PER_PAGE}
|
rowsPerPage={ROWS_PER_PAGE}
|
||||||
page={page}
|
page={page}
|
||||||
@@ -978,7 +976,7 @@ export default function Page() {
|
|||||||
page * ROWS_PER_PAGE,
|
page * ROWS_PER_PAGE,
|
||||||
Math.min(
|
Math.min(
|
||||||
page * ROWS_PER_PAGE + ROWS_PER_PAGE,
|
page * ROWS_PER_PAGE + ROWS_PER_PAGE,
|
||||||
ratingsInfo?.detail ? 0 : (ratingsInfo?.count ?? 1) - 1,
|
ratingInfo?.detail ? 0 : (ratingInfo?.count ?? 1) - 1,
|
||||||
),
|
),
|
||||||
).map((index) => {
|
).map((index) => {
|
||||||
const id = leaderboard[region][season]?.[index];
|
const id = leaderboard[region][season]?.[index];
|
||||||
@@ -990,8 +988,8 @@ export default function Page() {
|
|||||||
: highlightedPlayer.position === index
|
: highlightedPlayer.position === index
|
||||||
: false;
|
: false;
|
||||||
const reward =
|
const reward =
|
||||||
!ratingsInfo?.detail && ratingsInfo?.rewards
|
!ratingInfo?.detail && ratingInfo?.rewards
|
||||||
? ratingsInfo.rewards.find(
|
? ratingInfo.rewards.find(
|
||||||
(reward) =>
|
(reward) =>
|
||||||
reward.from_position <= position &&
|
reward.from_position <= position &&
|
||||||
reward.to_position >= position,
|
reward.to_position >= position,
|
||||||
@@ -1086,9 +1084,7 @@ export default function Page() {
|
|||||||
</Table.Root>
|
</Table.Root>
|
||||||
|
|
||||||
<PageTurner
|
<PageTurner
|
||||||
totalPlayers={
|
totalPlayers={(ratingInfo?.detail ? undefined : ratingInfo?.count) ?? 0}
|
||||||
(ratingsInfo?.detail ? undefined : ratingsInfo?.count) ?? 0
|
|
||||||
}
|
|
||||||
rowsPerPage={ROWS_PER_PAGE}
|
rowsPerPage={ROWS_PER_PAGE}
|
||||||
leaderboard={leaderboard[region][season] ?? {}}
|
leaderboard={leaderboard[region][season] ?? {}}
|
||||||
page={page}
|
page={page}
|
||||||
@@ -18,11 +18,13 @@ import {
|
|||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
import { ChangeEvent, useEffect, useRef, useState } from 'react';
|
import { ChangeEvent, useEffect, useRef, useState } from 'react';
|
||||||
import PageWrapper from '../../../components/PageWrapper';
|
import PageWrapper from '../../../components/PageWrapper';
|
||||||
import { REGION_NAMES } from '../../../constants/regions';
|
import { UNLOCALIZED_REGION_NAMES } from '../../../constants/regions';
|
||||||
import searchPlayersAcrossRegions, {
|
import searchPlayersAcrossRegions, {
|
||||||
AccountListWithServer,
|
AccountListWithServer,
|
||||||
} from '../../../core/blitz/searchPlayersAcrossRegions';
|
} from '../../../core/blitz/searchPlayersAcrossRegions';
|
||||||
import { resetSession, setSession, useSession } from '../../../stores/session';
|
import { resetSession } from '../../../core/blitzkrieg/resetSession';
|
||||||
|
import { setSession } from '../../../core/blitzkrieg/setSession';
|
||||||
|
import { useSession } from '../../../stores/session';
|
||||||
import SessionPage from '../../embeds/session/page';
|
import SessionPage from '../../embeds/session/page';
|
||||||
import { Menu } from './components/Menu';
|
import { Menu } from './components/Menu';
|
||||||
import * as styles from './page.css';
|
import * as styles from './page.css';
|
||||||
@@ -107,7 +109,7 @@ export default function Page() {
|
|||||||
setShowSearchResults(false);
|
setShowSearchResults(false);
|
||||||
setSession(region, id, nickname);
|
setSession(region, id, nickname);
|
||||||
}}
|
}}
|
||||||
shortcut={REGION_NAMES[region]}
|
shortcut={UNLOCALIZED_REGION_NAMES[region]}
|
||||||
>
|
>
|
||||||
{nickname}
|
{nickname}
|
||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import { pushTankopediaPath } from '../../../../../core/blitzkrieg/pushTankopedi
|
|||||||
import {
|
import {
|
||||||
SHELL_NAMES,
|
SHELL_NAMES,
|
||||||
TIER_ROMAN_NUMERALS,
|
TIER_ROMAN_NUMERALS,
|
||||||
} from '../../../../../core/blitzkrieg/tankDefinitions';
|
} from '../../../../../core/blitzkrieg/tankDefinitions/constants';
|
||||||
import { mutateDuel, useDuel } from '../../../../../stores/duel';
|
import { mutateDuel, useDuel } from '../../../../../stores/duel';
|
||||||
import {
|
import {
|
||||||
mutateTankopediaTemporary,
|
mutateTankopediaTemporary,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Flex, Heading } from '@radix-ui/themes';
|
import { Flex, Heading } from '@radix-ui/themes';
|
||||||
import { ModuleButton } from '../../../../../../../components/ModuleButtons/ModuleButton';
|
import { ModuleButton } from '../../../../../../../components/ModuleButtons/ModuleButton';
|
||||||
import { TIER_ROMAN_NUMERALS } from '../../../../../../../core/blitzkrieg/tankDefinitions';
|
import { TIER_ROMAN_NUMERALS } from '../../../../../../../core/blitzkrieg/tankDefinitions/constants';
|
||||||
import { mutateDuel, useDuel } from '../../../../../../../stores/duel';
|
import { mutateDuel, useDuel } from '../../../../../../../stores/duel';
|
||||||
import { mutateTankopediaTemporary } from '../../../../../../../stores/tankopedia';
|
import { mutateTankopediaTemporary } from '../../../../../../../stores/tankopedia';
|
||||||
import { ConfigurationChildWrapper } from './ConfigurationChildWrapper';
|
import { ConfigurationChildWrapper } from './ConfigurationChildWrapper';
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { debounce } from 'lodash';
|
|||||||
import { use, useEffect, useRef, useState } from 'react';
|
import { use, useEffect, useRef, useState } from 'react';
|
||||||
import { lerp } from 'three/src/math/MathUtils';
|
import { lerp } from 'three/src/math/MathUtils';
|
||||||
import { ShellButton } from '../../../../../../components/ModuleButtons/ShellButton';
|
import { ShellButton } from '../../../../../../components/ModuleButtons/ShellButton';
|
||||||
|
import { applyPitchYawLimits } from '../../../../../../core/blitz/applyPitchYawLimits';
|
||||||
import { isExplosive } from '../../../../../../core/blitz/isExplosive';
|
import { isExplosive } from '../../../../../../core/blitz/isExplosive';
|
||||||
import { resolveNearPenetration } from '../../../../../../core/blitz/resolveNearPenetration';
|
import { resolveNearPenetration } from '../../../../../../core/blitz/resolveNearPenetration';
|
||||||
import { coefficient } from '../../../../../../core/blitzkrieg/coefficient';
|
import { coefficient } from '../../../../../../core/blitzkrieg/coefficient';
|
||||||
@@ -17,7 +18,7 @@ import {
|
|||||||
CREW_MEMBER_NAMES,
|
CREW_MEMBER_NAMES,
|
||||||
GUN_TYPE_NAMES,
|
GUN_TYPE_NAMES,
|
||||||
SHELL_NAMES,
|
SHELL_NAMES,
|
||||||
} from '../../../../../../core/blitzkrieg/tankDefinitions';
|
} from '../../../../../../core/blitzkrieg/tankDefinitions/constants';
|
||||||
import { unionBoundingBox } from '../../../../../../core/blitzkrieg/unionBoundingBox';
|
import { unionBoundingBox } from '../../../../../../core/blitzkrieg/unionBoundingBox';
|
||||||
import { useConsumable } from '../../../../../../hooks/useConsumable';
|
import { useConsumable } from '../../../../../../hooks/useConsumable';
|
||||||
import { useEquipment } from '../../../../../../hooks/useEquipment';
|
import { useEquipment } from '../../../../../../hooks/useEquipment';
|
||||||
@@ -56,6 +57,7 @@ export function Characteristics() {
|
|||||||
turretModelDefinition.boundingBox,
|
turretModelDefinition.boundingBox,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
const gunDefaultPitch = tankModelDefinition.turretRotation?.pitch ?? 0;
|
||||||
const weight =
|
const weight =
|
||||||
tank.weight + engine.weight + track.weight + turret.weight + gun.weight;
|
tank.weight + engine.weight + track.weight + turret.weight + gun.weight;
|
||||||
const weightTons = weight / 1000;
|
const weightTons = weight / 1000;
|
||||||
@@ -113,7 +115,7 @@ export function Characteristics() {
|
|||||||
// TODO: add max rolls
|
// TODO: add max rolls
|
||||||
[hasTungsten, 0.15],
|
[hasTungsten, 0.15],
|
||||||
);
|
);
|
||||||
const interClipCoefficient = coefficient([hasShellReloadBoost, -0.3]);
|
const intraClipCoefficient = coefficient([hasShellReloadBoost, -0.3]);
|
||||||
const shellVelocityCoefficient = coefficient(
|
const shellVelocityCoefficient = coefficient(
|
||||||
[hasSupercharger, 0.3],
|
[hasSupercharger, 0.3],
|
||||||
[hasImprovedGunPowder, 0.3],
|
[hasImprovedGunPowder, 0.3],
|
||||||
@@ -136,12 +138,13 @@ export function Characteristics() {
|
|||||||
]);
|
]);
|
||||||
const enginePowerCoefficient = coefficient(
|
const enginePowerCoefficient = coefficient(
|
||||||
[
|
[
|
||||||
hasEngineAccelerator && (tank.type === 'light' || tank.type === 'medium'),
|
hasEngineAccelerator &&
|
||||||
|
(tank.class === 'lightTank' || tank.class === 'mediumTank'),
|
||||||
0.05,
|
0.05,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
hasEngineAccelerator &&
|
hasEngineAccelerator &&
|
||||||
(tank.type === 'heavy' || tank.type === 'tankDestroyer'),
|
(tank.class === 'heavyTank' || tank.class === 'AT-SPG'),
|
||||||
0.07,
|
0.07,
|
||||||
],
|
],
|
||||||
[hasEnginePowerBoost, 0.2],
|
[hasEnginePowerBoost, 0.2],
|
||||||
@@ -163,7 +166,7 @@ export function Characteristics() {
|
|||||||
const viewRangeCoefficient =
|
const viewRangeCoefficient =
|
||||||
coefficient([
|
coefficient([
|
||||||
hasImprovedOptics,
|
hasImprovedOptics,
|
||||||
tank.type === 'tankDestroyer' ? 0.05 : tank.type === 'heavy' ? 0.07 : 0.1,
|
tank.class === 'AT-SPG' ? 0.05 : tank.class === 'heavyTank' ? 0.07 : 0.1,
|
||||||
]) * coefficient([true, progressiveStat(commanderMastery)]);
|
]) * coefficient([true, progressiveStat(commanderMastery)]);
|
||||||
const fireChanceCoefficient = coefficient([hasProtectiveKit, -0.2]);
|
const fireChanceCoefficient = coefficient([hasProtectiveKit, -0.2]);
|
||||||
|
|
||||||
@@ -180,38 +183,26 @@ export function Characteristics() {
|
|||||||
const camouflageSumMoving = sum(
|
const camouflageSumMoving = sum(
|
||||||
[
|
[
|
||||||
hasCamouflageNet,
|
hasCamouflageNet,
|
||||||
tank.type === 'heavy'
|
tank.class === 'heavyTank' ? 0.03 : tank.class === 'AT-SPG' ? 0.07 : 0.05,
|
||||||
? 0.03
|
|
||||||
: tank.type === 'tankDestroyer'
|
|
||||||
? 0.07
|
|
||||||
: 0.05,
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
camouflage,
|
camouflage,
|
||||||
tank.type === 'tankDestroyer'
|
tank.class === 'AT-SPG' ? 0.04 : tank.class === 'heavyTank' ? 0.03 : 0.02,
|
||||||
? 0.04
|
|
||||||
: tank.type === 'heavy'
|
|
||||||
? 0.03
|
|
||||||
: 0.02,
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
const camouflageSumStill = sum(
|
const camouflageSumStill = sum(
|
||||||
[
|
[
|
||||||
hasCamouflageNet,
|
hasCamouflageNet,
|
||||||
2 *
|
2 *
|
||||||
(tank.type === 'heavy'
|
(tank.class === 'heavyTank'
|
||||||
? 0.03
|
? 0.03
|
||||||
: tank.type === 'tankDestroyer'
|
: tank.class === 'AT-SPG'
|
||||||
? 0.07
|
? 0.07
|
||||||
: 0.05),
|
: 0.05),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
camouflage,
|
camouflage,
|
||||||
tank.type === 'tankDestroyer'
|
tank.class === 'AT-SPG' ? 0.04 : tank.class === 'heavyTank' ? 0.03 : 0.02,
|
||||||
? 0.04
|
|
||||||
: tank.type === 'heavy'
|
|
||||||
? 0.03
|
|
||||||
: 0.02,
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -221,7 +212,7 @@ export function Characteristics() {
|
|||||||
shell,
|
shell,
|
||||||
damageCoefficient,
|
damageCoefficient,
|
||||||
reloadCoefficient,
|
reloadCoefficient,
|
||||||
interClipCoefficient,
|
intraClipCoefficient,
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -229,6 +220,17 @@ export function Characteristics() {
|
|||||||
penetrationDistanceInput.current.value = `${penetrationDistance}`;
|
penetrationDistanceInput.current.value = `${penetrationDistance}`;
|
||||||
}
|
}
|
||||||
}, [penetrationDistance]);
|
}, [penetrationDistance]);
|
||||||
|
useEffect(() => {
|
||||||
|
mutateDuel((draft) => {
|
||||||
|
[draft.protagonist!.pitch, draft.protagonist!.yaw] = applyPitchYawLimits(
|
||||||
|
draft.protagonist!.pitch,
|
||||||
|
draft.protagonist!.yaw,
|
||||||
|
gunModelDefinition.pitch,
|
||||||
|
turretModelDefinition.yaw,
|
||||||
|
hasImprovedVerticalStabilizer,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}, [hasImprovedVerticalStabilizer]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex direction="column" gap="8" style={{ width: '100%' }}>
|
<Flex direction="column" gap="8" style={{ width: '100%' }}>
|
||||||
@@ -266,9 +268,13 @@ export function Characteristics() {
|
|||||||
<>
|
<>
|
||||||
<InfoWithDelta decimals={0} indent name="Maximum" unit="hp / min">
|
<InfoWithDelta decimals={0} indent name="Maximum" unit="hp / min">
|
||||||
{gun.reload.at(-1)! < gun.reload.at(-2)!
|
{gun.reload.at(-1)! < gun.reload.at(-2)!
|
||||||
? (shell.damage.armor / (gun.reload.at(-1)! + gun.interClip)) *
|
? ((damageCoefficient * shell.damage.armor) /
|
||||||
|
(gun.reload.at(-1)! * reloadCoefficient +
|
||||||
|
gun.intraClip * intraClipCoefficient)) *
|
||||||
60
|
60
|
||||||
: (shell.damage.armor / gun.reload[0]) * 60}
|
: ((damageCoefficient * shell.damage.armor) /
|
||||||
|
(gun.reload[0] * reloadCoefficient)) *
|
||||||
|
60}
|
||||||
</InfoWithDelta>
|
</InfoWithDelta>
|
||||||
<InfoWithDelta
|
<InfoWithDelta
|
||||||
decimals={0}
|
decimals={0}
|
||||||
@@ -277,13 +283,26 @@ export function Characteristics() {
|
|||||||
unit="hp / min"
|
unit="hp / min"
|
||||||
>
|
>
|
||||||
{gun.reload.at(-1)! < gun.reload.at(-2)!
|
{gun.reload.at(-1)! < gun.reload.at(-2)!
|
||||||
? (shell.damage.armor / (gun.reload.at(-1)! + gun.interClip)) *
|
? ((damageCoefficient * shell.damage.armor) /
|
||||||
|
(gun.reload.at(-1)! * reloadCoefficient +
|
||||||
|
gun.intraClip * intraClipCoefficient)) *
|
||||||
(60 -
|
(60 -
|
||||||
(gun.reload.slice(0, -1).length - 1) * gun.interClip) +
|
(gun.reload.slice(0, -1).length - 1) *
|
||||||
shell.damage.armor * gun.reload.slice(0, -1).length
|
gun.intraClip *
|
||||||
: (shell.damage.armor / (gun.reload[0] + gun.interClip)) *
|
intraClipCoefficient) +
|
||||||
(60 - (gun.reload.slice(1).length - 1) * gun.interClip) +
|
damageCoefficient *
|
||||||
shell.damage.armor * gun.reload.slice(1).length}
|
shell.damage.armor *
|
||||||
|
gun.reload.slice(0, -1).length
|
||||||
|
: ((damageCoefficient * shell.damage.armor) /
|
||||||
|
(gun.reload[0] * reloadCoefficient +
|
||||||
|
gun.intraClip * intraClipCoefficient)) *
|
||||||
|
(60 -
|
||||||
|
(gun.reload.slice(1).length - 1) *
|
||||||
|
gun.intraClip *
|
||||||
|
intraClipCoefficient) +
|
||||||
|
damageCoefficient *
|
||||||
|
shell.damage.armor *
|
||||||
|
gun.reload.slice(1).length}
|
||||||
</InfoWithDelta>
|
</InfoWithDelta>
|
||||||
<Info
|
<Info
|
||||||
indent
|
indent
|
||||||
@@ -296,14 +315,15 @@ export function Characteristics() {
|
|||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Info indent name="Optimal shell index">
|
|
||||||
{gun.reload.at(-1)! < gun.reload.at(-2)! ? gun.reload.length : 1}
|
|
||||||
</Info>
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{gun.type === 'autoReloader' ? (
|
{gun.type === 'autoReloader' ? (
|
||||||
<>
|
<>
|
||||||
<Info name="Reload" unit="s" />
|
<InfoWithDelta name="Shells">{gun.reload.length}</InfoWithDelta>
|
||||||
|
<Info indent name="Most optimal">
|
||||||
|
{gun.reload.at(-1)! < gun.reload.at(-2)! ? gun.reload.length : 1}
|
||||||
|
</Info>
|
||||||
|
<Info name="Shell reloads" unit="s" />
|
||||||
{gun.reload.map((reload, index) => (
|
{gun.reload.map((reload, index) => (
|
||||||
<InfoWithDelta
|
<InfoWithDelta
|
||||||
key={index}
|
key={index}
|
||||||
@@ -312,7 +332,7 @@ export function Characteristics() {
|
|||||||
decimals={2}
|
decimals={2}
|
||||||
deltaType="lowerIsBetter"
|
deltaType="lowerIsBetter"
|
||||||
>
|
>
|
||||||
{reload}
|
{reload * reloadCoefficient}
|
||||||
</InfoWithDelta>
|
</InfoWithDelta>
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
@@ -326,17 +346,18 @@ export function Characteristics() {
|
|||||||
{gun.reload * reloadCoefficient}
|
{gun.reload * reloadCoefficient}
|
||||||
</InfoWithDelta>
|
</InfoWithDelta>
|
||||||
)}
|
)}
|
||||||
{gun.type === 'autoLoader' && (
|
{gun.type === 'autoLoader' ||
|
||||||
<InfoWithDelta
|
(gun.type === 'autoReloader' && (
|
||||||
indent
|
<InfoWithDelta
|
||||||
decimals={2}
|
indent
|
||||||
name="Inter-clip reload"
|
decimals={2}
|
||||||
unit="s"
|
name="Intra-clip"
|
||||||
deltaType="lowerIsBetter"
|
unit="s"
|
||||||
>
|
deltaType="lowerIsBetter"
|
||||||
{gun.interClip * interClipCoefficient}
|
>
|
||||||
</InfoWithDelta>
|
{gun.intraClip * intraClipCoefficient}
|
||||||
)}
|
</InfoWithDelta>
|
||||||
|
))}
|
||||||
<InfoWithDelta name="Caliber" decimals={0} unit="mm">
|
<InfoWithDelta name="Caliber" decimals={0} unit="mm">
|
||||||
{shell.caliber}
|
{shell.caliber}
|
||||||
</InfoWithDelta>
|
</InfoWithDelta>
|
||||||
@@ -398,6 +419,11 @@ export function Characteristics() {
|
|||||||
<InfoWithDelta name="Module damage" unit="hp" decimals={0}>
|
<InfoWithDelta name="Module damage" unit="hp" decimals={0}>
|
||||||
{shell.damage.module * damageCoefficient}
|
{shell.damage.module * damageCoefficient}
|
||||||
</InfoWithDelta>
|
</InfoWithDelta>
|
||||||
|
{isExplosive(shell.type) && (
|
||||||
|
<InfoWithDelta name="Splash radius" unit="m" decimals={0}>
|
||||||
|
{shell.explosionRadius!}
|
||||||
|
</InfoWithDelta>
|
||||||
|
)}
|
||||||
<InfoWithDelta name="Shell velocity" unit="m/s" decimals={0}>
|
<InfoWithDelta name="Shell velocity" unit="m/s" decimals={0}>
|
||||||
{shell.speed * shellVelocityCoefficient}
|
{shell.speed * shellVelocityCoefficient}
|
||||||
</InfoWithDelta>
|
</InfoWithDelta>
|
||||||
@@ -468,10 +494,12 @@ export function Characteristics() {
|
|||||||
<Info name="Gun flexibility" unit="°" />
|
<Info name="Gun flexibility" unit="°" />
|
||||||
<InfoWithDelta decimals={1} indent name="Depression">
|
<InfoWithDelta decimals={1} indent name="Depression">
|
||||||
{gunModelDefinition.pitch.max +
|
{gunModelDefinition.pitch.max +
|
||||||
|
gunDefaultPitch +
|
||||||
(hasImprovedVerticalStabilizer ? 3 : 0)}
|
(hasImprovedVerticalStabilizer ? 3 : 0)}
|
||||||
</InfoWithDelta>
|
</InfoWithDelta>
|
||||||
<InfoWithDelta decimals={1} indent name="Elevation">
|
<InfoWithDelta decimals={1} indent name="Elevation">
|
||||||
{-gunModelDefinition.pitch.min +
|
{-gunModelDefinition.pitch.min -
|
||||||
|
gunDefaultPitch +
|
||||||
(hasImprovedVerticalStabilizer ? 3 : 0)}
|
(hasImprovedVerticalStabilizer ? 3 : 0)}
|
||||||
</InfoWithDelta>
|
</InfoWithDelta>
|
||||||
{gunModelDefinition.pitch.front && (
|
{gunModelDefinition.pitch.front && (
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useEffect, useRef } from 'react';
|
|||||||
import { Vector3 } from 'three';
|
import { Vector3 } from 'three';
|
||||||
import { OrbitControls as OrbitControlsClass } from 'three-stdlib';
|
import { OrbitControls as OrbitControlsClass } from 'three-stdlib';
|
||||||
import { applyPitchYawLimits } from '../../../../../core/blitz/applyPitchYawLimits';
|
import { applyPitchYawLimits } from '../../../../../core/blitz/applyPitchYawLimits';
|
||||||
|
import { hasEquipment } from '../../../../../core/blitzkrieg/hasEquipment';
|
||||||
import { modelDefinitions } from '../../../../../core/blitzkrieg/modelDefinitions';
|
import { modelDefinitions } from '../../../../../core/blitzkrieg/modelDefinitions';
|
||||||
import { Pose, poseEvent } from '../../../../../core/blitzkrieg/pose';
|
import { Pose, poseEvent } from '../../../../../core/blitzkrieg/pose';
|
||||||
import { useAwait } from '../../../../../hooks/useAwait';
|
import { useAwait } from '../../../../../hooks/useAwait';
|
||||||
@@ -67,7 +68,9 @@ export function Controls() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
function handlePoseEvent(event: Pose) {
|
async function handlePoseEvent(event: Pose) {
|
||||||
|
const hasImprovedVerticalStabilizer = await hasEquipment(122);
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case Pose.HullDown: {
|
case Pose.HullDown: {
|
||||||
const [pitch] = applyPitchYawLimits(
|
const [pitch] = applyPitchYawLimits(
|
||||||
@@ -75,6 +78,7 @@ export function Controls() {
|
|||||||
0,
|
0,
|
||||||
protagonistGunModelDefinition.pitch,
|
protagonistGunModelDefinition.pitch,
|
||||||
protagonistTurretModelDefinition.yaw,
|
protagonistTurretModelDefinition.yaw,
|
||||||
|
hasImprovedVerticalStabilizer,
|
||||||
);
|
);
|
||||||
|
|
||||||
camera.position
|
camera.position
|
||||||
@@ -106,6 +110,7 @@ export function Controls() {
|
|||||||
0,
|
0,
|
||||||
protagonistGunModelDefinition.pitch,
|
protagonistGunModelDefinition.pitch,
|
||||||
protagonistTurretModelDefinition.yaw,
|
protagonistTurretModelDefinition.yaw,
|
||||||
|
hasImprovedVerticalStabilizer,
|
||||||
);
|
);
|
||||||
|
|
||||||
camera.position
|
camera.position
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ import { PerspectiveCamera } from '@react-three/drei';
|
|||||||
import { Canvas } from '@react-three/fiber';
|
import { Canvas } from '@react-three/fiber';
|
||||||
import { Suspense, use, useEffect, useRef, useState } from 'react';
|
import { Suspense, use, useEffect, useRef, useState } from 'react';
|
||||||
import { isMobile } from 'react-device-detect';
|
import { isMobile } from 'react-device-detect';
|
||||||
import { ShotDisplay } from '../../../../../../components/ShotDisplay';
|
import { Armor } from '../../../../../../components/Armor';
|
||||||
|
import { ShotDisplay } from '../../../../../../components/Armor/components/ShotDisplay';
|
||||||
import { applyPitchYawLimits } from '../../../../../../core/blitz/applyPitchYawLimits';
|
import { applyPitchYawLimits } from '../../../../../../core/blitz/applyPitchYawLimits';
|
||||||
import { modelDefinitions } from '../../../../../../core/blitzkrieg/modelDefinitions';
|
import { modelDefinitions } from '../../../../../../core/blitzkrieg/modelDefinitions';
|
||||||
import { modelTransformEvent } from '../../../../../../core/blitzkrieg/modelTransform';
|
import { modelTransformEvent } from '../../../../../../core/blitzkrieg/modelTransform';
|
||||||
import { Pose, poseEvent } from '../../../../../../core/blitzkrieg/pose';
|
import { Pose, poseEvent } from '../../../../../../core/blitzkrieg/pose';
|
||||||
import { tankIcon } from '../../../../../../core/blitzkrieg/tankIcon';
|
import { tankIcon } from '../../../../../../core/blitzkrieg/tankIcon';
|
||||||
|
import { useEquipment } from '../../../../../../hooks/useEquipment';
|
||||||
import { useWideFormat } from '../../../../../../hooks/useWideFormat';
|
import { useWideFormat } from '../../../../../../hooks/useWideFormat';
|
||||||
import { mutateDuel, useDuel } from '../../../../../../stores/duel';
|
import { mutateDuel, useDuel } from '../../../../../../stores/duel';
|
||||||
import mutateTankopediaPersistent, {
|
import mutateTankopediaPersistent, {
|
||||||
@@ -24,13 +26,11 @@ import { RotationInputs } from '../QuickInputs';
|
|||||||
import { SceneProps } from '../SceneProps';
|
import { SceneProps } from '../SceneProps';
|
||||||
import { ModelLoader } from './components/ModelLoader';
|
import { ModelLoader } from './components/ModelLoader';
|
||||||
import { Options } from './components/Options';
|
import { Options } from './components/Options';
|
||||||
import { TankArmor } from './components/TankArmor';
|
|
||||||
import { ExternalModuleMask } from './components/TankArmor/components/ExternalModuleMask';
|
|
||||||
import { SpacedArmorDepth } from './components/TankArmor/components/SpacedArmorDepth';
|
|
||||||
import { TankModel } from './components/TankModel';
|
import { TankModel } from './components/TankModel';
|
||||||
|
|
||||||
export function TankSandbox() {
|
export function TankSandbox() {
|
||||||
const canvas = useRef<HTMLCanvasElement>(null);
|
const canvas = useRef<HTMLCanvasElement>(null);
|
||||||
|
const hasImprovedVerticalStabilizer = useEquipment(122);
|
||||||
const awaitedModelDefinitions = use(modelDefinitions);
|
const awaitedModelDefinitions = use(modelDefinitions);
|
||||||
const canvasWrapper = useRef<HTMLDivElement>(null);
|
const canvasWrapper = useRef<HTMLDivElement>(null);
|
||||||
const [isFullScreen, setIsFullScreen] = useState(false);
|
const [isFullScreen, setIsFullScreen] = useState(false);
|
||||||
@@ -72,6 +72,7 @@ export function TankSandbox() {
|
|||||||
0,
|
0,
|
||||||
gunModelDefinition.pitch,
|
gunModelDefinition.pitch,
|
||||||
turretModelDefinition.yaw,
|
turretModelDefinition.yaw,
|
||||||
|
hasImprovedVerticalStabilizer,
|
||||||
);
|
);
|
||||||
|
|
||||||
modelTransformEvent.emit({ pitch, yaw });
|
modelTransformEvent.emit({ pitch, yaw });
|
||||||
@@ -89,6 +90,7 @@ export function TankSandbox() {
|
|||||||
0,
|
0,
|
||||||
gunModelDefinition.pitch,
|
gunModelDefinition.pitch,
|
||||||
turretModelDefinition.yaw,
|
turretModelDefinition.yaw,
|
||||||
|
hasImprovedVerticalStabilizer,
|
||||||
);
|
);
|
||||||
|
|
||||||
modelTransformEvent.emit({ pitch, yaw });
|
modelTransformEvent.emit({ pitch, yaw });
|
||||||
@@ -106,6 +108,7 @@ export function TankSandbox() {
|
|||||||
0,
|
0,
|
||||||
gunModelDefinition.pitch,
|
gunModelDefinition.pitch,
|
||||||
turretModelDefinition.yaw,
|
turretModelDefinition.yaw,
|
||||||
|
hasImprovedVerticalStabilizer,
|
||||||
);
|
);
|
||||||
|
|
||||||
modelTransformEvent.emit({ pitch, yaw });
|
modelTransformEvent.emit({ pitch, yaw });
|
||||||
@@ -133,6 +136,7 @@ export function TankSandbox() {
|
|||||||
draft.protagonist!.yaw,
|
draft.protagonist!.yaw,
|
||||||
gunModelDefinition.pitch,
|
gunModelDefinition.pitch,
|
||||||
turretModelDefinition.yaw,
|
turretModelDefinition.yaw,
|
||||||
|
hasImprovedVerticalStabilizer,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}, [protagonist.gun, protagonist.turret]);
|
}, [protagonist.gun, protagonist.turret]);
|
||||||
@@ -198,12 +202,11 @@ export function TankSandbox() {
|
|||||||
<SceneProps />
|
<SceneProps />
|
||||||
|
|
||||||
<Suspense fallback={<ModelLoader />}>
|
<Suspense fallback={<ModelLoader />}>
|
||||||
<ShotDisplay />
|
{/* TODO: add rotation cube to the top right */}
|
||||||
<Lighting />
|
<Lighting />
|
||||||
<TankModel />
|
<TankModel />
|
||||||
<TankArmor />
|
<Armor />
|
||||||
<ExternalModuleMask ornamental />
|
<ShotDisplay />
|
||||||
<SpacedArmorDepth ornamental />
|
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</Canvas>
|
</Canvas>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { Button, DropdownMenu, Flex } from '@radix-ui/themes';
|
|||||||
import { RefObject } from 'react';
|
import { RefObject } from 'react';
|
||||||
import { Pose, poseEvent } from '../../../../../../../core/blitzkrieg/pose';
|
import { Pose, poseEvent } from '../../../../../../../core/blitzkrieg/pose';
|
||||||
import mutateTankopediaPersistent, {
|
import mutateTankopediaPersistent, {
|
||||||
|
mutateTankopediaTemporary,
|
||||||
useTankopediaPersistent,
|
useTankopediaPersistent,
|
||||||
} from '../../../../../../../stores/tankopedia';
|
} from '../../../../../../../stores/tankopedia';
|
||||||
import { ENVIRONMENTS } from '../../Lighting';
|
import { ENVIRONMENTS } from '../../Lighting';
|
||||||
@@ -30,6 +31,10 @@ export function Options({ isFullScreen, canvasWrapper }: OptionsProps) {
|
|||||||
const wireframe = useTankopediaPersistent(
|
const wireframe = useTankopediaPersistent(
|
||||||
(state) => state.model.visual.wireframe,
|
(state) => state.model.visual.wireframe,
|
||||||
);
|
);
|
||||||
|
const showSpacedArmor = useTankopediaPersistent(
|
||||||
|
(state) => state.model.visual.showSpacedArmor,
|
||||||
|
);
|
||||||
|
const opaque = useTankopediaPersistent((state) => state.model.visual.opaque);
|
||||||
const fullScreenAvailable =
|
const fullScreenAvailable =
|
||||||
typeof document !== 'undefined' && document.fullscreenEnabled;
|
typeof document !== 'undefined' && document.fullscreenEnabled;
|
||||||
const environment = useTankopediaPersistent(
|
const environment = useTankopediaPersistent(
|
||||||
@@ -78,6 +83,22 @@ export function Options({ isFullScreen, canvasWrapper }: OptionsProps) {
|
|||||||
</DropdownMenu.Trigger>
|
</DropdownMenu.Trigger>
|
||||||
|
|
||||||
<DropdownMenu.Content>
|
<DropdownMenu.Content>
|
||||||
|
<DropdownMenu.Label>Armor</DropdownMenu.Label>
|
||||||
|
|
||||||
|
<DropdownMenu.CheckboxItem
|
||||||
|
checked={showSpacedArmor}
|
||||||
|
onCheckedChange={(checked) => {
|
||||||
|
mutateTankopediaPersistent((draft) => {
|
||||||
|
draft.model.visual.showSpacedArmor = checked;
|
||||||
|
});
|
||||||
|
mutateTankopediaTemporary((draft) => {
|
||||||
|
draft.shot = undefined;
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Spaced armor
|
||||||
|
</DropdownMenu.CheckboxItem>
|
||||||
|
|
||||||
<DropdownMenu.CheckboxItem
|
<DropdownMenu.CheckboxItem
|
||||||
checked={greenPenetration}
|
checked={greenPenetration}
|
||||||
onCheckedChange={(checked) => {
|
onCheckedChange={(checked) => {
|
||||||
@@ -89,6 +110,30 @@ export function Options({ isFullScreen, canvasWrapper }: OptionsProps) {
|
|||||||
Green penetration
|
Green penetration
|
||||||
</DropdownMenu.CheckboxItem>
|
</DropdownMenu.CheckboxItem>
|
||||||
|
|
||||||
|
<DropdownMenu.CheckboxItem
|
||||||
|
checked={wireframe}
|
||||||
|
onCheckedChange={(checked) => {
|
||||||
|
mutateTankopediaPersistent((draft) => {
|
||||||
|
draft.model.visual.wireframe = checked;
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Wireframe
|
||||||
|
</DropdownMenu.CheckboxItem>
|
||||||
|
|
||||||
|
<DropdownMenu.CheckboxItem
|
||||||
|
checked={opaque}
|
||||||
|
onCheckedChange={(checked) => {
|
||||||
|
mutateTankopediaPersistent((draft) => {
|
||||||
|
draft.model.visual.opaque = checked;
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Opaque
|
||||||
|
</DropdownMenu.CheckboxItem>
|
||||||
|
|
||||||
|
<DropdownMenu.Label>Environment</DropdownMenu.Label>
|
||||||
|
|
||||||
<DropdownMenu.CheckboxItem
|
<DropdownMenu.CheckboxItem
|
||||||
checked={showGrid}
|
checked={showGrid}
|
||||||
onCheckedChange={(checked) => {
|
onCheckedChange={(checked) => {
|
||||||
@@ -132,17 +177,6 @@ export function Options({ isFullScreen, canvasWrapper }: OptionsProps) {
|
|||||||
</DropdownMenu.RadioGroup>
|
</DropdownMenu.RadioGroup>
|
||||||
</DropdownMenu.SubContent>
|
</DropdownMenu.SubContent>
|
||||||
</DropdownMenu.Sub>
|
</DropdownMenu.Sub>
|
||||||
|
|
||||||
<DropdownMenu.CheckboxItem
|
|
||||||
checked={wireframe}
|
|
||||||
onCheckedChange={(checked) => {
|
|
||||||
mutateTankopediaPersistent((draft) => {
|
|
||||||
draft.model.visual.wireframe = checked;
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Wireframe
|
|
||||||
</DropdownMenu.CheckboxItem>
|
|
||||||
</DropdownMenu.Content>
|
</DropdownMenu.Content>
|
||||||
</DropdownMenu.Root>
|
</DropdownMenu.Root>
|
||||||
)}
|
)}
|
||||||
|
|||||||
-286
@@ -1,286 +0,0 @@
|
|||||||
import { memo, useEffect, useRef } from 'react';
|
|
||||||
import { Euler, Group, Vector3 } from 'three';
|
|
||||||
import { degToRad } from 'three/src/math/MathUtils';
|
|
||||||
import { ArmorMeshExternalModuleMask } from '../../../../../../../../../components/ArmorMesh';
|
|
||||||
import { I_HAT, J_HAT, K_HAT } from '../../../../../../../../../constants/axis';
|
|
||||||
import {
|
|
||||||
ModelTransformEventData,
|
|
||||||
modelTransformEvent,
|
|
||||||
} from '../../../../../../../../../core/blitzkrieg/modelTransform';
|
|
||||||
import { nameToArmorId } from '../../../../../../../../../core/blitzkrieg/nameToArmorId';
|
|
||||||
import { resolveArmor } from '../../../../../../../../../core/blitzkrieg/resolveThickness';
|
|
||||||
import { useArmor } from '../../../../../../../../../hooks/useArmor';
|
|
||||||
import { useModel } from '../../../../../../../../../hooks/useModel';
|
|
||||||
import { useModelDefinitions } from '../../../../../../../../../hooks/useModelDefinitions';
|
|
||||||
import { useDuel } from '../../../../../../../../../stores/duel';
|
|
||||||
import { useTankopediaPersistent } from '../../../../../../../../../stores/tankopedia';
|
|
||||||
|
|
||||||
interface ExternalModuleMaskProps {
|
|
||||||
ornamental?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When rendered, generates a mask and thickness buffer for external modules.
|
|
||||||
* - R: 1 means external module
|
|
||||||
* - G: normalized thickness; multiply with max thickness to get nominal thickness
|
|
||||||
* - B: no data
|
|
||||||
* - A: 1 means is armor; 0 is background
|
|
||||||
*/
|
|
||||||
export const ExternalModuleMask = memo<ExternalModuleMaskProps>(
|
|
||||||
({ ornamental = false }) => {
|
|
||||||
const protagonist = useDuel((state) => state.protagonist!);
|
|
||||||
const wrapper = useRef<Group>(null);
|
|
||||||
const modelDefinitions = useModelDefinitions();
|
|
||||||
const turretContainer = useRef<Group>(null);
|
|
||||||
const gunContainer = useRef<Group>(null);
|
|
||||||
const initialTankopediaState = useTankopediaPersistent.getState();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const hullOrigin = new Vector3(
|
|
||||||
trackModelDefinition.origin[0],
|
|
||||||
trackModelDefinition.origin[1],
|
|
||||||
-trackModelDefinition.origin[2],
|
|
||||||
).applyAxisAngle(I_HAT, Math.PI / 2);
|
|
||||||
const turretOrigin = new Vector3(
|
|
||||||
tankModelDefinition.turretOrigin[0],
|
|
||||||
tankModelDefinition.turretOrigin[1],
|
|
||||||
-tankModelDefinition.turretOrigin[2],
|
|
||||||
).applyAxisAngle(I_HAT, Math.PI / 2);
|
|
||||||
const gunOrigin = new Vector3(
|
|
||||||
turretModelDefinition.gunOrigin[0],
|
|
||||||
turretModelDefinition.gunOrigin[1],
|
|
||||||
-turretModelDefinition.gunOrigin[2],
|
|
||||||
).applyAxisAngle(I_HAT, Math.PI / 2);
|
|
||||||
const turretPosition = new Vector3();
|
|
||||||
const turretRotation = new Euler();
|
|
||||||
const gunPosition = new Vector3();
|
|
||||||
const gunRotation = new Euler();
|
|
||||||
|
|
||||||
function handleModelTransform({ yaw, pitch }: ModelTransformEventData) {
|
|
||||||
gunPosition
|
|
||||||
.set(0, 0, 0)
|
|
||||||
.sub(hullOrigin)
|
|
||||||
.sub(turretOrigin)
|
|
||||||
.sub(gunOrigin)
|
|
||||||
.applyAxisAngle(I_HAT, pitch)
|
|
||||||
.add(gunOrigin)
|
|
||||||
.add(turretOrigin)
|
|
||||||
.add(hullOrigin);
|
|
||||||
gunRotation.set(pitch, 0, 0);
|
|
||||||
gunContainer.current?.position.copy(gunPosition);
|
|
||||||
gunContainer.current?.rotation.copy(gunRotation);
|
|
||||||
|
|
||||||
if (yaw === undefined) return;
|
|
||||||
|
|
||||||
turretPosition
|
|
||||||
.set(0, 0, 0)
|
|
||||||
.sub(turretOrigin)
|
|
||||||
.sub(hullOrigin)
|
|
||||||
.applyAxisAngle(new Vector3(0, 0, 1), yaw);
|
|
||||||
turretRotation.set(0, 0, yaw);
|
|
||||||
|
|
||||||
if (tankModelDefinition.turretRotation) {
|
|
||||||
const initialPitch = -degToRad(
|
|
||||||
tankModelDefinition.turretRotation.pitch,
|
|
||||||
);
|
|
||||||
const initialYaw = -degToRad(tankModelDefinition.turretRotation.yaw);
|
|
||||||
const initialRoll = -degToRad(
|
|
||||||
tankModelDefinition.turretRotation.roll,
|
|
||||||
);
|
|
||||||
|
|
||||||
turretPosition
|
|
||||||
.applyAxisAngle(I_HAT, initialPitch)
|
|
||||||
.applyAxisAngle(J_HAT, initialRoll)
|
|
||||||
.applyAxisAngle(K_HAT, initialYaw);
|
|
||||||
turretRotation.x += initialPitch;
|
|
||||||
turretRotation.y += initialRoll;
|
|
||||||
turretRotation.z += initialYaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
turretPosition.add(turretOrigin).add(hullOrigin);
|
|
||||||
turretContainer.current?.position.copy(turretPosition);
|
|
||||||
turretContainer.current?.rotation.copy(turretRotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
handleModelTransform(protagonist);
|
|
||||||
modelTransformEvent.on(handleModelTransform);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
modelTransformEvent.off(handleModelTransform);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const unsubscribe = useTankopediaPersistent.subscribe(
|
|
||||||
(state) => state.mode,
|
|
||||||
(mode) => {
|
|
||||||
if (wrapper.current) wrapper.current.visible = mode === 'armor';
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
return unsubscribe;
|
|
||||||
});
|
|
||||||
|
|
||||||
const armorGltf = useArmor(protagonist.tank.id);
|
|
||||||
const { gltf: modelGltf } = useModel(protagonist.tank.id);
|
|
||||||
|
|
||||||
const armorNodes = Object.values(armorGltf.nodes);
|
|
||||||
const modelNodes = Object.values(modelGltf.nodes);
|
|
||||||
const tankModelDefinition = modelDefinitions[protagonist.tank.id];
|
|
||||||
const trackModelDefinition =
|
|
||||||
tankModelDefinition.tracks[protagonist.track.id];
|
|
||||||
const turretModelDefinition =
|
|
||||||
tankModelDefinition.turrets[protagonist.turret.id];
|
|
||||||
const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id];
|
|
||||||
const maxThickness = Math.max(
|
|
||||||
trackModelDefinition.thickness,
|
|
||||||
gunModelDefinition.thickness,
|
|
||||||
...armorNodes
|
|
||||||
.map((node) => {
|
|
||||||
const armorId = nameToArmorId(node.name);
|
|
||||||
return resolveArmor(tankModelDefinition.armor, armorId).thickness;
|
|
||||||
})
|
|
||||||
.filter(Boolean),
|
|
||||||
);
|
|
||||||
const hullOrigin = new Vector3(
|
|
||||||
trackModelDefinition.origin[0],
|
|
||||||
trackModelDefinition.origin[1],
|
|
||||||
-trackModelDefinition.origin[2],
|
|
||||||
).applyAxisAngle(I_HAT, Math.PI / 2);
|
|
||||||
const turretOrigin = new Vector3(
|
|
||||||
tankModelDefinition.turretOrigin[0],
|
|
||||||
tankModelDefinition.turretOrigin[1],
|
|
||||||
-tankModelDefinition.turretOrigin[2],
|
|
||||||
).applyAxisAngle(I_HAT, Math.PI / 2);
|
|
||||||
const gunOrigin = new Vector3(
|
|
||||||
turretModelDefinition.gunOrigin[0],
|
|
||||||
turretModelDefinition.gunOrigin[1],
|
|
||||||
-turretModelDefinition.gunOrigin[2],
|
|
||||||
).applyAxisAngle(I_HAT, Math.PI / 2);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<group
|
|
||||||
ref={wrapper}
|
|
||||||
rotation={[-Math.PI / 2, 0, 0]}
|
|
||||||
visible={initialTankopediaState.mode === 'armor'}
|
|
||||||
>
|
|
||||||
<group position={hullOrigin}>
|
|
||||||
{armorNodes.map((node) => {
|
|
||||||
const isHull = node.name.startsWith('hull_');
|
|
||||||
const isVisible = isHull;
|
|
||||||
const armorId = nameToArmorId(node.name);
|
|
||||||
const { thickness, spaced } = resolveArmor(
|
|
||||||
tankModelDefinition.armor,
|
|
||||||
armorId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isVisible || thickness === undefined || spaced) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ArmorMeshExternalModuleMask
|
|
||||||
ornamental={ornamental}
|
|
||||||
exclude
|
|
||||||
key={node.uuid}
|
|
||||||
node={node}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</group>
|
|
||||||
|
|
||||||
{modelNodes.map((node) => {
|
|
||||||
const isWheel = node.name.startsWith('chassis_wheel_');
|
|
||||||
const isTrack = node.name.startsWith('chassis_track_');
|
|
||||||
const isVisible = isWheel || isTrack;
|
|
||||||
|
|
||||||
if (!isVisible) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ArmorMeshExternalModuleMask
|
|
||||||
ornamental={ornamental}
|
|
||||||
maxThickness={maxThickness}
|
|
||||||
thickness={trackModelDefinition.thickness}
|
|
||||||
key={node.uuid}
|
|
||||||
node={node}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
|
|
||||||
<group ref={turretContainer}>
|
|
||||||
<group position={hullOrigin}>
|
|
||||||
{armorNodes.map((node) => {
|
|
||||||
const isCurrentTurret = node.name.startsWith(
|
|
||||||
`turret_${turretModelDefinition.model.toString().padStart(2, '0')}`,
|
|
||||||
);
|
|
||||||
const isVisible = isCurrentTurret;
|
|
||||||
const armorId = nameToArmorId(node.name);
|
|
||||||
const { thickness, spaced } = resolveArmor(
|
|
||||||
turretModelDefinition.armor,
|
|
||||||
armorId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isVisible || thickness === undefined || spaced) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<group key={node.uuid} position={turretOrigin}>
|
|
||||||
<ArmorMeshExternalModuleMask
|
|
||||||
ornamental={ornamental}
|
|
||||||
exclude
|
|
||||||
node={node}
|
|
||||||
/>
|
|
||||||
</group>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</group>
|
|
||||||
|
|
||||||
<group ref={gunContainer}>
|
|
||||||
{armorNodes.map((node) => {
|
|
||||||
const isCurrentGun = node.name.startsWith(
|
|
||||||
`gun_${gunModelDefinition.model.toString().padStart(2, '0')}`,
|
|
||||||
);
|
|
||||||
const isVisible = isCurrentGun;
|
|
||||||
const armorId = nameToArmorId(node.name);
|
|
||||||
const { thickness, spaced } = resolveArmor(
|
|
||||||
gunModelDefinition.armor,
|
|
||||||
armorId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isVisible || thickness === undefined || spaced) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<group
|
|
||||||
key={node.uuid}
|
|
||||||
position={turretOrigin.clone().add(gunOrigin)}
|
|
||||||
>
|
|
||||||
<ArmorMeshExternalModuleMask
|
|
||||||
ornamental={ornamental}
|
|
||||||
exclude
|
|
||||||
node={node}
|
|
||||||
/>
|
|
||||||
</group>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
|
|
||||||
{modelNodes.map((node) => {
|
|
||||||
const isCurrentGun =
|
|
||||||
node.name ===
|
|
||||||
`gun_${gunModelDefinition.model.toString().padStart(2, '0')}`;
|
|
||||||
const isVisible = isCurrentGun;
|
|
||||||
|
|
||||||
if (!isVisible) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ArmorMeshExternalModuleMask
|
|
||||||
ornamental={ornamental}
|
|
||||||
maxThickness={maxThickness}
|
|
||||||
thickness={gunModelDefinition.thickness}
|
|
||||||
key={node.uuid}
|
|
||||||
node={node}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</group>
|
|
||||||
</group>
|
|
||||||
</group>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
-299
@@ -1,299 +0,0 @@
|
|||||||
import { memo, useEffect, useRef } from 'react';
|
|
||||||
import { Euler, Group, Vector3 } from 'three';
|
|
||||||
import { degToRad } from 'three/src/math/MathUtils';
|
|
||||||
import { ArmorMeshSpacedArmorDepth } from '../../../../../../../../../components/ArmorMesh/components/SpacedArmorDepth';
|
|
||||||
import { I_HAT, J_HAT, K_HAT } from '../../../../../../../../../constants/axis';
|
|
||||||
import {
|
|
||||||
ModelTransformEventData,
|
|
||||||
modelTransformEvent,
|
|
||||||
} from '../../../../../../../../../core/blitzkrieg/modelTransform';
|
|
||||||
import { nameToArmorId } from '../../../../../../../../../core/blitzkrieg/nameToArmorId';
|
|
||||||
import { resolveArmor } from '../../../../../../../../../core/blitzkrieg/resolveThickness';
|
|
||||||
import { useArmor } from '../../../../../../../../../hooks/useArmor';
|
|
||||||
import { useModel } from '../../../../../../../../../hooks/useModel';
|
|
||||||
import { useModelDefinitions } from '../../../../../../../../../hooks/useModelDefinitions';
|
|
||||||
import { useDuel } from '../../../../../../../../../stores/duel';
|
|
||||||
import { useTankopediaPersistent } from '../../../../../../../../../stores/tankopedia';
|
|
||||||
|
|
||||||
interface SpacedArmorDepthProps {
|
|
||||||
ornamental?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When rendered, this component provides the depth buffer for the armor which
|
|
||||||
* when compared to the depth of the core armor will give you the distance
|
|
||||||
* between the first point of contact and the core armor. The color channels
|
|
||||||
* hold information about the thickness of the spaced armor (external modules
|
|
||||||
* not included).
|
|
||||||
* - R: angle of the armor where 0 is 0 and 1 is 90
|
|
||||||
* - G: normalized thickness; multiply with max thickness to get nominal thickness
|
|
||||||
* - B: no data
|
|
||||||
* - A: 1 means is armor; 0 is background
|
|
||||||
*/
|
|
||||||
export const SpacedArmorDepth = memo<SpacedArmorDepthProps>(
|
|
||||||
({ ornamental = false }) => {
|
|
||||||
const protagonist = useDuel((state) => state.protagonist!);
|
|
||||||
const wrapper = useRef<Group>(null);
|
|
||||||
const modelDefinitions = useModelDefinitions();
|
|
||||||
const turretContainer = useRef<Group>(null);
|
|
||||||
const gunContainer = useRef<Group>(null);
|
|
||||||
const initialTankopediaState = useTankopediaPersistent.getState();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!modelDefinitions) return;
|
|
||||||
|
|
||||||
const hullOrigin = new Vector3(
|
|
||||||
trackModelDefinition.origin[0],
|
|
||||||
trackModelDefinition.origin[1],
|
|
||||||
-trackModelDefinition.origin[2],
|
|
||||||
).applyAxisAngle(I_HAT, Math.PI / 2);
|
|
||||||
const turretOrigin = new Vector3(
|
|
||||||
tankModelDefinition.turretOrigin[0],
|
|
||||||
tankModelDefinition.turretOrigin[1],
|
|
||||||
-tankModelDefinition.turretOrigin[2],
|
|
||||||
).applyAxisAngle(I_HAT, Math.PI / 2);
|
|
||||||
const gunOrigin = new Vector3(
|
|
||||||
turretModelDefinition.gunOrigin[0],
|
|
||||||
turretModelDefinition.gunOrigin[1],
|
|
||||||
-turretModelDefinition.gunOrigin[2],
|
|
||||||
).applyAxisAngle(I_HAT, Math.PI / 2);
|
|
||||||
const turretPosition = new Vector3();
|
|
||||||
const turretRotation = new Euler();
|
|
||||||
const gunPosition = new Vector3();
|
|
||||||
const gunRotation = new Euler();
|
|
||||||
|
|
||||||
function handleModelTransform({ yaw, pitch }: ModelTransformEventData) {
|
|
||||||
gunPosition
|
|
||||||
.set(0, 0, 0)
|
|
||||||
.sub(hullOrigin)
|
|
||||||
.sub(turretOrigin)
|
|
||||||
.sub(gunOrigin)
|
|
||||||
.applyAxisAngle(I_HAT, pitch)
|
|
||||||
.add(gunOrigin)
|
|
||||||
.add(turretOrigin)
|
|
||||||
.add(hullOrigin);
|
|
||||||
gunRotation.set(pitch, 0, 0);
|
|
||||||
gunContainer.current?.position.copy(gunPosition);
|
|
||||||
gunContainer.current?.rotation.copy(gunRotation);
|
|
||||||
|
|
||||||
if (yaw === undefined) return;
|
|
||||||
|
|
||||||
turretPosition
|
|
||||||
.set(0, 0, 0)
|
|
||||||
.sub(hullOrigin)
|
|
||||||
.sub(turretOrigin)
|
|
||||||
.applyAxisAngle(new Vector3(0, 0, 1), yaw);
|
|
||||||
turretRotation.set(0, 0, yaw);
|
|
||||||
|
|
||||||
if (tankModelDefinition.turretRotation) {
|
|
||||||
const initialPitch = -degToRad(
|
|
||||||
tankModelDefinition.turretRotation.pitch,
|
|
||||||
);
|
|
||||||
const initialYaw = -degToRad(tankModelDefinition.turretRotation.yaw);
|
|
||||||
const initialRoll = -degToRad(
|
|
||||||
tankModelDefinition.turretRotation.roll,
|
|
||||||
);
|
|
||||||
|
|
||||||
turretPosition
|
|
||||||
.applyAxisAngle(I_HAT, initialPitch)
|
|
||||||
.applyAxisAngle(J_HAT, initialRoll)
|
|
||||||
.applyAxisAngle(K_HAT, initialYaw);
|
|
||||||
turretRotation.x += initialPitch;
|
|
||||||
turretRotation.y += initialRoll;
|
|
||||||
turretRotation.z += initialYaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
turretPosition.add(turretOrigin).add(hullOrigin);
|
|
||||||
turretContainer.current?.position.copy(turretPosition);
|
|
||||||
turretContainer.current?.rotation.copy(turretRotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
handleModelTransform(protagonist);
|
|
||||||
modelTransformEvent.on(handleModelTransform);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
modelTransformEvent.off(handleModelTransform);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const unsubscribe = useTankopediaPersistent.subscribe(
|
|
||||||
(state) => state.mode,
|
|
||||||
(mode) => {
|
|
||||||
if (wrapper.current) wrapper.current.visible = mode === 'armor';
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
return unsubscribe;
|
|
||||||
});
|
|
||||||
|
|
||||||
const armorGltf = useArmor(protagonist.tank.id);
|
|
||||||
const { gltf: modelGltf } = useModel(protagonist.tank.id);
|
|
||||||
|
|
||||||
const armorNodes = Object.values(armorGltf.nodes);
|
|
||||||
const modelNodes = Object.values(modelGltf.nodes);
|
|
||||||
const tankModelDefinition = modelDefinitions[protagonist.tank.id];
|
|
||||||
const trackModelDefinition =
|
|
||||||
tankModelDefinition.tracks[protagonist.track.id];
|
|
||||||
const turretModelDefinition =
|
|
||||||
tankModelDefinition.turrets[protagonist.turret.id];
|
|
||||||
const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id];
|
|
||||||
const maxThickness = Math.max(
|
|
||||||
trackModelDefinition.thickness,
|
|
||||||
gunModelDefinition.thickness,
|
|
||||||
...armorNodes
|
|
||||||
.map((node) => {
|
|
||||||
const armorId = nameToArmorId(node.name);
|
|
||||||
return resolveArmor(tankModelDefinition.armor, armorId).thickness;
|
|
||||||
})
|
|
||||||
.filter(Boolean),
|
|
||||||
);
|
|
||||||
const hullOrigin = new Vector3(
|
|
||||||
trackModelDefinition.origin[0],
|
|
||||||
trackModelDefinition.origin[1],
|
|
||||||
-trackModelDefinition.origin[2],
|
|
||||||
).applyAxisAngle(I_HAT, Math.PI / 2);
|
|
||||||
const turretOrigin = new Vector3(
|
|
||||||
tankModelDefinition.turretOrigin[0],
|
|
||||||
tankModelDefinition.turretOrigin[1],
|
|
||||||
-tankModelDefinition.turretOrigin[2],
|
|
||||||
).applyAxisAngle(I_HAT, Math.PI / 2);
|
|
||||||
const gunOrigin = new Vector3(
|
|
||||||
turretModelDefinition.gunOrigin[0],
|
|
||||||
turretModelDefinition.gunOrigin[1],
|
|
||||||
-turretModelDefinition.gunOrigin[2],
|
|
||||||
).applyAxisAngle(I_HAT, Math.PI / 2);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<group
|
|
||||||
ref={wrapper}
|
|
||||||
rotation={[-Math.PI / 2, 0, 0]}
|
|
||||||
visible={initialTankopediaState.mode === 'armor'}
|
|
||||||
>
|
|
||||||
<group position={hullOrigin}>
|
|
||||||
{armorNodes.map((node) => {
|
|
||||||
const isHull = node.name.startsWith('hull_');
|
|
||||||
const isVisible = isHull;
|
|
||||||
const armorId = nameToArmorId(node.name);
|
|
||||||
const { spaced, thickness } = resolveArmor(
|
|
||||||
tankModelDefinition.armor,
|
|
||||||
armorId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isVisible || thickness === undefined) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ArmorMeshSpacedArmorDepth
|
|
||||||
ornamental={ornamental}
|
|
||||||
include={spaced}
|
|
||||||
isExternalModule={false}
|
|
||||||
thickness={thickness}
|
|
||||||
maxThickness={maxThickness}
|
|
||||||
key={node.uuid}
|
|
||||||
node={node}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</group>
|
|
||||||
{modelNodes.map((node) => {
|
|
||||||
const isWheel = node.name.startsWith('chassis_wheel_');
|
|
||||||
const isTrack = node.name.startsWith('chassis_track_');
|
|
||||||
const isVisible = isWheel || isTrack;
|
|
||||||
|
|
||||||
if (!isVisible) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ArmorMeshSpacedArmorDepth
|
|
||||||
ornamental={ornamental}
|
|
||||||
isExternalModule
|
|
||||||
key={node.uuid}
|
|
||||||
node={node}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
|
|
||||||
<group ref={turretContainer}>
|
|
||||||
<group position={hullOrigin}>
|
|
||||||
{armorNodes.map((node) => {
|
|
||||||
const isCurrentTurret = node.name.startsWith(
|
|
||||||
`turret_${turretModelDefinition.model.toString().padStart(2, '0')}`,
|
|
||||||
);
|
|
||||||
const isVisible = isCurrentTurret;
|
|
||||||
const armorId = nameToArmorId(node.name);
|
|
||||||
const { spaced, thickness } = resolveArmor(
|
|
||||||
turretModelDefinition.armor,
|
|
||||||
armorId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isVisible || thickness === undefined) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<group key={node.uuid} position={turretOrigin}>
|
|
||||||
<ArmorMeshSpacedArmorDepth
|
|
||||||
ornamental={ornamental}
|
|
||||||
include={spaced}
|
|
||||||
isExternalModule={false}
|
|
||||||
thickness={thickness}
|
|
||||||
maxThickness={maxThickness}
|
|
||||||
node={node}
|
|
||||||
/>
|
|
||||||
</group>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</group>
|
|
||||||
<group ref={gunContainer}>
|
|
||||||
<group position={hullOrigin}>
|
|
||||||
{armorNodes.map((node) => {
|
|
||||||
const isCurrentGun = node.name.startsWith(
|
|
||||||
`gun_${gunModelDefinition.model.toString().padStart(2, '0')}`,
|
|
||||||
);
|
|
||||||
const isVisible = isCurrentGun;
|
|
||||||
const armorId = nameToArmorId(node.name);
|
|
||||||
const { spaced, thickness } = resolveArmor(
|
|
||||||
gunModelDefinition.armor,
|
|
||||||
armorId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isVisible || thickness === undefined) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<group
|
|
||||||
key={node.uuid}
|
|
||||||
position={turretOrigin.clone().add(gunOrigin)}
|
|
||||||
>
|
|
||||||
<ArmorMeshSpacedArmorDepth
|
|
||||||
ornamental={ornamental}
|
|
||||||
include={spaced}
|
|
||||||
isExternalModule={false}
|
|
||||||
thickness={thickness}
|
|
||||||
maxThickness={maxThickness}
|
|
||||||
node={node}
|
|
||||||
/>
|
|
||||||
</group>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</group>
|
|
||||||
|
|
||||||
{modelNodes.map((node) => {
|
|
||||||
const isCurrentGun =
|
|
||||||
node.name ===
|
|
||||||
`gun_${gunModelDefinition.model.toString().padStart(2, '0')}`;
|
|
||||||
const isVisible = isCurrentGun;
|
|
||||||
|
|
||||||
if (!isVisible) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ArmorMeshSpacedArmorDepth
|
|
||||||
ornamental={ornamental}
|
|
||||||
isExternalModule
|
|
||||||
key={node.uuid}
|
|
||||||
node={node}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</group>
|
|
||||||
</group>
|
|
||||||
</group>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
import { createPortal, useFrame } from '@react-three/fiber';
|
|
||||||
import { memo } from 'react';
|
|
||||||
import { DepthTexture, Scene, Vector2 } from 'three';
|
|
||||||
import { externalModuleMaskRenderTarget } from '../../../../../../../../components/ArmorMesh';
|
|
||||||
import { spacedArmorDepthRenderTarget } from '../../../../../../../../components/ArmorMesh/components/SpacedArmorDepth';
|
|
||||||
import { ArmorHighlighting } from './components/ArmorHighlighting';
|
|
||||||
import { ExternalModuleMask } from './components/ExternalModuleMask';
|
|
||||||
import { SpacedArmorDepth } from './components/SpacedArmorDepth';
|
|
||||||
|
|
||||||
export const TankArmor = memo(() => {
|
|
||||||
const externalModuleMaskScene = new Scene();
|
|
||||||
const spacedArmorDepthScene = new Scene();
|
|
||||||
const armorHighlightingScene = new Scene();
|
|
||||||
const externalModuleMaskPortal = createPortal(
|
|
||||||
<ExternalModuleMask />,
|
|
||||||
externalModuleMaskScene,
|
|
||||||
);
|
|
||||||
const spacedArmorDepthPortal = createPortal(
|
|
||||||
<SpacedArmorDepth />,
|
|
||||||
spacedArmorDepthScene,
|
|
||||||
);
|
|
||||||
const armorHighlightingPortal = createPortal(
|
|
||||||
<ArmorHighlighting />,
|
|
||||||
armorHighlightingScene,
|
|
||||||
);
|
|
||||||
const renderSize = new Vector2();
|
|
||||||
const newRenderSize = new Vector2();
|
|
||||||
|
|
||||||
useFrame(({ gl, scene, camera }) => {
|
|
||||||
const pixelRatio = gl.getPixelRatio();
|
|
||||||
gl.autoClear = true;
|
|
||||||
|
|
||||||
gl.getSize(newRenderSize).multiplyScalar(pixelRatio);
|
|
||||||
if (!newRenderSize.equals(renderSize)) {
|
|
||||||
renderSize.copy(newRenderSize);
|
|
||||||
spacedArmorDepthRenderTarget.depthTexture = new DepthTexture(
|
|
||||||
renderSize.x,
|
|
||||||
renderSize.y,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
externalModuleMaskRenderTarget.setSize(renderSize.x, renderSize.y);
|
|
||||||
gl.setRenderTarget(externalModuleMaskRenderTarget);
|
|
||||||
gl.render(externalModuleMaskScene, camera);
|
|
||||||
|
|
||||||
gl.clearDepth();
|
|
||||||
spacedArmorDepthRenderTarget.setSize(renderSize.x, renderSize.y * 0.5);
|
|
||||||
gl.setRenderTarget(spacedArmorDepthRenderTarget);
|
|
||||||
gl.render(spacedArmorDepthScene, camera);
|
|
||||||
|
|
||||||
gl.autoClear = false;
|
|
||||||
|
|
||||||
gl.setRenderTarget(null);
|
|
||||||
gl.render(scene, camera);
|
|
||||||
|
|
||||||
gl.clearDepth();
|
|
||||||
gl.render(armorHighlightingScene, camera);
|
|
||||||
}, 1);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{externalModuleMaskPortal}
|
|
||||||
{spacedArmorDepthPortal}
|
|
||||||
{armorHighlightingPortal}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
@@ -4,13 +4,14 @@ import { Euler, Group, Vector3 } from 'three';
|
|||||||
import { degToRad } from 'three/src/math/MathUtils';
|
import { degToRad } from 'three/src/math/MathUtils';
|
||||||
import { I_HAT, J_HAT, K_HAT } from '../../../../../../../constants/axis';
|
import { I_HAT, J_HAT, K_HAT } from '../../../../../../../constants/axis';
|
||||||
import { applyPitchYawLimits } from '../../../../../../../core/blitz/applyPitchYawLimits';
|
import { applyPitchYawLimits } from '../../../../../../../core/blitz/applyPitchYawLimits';
|
||||||
|
import { hasEquipment } from '../../../../../../../core/blitzkrieg/hasEquipment';
|
||||||
import { jsxTree } from '../../../../../../../core/blitzkrieg/jsxTree';
|
import { jsxTree } from '../../../../../../../core/blitzkrieg/jsxTree';
|
||||||
import { modelDefinitions } from '../../../../../../../core/blitzkrieg/modelDefinitions';
|
import { modelDefinitions } from '../../../../../../../core/blitzkrieg/modelDefinitions';
|
||||||
import {
|
import {
|
||||||
ModelTransformEventData,
|
ModelTransformEventData,
|
||||||
modelTransformEvent,
|
modelTransformEvent,
|
||||||
} from '../../../../../../../core/blitzkrieg/modelTransform';
|
} from '../../../../../../../core/blitzkrieg/modelTransform';
|
||||||
import { normalizeAnglePI } from '../../../../../../../core/math/normalizeAngle180';
|
import { normalizeAngleRad } from '../../../../../../../core/math/normalizeAngleRad';
|
||||||
import { useAwait } from '../../../../../../../hooks/useAwait';
|
import { useAwait } from '../../../../../../../hooks/useAwait';
|
||||||
import { useModel } from '../../../../../../../hooks/useModel';
|
import { useModel } from '../../../../../../../hooks/useModel';
|
||||||
import { mutateDuel, useDuel } from '../../../../../../../stores/duel';
|
import { mutateDuel, useDuel } from '../../../../../../../stores/duel';
|
||||||
@@ -106,7 +107,6 @@ export const TankModel = memo(() => {
|
|||||||
const turretModelDefinition =
|
const turretModelDefinition =
|
||||||
tankModelDefinition.turrets[protagonist.turret.id];
|
tankModelDefinition.turrets[protagonist.turret.id];
|
||||||
const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id];
|
const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id];
|
||||||
|
|
||||||
const { gltf } = useModel(protagonist.tank.id);
|
const { gltf } = useModel(protagonist.tank.id);
|
||||||
const nodes = Object.values(gltf.nodes);
|
const nodes = Object.values(gltf.nodes);
|
||||||
|
|
||||||
@@ -161,19 +161,21 @@ export const TankModel = memo(() => {
|
|||||||
window.addEventListener('pointerup', handlePointerUp);
|
window.addEventListener('pointerup', handlePointerUp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function handlePointerMove(event: PointerEvent) {
|
async function handlePointerMove(event: PointerEvent) {
|
||||||
|
const hasImprovedVerticalStabilizer = await hasEquipment(122);
|
||||||
[pitch, yaw] = applyPitchYawLimits(
|
[pitch, yaw] = applyPitchYawLimits(
|
||||||
pitch,
|
pitch,
|
||||||
yaw + event.movementX * (Math.PI / canvas.width),
|
yaw + event.movementX * (Math.PI / canvas.width),
|
||||||
gunModelDefinition.pitch,
|
gunModelDefinition.pitch,
|
||||||
turretModelDefinition.yaw,
|
turretModelDefinition.yaw,
|
||||||
|
hasImprovedVerticalStabilizer,
|
||||||
);
|
);
|
||||||
modelTransformEvent.emit({ pitch, yaw });
|
modelTransformEvent.emit({ pitch, yaw });
|
||||||
}
|
}
|
||||||
function handlePointerUp() {
|
function handlePointerUp() {
|
||||||
mutateDuel((draft) => {
|
mutateDuel((draft) => {
|
||||||
draft.protagonist!.pitch = normalizeAnglePI(pitch);
|
draft.protagonist!.pitch = normalizeAngleRad(pitch);
|
||||||
draft.protagonist!.yaw = normalizeAnglePI(yaw);
|
draft.protagonist!.yaw = normalizeAngleRad(yaw);
|
||||||
});
|
});
|
||||||
mutateTankopediaPersistent((draft) => {
|
mutateTankopediaPersistent((draft) => {
|
||||||
draft.model.visual.controlsEnabled = true;
|
draft.model.visual.controlsEnabled = true;
|
||||||
@@ -220,12 +222,14 @@ export const TankModel = memo(() => {
|
|||||||
window.addEventListener('pointermove', handlePointerMove);
|
window.addEventListener('pointermove', handlePointerMove);
|
||||||
window.addEventListener('pointerup', handlePointerUp);
|
window.addEventListener('pointerup', handlePointerUp);
|
||||||
}
|
}
|
||||||
function handlePointerMove(event: PointerEvent) {
|
async function handlePointerMove(event: PointerEvent) {
|
||||||
|
const hasImprovedVerticalStabilizer = await hasEquipment(122);
|
||||||
[pitch, yaw] = applyPitchYawLimits(
|
[pitch, yaw] = applyPitchYawLimits(
|
||||||
pitch - event.movementY * (Math.PI / canvas.height),
|
pitch - event.movementY * (Math.PI / canvas.height),
|
||||||
yaw + event.movementX * (Math.PI / canvas.width),
|
yaw + event.movementX * (Math.PI / canvas.width),
|
||||||
gunModelDefinition.pitch,
|
gunModelDefinition.pitch,
|
||||||
turretModelDefinition.yaw,
|
turretModelDefinition.yaw,
|
||||||
|
hasImprovedVerticalStabilizer,
|
||||||
);
|
);
|
||||||
modelTransformEvent.emit({ pitch, yaw });
|
modelTransformEvent.emit({ pitch, yaw });
|
||||||
}
|
}
|
||||||
@@ -234,8 +238,8 @@ export const TankModel = memo(() => {
|
|||||||
draft.model.visual.controlsEnabled = true;
|
draft.model.visual.controlsEnabled = true;
|
||||||
});
|
});
|
||||||
mutateDuel((draft) => {
|
mutateDuel((draft) => {
|
||||||
draft.protagonist!.pitch = normalizeAnglePI(pitch);
|
draft.protagonist!.pitch = normalizeAngleRad(pitch);
|
||||||
draft.protagonist!.yaw = normalizeAnglePI(yaw);
|
draft.protagonist!.yaw = normalizeAngleRad(yaw);
|
||||||
});
|
});
|
||||||
window.removeEventListener('pointermove', handlePointerMove);
|
window.removeEventListener('pointermove', handlePointerMove);
|
||||||
window.removeEventListener('pointerup', handlePointerUp);
|
window.removeEventListener('pointerup', handlePointerUp);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Flex, TextField } from '@radix-ui/themes';
|
import { Flex, TextField } from '@radix-ui/themes';
|
||||||
import { use, useEffect, useRef } from 'react';
|
import { use, useEffect, useRef } from 'react';
|
||||||
|
import { degToRad, radToDeg } from 'three/src/math/MathUtils';
|
||||||
import { applyPitchYawLimits } from '../../../../../../core/blitz/applyPitchYawLimits';
|
import { applyPitchYawLimits } from '../../../../../../core/blitz/applyPitchYawLimits';
|
||||||
import { modelDefinitions } from '../../../../../../core/blitzkrieg/modelDefinitions';
|
import { modelDefinitions } from '../../../../../../core/blitzkrieg/modelDefinitions';
|
||||||
import { modelTransformEvent } from '../../../../../../core/blitzkrieg/modelTransform';
|
import { modelTransformEvent } from '../../../../../../core/blitzkrieg/modelTransform';
|
||||||
@@ -20,22 +21,21 @@ export function RotationInputs({ isFullScreen }: RotationInputsProps) {
|
|||||||
const mode = useTankopediaPersistent((state) => state.mode);
|
const mode = useTankopediaPersistent((state) => state.mode);
|
||||||
const hasCalibratedShells = useEquipment(103, true);
|
const hasCalibratedShells = useEquipment(103, true);
|
||||||
const hasEnhancedArmor = useEquipment(110);
|
const hasEnhancedArmor = useEquipment(110);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
turretYawInput.current!.value = `${-Math.round(
|
|
||||||
protagonist.yaw * (180 / Math.PI),
|
|
||||||
)}`;
|
|
||||||
}, [protagonist.yaw]);
|
|
||||||
useEffect(() => {
|
|
||||||
gunPitchInput.current!.value = `${-Math.round(
|
|
||||||
protagonist.pitch * (180 / Math.PI),
|
|
||||||
)}`;
|
|
||||||
}, [protagonist.pitch]);
|
|
||||||
|
|
||||||
const tankModelDefinition = awaitedModelDefinitions[protagonist.tank.id];
|
const tankModelDefinition = awaitedModelDefinitions[protagonist.tank.id];
|
||||||
const turretModelDefinition =
|
const turretModelDefinition =
|
||||||
tankModelDefinition.turrets[protagonist.turret.id];
|
tankModelDefinition.turrets[protagonist.turret.id];
|
||||||
const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id];
|
const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id];
|
||||||
|
const initialGunPitch = tankModelDefinition.turretRotation?.pitch ?? 0;
|
||||||
|
const hasImprovedVerticalStabilizer = useEquipment(122);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
turretYawInput.current!.value = radToDeg(protagonist.yaw).toFixed(1);
|
||||||
|
}, [protagonist.yaw]);
|
||||||
|
useEffect(() => {
|
||||||
|
gunPitchInput.current!.value = (
|
||||||
|
-radToDeg(protagonist.pitch) + initialGunPitch
|
||||||
|
).toFixed(1);
|
||||||
|
}, [protagonist.pitch]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
@@ -46,15 +46,11 @@ export function RotationInputs({ isFullScreen }: RotationInputsProps) {
|
|||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
left: 8,
|
left: 8,
|
||||||
bottom: isFullScreen ? 80 : 8,
|
bottom: isFullScreen ? 80 : 8,
|
||||||
|
pointerEvents: 'none',
|
||||||
}}
|
}}
|
||||||
gap="4"
|
gap="4"
|
||||||
>
|
>
|
||||||
<Flex
|
<Flex gap="2" style={{ width: 256, pointerEvents: 'auto' }}>
|
||||||
gap="2"
|
|
||||||
style={{
|
|
||||||
width: 256,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<TextField.Root
|
<TextField.Root
|
||||||
style={{
|
style={{
|
||||||
flex: 1,
|
flex: 1,
|
||||||
@@ -68,22 +64,22 @@ export function RotationInputs({ isFullScreen }: RotationInputsProps) {
|
|||||||
Yaw
|
Yaw
|
||||||
</TextField.Slot>
|
</TextField.Slot>
|
||||||
<TextField.Input
|
<TextField.Input
|
||||||
defaultValue={Math.round(protagonist.yaw * (180 / Math.PI))}
|
|
||||||
onBlur={() => {
|
onBlur={() => {
|
||||||
const [pitch, yaw] = applyPitchYawLimits(
|
const [pitch, yaw] = applyPitchYawLimits(
|
||||||
protagonist.pitch,
|
protagonist.pitch,
|
||||||
-Number(turretYawInput.current?.value) * (Math.PI / 180),
|
degToRad(Number(turretYawInput.current!.value)),
|
||||||
gunModelDefinition.pitch,
|
gunModelDefinition.pitch,
|
||||||
turretModelDefinition.yaw,
|
turretModelDefinition.yaw,
|
||||||
|
hasImprovedVerticalStabilizer,
|
||||||
);
|
);
|
||||||
modelTransformEvent.emit({ pitch, yaw });
|
modelTransformEvent.emit({ pitch, yaw });
|
||||||
mutateDuel((state) => {
|
mutateDuel((state) => {
|
||||||
state.protagonist!.pitch = pitch;
|
state.protagonist!.pitch = pitch;
|
||||||
state.protagonist!.yaw = yaw;
|
state.protagonist!.yaw = yaw;
|
||||||
});
|
});
|
||||||
turretYawInput.current!.value = `${Math.round(
|
turretYawInput.current!.value = radToDeg(protagonist.yaw).toFixed(
|
||||||
yaw * (180 / Math.PI),
|
1,
|
||||||
)}`;
|
);
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
if (event.key === 'Enter') {
|
if (event.key === 'Enter') {
|
||||||
@@ -94,13 +90,7 @@ export function RotationInputs({ isFullScreen }: RotationInputsProps) {
|
|||||||
ref={turretYawInput}
|
ref={turretYawInput}
|
||||||
style={{ textAlign: 'right' }}
|
style={{ textAlign: 'right' }}
|
||||||
/>
|
/>
|
||||||
<TextField.Slot
|
<TextField.Slot style={{ userSelect: 'none' }}>°</TextField.Slot>
|
||||||
style={{
|
|
||||||
userSelect: 'none',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
°
|
|
||||||
</TextField.Slot>
|
|
||||||
</TextField.Root>
|
</TextField.Root>
|
||||||
|
|
||||||
<TextField.Root
|
<TextField.Root
|
||||||
@@ -116,22 +106,24 @@ export function RotationInputs({ isFullScreen }: RotationInputsProps) {
|
|||||||
Pitch
|
Pitch
|
||||||
</TextField.Slot>
|
</TextField.Slot>
|
||||||
<TextField.Input
|
<TextField.Input
|
||||||
defaultValue={-Math.round(protagonist.pitch * (180 / Math.PI))}
|
|
||||||
onBlur={() => {
|
onBlur={() => {
|
||||||
const [pitch, yaw] = applyPitchYawLimits(
|
const [pitch, yaw] = applyPitchYawLimits(
|
||||||
-Number(gunPitchInput.current?.value) * (Math.PI / 180),
|
degToRad(
|
||||||
|
-Number(gunPitchInput.current!.value) + initialGunPitch,
|
||||||
|
),
|
||||||
protagonist.yaw,
|
protagonist.yaw,
|
||||||
gunModelDefinition.pitch,
|
gunModelDefinition.pitch,
|
||||||
turretModelDefinition.yaw,
|
turretModelDefinition.yaw,
|
||||||
|
hasImprovedVerticalStabilizer,
|
||||||
);
|
);
|
||||||
modelTransformEvent.emit({ pitch, yaw });
|
modelTransformEvent.emit({ pitch, yaw });
|
||||||
mutateDuel((state) => {
|
mutateDuel((state) => {
|
||||||
state.protagonist!.pitch = pitch;
|
state.protagonist!.pitch = pitch;
|
||||||
state.protagonist!.yaw = yaw;
|
state.protagonist!.yaw = yaw;
|
||||||
});
|
});
|
||||||
gunPitchInput.current!.value = `${Math.round(
|
gunPitchInput.current!.value = (
|
||||||
pitch * (180 / Math.PI),
|
-radToDeg(protagonist.pitch) + initialGunPitch
|
||||||
)}`;
|
).toFixed(1);
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
if (event.key === 'Enter') {
|
if (event.key === 'Enter') {
|
||||||
@@ -153,7 +145,7 @@ export function RotationInputs({ isFullScreen }: RotationInputsProps) {
|
|||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
{mode === 'armor' && (
|
{mode === 'armor' && (
|
||||||
<Flex gap="4">
|
<Flex gap="4" style={{ pointerEvents: 'auto' }}>
|
||||||
<QuickEquipmentButton
|
<QuickEquipmentButton
|
||||||
equipment={103}
|
equipment={103}
|
||||||
active={hasCalibratedShells}
|
active={hasCalibratedShells}
|
||||||
|
|||||||
@@ -1,32 +1,30 @@
|
|||||||
import { Color } from 'three';
|
import { useFrame, useLoader } from '@react-three/fiber';
|
||||||
import InfiniteGridHelper from '../../../../../components/InfiniteGridHelper';
|
import { clamp } from 'lodash';
|
||||||
|
import { useRef } from 'react';
|
||||||
|
import { MeshStandardMaterial, TextureLoader } from 'three';
|
||||||
import { useTankopediaPersistent } from '../../../../../stores/tankopedia';
|
import { useTankopediaPersistent } from '../../../../../stores/tankopedia';
|
||||||
|
|
||||||
export function SceneProps() {
|
export function SceneProps() {
|
||||||
const showGrid = useTankopediaPersistent(
|
const show = useTankopediaPersistent(
|
||||||
(state) => state.model.visual.showGrid,
|
(state) =>
|
||||||
);
|
state.model.visual.showGrid && !state.model.visual.showEnvironment,
|
||||||
const showEnvironment = useTankopediaPersistent(
|
|
||||||
(state) => state.model.visual.showEnvironment,
|
|
||||||
);
|
);
|
||||||
|
const texture = useLoader(TextureLoader, 'https://i.imgur.com/C28Z8nU.png');
|
||||||
|
const material = useRef<MeshStandardMaterial>(null);
|
||||||
|
|
||||||
if (!showGrid || showEnvironment) return null;
|
useFrame(({ camera }) => {
|
||||||
|
if (!material.current) return;
|
||||||
|
material.current.opacity = clamp(0.1 * camera.position.y, 0, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
texture.anisotropy = 2;
|
||||||
|
|
||||||
|
if (!show) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<mesh rotation={[-Math.PI / 2, 0, 0]}>
|
||||||
<InfiniteGridHelper
|
<planeGeometry args={[10, 10]} />
|
||||||
size1={1 / 5}
|
<meshStandardMaterial ref={material} map={texture} transparent />
|
||||||
size2={1}
|
</mesh>
|
||||||
distance={20}
|
|
||||||
color={new Color('#ffffff')}
|
|
||||||
/>
|
|
||||||
<InfiniteGridHelper
|
|
||||||
position={[0, 1e-4, 0]}
|
|
||||||
size1={0}
|
|
||||||
size2={100}
|
|
||||||
distance={25}
|
|
||||||
color={new Color('red')}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { UpdateIcon } from '@radix-ui/react-icons';
|
import { UpdateIcon } from '@radix-ui/react-icons';
|
||||||
import { Button, Dialog, Flex, Heading } from '@radix-ui/themes';
|
import { Button, Dialog, Flex, Heading } from '@radix-ui/themes';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { TREE_TYPE_ICONS } from '../../../../../components/Tanks';
|
import { TREE_TYPE_ICONS } from '../../../../../components/Tanks/components/Item/constants';
|
||||||
import { assignDuelMember } from '../../../../../core/blitzkrieg/assignDuelMember';
|
import { assignDuelMember } from '../../../../../core/blitzkrieg/assignDuelMember';
|
||||||
import { pushTankopediaPath } from '../../../../../core/blitzkrieg/pushTankopediaPath';
|
import { pushTankopediaPath } from '../../../../../core/blitzkrieg/pushTankopediaPath';
|
||||||
import { useDuel } from '../../../../../stores/duel';
|
import { useDuel } from '../../../../../stores/duel';
|
||||||
@@ -30,7 +30,7 @@ export function Title() {
|
|||||||
<img
|
<img
|
||||||
src={
|
src={
|
||||||
TREE_TYPE_ICONS[protagonist.tank.treeType][
|
TREE_TYPE_ICONS[protagonist.tank.treeType][
|
||||||
protagonist.tank.type
|
protagonist.tank.class
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
};
|
};
|
||||||
}, [initialId, assigned]);
|
}, [initialId, assigned]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageWrapper color="purple" size="double">
|
<PageWrapper color="purple" size="double">
|
||||||
{assigned && (
|
{assigned && (
|
||||||
|
|||||||
+2
-4
@@ -1,9 +1,7 @@
|
|||||||
import { Button, Flex, Text } from '@radix-ui/themes';
|
import { Button, Flex, Text } from '@radix-ui/themes';
|
||||||
import { SmallTankIcon } from '../../../../../../components/SmallTankIcon';
|
import { SmallTankIcon } from '../../../../../../components/SmallTankIcon';
|
||||||
import {
|
import { TankDefinition } from '../../../../../../core/blitzkrieg/tankDefinitions';
|
||||||
TIER_ROMAN_NUMERALS,
|
import { TIER_ROMAN_NUMERALS } from '../../../../../../core/blitzkrieg/tankDefinitions/constants';
|
||||||
TankDefinition,
|
|
||||||
} from '../../../../../../core/blitzkrieg/tankDefinitions';
|
|
||||||
|
|
||||||
interface CompactSearchResultRowProps {
|
interface CompactSearchResultRowProps {
|
||||||
tanks: TankDefinition[];
|
tanks: TankDefinition[];
|
||||||
|
|||||||
@@ -4,17 +4,18 @@ import { CaretDownIcon } from '@radix-ui/react-icons';
|
|||||||
import { Button, DropdownMenu, Flex } from '@radix-ui/themes';
|
import { Button, DropdownMenu, Flex } from '@radix-ui/themes';
|
||||||
import { use } from 'react';
|
import { use } from 'react';
|
||||||
import { Flag } from '../../../../../../../components/Flag';
|
import { Flag } from '../../../../../../../components/Flag';
|
||||||
|
import {} from '../../../../../../../components/Tanks';
|
||||||
import {
|
import {
|
||||||
TANK_TYPES,
|
TANK_CLASSES,
|
||||||
TREE_TYPES,
|
TREE_TYPES,
|
||||||
TREE_TYPE_ICONS,
|
TREE_TYPE_ICONS,
|
||||||
TREE_TYPE_IMAGES,
|
TREE_TYPE_IMAGES,
|
||||||
} from '../../../../../../../components/Tanks';
|
} from '../../../../../../../components/Tanks/components/Item/constants';
|
||||||
|
import { NATIONS } from '../../../../../../../core/blitzkrieg/tankDefinitions';
|
||||||
import {
|
import {
|
||||||
NATIONS,
|
|
||||||
TIERS,
|
TIERS,
|
||||||
TIER_ROMAN_NUMERALS,
|
TIER_ROMAN_NUMERALS,
|
||||||
} from '../../../../../../../core/blitzkrieg/tankDefinitions';
|
} from '../../../../../../../core/blitzkrieg/tankDefinitions/constants';
|
||||||
import mutateTankopediaPersistent, {
|
import mutateTankopediaPersistent, {
|
||||||
TankopediaTestTankDisplay,
|
TankopediaTestTankDisplay,
|
||||||
useTankopediaPersistent,
|
useTankopediaPersistent,
|
||||||
@@ -121,7 +122,7 @@ export function Options() {
|
|||||||
))}
|
))}
|
||||||
</Flex>
|
</Flex>
|
||||||
<Flex>
|
<Flex>
|
||||||
{[...TANK_TYPES].map((type, index) => (
|
{[...TANK_CLASSES].map((type, index) => (
|
||||||
<Button
|
<Button
|
||||||
key={type}
|
key={type}
|
||||||
color={filters.types.includes(type) ? undefined : 'gray'}
|
color={filters.types.includes(type) ? undefined : 'gray'}
|
||||||
@@ -132,9 +133,9 @@ export function Options() {
|
|||||||
borderTopLeftRadius: index === 0 ? undefined : 0,
|
borderTopLeftRadius: index === 0 ? undefined : 0,
|
||||||
borderBottomLeftRadius: index === 0 ? undefined : 0,
|
borderBottomLeftRadius: index === 0 ? undefined : 0,
|
||||||
borderTopRightRadius:
|
borderTopRightRadius:
|
||||||
index === TANK_TYPES.length - 1 ? undefined : 0,
|
index === TANK_CLASSES.length - 1 ? undefined : 0,
|
||||||
borderBottomRightRadius:
|
borderBottomRightRadius:
|
||||||
index === TANK_TYPES.length - 1 ? undefined : 0,
|
index === TANK_CLASSES.length - 1 ? undefined : 0,
|
||||||
}}
|
}}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
mutateTankopediaPersistent((draft) => {
|
mutateTankopediaPersistent((draft) => {
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ import {
|
|||||||
} from '@radix-ui/themes';
|
} from '@radix-ui/themes';
|
||||||
import { go } from 'fuzzysort';
|
import { go } from 'fuzzysort';
|
||||||
import { use, useEffect, useMemo, useRef, useState } from 'react';
|
import { use, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { TankType, TreeType } from '../../../../../components/Tanks';
|
import { TreeType } from '../../../../../components/Tanks';
|
||||||
|
import { TANK_CLASSES } from '../../../../../components/Tanks/components/Item/constants';
|
||||||
import { resolveNearPenetration } from '../../../../../core/blitz/resolveNearPenetration';
|
import { resolveNearPenetration } from '../../../../../core/blitz/resolveNearPenetration';
|
||||||
import { asset } from '../../../../../core/blitzkrieg/asset';
|
import { asset } from '../../../../../core/blitzkrieg/asset';
|
||||||
import { modelDefinitions } from '../../../../../core/blitzkrieg/modelDefinitions';
|
import { modelDefinitions } from '../../../../../core/blitzkrieg/modelDefinitions';
|
||||||
@@ -24,13 +25,15 @@ import { resolveDpm } from '../../../../../core/blitzkrieg/resolveDpm';
|
|||||||
import { resolveReload } from '../../../../../core/blitzkrieg/resolveReload';
|
import { resolveReload } from '../../../../../core/blitzkrieg/resolveReload';
|
||||||
import {
|
import {
|
||||||
NATIONS,
|
NATIONS,
|
||||||
|
TankDefinition,
|
||||||
|
tanksDefinitionsArray,
|
||||||
|
} from '../../../../../core/blitzkrieg/tankDefinitions';
|
||||||
|
import {
|
||||||
TANK_ICONS,
|
TANK_ICONS,
|
||||||
TANK_ICONS_COLLECTOR,
|
TANK_ICONS_COLLECTOR,
|
||||||
TANK_ICONS_PREMIUM,
|
TANK_ICONS_PREMIUM,
|
||||||
TIER_ROMAN_NUMERALS,
|
TIER_ROMAN_NUMERALS,
|
||||||
TankDefinition,
|
} from '../../../../../core/blitzkrieg/tankDefinitions/constants';
|
||||||
tanksDefinitionsArray,
|
|
||||||
} from '../../../../../core/blitzkrieg/tankDefinitions';
|
|
||||||
import { tankIcon } from '../../../../../core/blitzkrieg/tankIcon';
|
import { tankIcon } from '../../../../../core/blitzkrieg/tankIcon';
|
||||||
import { unionBoundingBox } from '../../../../../core/blitzkrieg/unionBoundingBox';
|
import { unionBoundingBox } from '../../../../../core/blitzkrieg/unionBoundingBox';
|
||||||
import { theme } from '../../../../../stitches.config';
|
import { theme } from '../../../../../stitches.config';
|
||||||
@@ -49,7 +52,6 @@ interface TankSearchProps {
|
|||||||
onSelect?: (tank: TankDefinition) => void;
|
onSelect?: (tank: TankDefinition) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tankTypeOrder: TankType[] = ['light', 'medium', 'heavy', 'tankDestroyer'];
|
|
||||||
const treeTypeOrder: TreeType[] = ['researchable', 'premium', 'collector'];
|
const treeTypeOrder: TreeType[] = ['researchable', 'premium', 'collector'];
|
||||||
|
|
||||||
export function TankSearch({ compact, onSelect = () => {} }: TankSearchProps) {
|
export function TankSearch({ compact, onSelect = () => {} }: TankSearchProps) {
|
||||||
@@ -70,7 +72,7 @@ export function TankSearch({ compact, onSelect = () => {} }: TankSearchProps) {
|
|||||||
)
|
)
|
||||||
.sort(
|
.sort(
|
||||||
(a, b) =>
|
(a, b) =>
|
||||||
(tankTypeOrder.indexOf(a.type) - tankTypeOrder.indexOf(b.type)) *
|
(TANK_CLASSES.indexOf(a.class) - TANK_CLASSES.indexOf(b.class)) *
|
||||||
(sort.direction === 'descending' ? -1 : 1),
|
(sort.direction === 'descending' ? -1 : 1),
|
||||||
)
|
)
|
||||||
.sort(
|
.sort(
|
||||||
@@ -89,7 +91,7 @@ export function TankSearch({ compact, onSelect = () => {} }: TankSearchProps) {
|
|||||||
: filters.tiers.includes(tank.tier)) &&
|
: filters.tiers.includes(tank.tier)) &&
|
||||||
(filters.types.length === 0
|
(filters.types.length === 0
|
||||||
? true
|
? true
|
||||||
: filters.types.includes(tank.type)) &&
|
: filters.types.includes(tank.class)) &&
|
||||||
(filters.treeTypes.length === 0
|
(filters.treeTypes.length === 0
|
||||||
? true
|
? true
|
||||||
: filters.treeTypes.includes(tank.treeType)) &&
|
: filters.treeTypes.includes(tank.treeType)) &&
|
||||||
@@ -844,7 +846,7 @@ export function TankSearch({ compact, onSelect = () => {} }: TankSearchProps) {
|
|||||||
? TANK_ICONS_COLLECTOR
|
? TANK_ICONS_COLLECTOR
|
||||||
: tank.treeType === 'premium'
|
: tank.treeType === 'premium'
|
||||||
? TANK_ICONS_PREMIUM
|
? TANK_ICONS_PREMIUM
|
||||||
: TANK_ICONS)[tank.type]
|
: TANK_ICONS)[tank.class]
|
||||||
}
|
}
|
||||||
style={{ width: '1em', height: '1em' }}
|
style={{ width: '1em', height: '1em' }}
|
||||||
/>
|
/>
|
||||||
|
|||||||
+54
-52
@@ -1,67 +1,69 @@
|
|||||||
import {
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
SlashCommandBuilder,
|
import { translator } from '../core/localization/translator';
|
||||||
SlashCommandSubcommandsOnlyBuilder,
|
|
||||||
} from 'discord.js';
|
|
||||||
import { COMMANDS_RAW, CommandRegistry } from '../events/interactionCreate';
|
import { COMMANDS_RAW, CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|
||||||
const RAW_PATH = `https://raw.githubusercontent.com/tresabhi/blitzkrieg/main/docs/`;
|
const subcommands = [
|
||||||
const DOCS = {
|
'embeds',
|
||||||
|
'introduction',
|
||||||
|
'invite',
|
||||||
|
'timezones',
|
||||||
|
'creators',
|
||||||
|
] as const;
|
||||||
|
type Subcommand = (typeof subcommands)[number];
|
||||||
|
|
||||||
|
const DOCS: Record<Subcommand, string> = {
|
||||||
embeds: 'guide/embeds',
|
embeds: 'guide/embeds',
|
||||||
introduction: 'guide/introduction',
|
introduction: 'guide/introduction',
|
||||||
invite: 'guide/invite',
|
invite: 'guide/invite',
|
||||||
timezones: 'guide/timezones',
|
timezones: 'guide/timezones',
|
||||||
creators: 'guide/creators',
|
creators: 'guide/creators',
|
||||||
};
|
};
|
||||||
const DOC_DESCRIPTIONS: Record<keyof typeof DOCS, string> = {
|
|
||||||
embeds: 'How embeds work',
|
|
||||||
introduction: 'About the bot',
|
|
||||||
invite: 'How to invite the bot',
|
|
||||||
timezones: 'How Blitzkrieg infers and uses your timezone',
|
|
||||||
creators: 'Who created the bot',
|
|
||||||
};
|
|
||||||
|
|
||||||
function addDocsSubcommands(option: SlashCommandSubcommandsOnlyBuilder) {
|
export const aboutCommand = new Promise<CommandRegistry>(async (resolve) => {
|
||||||
Object.entries(DOC_DESCRIPTIONS).forEach(([key, value]) => {
|
resolve({
|
||||||
option.addSubcommand((sub) => sub.setName(key).setDescription(value));
|
inProduction: true,
|
||||||
});
|
inPublic: true,
|
||||||
|
|
||||||
return option;
|
command: createLocalizedCommand('about', [
|
||||||
}
|
{ subcommand: 'commands' },
|
||||||
|
...subcommands.map((subcommand) => ({ subcommand })),
|
||||||
|
]),
|
||||||
|
|
||||||
export const aboutCommand: CommandRegistry = {
|
async handler(interaction) {
|
||||||
inProduction: true,
|
const subcommand = interaction.options.getSubcommand();
|
||||||
inPublic: true,
|
const { t } = translator(interaction.locale);
|
||||||
|
|
||||||
command: addDocsSubcommands(
|
if (subcommand === 'commands') {
|
||||||
new SlashCommandBuilder()
|
return t`bot.commands.about.subcommands.commands.body${(
|
||||||
.setName('about')
|
await Promise.all(COMMANDS_RAW)
|
||||||
.setDescription('All the info you need about the bot')
|
|
||||||
.addSubcommand((option) =>
|
|
||||||
option
|
|
||||||
.setName('commands')
|
|
||||||
.setDescription('List of all commands and their descriptions'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
async handler(interaction) {
|
|
||||||
const subcommand = interaction.options.getSubcommand();
|
|
||||||
|
|
||||||
if (subcommand === 'commands') {
|
|
||||||
return `# Commands\n\nBlitzkrieg offers the following commands:\n\n${(
|
|
||||||
await Promise.all(COMMANDS_RAW)
|
|
||||||
)
|
|
||||||
.filter((registry) => registry.inPublic && registry.inProduction)
|
|
||||||
.sort((a, b) => (a.command.name < b.command.name ? -1 : 1))
|
|
||||||
.map(
|
|
||||||
(registry) =>
|
|
||||||
`- \`/${registry.command.name}\`: ${registry.command.description}`,
|
|
||||||
)
|
)
|
||||||
.join('\n')}`;
|
.filter((registry) => registry.inPublic && registry.inProduction)
|
||||||
}
|
.sort((a, b) =>
|
||||||
|
(a.command.name_localizations?.[interaction.locale] ??
|
||||||
|
a.command.name) <
|
||||||
|
(b.command.name_localizations?.[interaction.locale] ??
|
||||||
|
b.command.name)
|
||||||
|
? -1
|
||||||
|
: 1,
|
||||||
|
)
|
||||||
|
.map(
|
||||||
|
(registry) =>
|
||||||
|
`- \`/${
|
||||||
|
registry.command.name_localizations?.[interaction.locale] ??
|
||||||
|
registry.command.name
|
||||||
|
}\`: ${
|
||||||
|
registry.command.description_localizations?.[
|
||||||
|
interaction.locale
|
||||||
|
] ?? registry.command.description
|
||||||
|
}`,
|
||||||
|
)
|
||||||
|
.join('\n')}`;
|
||||||
|
}
|
||||||
|
|
||||||
const url = `${RAW_PATH}${DOCS[subcommand as keyof typeof DOCS]}.md`;
|
const url = `https://raw.githubusercontent.com/tresabhi/blitzkrieg/main/docs/${DOCS[subcommand as Subcommand]}.md`;
|
||||||
const content = fetch(url).then((response) => response.text());
|
const content = fetch(url).then((response) => response.text());
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
import { getBlitzStarsLinkButton } from '../../core/blitzstars/getBlitzStarsLinkButton';
|
||||||
|
import addPeriodicFilterOptions from '../../core/discord/addPeriodicFilterOptions';
|
||||||
|
import addUsernameChoices from '../../core/discord/addUsernameChoices';
|
||||||
|
import autocompleteTanks from '../../core/discord/autocompleteTanks';
|
||||||
|
import autocompleteUsername from '../../core/discord/autocompleteUsername';
|
||||||
|
import { buttonRefresh } from '../../core/discord/buttonRefresh';
|
||||||
|
import commandToURL from '../../core/discord/commandToURL';
|
||||||
|
import { createLocalizedCommand } from '../../core/discord/createLocalizedCommand';
|
||||||
|
import { getCustomPeriodParams } from '../../core/discord/getCustomPeriodParams';
|
||||||
|
import { getFiltersFromButton } from '../../core/discord/getFiltersFromButton';
|
||||||
|
import { getFiltersFromCommand } from '../../core/discord/getFiltersFromCommand';
|
||||||
|
import resolvePeriodFromButton from '../../core/discord/resolvePeriodFromButton';
|
||||||
|
import resolvePeriodFromCommand from '../../core/discord/resolvePeriodFromCommand';
|
||||||
|
import resolvePlayerFromButton from '../../core/discord/resolvePlayerFromButton';
|
||||||
|
import resolvePlayerFromCommand from '../../core/discord/resolvePlayerFromCommand';
|
||||||
|
import { CommandRegistry } from '../../events/interactionCreate';
|
||||||
|
import { renderBreakdown } from './render';
|
||||||
|
|
||||||
|
export const breakdownCommand = new Promise<CommandRegistry>(
|
||||||
|
async (resolve) => {
|
||||||
|
resolve({
|
||||||
|
inProduction: true,
|
||||||
|
inPublic: true,
|
||||||
|
|
||||||
|
command: await addPeriodicFilterOptions(
|
||||||
|
createLocalizedCommand('breakdown'),
|
||||||
|
(option) => option.addStringOption(addUsernameChoices),
|
||||||
|
),
|
||||||
|
|
||||||
|
async handler(interaction) {
|
||||||
|
const player = await resolvePlayerFromCommand(interaction);
|
||||||
|
const period = resolvePeriodFromCommand(player.region, interaction);
|
||||||
|
const filters = await getFiltersFromCommand(interaction);
|
||||||
|
const path = commandToURL(interaction, {
|
||||||
|
...player,
|
||||||
|
...getCustomPeriodParams(interaction),
|
||||||
|
...filters,
|
||||||
|
});
|
||||||
|
|
||||||
|
return [
|
||||||
|
...(await renderBreakdown(
|
||||||
|
player,
|
||||||
|
period,
|
||||||
|
filters,
|
||||||
|
interaction.locale,
|
||||||
|
)),
|
||||||
|
buttonRefresh(interaction, path),
|
||||||
|
await getBlitzStarsLinkButton(player.region, player.id),
|
||||||
|
];
|
||||||
|
},
|
||||||
|
|
||||||
|
autocomplete: (interaction) => {
|
||||||
|
autocompleteUsername(interaction);
|
||||||
|
autocompleteTanks(interaction);
|
||||||
|
},
|
||||||
|
|
||||||
|
async button(interaction) {
|
||||||
|
const player = await resolvePlayerFromButton(interaction);
|
||||||
|
const period = resolvePeriodFromButton(player.region, interaction);
|
||||||
|
const filters = getFiltersFromButton(interaction);
|
||||||
|
|
||||||
|
return await renderBreakdown(
|
||||||
|
player,
|
||||||
|
period,
|
||||||
|
filters,
|
||||||
|
interaction.locale,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
@@ -1,41 +1,25 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { Locale } from 'discord.js';
|
||||||
import { chunk } from 'lodash';
|
import { chunk } from 'lodash';
|
||||||
import * as Breakdown from '../components/Breakdown';
|
import * as Breakdown from '../../components/Breakdown';
|
||||||
import NoData, { NoDataType } from '../components/NoData';
|
import CommandWrapper from '../../components/CommandWrapper';
|
||||||
import TitleBar from '../components/TitleBar';
|
import NoData from '../../components/NoData';
|
||||||
import Wrapper from '../components/Wrapper';
|
import TitleBar from '../../components/TitleBar';
|
||||||
import { AllStats, getAccountInfo } from '../core/blitz/getAccountInfo';
|
import { AllStats, getAccountInfo } from '../../core/blitz/getAccountInfo';
|
||||||
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
import { getClanAccountInfo } from '../../core/blitz/getClanAccountInfo';
|
||||||
import getTankStats from '../core/blitz/getTankStats';
|
import getTankStats from '../../core/blitz/getTankStats';
|
||||||
import { filtersToDescription } from '../core/blitzkrieg/filtersToDescription';
|
import { filtersToDescription } from '../../core/blitzkrieg/filtersToDescription';
|
||||||
import {
|
import {
|
||||||
TankDefinition,
|
TankDefinition,
|
||||||
tankDefinitions,
|
tankDefinitions,
|
||||||
} from '../core/blitzkrieg/tankDefinitions';
|
} from '../../core/blitzkrieg/tankDefinitions';
|
||||||
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
import getStatsInPeriod from '../../core/blitzstars/getStatsInPeriod';
|
||||||
import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod';
|
import { tankAverages } from '../../core/blitzstars/tankAverages';
|
||||||
import { tankAverages } from '../core/blitzstars/tankAverages';
|
import { ResolvedPeriod } from '../../core/discord/resolvePeriodFromCommand';
|
||||||
import addPeriodicFilterOptions from '../core/discord/addPeriodicFilterOptions';
|
import { ResolvedPlayer } from '../../core/discord/resolvePlayerFromCommand';
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import { translator } from '../../core/localization/translator';
|
||||||
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
import calculateWN8 from '../../core/statistics/calculateWN8';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import { StatFilters, filterStats } from '../../core/statistics/filterStats';
|
||||||
import buttonPrimary from '../core/discord/buttonPrimary';
|
import getWN8Percentile from '../../core/statistics/getWN8Percentile';
|
||||||
import commandToURL from '../core/discord/commandToURL';
|
|
||||||
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
|
||||||
import { getFiltersFromButton } from '../core/discord/getFiltersFromButton';
|
|
||||||
import { getFiltersFromCommand } from '../core/discord/getFiltersFromCommand';
|
|
||||||
import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
|
||||||
import resolvePeriodFromCommand, {
|
|
||||||
ResolvedPeriod,
|
|
||||||
} from '../core/discord/resolvePeriodFromCommand';
|
|
||||||
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
|
||||||
import resolvePlayerFromCommand, {
|
|
||||||
ResolvedPlayer,
|
|
||||||
} from '../core/discord/resolvePlayerFromCommand';
|
|
||||||
import calculateWN8 from '../core/statistics/calculateWN8';
|
|
||||||
import { StatFilters, filterStats } from '../core/statistics/filterStats';
|
|
||||||
import getWN8Percentile from '../core/statistics/getWN8Percentile';
|
|
||||||
import { CommandRegistryPromisable } from '../events/interactionCreate';
|
|
||||||
|
|
||||||
const ROWS_PER_PAGE = 8;
|
const ROWS_PER_PAGE = 8;
|
||||||
const MAX_PAGES = 9;
|
const MAX_PAGES = 9;
|
||||||
@@ -44,15 +28,17 @@ export async function renderBreakdown(
|
|||||||
{ region, id }: ResolvedPlayer,
|
{ region, id }: ResolvedPlayer,
|
||||||
{ start, end, name }: ResolvedPeriod,
|
{ start, end, name }: ResolvedPeriod,
|
||||||
filters: StatFilters,
|
filters: StatFilters,
|
||||||
|
locale: Locale,
|
||||||
) {
|
) {
|
||||||
|
const { t, translate } = translator(locale);
|
||||||
const awaitedTankDefinitions = await tankDefinitions;
|
const awaitedTankDefinitions = await tankDefinitions;
|
||||||
const awaitedTankAverages = await tankAverages;
|
const awaitedTankAverages = await tankAverages;
|
||||||
const statsInPeriod = await getStatsInPeriod(region, id, start, end);
|
const statsInPeriod = await getStatsInPeriod(region, id, start, end, locale);
|
||||||
const { filteredOrder } = await filterStats(statsInPeriod, filters);
|
const { filteredOrder } = await filterStats(statsInPeriod, filters);
|
||||||
const accountInfo = await getAccountInfo(region, id);
|
const accountInfo = await getAccountInfo(region, id);
|
||||||
const clanData = await getClanAccountInfo(region, id, ['clan']);
|
const clanData = await getClanAccountInfo(region, id, ['clan']);
|
||||||
const tankStats = await getTankStats(region, id);
|
const tankStats = await getTankStats(region, id, locale);
|
||||||
const filterDescriptions = await filtersToDescription(filters);
|
const filterDescriptions = await filtersToDescription(filters, locale);
|
||||||
const orderedCurrentStats: AllStats[] = [];
|
const orderedCurrentStats: AllStats[] = [];
|
||||||
const orderedCareerStats: AllStats[] = [];
|
const orderedCareerStats: AllStats[] = [];
|
||||||
const orderedCurrentWN8: (number | undefined)[] = [];
|
const orderedCurrentWN8: (number | undefined)[] = [];
|
||||||
@@ -144,21 +130,21 @@ export async function renderBreakdown(
|
|||||||
<Breakdown.Row
|
<Breakdown.Row
|
||||||
key={id}
|
key={id}
|
||||||
type="summary"
|
type="summary"
|
||||||
title="Total"
|
title={t`bot.commands.breakdown.body.total`}
|
||||||
stats={[
|
stats={[
|
||||||
{
|
{
|
||||||
title: 'Battles',
|
title: t`bot.commands.breakdown.body.battles`,
|
||||||
current: currentBattles,
|
current: currentBattles,
|
||||||
career: careerBattles,
|
career: careerBattles,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Winrate',
|
title: t`bot.commands.breakdown.body.winrate`,
|
||||||
current: `${(100 * currentWinrate).toFixed(2)}%`,
|
current: `${(100 * currentWinrate).toFixed(2)}%`,
|
||||||
career: `${(100 * careerWinrate).toFixed(2)}%`,
|
career: `${(100 * careerWinrate).toFixed(2)}%`,
|
||||||
delta: currentWinrate - careerWinrate,
|
delta: currentWinrate - careerWinrate,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'WN8',
|
title: t`bot.commands.breakdown.body.wn8`,
|
||||||
current:
|
current:
|
||||||
currentWN8 === undefined
|
currentWN8 === undefined
|
||||||
? undefined
|
? undefined
|
||||||
@@ -173,7 +159,7 @@ export async function renderBreakdown(
|
|||||||
: getWN8Percentile(currentWN8),
|
: getWN8Percentile(currentWN8),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Damage',
|
title: t`bot.commands.breakdown.body.damage`,
|
||||||
current: Math.round(currentDamage).toLocaleString(),
|
current: Math.round(currentDamage).toLocaleString(),
|
||||||
career: Math.round(careerDamage).toLocaleString(),
|
career: Math.round(careerDamage).toLocaleString(),
|
||||||
delta: currentDamage - careerDamage,
|
delta: currentDamage - careerDamage,
|
||||||
@@ -195,17 +181,20 @@ export async function renderBreakdown(
|
|||||||
<Breakdown.Row
|
<Breakdown.Row
|
||||||
key={id}
|
key={id}
|
||||||
type="tank"
|
type="tank"
|
||||||
tankType={tankDefinition?.type}
|
tankType={tankDefinition?.class}
|
||||||
treeType={tankDefinition?.treeType}
|
treeType={tankDefinition?.treeType}
|
||||||
title={tankDefinition?.name ?? `Unknown tank ${id}`}
|
title={
|
||||||
|
tankDefinition?.name ??
|
||||||
|
translate('bot.commands.breakdown.body.unknown_tank', [`${id}`])
|
||||||
|
}
|
||||||
stats={[
|
stats={[
|
||||||
{
|
{
|
||||||
title: 'Battles',
|
title: t`bot.commands.breakdown.body.battles`,
|
||||||
current: current.battles.toLocaleString(),
|
current: current.battles.toLocaleString(),
|
||||||
career: career.battles.toLocaleString(),
|
career: career.battles.toLocaleString(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Winrate',
|
title: t`bot.commands.breakdown.body.winrate`,
|
||||||
current: `${(100 * (current.wins / current.battles)).toFixed(
|
current: `${(100 * (current.wins / current.battles)).toFixed(
|
||||||
2,
|
2,
|
||||||
)}%`,
|
)}%`,
|
||||||
@@ -214,7 +203,7 @@ export async function renderBreakdown(
|
|||||||
current.wins / current.battles - career.wins / career.battles,
|
current.wins / current.battles - career.wins / career.battles,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'WN8',
|
title: t`bot.commands.breakdown.body.wn8`,
|
||||||
current:
|
current:
|
||||||
currentWN8 === undefined
|
currentWN8 === undefined
|
||||||
? undefined
|
? undefined
|
||||||
@@ -229,7 +218,7 @@ export async function renderBreakdown(
|
|||||||
: getWN8Percentile(currentWN8),
|
: getWN8Percentile(currentWN8),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Damage',
|
title: t`bot.commands.breakdown.body.damage`,
|
||||||
current: Math.round(
|
current: Math.round(
|
||||||
current.damage_dealt / current.battles,
|
current.damage_dealt / current.battles,
|
||||||
).toLocaleString(),
|
).toLocaleString(),
|
||||||
@@ -254,10 +243,10 @@ export async function renderBreakdown(
|
|||||||
if (filteredOrder.length > 0) {
|
if (filteredOrder.length > 0) {
|
||||||
return pages
|
return pages
|
||||||
.map((page, index) => (
|
.map((page, index) => (
|
||||||
<Wrapper>
|
<CommandWrapper>
|
||||||
{index === 0 && (
|
{index === 0 && (
|
||||||
<TitleBar
|
<TitleBar
|
||||||
name={accountInfo.nickname}
|
title={accountInfo.nickname}
|
||||||
image={
|
image={
|
||||||
clanData?.clan
|
clanData?.clan
|
||||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData?.clan?.emblem_set_id}.png`
|
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData?.clan?.emblem_set_id}.png`
|
||||||
@@ -268,14 +257,14 @@ export async function renderBreakdown(
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<Breakdown.Root>{page}</Breakdown.Root>
|
<Breakdown.Root>{page}</Breakdown.Root>
|
||||||
</Wrapper>
|
</CommandWrapper>
|
||||||
))
|
))
|
||||||
.reverse();
|
.reverse();
|
||||||
} else {
|
} else {
|
||||||
return [
|
return [
|
||||||
<Wrapper>
|
<CommandWrapper>
|
||||||
<TitleBar
|
<TitleBar
|
||||||
name={accountInfo.nickname}
|
title={accountInfo.nickname}
|
||||||
image={
|
image={
|
||||||
clanData?.clan
|
clanData?.clan
|
||||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData?.clan?.emblem_set_id}.png`
|
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData?.clan?.emblem_set_id}.png`
|
||||||
@@ -284,56 +273,8 @@ export async function renderBreakdown(
|
|||||||
description={`${name} • ${filterDescriptions}`}
|
description={`${name} • ${filterDescriptions}`}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<NoData type={NoDataType.BattlesInPeriod} />
|
<NoData type="battles_in_period" locale={locale} />
|
||||||
</Wrapper>,
|
</CommandWrapper>,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const breakdownCommand = new Promise<CommandRegistryPromisable>(
|
|
||||||
async (resolve) => {
|
|
||||||
const command = await addPeriodicFilterOptions(
|
|
||||||
new SlashCommandBuilder()
|
|
||||||
.setName('breakdown')
|
|
||||||
.setDescription("A period's breakdown by tanks played"),
|
|
||||||
(option) => option.addStringOption(addUsernameChoices),
|
|
||||||
);
|
|
||||||
|
|
||||||
resolve({
|
|
||||||
inProduction: true,
|
|
||||||
inPublic: true,
|
|
||||||
|
|
||||||
command,
|
|
||||||
|
|
||||||
async handler(interaction) {
|
|
||||||
const player = await resolvePlayerFromCommand(interaction);
|
|
||||||
const period = resolvePeriodFromCommand(player.region, interaction);
|
|
||||||
const filters = await getFiltersFromCommand(interaction);
|
|
||||||
const path = commandToURL(interaction, {
|
|
||||||
...player,
|
|
||||||
...getCustomPeriodParams(interaction),
|
|
||||||
...filters,
|
|
||||||
});
|
|
||||||
|
|
||||||
return [
|
|
||||||
...(await renderBreakdown(player, period, filters)),
|
|
||||||
buttonPrimary(path, 'Refresh'),
|
|
||||||
await getBlitzStarsLinkButton(player.region, player.id),
|
|
||||||
];
|
|
||||||
},
|
|
||||||
|
|
||||||
autocomplete: (interaction) => {
|
|
||||||
autocompleteUsername(interaction);
|
|
||||||
autocompleteTanks(interaction);
|
|
||||||
},
|
|
||||||
|
|
||||||
async button(interaction) {
|
|
||||||
const player = await resolvePlayerFromButton(interaction);
|
|
||||||
const period = resolvePeriodFromButton(player.region, interaction);
|
|
||||||
const filters = getFiltersFromButton(interaction);
|
|
||||||
|
|
||||||
return await renderBreakdown(player, period, filters);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
+32
-28
@@ -1,36 +1,40 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
|
||||||
import packageJSON from '../../package.json' assert { type: 'json' };
|
import packageJSON from '../../package.json' assert { type: 'json' };
|
||||||
import { client } from '../core/discord/client';
|
import { client } from '../core/discord/client';
|
||||||
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
|
import { translator } from '../core/localization/translator';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|
||||||
const executionStart = new Date().getTime();
|
const executionStart = new Date().getTime();
|
||||||
|
|
||||||
export const debugCommand: CommandRegistry = {
|
export const debugCommand = new Promise<CommandRegistry>((resolve) => {
|
||||||
inProduction: true,
|
resolve({
|
||||||
inPublic: true,
|
inProduction: true,
|
||||||
|
inPublic: true,
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
command: createLocalizedCommand('debug'),
|
||||||
.setName('debug')
|
|
||||||
.setDescription('Debug information about the bot'),
|
|
||||||
|
|
||||||
async handler() {
|
async handler(interaction) {
|
||||||
const currentTime = new Date().getTime();
|
const { t } = translator(interaction.locale);
|
||||||
const uptime = currentTime - executionStart;
|
const currentTime = new Date().getTime();
|
||||||
const list = [
|
const uptime = currentTime - executionStart;
|
||||||
['Version', packageJSON.version],
|
const list = [
|
||||||
['Shard', client.shard?.ids[0] ?? 'default'],
|
[t`bot.commands.debug.body.version`, packageJSON.version],
|
||||||
[
|
[
|
||||||
'Uptime',
|
t`bot.commands.debug.body.shard`,
|
||||||
`${Math.floor((uptime / 1000 / 60 / 60) % 24)}h ${Math.floor(
|
client.shard?.ids[0] ?? t`bot.commands.debug.body.shard.default`,
|
||||||
(uptime / 1000 / 60) % 60,
|
],
|
||||||
)}m ${Math.floor((uptime / 1000) % 60)}s ${Math.floor(
|
[
|
||||||
uptime % 1000,
|
t`bot.commands.debug.body.uptime`,
|
||||||
)}ms`,
|
`${Math.floor((uptime / 1000 / 60 / 60) % 24)}h ${Math.floor(
|
||||||
],
|
(uptime / 1000 / 60) % 60,
|
||||||
]
|
)}m ${Math.floor((uptime / 1000) % 60)}s ${Math.floor(
|
||||||
.map(([key, value]) => `- ${key}: ${value}`)
|
uptime % 1000,
|
||||||
.join('\n');
|
)}ms`,
|
||||||
|
],
|
||||||
return `# Debug\n\n${list}`;
|
];
|
||||||
},
|
return t`bot.commands.debug.body.title${list
|
||||||
};
|
.map(([key, value]) => `- ${key}: ${value}`)
|
||||||
|
.join('\n')}`;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
+185
-178
@@ -1,198 +1,205 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
// _____ _____ _ _ _ _ _____ ____ __ __ ______ ____ _____ _ __
|
||||||
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
// |_ _| / ____| | | | /\ | | | | / ____/ __ \| \/ | ____| | _ \ /\ / ____| |/ /
|
||||||
import getPeriodNow from '../core/blitzkrieg/getPeriodNow';
|
// | | | (___ | |__| | / \ | | | | | | | | | | \ / | |__ | |_) | / \ | | | ' /
|
||||||
import getTimeDaysAgo from '../core/blitzkrieg/getTimeDaysAgo';
|
// | | \___ \| __ | / /\ \ | | | | | | | | | | |\/| | __| | _ < / /\ \| | | <
|
||||||
import { tankDefinitions } from '../core/blitzkrieg/tankDefinitions';
|
// _| |_ ____) | | | |/ ____ \| |____| |____ | |___| |__| | | | | |____ | |_) / ____ \ |____| . \
|
||||||
import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod';
|
// |_____| |_____/|_| |_/_/ \_\______|______| \_____\____/|_| |_|______| |____/_/ \_\_____|_|\_\
|
||||||
import { tankAverages } from '../core/blitzstars/tankAverages';
|
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
|
||||||
import embedNegative from '../core/discord/embedNegative';
|
|
||||||
import embedPositive from '../core/discord/embedPositive';
|
|
||||||
import markdownTable, { TableInput } from '../core/discord/markdownTable';
|
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
|
||||||
import calculateWN8 from '../core/statistics/calculateWN8';
|
|
||||||
import sumStats from '../core/statistics/sumStats';
|
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
|
||||||
import { PossiblyPromise } from '../types/possiblyPromise';
|
|
||||||
|
|
||||||
export type SkilledClan = 'SKLLD' | 'SMRI';
|
// import { SlashCommandBuilder } from 'discord.js';
|
||||||
|
// import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
|
// import getPeriodNow from '../core/blitzkrieg/getPeriodNow';
|
||||||
|
// import getTimeDaysAgo from '../core/blitzkrieg/getTimeDaysAgo';
|
||||||
|
// import { tankDefinitions } from '../core/blitzkrieg/tankDefinitions';
|
||||||
|
// import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod';
|
||||||
|
// import { tankAverages } from '../core/blitzstars/tankAverages';
|
||||||
|
// import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
|
// import embedNegative from '../core/discord/embedNegative';
|
||||||
|
// import embedPositive from '../core/discord/embedPositive';
|
||||||
|
// import markdownTable, { TableInput } from '../core/discord/markdownTable';
|
||||||
|
// import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||||
|
// import calculateWN8 from '../core/statistics/calculateWN8';
|
||||||
|
// import sumStats from '../core/statistics/sumStats';
|
||||||
|
// import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
// import { PossiblyPromise } from '../types/possiblyPromise';
|
||||||
|
|
||||||
export const SKILLED_CLANS: Record<SkilledClan, string> = {
|
// export type SkilledClan = 'SKLLD' | 'SMRI';
|
||||||
SKLLD: 'Skilled',
|
|
||||||
SMRI: 'Samurai',
|
|
||||||
};
|
|
||||||
|
|
||||||
export const eligibleCommand: CommandRegistry = {
|
// export const SKILLED_CLANS: Record<SkilledClan, string> = {
|
||||||
inProduction: true,
|
// SKLLD: 'Skilled',
|
||||||
inPublic: false,
|
// SMRI: 'Samurai',
|
||||||
|
// };
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
// export const eligibleCommand: CommandRegistry = {
|
||||||
.setName('eligible')
|
// inProduction: true,
|
||||||
.setDescription('Checks eligibility for any Skilled clan')
|
// inPublic: false,
|
||||||
.addStringOption((option) =>
|
|
||||||
option
|
|
||||||
.setName('clan')
|
|
||||||
.setDescription('The clan to check')
|
|
||||||
.setChoices(
|
|
||||||
{
|
|
||||||
name: SKILLED_CLANS.SKLLD,
|
|
||||||
value: 'SKLLD' satisfies SkilledClan,
|
|
||||||
},
|
|
||||||
{ name: SKILLED_CLANS.SMRI, value: 'SMRI' satisfies SkilledClan },
|
|
||||||
)
|
|
||||||
.setRequired(true),
|
|
||||||
)
|
|
||||||
.addStringOption(addUsernameChoices),
|
|
||||||
|
|
||||||
async handler(interaction) {
|
// command: new SlashCommandBuilder()
|
||||||
const clan = interaction.options.getString('clan') as SkilledClan;
|
// .setName('eligible')
|
||||||
const { id, region: region } = await resolvePlayerFromCommand(interaction);
|
// .setDescription('Checks eligibility for any Skilled clan')
|
||||||
const accountInfo = await getAccountInfo(region, id);
|
// .addStringOption((option) =>
|
||||||
const problems: TableInput = [];
|
// option
|
||||||
const title = `${accountInfo.nickname}'s eligibility for ${SKILLED_CLANS[clan]}`;
|
// .setName('clan')
|
||||||
let isEligible = false;
|
// .setDescription('The clan to check')
|
||||||
let body = '';
|
// .setChoices(
|
||||||
|
// {
|
||||||
|
// name: SKILLED_CLANS.SKLLD,
|
||||||
|
// value: 'SKLLD' satisfies SkilledClan,
|
||||||
|
// },
|
||||||
|
// { name: SKILLED_CLANS.SMRI, value: 'SMRI' satisfies SkilledClan },
|
||||||
|
// )
|
||||||
|
// .setRequired(true),
|
||||||
|
// )
|
||||||
|
// .addStringOption(addUsernameChoices),
|
||||||
|
|
||||||
if (clan === 'SKLLD') {
|
// async handler(interaction) {
|
||||||
const { diff: diffed } = await getStatsInPeriod(
|
// const clan = interaction.options.getString('clan') as SkilledClan;
|
||||||
region,
|
// const { id, region: region } = await resolvePlayerFromCommand(interaction);
|
||||||
id,
|
// const accountInfo = await getAccountInfo(region, id);
|
||||||
getTimeDaysAgo(region, 30),
|
// const problems: TableInput = [];
|
||||||
getPeriodNow(),
|
// const title = `${accountInfo.nickname}'s eligibility for ${SKILLED_CLANS[clan]}`;
|
||||||
);
|
// let isEligible = false;
|
||||||
const entries = Object.entries(diffed);
|
// let body = '';
|
||||||
const stats = sumStats(entries.map(([, stats]) => stats));
|
|
||||||
const averageTier =
|
|
||||||
(await entries.reduce<PossiblyPromise<number>>(
|
|
||||||
async (accumulator, [tankIdString, stats]) => {
|
|
||||||
const tankId = parseInt(tankIdString);
|
|
||||||
const tankDefinition = (await tankDefinitions)[tankId];
|
|
||||||
|
|
||||||
if (!tankDefinition) return accumulator;
|
// if (clan === 'SKLLD') {
|
||||||
|
// const { diff: diffed } = await getStatsInPeriod(
|
||||||
|
// region,
|
||||||
|
// id,
|
||||||
|
// getTimeDaysAgo(region, 30),
|
||||||
|
// getPeriodNow(),
|
||||||
|
// );
|
||||||
|
// const entries = Object.entries(diffed);
|
||||||
|
// const stats = sumStats(entries.map(([, stats]) => stats));
|
||||||
|
// const averageTier =
|
||||||
|
// (await entries.reduce<PossiblyPromise<number>>(
|
||||||
|
// async (accumulator, [tankIdString, stats]) => {
|
||||||
|
// const tankId = parseInt(tankIdString);
|
||||||
|
// const tankDefinition = (await tankDefinitions)[tankId];
|
||||||
|
|
||||||
const tankTier = tankDefinition.tier;
|
// if (!tankDefinition) return accumulator;
|
||||||
|
|
||||||
return (await accumulator) + tankTier * stats.battles;
|
// const tankTier = tankDefinition.tier;
|
||||||
},
|
|
||||||
0,
|
|
||||||
)) /
|
|
||||||
(await entries.reduce<PossiblyPromise<number>>(
|
|
||||||
async (accumulator, [tankIdString, stats]) => {
|
|
||||||
const tankId = parseInt(tankIdString);
|
|
||||||
const tankDefinition = (await tankDefinitions)[tankId];
|
|
||||||
|
|
||||||
if (!tankDefinition) return accumulator;
|
// return (await accumulator) + tankTier * stats.battles;
|
||||||
|
// },
|
||||||
|
// 0,
|
||||||
|
// )) /
|
||||||
|
// (await entries.reduce<PossiblyPromise<number>>(
|
||||||
|
// async (accumulator, [tankIdString, stats]) => {
|
||||||
|
// const tankId = parseInt(tankIdString);
|
||||||
|
// const tankDefinition = (await tankDefinitions)[tankId];
|
||||||
|
|
||||||
return stats.battles;
|
// if (!tankDefinition) return accumulator;
|
||||||
},
|
|
||||||
0,
|
|
||||||
));
|
|
||||||
const WN8 =
|
|
||||||
(await entries.reduce<PossiblyPromise<number>>(
|
|
||||||
async (accumulator, [tankIdString, stats]) => {
|
|
||||||
const tankId = parseInt(tankIdString);
|
|
||||||
|
|
||||||
// edge case where new tanks don't have averages
|
// return stats.battles;
|
||||||
if ((await tankAverages)[tankId]) {
|
// },
|
||||||
const tankWN8 = calculateWN8(
|
// 0,
|
||||||
(await tankAverages)[tankId].all,
|
// ));
|
||||||
stats,
|
// const WN8 =
|
||||||
);
|
// (await entries.reduce<PossiblyPromise<number>>(
|
||||||
|
// async (accumulator, [tankIdString, stats]) => {
|
||||||
|
// const tankId = parseInt(tankIdString);
|
||||||
|
|
||||||
if (isNaN(tankWN8)) return accumulator;
|
// // edge case where new tanks don't have averages
|
||||||
return (await accumulator) + tankWN8 * stats.battles;
|
// if ((await tankAverages)[tankId]) {
|
||||||
} else return accumulator;
|
// const tankWN8 = calculateWN8(
|
||||||
},
|
// (await tankAverages)[tankId].all,
|
||||||
0,
|
// stats,
|
||||||
)) / stats.battles;
|
// );
|
||||||
const tier10Damage =
|
|
||||||
(await entries.reduce<PossiblyPromise<number>>(
|
|
||||||
async (accumulator, [tankIdString, stats]) => {
|
|
||||||
const tankId = parseInt(tankIdString);
|
|
||||||
|
|
||||||
if ((await tankDefinitions)[tankId]?.tier === 10) {
|
// if (isNaN(tankWN8)) return accumulator;
|
||||||
const tankStats = diffed[tankId];
|
// return (await accumulator) + tankWN8 * stats.battles;
|
||||||
return (await accumulator) + tankStats.damage_dealt;
|
// } else return accumulator;
|
||||||
} else return accumulator;
|
// },
|
||||||
},
|
// 0,
|
||||||
0,
|
// )) / stats.battles;
|
||||||
)) /
|
// const tier10Damage =
|
||||||
(await entries.reduce<PossiblyPromise<number>>(
|
// (await entries.reduce<PossiblyPromise<number>>(
|
||||||
async (accumulator, [tankIdString, stats]) => {
|
// async (accumulator, [tankIdString, stats]) => {
|
||||||
const tankId = parseInt(tankIdString);
|
// const tankId = parseInt(tankIdString);
|
||||||
|
|
||||||
if ((await tankDefinitions)[tankId]?.tier === 10) {
|
// if ((await tankDefinitions)[tankId]?.tier === 10) {
|
||||||
const tankStats = diffed[tankId];
|
// const tankStats = diffed[tankId];
|
||||||
return (await accumulator) + tankStats.battles;
|
// return (await accumulator) + tankStats.damage_dealt;
|
||||||
} else return accumulator;
|
// } else return accumulator;
|
||||||
},
|
// },
|
||||||
0,
|
// 0,
|
||||||
));
|
// )) /
|
||||||
|
// (await entries.reduce<PossiblyPromise<number>>(
|
||||||
|
// async (accumulator, [tankIdString, stats]) => {
|
||||||
|
// const tankId = parseInt(tankIdString);
|
||||||
|
|
||||||
if (stats.battles < 126) {
|
// if ((await tankDefinitions)[tankId]?.tier === 10) {
|
||||||
problems.push(['Battles', `${stats.battles} (${stats.battles - 126})`]);
|
// const tankStats = diffed[tankId];
|
||||||
}
|
// return (await accumulator) + tankStats.battles;
|
||||||
if (averageTier < 8) {
|
// } else return accumulator;
|
||||||
problems.push([
|
// },
|
||||||
'Average tier',
|
// 0,
|
||||||
`${averageTier.toFixed(2)} (${(averageTier - 8).toFixed(2)})`,
|
// ));
|
||||||
]);
|
|
||||||
}
|
|
||||||
if (stats.wins / stats.battles < 0.6) {
|
|
||||||
problems.push([
|
|
||||||
'Winrate',
|
|
||||||
`${(100 * (stats.wins / stats.battles)).toFixed(2)}% (${(
|
|
||||||
100 *
|
|
||||||
(stats.wins / stats.battles - 0.6)
|
|
||||||
).toFixed(2)}%)`,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
if (WN8 < 2450) {
|
|
||||||
problems.push([
|
|
||||||
'WN8',
|
|
||||||
`${WN8.toFixed(0)} (${(WN8 - 2450).toFixed(0)})`,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
if (tier10Damage < 1250) {
|
|
||||||
problems.push([
|
|
||||||
'Tier 10 damage',
|
|
||||||
`${tier10Damage.toFixed(0)} (${tier10Damage - 1250})`,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
isEligible = problems.length === 0;
|
// if (stats.battles < 126) {
|
||||||
body = isEligible
|
// problems.push(['Battles', `${stats.battles} (${stats.battles - 126})`]);
|
||||||
? 'Player is fully eligible.'
|
// }
|
||||||
: `Player is not eligible. Shortcomings in 30-day statistics:\n\n${markdownTable(
|
// if (averageTier < 8) {
|
||||||
problems,
|
// problems.push([
|
||||||
)}`;
|
// 'Average tier',
|
||||||
} else if (clan === 'SMRI') {
|
// `${averageTier.toFixed(2)} (${(averageTier - 8).toFixed(2)})`,
|
||||||
const stats = accountInfo.statistics.all;
|
// ]);
|
||||||
|
// }
|
||||||
|
// if (stats.wins / stats.battles < 0.6) {
|
||||||
|
// problems.push([
|
||||||
|
// 'Winrate',
|
||||||
|
// `${(100 * (stats.wins / stats.battles)).toFixed(2)}% (${(
|
||||||
|
// 100 *
|
||||||
|
// (stats.wins / stats.battles - 0.6)
|
||||||
|
// ).toFixed(2)}%)`,
|
||||||
|
// ]);
|
||||||
|
// }
|
||||||
|
// if (WN8 < 2450) {
|
||||||
|
// problems.push([
|
||||||
|
// 'WN8',
|
||||||
|
// `${WN8.toFixed(0)} (${(WN8 - 2450).toFixed(0)})`,
|
||||||
|
// ]);
|
||||||
|
// }
|
||||||
|
// if (tier10Damage < 1250) {
|
||||||
|
// problems.push([
|
||||||
|
// 'Tier 10 damage',
|
||||||
|
// `${tier10Damage.toFixed(0)} (${tier10Damage - 1250})`,
|
||||||
|
// ]);
|
||||||
|
// }
|
||||||
|
|
||||||
if (stats.battles < 1500) {
|
// isEligible = problems.length === 0;
|
||||||
problems.push([
|
// body = isEligible
|
||||||
'Battles',
|
// ? 'Player is fully eligible.'
|
||||||
`${stats.battles} (${stats.battles - 1500})`,
|
// : `Player is not eligible. Shortcomings in 30-day statistics:\n\n${markdownTable(
|
||||||
]);
|
// problems,
|
||||||
}
|
// )}`;
|
||||||
if (stats.wins / stats.battles <= 0.53) {
|
// } else if (clan === 'SMRI') {
|
||||||
problems.push([
|
// const stats = accountInfo.statistics.all;
|
||||||
'Winrate',
|
|
||||||
`${(100 * (stats.wins / stats.battles)).toFixed(2)}% (${(
|
|
||||||
100 *
|
|
||||||
(stats.wins / stats.battles - 0.53)
|
|
||||||
).toFixed(2)}%)`,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
isEligible = problems.length === 0;
|
// if (stats.battles < 1500) {
|
||||||
body = isEligible
|
// problems.push([
|
||||||
? 'Player is fully eligible.'
|
// 'Battles',
|
||||||
: `Player is not eligible. Shortcomings in career statistics:\n\n${markdownTable(
|
// `${stats.battles} (${stats.battles - 1500})`,
|
||||||
problems,
|
// ]);
|
||||||
)}`;
|
// }
|
||||||
}
|
// if (stats.wins / stats.battles <= 0.53) {
|
||||||
|
// problems.push([
|
||||||
|
// 'Winrate',
|
||||||
|
// `${(100 * (stats.wins / stats.battles)).toFixed(2)}% (${(
|
||||||
|
// 100 *
|
||||||
|
// (stats.wins / stats.battles - 0.53)
|
||||||
|
// ).toFixed(2)}%)`,
|
||||||
|
// ]);
|
||||||
|
// }
|
||||||
|
|
||||||
return (isEligible ? embedPositive : embedNegative)(title, body);
|
// isEligible = problems.length === 0;
|
||||||
},
|
// body = isEligible
|
||||||
};
|
// ? 'Player is fully eligible.'
|
||||||
|
// : `Player is not eligible. Shortcomings in career statistics:\n\n${markdownTable(
|
||||||
|
// problems,
|
||||||
|
// )}`;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return (isEligible ? embedPositive : embedNegative)(title, body);
|
||||||
|
// },
|
||||||
|
// };
|
||||||
+52
-55
@@ -1,25 +1,24 @@
|
|||||||
import {
|
import { Locale, SlashCommandSubcommandGroupBuilder } from 'discord.js';
|
||||||
SlashCommandBuilder,
|
import CommandWrapper from '../components/CommandWrapper';
|
||||||
SlashCommandSubcommandGroupBuilder,
|
|
||||||
} from 'discord.js';
|
|
||||||
import * as Graph from '../components/Graph';
|
import * as Graph from '../components/Graph';
|
||||||
import NoData, { NoDataType } from '../components/NoData';
|
import { LineColor } from '../components/Graph/components/Line/constants';
|
||||||
|
import NoData from '../components/NoData';
|
||||||
import TitleBar from '../components/TitleBar';
|
import TitleBar from '../components/TitleBar';
|
||||||
import Wrapper from '../components/Wrapper';
|
|
||||||
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||||
import resolveTankId from '../core/blitz/resolveTankId';
|
import resolveTankId from '../core/blitz/resolveTankId';
|
||||||
import { emblemIdToURL } from '../core/blitzkrieg/emblemIdToURL';
|
import { emblemURL } from '../core/blitzkrieg/emblemURL';
|
||||||
import getTankHistories from '../core/blitzkrieg/getTankHistories';
|
import getTankHistories from '../core/blitzkrieg/getTankHistories';
|
||||||
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||||
import getPlayerHistories from '../core/blitzstars/getPlayerHistories';
|
import getPlayerHistories from '../core/blitzstars/getPlayerHistories';
|
||||||
import addPeriodSubCommands from '../core/discord/addPeriodSubCommands';
|
import { addPeriodSubCommands } from '../core/discord/addPeriodSubCommands';
|
||||||
import addTankChoices from '../core/discord/addTankChoices';
|
import addTankChoices from '../core/discord/addTankChoices';
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
import buttonPrimary from '../core/discord/buttonPrimary';
|
import { buttonRefresh } from '../core/discord/buttonRefresh';
|
||||||
import commandToURL from '../core/discord/commandToURL';
|
import commandToURL from '../core/discord/commandToURL';
|
||||||
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
||||||
import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
||||||
import resolvePeriodFromCommand, {
|
import resolvePeriodFromCommand, {
|
||||||
@@ -29,7 +28,7 @@ import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
|||||||
import resolvePlayerFromCommand, {
|
import resolvePlayerFromCommand, {
|
||||||
ResolvedPlayer,
|
ResolvedPlayer,
|
||||||
} from '../core/discord/resolvePlayerFromCommand';
|
} from '../core/discord/resolvePlayerFromCommand';
|
||||||
import { CommandRegistryPromisable } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|
||||||
type EvolutionStatType = 'player' | 'tank';
|
type EvolutionStatType = 'player' | 'tank';
|
||||||
|
|
||||||
@@ -38,10 +37,11 @@ async function render(
|
|||||||
{ start, end, name }: ResolvedPeriod,
|
{ start, end, name }: ResolvedPeriod,
|
||||||
type: 'player' | 'tank',
|
type: 'player' | 'tank',
|
||||||
tankId: number | null,
|
tankId: number | null,
|
||||||
|
locale: Locale,
|
||||||
) {
|
) {
|
||||||
const accountInfo = await getAccountInfo(region, id);
|
const accountInfo = await getAccountInfo(region, id);
|
||||||
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
||||||
const logo = clan ? emblemIdToURL(clan.emblem_set_id) : undefined;
|
const logo = clan ? emblemURL(clan.emblem_set_id) : undefined;
|
||||||
const histories = await (type === 'player'
|
const histories = await (type === 'player'
|
||||||
? getPlayerHistories(region, id, {
|
? getPlayerHistories(region, id, {
|
||||||
start,
|
start,
|
||||||
@@ -49,7 +49,7 @@ async function render(
|
|||||||
includeLatestHistories: true,
|
includeLatestHistories: true,
|
||||||
includePreviousHistories: true,
|
includePreviousHistories: true,
|
||||||
})
|
})
|
||||||
: getTankHistories(region, id, {
|
: getTankHistories(region, id, locale, {
|
||||||
tankId: tankId!,
|
tankId: tankId!,
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
@@ -74,8 +74,8 @@ async function render(
|
|||||||
const minX = Math.min(...xs);
|
const minX = Math.min(...xs);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper>
|
<CommandWrapper>
|
||||||
<TitleBar name={accountInfo.nickname} image={logo} description={name} />
|
<TitleBar title={accountInfo.nickname} image={logo} description={name} />
|
||||||
|
|
||||||
{plot.length > 0 && (
|
{plot.length > 0 && (
|
||||||
<Graph.Root
|
<Graph.Root
|
||||||
@@ -90,11 +90,11 @@ async function render(
|
|||||||
max: maxX,
|
max: maxX,
|
||||||
precision: 0,
|
precision: 0,
|
||||||
}}
|
}}
|
||||||
xMinLabel={new Date(minTime * 1000).toDateString()}
|
xMinLabel={new Date(minTime * 1000).toLocaleDateString(locale)}
|
||||||
xMaxLabel={new Date(maxTime * 1000).toDateString()}
|
xMaxLabel={new Date(maxTime * 1000).toLocaleDateString(locale)}
|
||||||
>
|
>
|
||||||
{Graph.Line({
|
{Graph.Line({
|
||||||
color: Graph.LineColor.Red,
|
color: LineColor.Red,
|
||||||
plot: plot,
|
plot: plot,
|
||||||
minY,
|
minY,
|
||||||
maxY,
|
maxY,
|
||||||
@@ -102,47 +102,37 @@ async function render(
|
|||||||
</Graph.Root>
|
</Graph.Root>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{plot.length === 0 && <NoData type={NoDataType.BattlesInPeriod} />}
|
{plot.length === 0 && <NoData type="battles_in_period" locale={locale} />}
|
||||||
</Wrapper>
|
</CommandWrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const evolutionCommand = new Promise<CommandRegistryPromisable>(
|
export const evolutionCommand = new Promise<CommandRegistry>(
|
||||||
async (resolve) => {
|
async (resolve) => {
|
||||||
let playerGroup: SlashCommandSubcommandGroupBuilder;
|
|
||||||
let tankGroup: SlashCommandSubcommandGroupBuilder;
|
|
||||||
const command = new SlashCommandBuilder()
|
|
||||||
.setName('evolution')
|
|
||||||
.setDescription('Evolution of statistics')
|
|
||||||
.addSubcommandGroup((option) => {
|
|
||||||
playerGroup = option
|
|
||||||
.setName('player')
|
|
||||||
.setDescription('Player statistics');
|
|
||||||
|
|
||||||
return playerGroup;
|
|
||||||
})
|
|
||||||
.addSubcommandGroup((option) => {
|
|
||||||
tankGroup = option.setName('tank').setDescription('Tank statistics');
|
|
||||||
|
|
||||||
return tankGroup;
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.all([
|
|
||||||
addPeriodSubCommands(playerGroup!, (option) =>
|
|
||||||
option.addStringOption(addUsernameChoices),
|
|
||||||
),
|
|
||||||
addPeriodSubCommands(tankGroup!, (option) =>
|
|
||||||
option
|
|
||||||
.addStringOption(addTankChoices)
|
|
||||||
.addStringOption(addUsernameChoices),
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
|
|
||||||
resolve({
|
resolve({
|
||||||
inProduction: true,
|
inProduction: true,
|
||||||
inPublic: true,
|
inPublic: true,
|
||||||
|
|
||||||
command,
|
command: createLocalizedCommand('evolution', [
|
||||||
|
{
|
||||||
|
group: 'player',
|
||||||
|
modify(option: SlashCommandSubcommandGroupBuilder) {
|
||||||
|
addPeriodSubCommands(option, (option) =>
|
||||||
|
option.addStringOption(addUsernameChoices),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group: 'tank',
|
||||||
|
modify(option: SlashCommandSubcommandGroupBuilder) {
|
||||||
|
addPeriodSubCommands(option, (option) =>
|
||||||
|
option
|
||||||
|
.addStringOption(addTankChoices)
|
||||||
|
.addStringOption(addUsernameChoices),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
|
||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
const commandGroup =
|
const commandGroup =
|
||||||
@@ -151,18 +141,24 @@ export const evolutionCommand = new Promise<CommandRegistryPromisable>(
|
|||||||
const period = resolvePeriodFromCommand(player.region, interaction);
|
const period = resolvePeriodFromCommand(player.region, interaction);
|
||||||
const tankIdRaw = interaction.options.getString('tank')!;
|
const tankIdRaw = interaction.options.getString('tank')!;
|
||||||
const tankId =
|
const tankId =
|
||||||
commandGroup === 'tank' ? await resolveTankId(tankIdRaw) : null;
|
commandGroup === 'tank'
|
||||||
|
? await resolveTankId(tankIdRaw, interaction.locale)
|
||||||
|
: null;
|
||||||
const path = commandToURL(interaction, {
|
const path = commandToURL(interaction, {
|
||||||
...player,
|
...player,
|
||||||
...getCustomPeriodParams(interaction),
|
...getCustomPeriodParams(interaction),
|
||||||
tankId,
|
tankId,
|
||||||
});
|
});
|
||||||
|
|
||||||
getBlitzStarsLinkButton;
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
await render(player, period, commandGroup, tankId),
|
await render(
|
||||||
buttonPrimary(path, 'Refresh'),
|
player,
|
||||||
|
period,
|
||||||
|
commandGroup,
|
||||||
|
tankId,
|
||||||
|
interaction.locale,
|
||||||
|
),
|
||||||
|
buttonRefresh(interaction, path),
|
||||||
await getBlitzStarsLinkButton(
|
await getBlitzStarsLinkButton(
|
||||||
player.region,
|
player.region,
|
||||||
player.id,
|
player.id,
|
||||||
@@ -188,6 +184,7 @@ export const evolutionCommand = new Promise<CommandRegistryPromisable>(
|
|||||||
period,
|
period,
|
||||||
commandGroup,
|
commandGroup,
|
||||||
parseInt(url.searchParams.get('tankId') ?? '0') || null,
|
parseInt(url.searchParams.get('tankId') ?? '0') || null,
|
||||||
|
interaction.locale,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
+34
-24
@@ -1,12 +1,12 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { Locale } from 'discord.js';
|
||||||
|
import CommandWrapper from '../components/CommandWrapper';
|
||||||
import GenericAllStats from '../components/GenericAllStats';
|
import GenericAllStats from '../components/GenericAllStats';
|
||||||
import NoData, { NoDataType } from '../components/NoData';
|
import NoData from '../components/NoData';
|
||||||
import TierWeights from '../components/TierWeights';
|
import TierWeights from '../components/TierWeights';
|
||||||
import TitleBar from '../components/TitleBar';
|
import TitleBar from '../components/TitleBar';
|
||||||
import Wrapper from '../components/Wrapper';
|
|
||||||
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||||
import { emblemIdToURL } from '../core/blitzkrieg/emblemIdToURL';
|
import { emblemURL } from '../core/blitzkrieg/emblemURL';
|
||||||
import { filtersToDescription } from '../core/blitzkrieg/filtersToDescription';
|
import { filtersToDescription } from '../core/blitzkrieg/filtersToDescription';
|
||||||
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||||
import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod';
|
import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod';
|
||||||
@@ -16,6 +16,7 @@ import autocompleteTanks from '../core/discord/autocompleteTanks';
|
|||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
import { buttonRefresh } from '../core/discord/buttonRefresh';
|
import { buttonRefresh } from '../core/discord/buttonRefresh';
|
||||||
import commandToURL from '../core/discord/commandToURL';
|
import commandToURL from '../core/discord/commandToURL';
|
||||||
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
||||||
import { getFiltersFromButton } from '../core/discord/getFiltersFromButton';
|
import { getFiltersFromButton } from '../core/discord/getFiltersFromButton';
|
||||||
import { getFiltersFromCommand } from '../core/discord/getFiltersFromCommand';
|
import { getFiltersFromCommand } from '../core/discord/getFiltersFromCommand';
|
||||||
@@ -29,55 +30,64 @@ import resolvePlayerFromCommand, {
|
|||||||
} from '../core/discord/resolvePlayerFromCommand';
|
} from '../core/discord/resolvePlayerFromCommand';
|
||||||
import { StatFilters, filterStats } from '../core/statistics/filterStats';
|
import { StatFilters, filterStats } from '../core/statistics/filterStats';
|
||||||
import { getTierWeights } from '../core/statistics/getTierWeights';
|
import { getTierWeights } from '../core/statistics/getTierWeights';
|
||||||
import { CommandRegistryPromisable } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|
||||||
async function render(
|
async function render(
|
||||||
{ region, id }: ResolvedPlayer,
|
{ region, id }: ResolvedPlayer,
|
||||||
{ start, end, name }: ResolvedPeriod,
|
{ start, end, name }: ResolvedPeriod,
|
||||||
filters: StatFilters,
|
filters: StatFilters,
|
||||||
|
locale: Locale,
|
||||||
) {
|
) {
|
||||||
const { nickname } = await getAccountInfo(region, id);
|
const { nickname } = await getAccountInfo(region, id);
|
||||||
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
||||||
const clanImage = clan ? emblemIdToURL(clan.emblem_set_id) : undefined;
|
const clanImage = clan ? emblemURL(clan.emblem_set_id) : undefined;
|
||||||
const diffedTankStats = await getStatsInPeriod(region, id, start, end);
|
const diffedTankStats = await getStatsInPeriod(
|
||||||
|
region,
|
||||||
|
id,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
locale,
|
||||||
|
);
|
||||||
const { stats, supplementary, filteredOrder } = await filterStats(
|
const { stats, supplementary, filteredOrder } = await filterStats(
|
||||||
diffedTankStats,
|
diffedTankStats,
|
||||||
filters,
|
filters,
|
||||||
);
|
);
|
||||||
const filterDescriptions = await filtersToDescription(filters);
|
const filterDescriptions = await filtersToDescription(filters, locale);
|
||||||
const tierWeights = await getTierWeights(diffedTankStats.diff, filteredOrder);
|
const tierWeights = await getTierWeights(diffedTankStats.diff, filteredOrder);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper>
|
<CommandWrapper>
|
||||||
<TitleBar
|
<TitleBar
|
||||||
name={nickname}
|
title={nickname}
|
||||||
image={clanImage}
|
image={clanImage}
|
||||||
description={`${name} • ${filterDescriptions}`}
|
description={`${name} • ${filterDescriptions}`}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{stats.battles === 0 && <NoData type={NoDataType.BattlesInPeriod} />}
|
{stats.battles === 0 && (
|
||||||
|
<NoData type="battles_in_period" locale={locale} />
|
||||||
|
)}
|
||||||
{stats.battles > 0 && <TierWeights weights={tierWeights!} />}
|
{stats.battles > 0 && <TierWeights weights={tierWeights!} />}
|
||||||
{stats.battles > 0 && (
|
{stats.battles > 0 && (
|
||||||
<GenericAllStats stats={stats} supplementaryStats={supplementary} />
|
<GenericAllStats
|
||||||
|
stats={stats}
|
||||||
|
supplementaryStats={supplementary}
|
||||||
|
locale={locale}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</Wrapper>
|
</CommandWrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fullStatsCommand = new Promise<CommandRegistryPromisable>(
|
export const fullStatsCommand = new Promise<CommandRegistry>(
|
||||||
async (resolve) => {
|
async (resolve) => {
|
||||||
const command = await addPeriodicFilterOptions(
|
|
||||||
new SlashCommandBuilder()
|
|
||||||
.setName('full-stats')
|
|
||||||
.setDescription('Full in-game statistics'),
|
|
||||||
(option) => option.addStringOption(addUsernameChoices),
|
|
||||||
);
|
|
||||||
|
|
||||||
resolve({
|
resolve({
|
||||||
inProduction: true,
|
inProduction: true,
|
||||||
inPublic: true,
|
inPublic: true,
|
||||||
|
|
||||||
command,
|
command: await addPeriodicFilterOptions(
|
||||||
|
createLocalizedCommand('full-stats'),
|
||||||
|
(option) => option.addStringOption(addUsernameChoices),
|
||||||
|
),
|
||||||
|
|
||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
const player = await resolvePlayerFromCommand(interaction);
|
const player = await resolvePlayerFromCommand(interaction);
|
||||||
@@ -90,7 +100,7 @@ export const fullStatsCommand = new Promise<CommandRegistryPromisable>(
|
|||||||
});
|
});
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
render(player, period, filters),
|
render(player, period, filters, interaction.locale),
|
||||||
buttonRefresh(interaction, path),
|
buttonRefresh(interaction, path),
|
||||||
getBlitzStarsLinkButton(player.region, player.id),
|
getBlitzStarsLinkButton(player.region, player.id),
|
||||||
]);
|
]);
|
||||||
@@ -106,7 +116,7 @@ export const fullStatsCommand = new Promise<CommandRegistryPromisable>(
|
|||||||
const period = resolvePeriodFromButton(player.region, interaction);
|
const period = resolvePeriodFromButton(player.region, interaction);
|
||||||
const filters = getFiltersFromButton(interaction);
|
const filters = getFiltersFromButton(interaction);
|
||||||
|
|
||||||
return await render(player, period, filters);
|
return await render(player, period, filters, interaction.locale);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
+75
-53
@@ -1,69 +1,91 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { Locale } from 'discord.js';
|
||||||
|
import CommandWrapper from '../components/CommandWrapper';
|
||||||
import GenericStats from '../components/GenericStats';
|
import GenericStats from '../components/GenericStats';
|
||||||
import NoData, { NoDataType } from '../components/NoData';
|
import NoData from '../components/NoData';
|
||||||
import TitleBar from '../components/TitleBar';
|
import TitleBar from '../components/TitleBar';
|
||||||
import Wrapper from '../components/Wrapper';
|
|
||||||
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
import { getClanInfo } from '../core/blitz/getClanInfo';
|
import { getClanInfo } from '../core/blitz/getClanInfo';
|
||||||
import addClanChoices from '../core/discord/addClanChoices';
|
import addClanChoices from '../core/discord/addClanChoices';
|
||||||
import autocompleteClan from '../core/discord/autocompleteClan';
|
import autocompleteClan from '../core/discord/autocompleteClan';
|
||||||
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
|
import { localizationObject } from '../core/discord/localizationObject';
|
||||||
import resolveClanFromCommand from '../core/discord/resolveClanFromCommand';
|
import resolveClanFromCommand from '../core/discord/resolveClanFromCommand';
|
||||||
|
import { translator } from '../core/localization/translator';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|
||||||
const DEFAULT_THRESHOLD = 7;
|
const DEFAULT_THRESHOLD = 7;
|
||||||
|
|
||||||
export const inactiveCommand: CommandRegistry = {
|
export const inactiveCommand = new Promise<CommandRegistry>((resolve) => {
|
||||||
inProduction: true,
|
resolve({
|
||||||
inPublic: true,
|
inProduction: true,
|
||||||
|
inPublic: true,
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
command: createLocalizedCommand('inactive')
|
||||||
.setName('inactive')
|
.addStringOption(addClanChoices)
|
||||||
.setDescription('Lists all inactive players')
|
.addNumberOption((option) => {
|
||||||
.addStringOption(addClanChoices)
|
const { translate } = translator(Locale.EnglishUS);
|
||||||
.addNumberOption((option) =>
|
|
||||||
option
|
return option
|
||||||
.setName('threshold')
|
.setName('threshold')
|
||||||
.setDescription(
|
.setNameLocalizations(
|
||||||
`The number of days inactive (default: ${DEFAULT_THRESHOLD})`,
|
localizationObject('bot.commands.inactive.options.threshold'),
|
||||||
|
)
|
||||||
|
.setDescription(
|
||||||
|
translate('bot.commands.inactive.options.threshold.description'),
|
||||||
|
)
|
||||||
|
.setDescriptionLocalizations(
|
||||||
|
localizationObject(
|
||||||
|
'bot.commands.inactive.options.threshold.description',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.setMinValue(0);
|
||||||
|
}),
|
||||||
|
|
||||||
|
async handler(interaction) {
|
||||||
|
const { translate } = translator(interaction.locale);
|
||||||
|
const { region, id } = await resolveClanFromCommand(interaction);
|
||||||
|
const threshold =
|
||||||
|
interaction.options.getNumber('threshold')! ?? DEFAULT_THRESHOLD;
|
||||||
|
const time = new Date().getTime() / 1000;
|
||||||
|
const clanInfo = await getClanInfo(region, id);
|
||||||
|
const accountInfo = await getAccountInfo(region, clanInfo.members_ids);
|
||||||
|
const inactive = accountInfo
|
||||||
|
.map(
|
||||||
|
(account) =>
|
||||||
|
[
|
||||||
|
account.nickname,
|
||||||
|
(time - account.last_battle_time) / 60 / 60 / 24,
|
||||||
|
] as [string, number],
|
||||||
)
|
)
|
||||||
.setMinValue(0),
|
.filter(([, inactiveDays]) => inactiveDays >= threshold)
|
||||||
),
|
.sort((a, b) => b[1] - a[1])
|
||||||
|
.map(
|
||||||
|
([name, days]) =>
|
||||||
|
[
|
||||||
|
name,
|
||||||
|
translate('bot.commands.inactive.body.listing', [
|
||||||
|
days.toFixed(0),
|
||||||
|
]),
|
||||||
|
] as [string, string],
|
||||||
|
);
|
||||||
|
const hasInactiveMembers = inactive.length > 0;
|
||||||
|
|
||||||
async handler(interaction) {
|
return (
|
||||||
const { region, id } = await resolveClanFromCommand(interaction);
|
<CommandWrapper>
|
||||||
const threshold =
|
<TitleBar
|
||||||
interaction.options.getNumber('threshold')! ?? DEFAULT_THRESHOLD;
|
title={clanInfo.name}
|
||||||
const time = new Date().getTime() / 1000;
|
image={`https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanInfo.emblem_set_id}.png`}
|
||||||
const clanInfo = await getClanInfo(region, id);
|
description={`${translate('bot.commands.inactive.body.subtitle', [`${threshold}`])} • ${new Date().toLocaleDateString(interaction.locale)}`}
|
||||||
const accountInfo = await getAccountInfo(region, clanInfo.members_ids);
|
/>
|
||||||
const inactive = accountInfo
|
|
||||||
.map(
|
{!hasInactiveMembers && (
|
||||||
(account) =>
|
<NoData type="players_in_period" locale={interaction.locale} />
|
||||||
[
|
)}
|
||||||
account.nickname,
|
{hasInactiveMembers && <GenericStats stats={inactive} />}
|
||||||
(time - account.last_battle_time) / 60 / 60 / 24,
|
</CommandWrapper>
|
||||||
] as [string, number],
|
|
||||||
)
|
|
||||||
.filter(([, inactiveDays]) => inactiveDays >= threshold)
|
|
||||||
.sort((a, b) => b[1] - a[1])
|
|
||||||
.map(
|
|
||||||
([name, days]) => [name, `${days.toFixed(0)} days`] as [string, string],
|
|
||||||
);
|
);
|
||||||
const hasInactiveMembers = inactive.length > 0;
|
},
|
||||||
|
|
||||||
return (
|
autocomplete: autocompleteClan,
|
||||||
<Wrapper>
|
});
|
||||||
<TitleBar
|
});
|
||||||
name={clanInfo.name}
|
|
||||||
image={`https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanInfo.emblem_set_id}.png`}
|
|
||||||
description={`Inactive for ${threshold}+ Days • ${new Date().toDateString()}`}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{!hasInactiveMembers && <NoData type={NoDataType.PlayersInPeriod} />}
|
|
||||||
{hasInactiveMembers && <GenericStats stats={inactive} />}
|
|
||||||
</Wrapper>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
autocomplete: autocompleteClan,
|
|
||||||
};
|
|
||||||
+159
-148
@@ -1,209 +1,220 @@
|
|||||||
import { teal } from '@radix-ui/colors';
|
import { teal } from '@radix-ui/colors';
|
||||||
import { GuildMemberRoleManager, SlashCommandBuilder } from 'discord.js';
|
import { GuildMemberRoleManager } from 'discord.js';
|
||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import discord from '../../discord.json' assert { type: 'json' };
|
import discord from '../../discord.json' assert { type: 'json' };
|
||||||
import { Glow } from '../components/AllStatsOverview/components/WN8Display/components/Glow';
|
import { Glow } from '../components/AllStatsOverview/components/HeroStat/components/Glow';
|
||||||
import Wrapper from '../components/Wrapper';
|
import CommandWrapper from '../components/CommandWrapper';
|
||||||
import { REGION_NAMES } from '../constants/regions';
|
|
||||||
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||||
import { linkBlitzAndDiscord } from '../core/blitzkrieg/discordBlitz';
|
import { linkBlitzAndDiscord } from '../core/blitzkrieg/discordBlitz';
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
import embedInfo from '../core/discord/embedInfo';
|
import embedInfo from '../core/discord/embedInfo';
|
||||||
import embedNegative from '../core/discord/embedNegative';
|
import embedNegative from '../core/discord/embedNegative';
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||||
|
import { translator } from '../core/localization/translator';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
import { theme } from '../stitches.config';
|
import { theme } from '../stitches.config';
|
||||||
|
|
||||||
export const verifyCommand: CommandRegistry = {
|
export const verifyCommand = new Promise<CommandRegistry>((resolve) => {
|
||||||
inProduction: true,
|
resolve({
|
||||||
inPublic: true,
|
inProduction: true,
|
||||||
|
inPublic: true,
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
command: createLocalizedCommand('link').addStringOption((option) =>
|
||||||
.setName('link')
|
addUsernameChoices(option).setRequired(true),
|
||||||
.setDescription('Links your Blitz and Discord account')
|
),
|
||||||
.addStringOption((option) => addUsernameChoices(option).setRequired(true)),
|
|
||||||
|
|
||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
const { id, region } = await resolvePlayerFromCommand(interaction);
|
const { t, translate } = translator(interaction.locale);
|
||||||
const discordId = parseInt(interaction.user.id);
|
const { id, region } = await resolvePlayerFromCommand(interaction);
|
||||||
const accountInfo = await getAccountInfo(region, id);
|
const discordId = parseInt(interaction.user.id);
|
||||||
const clanAccountInfo = await getClanAccountInfo(region, id, ['clan']);
|
const accountInfo = await getAccountInfo(region, id);
|
||||||
|
const clanAccountInfo = await getClanAccountInfo(region, id, ['clan']);
|
||||||
|
|
||||||
await linkBlitzAndDiscord(discordId, region, id);
|
await linkBlitzAndDiscord(discordId, region, id);
|
||||||
|
|
||||||
if (interaction.guildId === discord.sklld_guild_id) {
|
if (interaction.guildId === discord.sklld_guild_id) {
|
||||||
if (!interaction.guild?.members.me?.permissions.has('ManageRoles')) {
|
if (!interaction.guild?.members.me?.permissions.has('ManageRoles')) {
|
||||||
return embedNegative(
|
return embedNegative(
|
||||||
`${markdownEscape(interaction.user.username)} failed to verify`,
|
translate(translate('bot.commands.link.body.no_role_permissions'), [
|
||||||
"I don't have the permission to change your manage roles.",
|
markdownEscape(interaction.user.username),
|
||||||
|
]),
|
||||||
|
translate(
|
||||||
|
translate(
|
||||||
|
'bot.commands.link.body.no_role_permissions.description',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await (interaction.member!.roles as GuildMemberRoleManager).remove(
|
||||||
|
discord.sklld_verify_role,
|
||||||
|
);
|
||||||
|
await (interaction.member!.roles as GuildMemberRoleManager).add(
|
||||||
|
discord.sklld_peasant_role,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await (interaction.member!.roles as GuildMemberRoleManager).remove(
|
return [
|
||||||
discord.sklld_verify_role,
|
<CommandWrapper fat>
|
||||||
);
|
|
||||||
await (interaction.member!.roles as GuildMemberRoleManager).add(
|
|
||||||
discord.sklld_peasant_role,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
<Wrapper fat>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Glow color={teal.teal9} rotation={90} />
|
|
||||||
|
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'space-between',
|
||||||
gap: 16,
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<Glow color={teal.teal9} rotation={90} />
|
||||||
|
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
gap: 8,
|
flexDirection: 'column',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
|
gap: 16,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<img
|
|
||||||
src={
|
|
||||||
interaction.user.avatarURL({ extension: 'png' }) ??
|
|
||||||
'https://i.stack.imgur.com/l60Hf.png'
|
|
||||||
}
|
|
||||||
style={{
|
|
||||||
width: 64,
|
|
||||||
height: 64,
|
|
||||||
borderRadius: 32,
|
|
||||||
objectFit: 'cover',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
gap: 8,
|
||||||
gap: 4,
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: 32,
|
|
||||||
color: theme.colors.textHighContrast,
|
|
||||||
fontWeight: 900,
|
|
||||||
maxWidth: 240,
|
|
||||||
overflow: 'hidden',
|
|
||||||
textOverflow: 'ellipsis',
|
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{interaction.user.displayName}
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: 16,
|
|
||||||
color: theme.colors.textLowContrast,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
@{interaction.user.username}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
gap: 4,
|
|
||||||
color: theme.colors.textLowContrast_teal,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src="https://i.imgur.com/jIcRgog.png"
|
|
||||||
style={{
|
|
||||||
width: 16,
|
|
||||||
height: 16,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<span style={{ fontSize: 16 }}>Accounts linked</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
gap: 8,
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{clanAccountInfo?.clan ? (
|
|
||||||
<img
|
<img
|
||||||
|
src={
|
||||||
|
interaction.user.avatarURL({ extension: 'png' }) ??
|
||||||
|
'https://i.stack.imgur.com/l60Hf.png'
|
||||||
|
}
|
||||||
style={{
|
style={{
|
||||||
width: 64,
|
width: 64,
|
||||||
height: 64,
|
height: 64,
|
||||||
borderRadius: 32,
|
borderRadius: 32,
|
||||||
objectFit: 'cover',
|
objectFit: 'cover',
|
||||||
}}
|
}}
|
||||||
src={`https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanAccountInfo?.clan?.emblem_set_id}.png`}
|
|
||||||
/>
|
/>
|
||||||
) : null}
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: 4,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 32,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
fontWeight: 900,
|
||||||
|
maxWidth: 240,
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{interaction.user.displayName}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textLowContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
@{interaction.user.username}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
gap: 4,
|
gap: 4,
|
||||||
|
color: theme.colors.textLowContrast_teal,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span
|
<img
|
||||||
|
src="https://i.imgur.com/jIcRgog.png"
|
||||||
style={{
|
style={{
|
||||||
fontSize: 32,
|
width: 16,
|
||||||
color: theme.colors.textHighContrast,
|
height: 16,
|
||||||
fontWeight: 900,
|
}}
|
||||||
maxWidth: 240,
|
/>
|
||||||
overflow: 'hidden',
|
<span
|
||||||
textOverflow: 'ellipsis',
|
style={{ fontSize: 16 }}
|
||||||
whiteSpace: 'nowrap',
|
>{t`bot.commands.link.body.accounts_linked`}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
gap: 8,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{clanAccountInfo?.clan ? (
|
||||||
|
<img
|
||||||
|
style={{
|
||||||
|
width: 64,
|
||||||
|
height: 64,
|
||||||
|
borderRadius: 32,
|
||||||
|
objectFit: 'cover',
|
||||||
|
}}
|
||||||
|
src={`https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanAccountInfo?.clan?.emblem_set_id}.png`}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: 4,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{accountInfo.nickname}
|
<span
|
||||||
</span>
|
style={{
|
||||||
<span
|
fontSize: 32,
|
||||||
style={{
|
color: theme.colors.textHighContrast,
|
||||||
fontSize: 16,
|
fontWeight: 900,
|
||||||
color: theme.colors.textLowContrast,
|
maxWidth: 240,
|
||||||
}}
|
overflow: 'hidden',
|
||||||
>
|
textOverflow: 'ellipsis',
|
||||||
{clanAccountInfo?.clan
|
whiteSpace: 'nowrap',
|
||||||
? `[${clanAccountInfo?.clan?.tag}] - `
|
}}
|
||||||
: ''}
|
>
|
||||||
{REGION_NAMES[region]}
|
{accountInfo.nickname}
|
||||||
</span>
|
</span>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textLowContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{clanAccountInfo?.clan
|
||||||
|
? `[${clanAccountInfo?.clan?.tag}] • `
|
||||||
|
: ''}
|
||||||
|
{translate(`common.regions.normal.${region}`)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Glow color={teal.teal9} rotation={-90} />
|
||||||
</div>
|
</div>
|
||||||
|
</CommandWrapper>,
|
||||||
|
|
||||||
<Glow color={teal.teal9} rotation={-90} />
|
embedInfo(
|
||||||
</div>
|
t`bot.commands.link.embed.title`,
|
||||||
</Wrapper>,
|
t`bot.commands.link.embed.description`,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
},
|
||||||
|
|
||||||
embedInfo(
|
autocomplete: autocompleteUsername,
|
||||||
'Incorrect account?',
|
});
|
||||||
'Use the command again and select a username from the search results.',
|
});
|
||||||
),
|
|
||||||
];
|
|
||||||
},
|
|
||||||
|
|
||||||
autocomplete: autocompleteUsername,
|
|
||||||
};
|
|
||||||
+66
-108
@@ -1,128 +1,86 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { chunk } from 'lodash';
|
||||||
import NoData, { NoDataType } from '../components/NoData';
|
import markdownEscape from 'markdown-escape';
|
||||||
import * as Tanks from '../components/Tanks';
|
import { TANK_CLASSES } from '../components/Tanks/components/Item/constants';
|
||||||
import TitleBar from '../components/TitleBar';
|
|
||||||
import Wrapper from '../components/Wrapper';
|
|
||||||
import { encyclopediaInfo } from '../core/blitz/encyclopediaInfo';
|
|
||||||
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
|
||||||
import getTankStats from '../core/blitz/getTankStats';
|
import getTankStats from '../core/blitz/getTankStats';
|
||||||
import { emblemIdToURL } from '../core/blitzkrieg/emblemIdToURL';
|
|
||||||
import {
|
import {
|
||||||
TIER_ROMAN_NUMERALS,
|
NATIONS,
|
||||||
TankDefinition,
|
TankDefinition,
|
||||||
Tier,
|
Tier,
|
||||||
|
flags,
|
||||||
tankDefinitions,
|
tankDefinitions,
|
||||||
} from '../core/blitzkrieg/tankDefinitions';
|
} from '../core/blitzkrieg/tankDefinitions';
|
||||||
import { tankIcon } from '../core/blitzkrieg/tankIcon';
|
import { TIER_ROMAN_NUMERALS } from '../core/blitzkrieg/tankDefinitions/constants';
|
||||||
import addTierChoices from '../core/discord/addTierChoices';
|
import addTierChoices from '../core/discord/addTierChoices';
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||||
|
import { translator } from '../core/localization/translator';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|
||||||
export const ownedTanksCommand: CommandRegistry = {
|
const TANKS_PER_MESSAGE = 64;
|
||||||
inProduction: true,
|
|
||||||
inPublic: true,
|
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
export const ownedTanksCommand = new Promise<CommandRegistry>((resolve) => {
|
||||||
.setName('owned-tanks')
|
resolve({
|
||||||
.setDescription("Shows a player's owned tanks")
|
inProduction: true,
|
||||||
.addStringOption(addTierChoices)
|
inPublic: true,
|
||||||
.addStringOption(addUsernameChoices),
|
|
||||||
|
|
||||||
async handler(interaction) {
|
command: createLocalizedCommand('owned-tanks')
|
||||||
const tier = Number(interaction.options.getString('tier'));
|
.addStringOption(addTierChoices)
|
||||||
const account = await resolvePlayerFromCommand(interaction);
|
.addStringOption(addUsernameChoices),
|
||||||
const { id, region: server } = account;
|
|
||||||
const accountInfo = await getAccountInfo(server, id);
|
|
||||||
const tankStats = await getTankStats(server, id);
|
|
||||||
const filteredTanks = (
|
|
||||||
await Promise.all(
|
|
||||||
tankStats.map(async (tankData) => ({
|
|
||||||
tankDefinitions: (await tankDefinitions)[tankData.tank_id]!,
|
|
||||||
id: tankData.tank_id,
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
).filter((tank) => tank.tankDefinitions?.tier === tier);
|
|
||||||
const clanAccountInfo = await getClanAccountInfo(server, id, ['clan']);
|
|
||||||
const groupedTanks: Record<string, TankDefinition[]> = {};
|
|
||||||
const nations: string[] = [];
|
|
||||||
|
|
||||||
filteredTanks.forEach((tank) => {
|
async handler(interaction) {
|
||||||
if (groupedTanks[tank.tankDefinitions.nation] === undefined) {
|
const { translate } = translator(interaction.locale);
|
||||||
groupedTanks[tank.tankDefinitions.nation] = [tank.tankDefinitions];
|
const tier = Number(interaction.options.getString('tier'));
|
||||||
nations.push(tank.tankDefinitions.nation);
|
const { id, region } = await resolvePlayerFromCommand(interaction);
|
||||||
} else {
|
const accountInfo = await getAccountInfo(region, id);
|
||||||
groupedTanks[tank.tankDefinitions.nation].push(tank.tankDefinitions);
|
const tankStats = await getTankStats(region, id, interaction.locale);
|
||||||
}
|
const filteredTanks = (
|
||||||
});
|
await Promise.all(
|
||||||
|
tankStats.map(async (tankData) => ({
|
||||||
|
tankDefinitions: (await tankDefinitions)[tankData.tank_id]!,
|
||||||
|
id: tankData.tank_id,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
).filter((tank) => tank.tankDefinitions?.tier === tier);
|
||||||
|
const groupedTanks: Record<string, TankDefinition[]> = {};
|
||||||
|
const nations: string[] = [];
|
||||||
|
|
||||||
nations.sort();
|
filteredTanks.forEach((tank) => {
|
||||||
|
if (groupedTanks[tank.tankDefinitions.nation] === undefined) {
|
||||||
|
groupedTanks[tank.tankDefinitions.nation] = [tank.tankDefinitions];
|
||||||
|
nations.push(tank.tankDefinitions.nation);
|
||||||
|
} else {
|
||||||
|
groupedTanks[tank.tankDefinitions.nation].push(tank.tankDefinitions);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
const awaitedTankDefinitions = await tankDefinitions;
|
||||||
<Wrapper>
|
const awaitedNations = await NATIONS;
|
||||||
<TitleBar
|
const lines = tankStats
|
||||||
name={accountInfo.nickname}
|
.map(({ tank_id }) => awaitedTankDefinitions[tank_id])
|
||||||
image={
|
.filter((tank) => tank.tier === tier)
|
||||||
clanAccountInfo?.clan
|
.sort(
|
||||||
? emblemIdToURL(clanAccountInfo.clan.emblem_set_id)
|
(a, b) =>
|
||||||
: undefined
|
TANK_CLASSES.indexOf(a.class) - TANK_CLASSES.indexOf(b.class),
|
||||||
}
|
)
|
||||||
description={`Tier ${TIER_ROMAN_NUMERALS[tier as Tier]} tanks`}
|
.sort(
|
||||||
/>
|
(a, b) =>
|
||||||
|
awaitedNations.indexOf(a.nation) - awaitedNations.indexOf(b.nation),
|
||||||
|
)
|
||||||
|
.map((tank) => `${flags[tank.nation]} ${markdownEscape(tank.name)}`);
|
||||||
|
|
||||||
{filteredTanks.length === 0 && <NoData type={NoDataType.TanksFound} />}
|
return chunk(lines, TANKS_PER_MESSAGE).map((lines, index) =>
|
||||||
|
index === 0
|
||||||
|
? `${translate('bot.commands.owned_tanks.body.title', [
|
||||||
|
markdownEscape(accountInfo.nickname),
|
||||||
|
TIER_ROMAN_NUMERALS[tier as Tier],
|
||||||
|
])}${lines.join('\n')}`
|
||||||
|
: lines.join('\n'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
{filteredTanks.length > 0 &&
|
autocomplete: autocompleteUsername,
|
||||||
(await Promise.all(
|
});
|
||||||
nations.map(async (nation) => {
|
});
|
||||||
const tanks = groupedTanks[nation];
|
|
||||||
const leftColumnSize = Math.ceil(tanks.length / 2);
|
|
||||||
const leftColumn = tanks.slice(0, leftColumnSize);
|
|
||||||
const rightColumn = tanks.slice(leftColumnSize);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Tanks.Root>
|
|
||||||
<Tanks.Title>
|
|
||||||
{(await encyclopediaInfo).vehicle_nations[nation]}
|
|
||||||
</Tanks.Title>
|
|
||||||
|
|
||||||
<Tanks.Row>
|
|
||||||
<Tanks.Column>
|
|
||||||
{await Promise.all(
|
|
||||||
leftColumn.map(async (tank) => (
|
|
||||||
<Tanks.Item
|
|
||||||
key={tank.id}
|
|
||||||
name={tank.name}
|
|
||||||
tankType={tank.type}
|
|
||||||
image={tankIcon(tank.id)}
|
|
||||||
treeType={tank.treeType}
|
|
||||||
/>
|
|
||||||
)),
|
|
||||||
)}
|
|
||||||
</Tanks.Column>
|
|
||||||
<Tanks.Column>
|
|
||||||
{await Promise.all(
|
|
||||||
rightColumn.map(async (tank) => (
|
|
||||||
<Tanks.Item
|
|
||||||
key={tank.id}
|
|
||||||
name={tank.name}
|
|
||||||
tankType={tank.type}
|
|
||||||
image={tankIcon(tank.id)}
|
|
||||||
treeType={tank.treeType}
|
|
||||||
/>
|
|
||||||
)),
|
|
||||||
)}
|
|
||||||
</Tanks.Column>
|
|
||||||
</Tanks.Row>
|
|
||||||
</Tanks.Root>
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
))}
|
|
||||||
</Wrapper>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
autocomplete: autocompleteUsername,
|
|
||||||
};
|
|
||||||
+43
-37
@@ -1,42 +1,48 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
|
import { translator } from '../core/localization/translator';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|
||||||
export const permissionsCommand: CommandRegistry = {
|
export const permissionsCommand = new Promise<CommandRegistry>((resolve) => {
|
||||||
inProduction: true,
|
resolve({
|
||||||
inPublic: true,
|
inProduction: true,
|
||||||
|
inPublic: true,
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
command: createLocalizedCommand('permissions'),
|
||||||
.setName('permissions')
|
|
||||||
.setDescription('Checks wether the bot has the required permissions'),
|
|
||||||
|
|
||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
// friday the 13th permissions easter egg
|
const { t, translate } = translator(interaction.locale);
|
||||||
const isFridayThe13th =
|
// friday the 13th permissions easter egg
|
||||||
new Date().getDay() === 5 && new Date().getDate() === 13;
|
const isFridayThe13th =
|
||||||
const permissions = [
|
new Date().getDay() === 5 && new Date().getDate() === 13;
|
||||||
[
|
const permissions = [
|
||||||
interaction.appPermissions?.has('ViewChannel'),
|
[
|
||||||
'View channels: needed for the refresh button to work',
|
interaction.appPermissions?.has('ViewChannel'),
|
||||||
],
|
t`bot.commands.permissions.body.view_channels`,
|
||||||
[
|
],
|
||||||
interaction.appPermissions?.has('ReadMessageHistory'),
|
[
|
||||||
'Read message history: also needed for the refresh button to work',
|
interaction.appPermissions?.has('ReadMessageHistory'),
|
||||||
],
|
t`bot.commands.permissions.body.read_message_history`,
|
||||||
[
|
],
|
||||||
interaction.appPermissions?.has('AttachFiles'),
|
[
|
||||||
'Attach files: needed for image-based commands to work',
|
interaction.appPermissions?.has('AttachFiles'),
|
||||||
],
|
t`bot.commands.permissions.body.attach_files`,
|
||||||
];
|
],
|
||||||
const body = permissions
|
[
|
||||||
.map(([hasPermission, description]) => {
|
interaction.appPermissions?.has('UseExternalEmojis'),
|
||||||
if (hasPermission) {
|
t`bot.commands.permissions.body.external_emojis`,
|
||||||
return `${isFridayThe13th ? '😇' : '✅'} ${description}`;
|
],
|
||||||
} else {
|
];
|
||||||
return `${isFridayThe13th ? '💀' : '❌'} ${description}`;
|
const body = permissions
|
||||||
}
|
.map(([hasPermission, description]) => {
|
||||||
})
|
if (hasPermission) {
|
||||||
.join('\n');
|
return `${isFridayThe13th ? '😇' : '✅'} ${description}`;
|
||||||
|
} else {
|
||||||
|
return `${isFridayThe13th ? '💀' : '❌'} ${description}`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.join('\n');
|
||||||
|
|
||||||
return `# Permissions\n${body}`;
|
return translate('bot.commands.permissions.body.title', [body]);
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
});
|
||||||
+29
-26
@@ -1,32 +1,35 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
|
import { translator } from '../core/localization/translator';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|
||||||
export const pingCommand: CommandRegistry = {
|
export const pingCommand = new Promise<CommandRegistry>((resolve) => {
|
||||||
inProduction: true,
|
resolve({
|
||||||
inPublic: true,
|
inProduction: true,
|
||||||
handlesInteraction: true,
|
inPublic: true,
|
||||||
|
handlesInteraction: true,
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
command: createLocalizedCommand('ping', [
|
||||||
.setName('ping')
|
{ subcommand: 'blitzkrieg' },
|
||||||
.setDescription('Check if the bot is alive')
|
{ subcommand: 'wotb' },
|
||||||
.addSubcommand((option) =>
|
]),
|
||||||
option.setName('blitzkrieg').setDescription('Ping Blitzkrieg'),
|
|
||||||
)
|
|
||||||
.addSubcommand((option) =>
|
|
||||||
option.setName('blitz').setDescription('Ping Blitz'),
|
|
||||||
),
|
|
||||||
|
|
||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
const subcommand = interaction.options.getSubcommand();
|
const { t, translate } = translator(interaction.locale);
|
||||||
const executionStart = Date.now();
|
const subcommand = interaction.options.getSubcommand();
|
||||||
|
const executionStart = Date.now();
|
||||||
|
|
||||||
if (subcommand === 'blitzkrieg') {
|
if (subcommand === 'blitzkrieg') {
|
||||||
await interaction.editReply('Pong 🏓');
|
await interaction.editReply(t`bot.commands.ping.body.pong`);
|
||||||
} else {
|
} else {
|
||||||
await fetch('https://api.wotblitz.com/');
|
await fetch('https://api.wotblitz.com/');
|
||||||
}
|
}
|
||||||
|
|
||||||
const executionTime = Date.now() - executionStart;
|
const executionTime = Date.now() - executionStart;
|
||||||
interaction.editReply(`Pong 🏓 - ${executionTime}ms`);
|
interaction.editReply(
|
||||||
},
|
translate('bot.commands.ping.body.pong_with_time', [
|
||||||
};
|
`${Math.round(executionTime)}`,
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,68 +1,80 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
// _____ _____ _ _ _ _ _____ ____ __ __ ______ ____ _____ _ __
|
||||||
import { startCase } from 'lodash';
|
// |_ _| / ____| | | | /\ | | | | / ____/ __ \| \/ | ____| | _ \ /\ / ____| |/ /
|
||||||
import markdownEscape from 'markdown-escape';
|
// | | | (___ | |__| | / \ | | | | | | | | | | \ / | |__ | |_) | / \ | | | ' /
|
||||||
import { getAccountAchievements } from '../core/blitz/getAccountAchievements';
|
// | | \___ \| __ | / /\ \ | | | | | | | | | | |\/| | __| | _ < / /\ \| | | <
|
||||||
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
// _| |_ ____) | | | |/ ____ \| |____| |____ | |___| |__| | | | | |____ | |_) / ____ \ |____| . \
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
// |_____| |_____/|_| |_/_/ \_\______|______| \_____\____/|_| |_|______| |____/_/ \_\_____|_|\_\
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
|
||||||
import embedInfo from '../core/discord/embedInfo';
|
|
||||||
import markdownTable, { TableInputEntry } from '../core/discord/markdownTable';
|
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
|
||||||
|
|
||||||
type SortBy = 'name' | 'count';
|
// import { SlashCommandBuilder } from 'discord.js';
|
||||||
|
// import { startCase } from 'lodash';
|
||||||
|
// import markdownEscape from 'markdown-escape';
|
||||||
|
// import { getAccountAchievements } from '../core/blitz/getAccountAchievements';
|
||||||
|
// import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
|
// import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
|
// import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
|
// import embedInfo from '../core/discord/embedInfo';
|
||||||
|
// import markdownTable, { TableInputEntry } from '../core/discord/markdownTable';
|
||||||
|
// import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||||
|
// import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|
||||||
export const playerAchievementsCommand: CommandRegistry = {
|
// type SortBy = 'name' | 'count';
|
||||||
inProduction: true,
|
|
||||||
inPublic: true,
|
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
// export const playerAchievementsCommand = new Promise<CommandRegistry>(
|
||||||
.setName('player-achievements')
|
// (resolve) => {
|
||||||
.setDescription("All the player's achievements")
|
// resolve({
|
||||||
.addStringOption(addUsernameChoices)
|
// inProduction: true,
|
||||||
.addStringOption((option) =>
|
// inPublic: true,
|
||||||
option
|
|
||||||
.setName('sort')
|
|
||||||
.setDescription('What to sort by (default: name)')
|
|
||||||
.addChoices(
|
|
||||||
{ name: 'By name', value: 'name' satisfies SortBy },
|
|
||||||
{ name: 'By count', value: 'count' satisfies SortBy },
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
async handler(interaction) {
|
// command: new SlashCommandBuilder()
|
||||||
const sortBy = (interaction.options.getString('sort') ?? 'name') as SortBy;
|
// .setName('player-achievements')
|
||||||
const account = await resolvePlayerFromCommand(interaction);
|
// .setDescription("All the player's achievements")
|
||||||
const { id, region: region } = account;
|
// .addStringOption(addUsernameChoices)
|
||||||
const accountInfo = await getAccountInfo(region, id);
|
// .addStringOption((option) =>
|
||||||
const accountsAchievements = await getAccountAchievements(region, id);
|
// option
|
||||||
const accountAchievements = accountsAchievements;
|
// .setName('sort')
|
||||||
const compound = {
|
// .setDescription('What to sort by (default: name)')
|
||||||
...accountAchievements.achievements,
|
// .addChoices(
|
||||||
...accountAchievements.max_series,
|
// { name: 'By name', value: 'name' satisfies SortBy },
|
||||||
};
|
// { name: 'By count', value: 'count' satisfies SortBy },
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
|
||||||
return embedInfo(
|
// async handler(interaction) {
|
||||||
`${markdownEscape(accountInfo.nickname)}'s information`,
|
// const sortBy = (interaction.options.getString('sort') ??
|
||||||
|
// 'name') as SortBy;
|
||||||
|
// const account = await resolvePlayerFromCommand(interaction);
|
||||||
|
// const { id, region: region } = account;
|
||||||
|
// const accountInfo = await getAccountInfo(region, id);
|
||||||
|
// const accountsAchievements = await getAccountAchievements(region, id);
|
||||||
|
// const accountAchievements = accountsAchievements;
|
||||||
|
// const compound = {
|
||||||
|
// ...accountAchievements.achievements,
|
||||||
|
// ...accountAchievements.max_series,
|
||||||
|
// };
|
||||||
|
|
||||||
markdownTable(
|
// return embedInfo(
|
||||||
Object.keys(compound)
|
// `${markdownEscape(accountInfo.nickname)}'s information`,
|
||||||
.filter((achievement) => compound[achievement] > 0)
|
|
||||||
.sort(
|
|
||||||
sortBy === 'count'
|
|
||||||
? (a, b) => compound[b] - compound[a]
|
|
||||||
: undefined,
|
|
||||||
)
|
|
||||||
.map(
|
|
||||||
(achievement) =>
|
|
||||||
[
|
|
||||||
startCase(achievement),
|
|
||||||
compound[achievement],
|
|
||||||
] as TableInputEntry,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
autocomplete: autocompleteUsername,
|
// markdownTable(
|
||||||
};
|
// Object.keys(compound)
|
||||||
|
// .filter((achievement) => compound[achievement] > 0)
|
||||||
|
// .sort(
|
||||||
|
// sortBy === 'count'
|
||||||
|
// ? (a, b) => compound[b] - compound[a]
|
||||||
|
// : undefined,
|
||||||
|
// )
|
||||||
|
// .map(
|
||||||
|
// (achievement) =>
|
||||||
|
// [
|
||||||
|
// startCase(achievement),
|
||||||
|
// compound[achievement],
|
||||||
|
// ] as TableInputEntry,
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
|
||||||
|
// autocomplete: autocompleteUsername,
|
||||||
|
// });
|
||||||
|
// },
|
||||||
|
// );
|
||||||
+57
-40
@@ -1,54 +1,71 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
|
||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
import embedInfo from '../core/discord/embedInfo';
|
import embedInfo from '../core/discord/embedInfo';
|
||||||
import markdownTable from '../core/discord/markdownTable';
|
import markdownTable from '../core/discord/markdownTable';
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||||
|
import { translator } from '../core/localization/translator';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|
||||||
export const playerInfoCommand: CommandRegistry = {
|
export const playerInfoCommand = new Promise<CommandRegistry>((resolve) => {
|
||||||
inProduction: true,
|
resolve({
|
||||||
inPublic: true,
|
inProduction: true,
|
||||||
|
inPublic: true,
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
command:
|
||||||
.setName('player-info')
|
createLocalizedCommand('player-info').addStringOption(addUsernameChoices),
|
||||||
.setDescription('Basic information about a player')
|
|
||||||
.addStringOption(addUsernameChoices),
|
|
||||||
|
|
||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
const account = await resolvePlayerFromCommand(interaction);
|
const { t, translate } = translator(interaction.locale);
|
||||||
const { id, region: region } = account;
|
const account = await resolvePlayerFromCommand(interaction);
|
||||||
const accountInfo = await getAccountInfo(region, id);
|
const { id, region: region } = account;
|
||||||
|
const accountInfo = await getAccountInfo(region, id);
|
||||||
|
|
||||||
return embedInfo(
|
return embedInfo(
|
||||||
`${markdownEscape(accountInfo.nickname)}'s information`,
|
translate('bot.commands.player_info.body.title', [
|
||||||
|
markdownEscape(accountInfo.nickname),
|
||||||
|
]),
|
||||||
|
|
||||||
markdownTable([
|
markdownTable([
|
||||||
['Nickname', `${accountInfo.nickname}`],
|
[
|
||||||
['Battles', `${accountInfo.statistics.all.battles}`],
|
t`bot.commands.player_info.body.nickname`,
|
||||||
[
|
`${accountInfo.nickname}`,
|
||||||
'Winrate',
|
],
|
||||||
`${(
|
[
|
||||||
100 *
|
t`bot.commands.player_info.body.battles`,
|
||||||
(accountInfo.statistics.all.wins /
|
`${accountInfo.statistics.all.battles}`,
|
||||||
accountInfo.statistics.all.battles)
|
],
|
||||||
).toFixed(2)}%`,
|
[
|
||||||
],
|
t`bot.commands.player_info.body.winrate`,
|
||||||
[],
|
`${(
|
||||||
['Account ID', `${accountInfo.account_id}`],
|
100 *
|
||||||
[
|
(accountInfo.statistics.all.wins /
|
||||||
'Created',
|
accountInfo.statistics.all.battles)
|
||||||
`${new Date(accountInfo.created_at * 1000).toDateString()}`,
|
).toFixed(2)}%`,
|
||||||
],
|
],
|
||||||
[
|
[],
|
||||||
'Last battle',
|
[
|
||||||
`${new Date(accountInfo.last_battle_time * 1000).toDateString()}`,
|
t`bot.commands.player_info.body.account_id`,
|
||||||
],
|
`${accountInfo.account_id}`,
|
||||||
]),
|
],
|
||||||
);
|
[
|
||||||
},
|
t`bot.commands.player_info.body.created`,
|
||||||
|
new Date(accountInfo.created_at * 1000).toLocaleDateString(
|
||||||
|
interaction.locale,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
t`bot.commands.player_info.body.last_battle`,
|
||||||
|
new Date(accountInfo.last_battle_time * 1000).toLocaleDateString(
|
||||||
|
interaction.locale,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
autocomplete: autocompleteUsername,
|
autocomplete: autocompleteUsername,
|
||||||
};
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,494 @@
|
|||||||
|
import markdownEscape from 'markdown-escape';
|
||||||
|
import { Glow } from '../components/AllStatsOverview/components/HeroStat/components/Glow';
|
||||||
|
import CommandWrapper from '../components/CommandWrapper';
|
||||||
|
import { DeltaCaret } from '../components/DeltaCaret';
|
||||||
|
import TitleBar from '../components/TitleBar';
|
||||||
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
|
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||||
|
import { getLeagueFromScore } from '../core/blitz/getLeagueFromScore';
|
||||||
|
import getRatingInfo from '../core/blitz/getRatingInfo';
|
||||||
|
import { getRatingNeighbors } from '../core/blitz/getRatingNeighbors';
|
||||||
|
import { normalizeLeagueIcon } from '../core/blitz/normalizeLeagueIcon';
|
||||||
|
import { emblemURL } from '../core/blitzkrieg/emblemURL';
|
||||||
|
import getArchivedRatingMidnightLeaderboard from '../core/blitzkrieg/getArchivedRatingMidnightLeaderboard';
|
||||||
|
import { webpToPng } from '../core/blitzkrieg/iconPng';
|
||||||
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||||
|
import { translator } from '../core/localization/translator';
|
||||||
|
import { deltaBkrlBlitzStats } from '../core/statistics/deltaBkrlBlitzStats';
|
||||||
|
import { BkrlFormat } from '../core/streams/bkrl';
|
||||||
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
import { theme } from '../stitches.config';
|
||||||
|
|
||||||
|
const LEAGUE_ACCENT = [
|
||||||
|
'_purple',
|
||||||
|
'_sand',
|
||||||
|
'_amber',
|
||||||
|
'_mauve',
|
||||||
|
'_brown',
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export const ratingCommand = new Promise<CommandRegistry>((resolve) => {
|
||||||
|
resolve({
|
||||||
|
command:
|
||||||
|
createLocalizedCommand('rating').addStringOption(addUsernameChoices),
|
||||||
|
|
||||||
|
inProduction: true,
|
||||||
|
inPublic: true,
|
||||||
|
|
||||||
|
async handler(interaction) {
|
||||||
|
const { t, translate } = translator(interaction.locale);
|
||||||
|
const { id, region } = await resolvePlayerFromCommand(interaction);
|
||||||
|
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
||||||
|
const clanImage = clan ? emblemURL(clan.emblem_set_id) : undefined;
|
||||||
|
const leaderboard = await getArchivedRatingMidnightLeaderboard(
|
||||||
|
region,
|
||||||
|
53,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (leaderboard?.format === BkrlFormat.Base) {
|
||||||
|
throw new Error(
|
||||||
|
'Encountered bkrl minimal format in latest season. Wait till next cron?',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const ratingInfo = await getRatingInfo(region);
|
||||||
|
const accountInfo = await getAccountInfo(region, id, [
|
||||||
|
'statistics.rating',
|
||||||
|
]);
|
||||||
|
const statsIndex = leaderboard?.entries.findIndex(
|
||||||
|
(entry) => entry.id === id,
|
||||||
|
);
|
||||||
|
const statsA = leaderboard ? leaderboard.entries[statsIndex!] : null;
|
||||||
|
const positionA = leaderboard ? statsIndex! + 1 : undefined;
|
||||||
|
const statsB1 = accountInfo.statistics.rating!;
|
||||||
|
const [statsB2] = (await getRatingNeighbors(region, id, 0)).neighbors;
|
||||||
|
const league = getLeagueFromScore(statsB2.score);
|
||||||
|
|
||||||
|
if (ratingInfo.detail) {
|
||||||
|
throw new Error(`Rating info not available for ${region}`);
|
||||||
|
}
|
||||||
|
if (!statsA) {
|
||||||
|
return t`bot.commands.rating.errors.unrecorded_stats`;
|
||||||
|
}
|
||||||
|
if (!statsB1) {
|
||||||
|
return translate('bot.commands.rating.errors.no_participation', [
|
||||||
|
markdownEscape(accountInfo.nickname),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const reward = ratingInfo.rewards.find(
|
||||||
|
(reward) =>
|
||||||
|
statsB2.number >= reward.from_position &&
|
||||||
|
statsB2.number <= reward.to_position,
|
||||||
|
);
|
||||||
|
const positionDelta = leaderboard
|
||||||
|
? statsB2.number - positionA!
|
||||||
|
: undefined;
|
||||||
|
const delta = deltaBkrlBlitzStats(
|
||||||
|
statsA,
|
||||||
|
accountInfo.statistics.rating!,
|
||||||
|
statsB2,
|
||||||
|
);
|
||||||
|
const leagueTheme = LEAGUE_ACCENT[league.index];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CommandWrapper>
|
||||||
|
<TitleBar
|
||||||
|
title={accountInfo.nickname}
|
||||||
|
image={clanImage}
|
||||||
|
description={`${t`bot.commands.rating.body.subtitle`} • ${new Date().toLocaleDateString(
|
||||||
|
interaction.locale,
|
||||||
|
)}`}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: 'relative',
|
||||||
|
display: 'flex',
|
||||||
|
overflow: 'hidden',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: 'relative',
|
||||||
|
padding: 16,
|
||||||
|
backgroundColor: theme.colors[`appBackground2${leagueTheme}`],
|
||||||
|
borderRadius: 4,
|
||||||
|
border: `1px solid ${theme.colors[`componentInteractive${leagueTheme}`]}`,
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
width: '100%',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{reward === undefined && (
|
||||||
|
<Glow
|
||||||
|
endOpacity={3 / 4}
|
||||||
|
color={theme.colors[`solidBackground${leagueTheme}`]}
|
||||||
|
style={{
|
||||||
|
transform: 'translateX(-16px) rotate(90deg)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
gap: 8,
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
style={{
|
||||||
|
width: 64,
|
||||||
|
height: 64,
|
||||||
|
objectFit: 'contain',
|
||||||
|
}}
|
||||||
|
src={normalizeLeagueIcon(
|
||||||
|
ratingInfo.leagues[league.index].big_icon,
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'flex-start',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color: theme.colors[`textHighContrast${leagueTheme}`],
|
||||||
|
fontSize: 24,
|
||||||
|
fontWeight: 900,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{statsB2.score.toLocaleString(interaction.locale)}
|
||||||
|
</span>
|
||||||
|
{delta.score !== 0 && (
|
||||||
|
<>
|
||||||
|
<DeltaCaret delta={delta.score} />
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color:
|
||||||
|
delta.score > 0
|
||||||
|
? theme.colors.textLowContrast_green
|
||||||
|
: theme.colors.textLowContrast_red,
|
||||||
|
fontSize: 16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{Math.abs(delta.score).toLocaleString(
|
||||||
|
interaction.locale,
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'flex-start',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color: theme.colors[`textLowContrast${leagueTheme}`],
|
||||||
|
fontSize: 16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
#{statsB2.number.toLocaleString(interaction.locale)}
|
||||||
|
</span>
|
||||||
|
{positionDelta !== undefined && positionDelta !== 0 && (
|
||||||
|
<>
|
||||||
|
<DeltaCaret delta={positionDelta} />
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color:
|
||||||
|
positionDelta > 0
|
||||||
|
? theme.colors.textLowContrast_green
|
||||||
|
: theme.colors.textLowContrast_red,
|
||||||
|
fontSize: 16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{Math.abs(positionDelta).toLocaleString(
|
||||||
|
interaction.locale,
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{reward && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
gap: 8,
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'flex-end',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color: theme.colors[`textHighContrast${leagueTheme}`],
|
||||||
|
fontSize: 16,
|
||||||
|
maxWidth: 136,
|
||||||
|
textAlign: 'right',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
overflow: 'hidden',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{reward.type === 'vehicle'
|
||||||
|
? reward.vehicle.user_string
|
||||||
|
: reward.stuff.title}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'flex-end',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color: theme.colors[`textLowContrast${leagueTheme}`],
|
||||||
|
fontSize: 16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Reward
|
||||||
|
{reward.type === 'stuff' ? ` x${reward.count}` : ''}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<img
|
||||||
|
style={{
|
||||||
|
width: 64,
|
||||||
|
height: 64,
|
||||||
|
objectFit: 'cover',
|
||||||
|
}}
|
||||||
|
src={await webpToPng(
|
||||||
|
reward.type === 'vehicle'
|
||||||
|
? reward.vehicle.preview_image_url
|
||||||
|
: reward.stuff.image_url,
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{reward === undefined && (
|
||||||
|
<Glow
|
||||||
|
endOpacity={3 / 4}
|
||||||
|
color={theme.colors[`solidBackground${leagueTheme}`]}
|
||||||
|
style={{
|
||||||
|
transform: 'translateX(16px) rotate(-90deg)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* separated because fragment middle man invalidates relative parent: https://github.com/vercel/satori/issues/605 */}
|
||||||
|
{reward && (
|
||||||
|
<Glow
|
||||||
|
direction="reverse"
|
||||||
|
color={theme.colors[`solidBackground${leagueTheme}`]}
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: -40,
|
||||||
|
left: '50%',
|
||||||
|
transform: 'translateX(-50%)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{reward && (
|
||||||
|
<Glow
|
||||||
|
color={theme.colors[`solidBackground${leagueTheme}`]}
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
bottom: -40,
|
||||||
|
left: '50%',
|
||||||
|
transform: 'translateX(-50%)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{delta.battles > 0 && (
|
||||||
|
<div style={{ padding: '8px 0', display: 'flex' }}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: 4,
|
||||||
|
flex: 1,
|
||||||
|
flexDirection: 'column',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 24,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
fontWeight: 'bold',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{delta.battles.toLocaleString(interaction.locale)}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textLowContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Battles
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: 4,
|
||||||
|
flex: 1,
|
||||||
|
flexDirection: 'column',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 24,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
fontWeight: 'bold',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{(100 * (delta.wins / delta.battles)).toFixed(0)}%
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textLowContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Winrate
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: 4,
|
||||||
|
flex: 1,
|
||||||
|
flexDirection: 'column',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 24,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
fontWeight: 'bold',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{Math.round(delta.damage / delta.battles).toLocaleString(
|
||||||
|
interaction.locale,
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textLowContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Damage
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: 4,
|
||||||
|
flex: 1,
|
||||||
|
flexDirection: 'column',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 24,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
fontWeight: 'bold',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{(100 * (delta.survived / delta.battles)).toFixed(0)}%
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textLowContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Survival
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: 4,
|
||||||
|
flex: 1,
|
||||||
|
flexDirection: 'column',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 24,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
fontWeight: 'bold',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{(delta.kills / delta.battles).toFixed(2)}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textLowContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Kills
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</CommandWrapper>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,36 +1,38 @@
|
|||||||
import {
|
import {
|
||||||
APIApplicationCommandOptionChoice,
|
APIApplicationCommandOptionChoice,
|
||||||
SlashCommandBuilder,
|
Locale,
|
||||||
SlashCommandSubcommandBuilder,
|
SlashCommandSubcommandBuilder,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { range } from 'lodash';
|
import { range } from 'lodash';
|
||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import { BlitzkriegRatingsLeaderboard } from '../../scripts/buildRatingsLeaderboard';
|
import CommandWrapper from '../components/CommandWrapper';
|
||||||
import * as Leaderboard from '../components/Leaderboard';
|
import * as Leaderboard from '../components/Leaderboard';
|
||||||
import TitleBar from '../components/TitleBar';
|
import TitleBar from '../components/TitleBar';
|
||||||
import Wrapper from '../components/Wrapper';
|
|
||||||
import { LEAGUES } from '../constants/leagues';
|
import { LEAGUES } from '../constants/leagues';
|
||||||
import { FIRST_ARCHIVED_RATINGS_SEASON } from '../constants/ratings';
|
import { FIRST_MINIMAL_ARCHIVED_RATING_SEASON } from '../constants/rating';
|
||||||
import { REGION_NAMES_SHORT, Region } from '../constants/regions';
|
import { Region } from '../constants/regions';
|
||||||
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||||
import getRatingsInfo from '../core/blitz/getRatingsInfo';
|
import getRatingInfo from '../core/blitz/getRatingInfo';
|
||||||
import { getRatingsLeague } from '../core/blitz/getRatingsLeague';
|
import { getRatingLeague } from '../core/blitz/getRatingLeague';
|
||||||
import { getRatingsNeighbors } from '../core/blitz/getRatingsNeighbors';
|
import { getRatingNeighbors } from '../core/blitz/getRatingNeighbors';
|
||||||
import { isOnGoingRatingsSeason } from '../core/blitz/isOnGoingRatingsSeason';
|
import { isOnGoingRatingSeason } from '../core/blitz/isOnGoingRatingSeason';
|
||||||
import { getArchivedLatestSeasonNumber } from '../core/blitzkrieg/getArchivedLatestSeasonNumber';
|
import { getArchivedLatestSeasonNumber } from '../core/blitzkrieg/getArchivedLatestSeasonNumber';
|
||||||
import getArchivedRatingsInfo from '../core/blitzkrieg/getArchivedRatingsInfo';
|
import getArchivedRatingInfo from '../core/blitzkrieg/getArchivedRatingInfo';
|
||||||
import { getArchivedRatingsLeaderboard } from '../core/blitzkrieg/getArchivedRatingsLeaderboard';
|
import { getArchivedRatingLeaderboard } from '../core/blitzkrieg/getArchivedRatingLeaderboard';
|
||||||
import getArchivedRatingsMidnightLeaderboard from '../core/blitzkrieg/getArchivedRatingsMidnightLeaderboard';
|
import getArchivedRatingMidnightLeaderboard from '../core/blitzkrieg/getArchivedRatingMidnightLeaderboard';
|
||||||
import addRegionChoices from '../core/discord/addRegionChoices';
|
import addRegionChoices from '../core/discord/addRegionChoices';
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
import embedNegative from '../core/discord/embedNegative';
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
|
import { localizationObject } from '../core/discord/localizationObject';
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||||
import { CommandRegistryPromisable } from '../events/interactionCreate';
|
import { translator } from '../core/localization/translator';
|
||||||
|
import { BkrlDiscriminatedEntries } from '../core/streams/bkrl';
|
||||||
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
import { UserError } from '../hooks/userError';
|
import { UserError } from '../hooks/userError';
|
||||||
|
|
||||||
export interface RatingsPlayer {
|
export interface RatingPlayer {
|
||||||
spa_id: number;
|
spa_id: number;
|
||||||
mmr: number;
|
mmr: number;
|
||||||
season_number: number;
|
season_number: number;
|
||||||
@@ -45,10 +47,10 @@ export interface RatingsPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface LeagueTop {
|
export interface LeagueTop {
|
||||||
result: RatingsPlayer[];
|
result: RatingPlayer[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RatingsReward = {
|
export type RatingReward = {
|
||||||
from_position: number;
|
from_position: number;
|
||||||
to_position: number;
|
to_position: number;
|
||||||
count: number;
|
count: number;
|
||||||
@@ -67,7 +69,7 @@ export type RatingsReward = {
|
|||||||
roman_level: string;
|
roman_level: string;
|
||||||
user_string: string;
|
user_string: string;
|
||||||
image_url: string;
|
image_url: string;
|
||||||
preview_url: string;
|
preview_image_url: string;
|
||||||
is_premium: boolean;
|
is_premium: boolean;
|
||||||
is_collectible: boolean;
|
is_collectible: boolean;
|
||||||
};
|
};
|
||||||
@@ -87,7 +89,7 @@ export type RatingsReward = {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export interface RatingsLeague {
|
export interface RatingLeague {
|
||||||
title: string;
|
title: string;
|
||||||
small_icon: string;
|
small_icon: string;
|
||||||
big_icon: string;
|
big_icon: string;
|
||||||
@@ -96,7 +98,7 @@ export interface RatingsLeague {
|
|||||||
percentile: number;
|
percentile: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RatingsInfo =
|
export type RatingInfo =
|
||||||
| {
|
| {
|
||||||
detail: undefined;
|
detail: undefined;
|
||||||
|
|
||||||
@@ -108,112 +110,172 @@ export type RatingsInfo =
|
|||||||
updated_at: string;
|
updated_at: string;
|
||||||
count: number;
|
count: number;
|
||||||
|
|
||||||
rewards: RatingsReward[];
|
rewards: RatingReward[];
|
||||||
leagues: RatingsLeague[];
|
leagues: RatingLeague[];
|
||||||
}
|
}
|
||||||
| { detail: { error: string } };
|
| { detail: { error: string } };
|
||||||
|
|
||||||
export interface RatingsNeighbors {
|
export interface RatingNeighbors {
|
||||||
neighbors: RatingsPlayer[];
|
neighbors: RatingPlayer[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const noOngoingSeason = embedNegative(
|
interface SimplifiedPlayer {
|
||||||
'No ongoing season',
|
id: number;
|
||||||
"Wargaming didn't provide any data for this season.",
|
score: number;
|
||||||
);
|
position: number;
|
||||||
|
clan: string | undefined;
|
||||||
|
nickname: string;
|
||||||
|
}
|
||||||
|
|
||||||
export const ratingsCommand = new Promise<CommandRegistryPromisable>(
|
const DEFAULT_LIMIT = 10;
|
||||||
|
|
||||||
|
export const ratingLeaderboardCommand = new Promise<CommandRegistry>(
|
||||||
async (resolve) => {
|
async (resolve) => {
|
||||||
const latestArchivedSeasonNumber = await getArchivedLatestSeasonNumber();
|
const latestArchivedSeasonNumber = await getArchivedLatestSeasonNumber();
|
||||||
const onGoingSeason = await isOnGoingRatingsSeason();
|
const onGoingSeason = await isOnGoingRatingSeason();
|
||||||
const seasonNumbers = range(
|
const seasonNumbers = range(
|
||||||
FIRST_ARCHIVED_RATINGS_SEASON,
|
FIRST_MINIMAL_ARCHIVED_RATING_SEASON,
|
||||||
latestArchivedSeasonNumber + (onGoingSeason ? 1 : 0) + 1,
|
latestArchivedSeasonNumber + (onGoingSeason ? 1 : 0) + 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
function addSubcommands(option: SlashCommandSubcommandBuilder) {
|
function addOptions(option: SlashCommandSubcommandBuilder) {
|
||||||
|
const { t, translate } = translator(Locale.EnglishUS);
|
||||||
|
|
||||||
return option
|
return option
|
||||||
.addStringOption(addUsernameChoices)
|
|
||||||
.addIntegerOption((option) =>
|
.addIntegerOption((option) =>
|
||||||
option
|
option
|
||||||
.setName('limit')
|
.setName(t`bot.commands.rating_leaderboard.options.limit`)
|
||||||
.setDescription('How many neighbors to display (default: 10)')
|
.setNameLocalizations(
|
||||||
|
localizationObject(
|
||||||
|
'bot.commands.rating_leaderboard.options.limit',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.setDescription(
|
||||||
|
translate(
|
||||||
|
'bot.commands.rating_leaderboard.options.limit.description',
|
||||||
|
[`${DEFAULT_LIMIT}`],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.setDescriptionLocalizations(
|
||||||
|
localizationObject(
|
||||||
|
'bot.commands.rating_leaderboard.options.limit.description',
|
||||||
|
[`${DEFAULT_LIMIT}`],
|
||||||
|
),
|
||||||
|
)
|
||||||
.setRequired(false)
|
.setRequired(false)
|
||||||
.setMinValue(5)
|
.setMinValue(5)
|
||||||
.setMaxValue(30),
|
.setMaxValue(30),
|
||||||
)
|
)
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
.setName('season')
|
.setName(t`bot.commands.rating_leaderboard.options.season`)
|
||||||
.setDescription('Season number')
|
.setNameLocalizations(
|
||||||
|
localizationObject(
|
||||||
|
'bot.commands.rating_leaderboard.options.season',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.setDescription(
|
||||||
|
translate(
|
||||||
|
'bot.commands.rating_leaderboard.options.season.description',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.setDescriptionLocalizations(
|
||||||
|
localizationObject(
|
||||||
|
'bot.commands.rating_leaderboard.options.season.description',
|
||||||
|
),
|
||||||
|
)
|
||||||
.setRequired(false)
|
.setRequired(false)
|
||||||
.addChoices(
|
.addChoices(
|
||||||
...seasonNumbers
|
...seasonNumbers
|
||||||
.map(
|
.map((number, index) => {
|
||||||
(number, index) =>
|
const current =
|
||||||
({
|
index === seasonNumbers.length - 1 && onGoingSeason;
|
||||||
name: `${number}${index === seasonNumbers.length - 1 && onGoingSeason ? ' (current)' : ''}`,
|
|
||||||
value: `${number}`,
|
return {
|
||||||
}) satisfies APIApplicationCommandOptionChoice<string>,
|
name: current
|
||||||
)
|
? translate(
|
||||||
|
'bot.commands.rating_leaderboard.options.season.choices.current',
|
||||||
|
[`${number}`],
|
||||||
|
)
|
||||||
|
: `${number}`,
|
||||||
|
value: `${number}`,
|
||||||
|
name_localizations: current
|
||||||
|
? localizationObject(
|
||||||
|
'bot.commands.rating_leaderboard.options.season.choices.current',
|
||||||
|
[`${number}`],
|
||||||
|
)
|
||||||
|
: undefined,
|
||||||
|
} satisfies APIApplicationCommandOptionChoice<string>;
|
||||||
|
})
|
||||||
.reverse(),
|
.reverse(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const command = new SlashCommandBuilder()
|
|
||||||
.setName('ratings')
|
|
||||||
.setDescription('Ratings battles statistics')
|
|
||||||
.addSubcommand((option) =>
|
|
||||||
addSubcommands(
|
|
||||||
option
|
|
||||||
.setName('neighbors')
|
|
||||||
.setDescription('Shows neighboring players on the leaderboard'),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.addSubcommand((option) =>
|
|
||||||
addSubcommands(
|
|
||||||
option
|
|
||||||
.setName('league')
|
|
||||||
.setDescription('Shows top players from a league')
|
|
||||||
.addStringOption(addRegionChoices)
|
|
||||||
.addStringOption((option) =>
|
|
||||||
option
|
|
||||||
.setName('league')
|
|
||||||
.setDescription('The league to display')
|
|
||||||
.addChoices(
|
|
||||||
...LEAGUES.map(
|
|
||||||
({ name }, value) =>
|
|
||||||
({
|
|
||||||
name,
|
|
||||||
value: `${value}`,
|
|
||||||
}) satisfies APIApplicationCommandOptionChoice<string>,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.setRequired(true),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
resolve({
|
resolve({
|
||||||
inProduction: true,
|
inProduction: true,
|
||||||
inPublic: true,
|
inPublic: true,
|
||||||
|
|
||||||
command,
|
command: createLocalizedCommand('rating-leaderboard', [
|
||||||
|
{
|
||||||
|
subcommand: 'neighbors',
|
||||||
|
modify(option: SlashCommandSubcommandBuilder) {
|
||||||
|
option.addStringOption(addUsernameChoices);
|
||||||
|
addOptions(option);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
subcommand: 'league',
|
||||||
|
modify(option: SlashCommandSubcommandBuilder) {
|
||||||
|
option
|
||||||
|
.addStringOption((option) => {
|
||||||
|
const { t, translate } = translator(Locale.EnglishUS);
|
||||||
|
|
||||||
|
return option
|
||||||
|
.setName(t`bot.commands.rating_leaderboard.options.league`)
|
||||||
|
.setNameLocalizations(
|
||||||
|
localizationObject(
|
||||||
|
'bot.commands.rating_leaderboard.options.league',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.setDescription(
|
||||||
|
translate(
|
||||||
|
'bot.commands.rating_leaderboard.options.league.description',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.setDescriptionLocalizations(
|
||||||
|
localizationObject(
|
||||||
|
'bot.commands.rating_leaderboard.options.league.description',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.addChoices(
|
||||||
|
...LEAGUES.map(
|
||||||
|
({ name }, value) =>
|
||||||
|
({
|
||||||
|
name: translate(`common.leagues.${name}`),
|
||||||
|
value: `${value}`,
|
||||||
|
name_localizations: localizationObject(
|
||||||
|
`common.leagues.${name}`,
|
||||||
|
),
|
||||||
|
}) satisfies APIApplicationCommandOptionChoice<string>,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.setRequired(true);
|
||||||
|
})
|
||||||
|
.addStringOption(addRegionChoices);
|
||||||
|
addOptions(option);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
|
||||||
|
// BIG TODO: title seems to be in english
|
||||||
|
|
||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
interface SimplifiedPlayer {
|
const { t, translate } = translator(interaction.locale);
|
||||||
id: number;
|
|
||||||
score: number;
|
|
||||||
position: number;
|
|
||||||
clan: string | undefined;
|
|
||||||
nickname: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const subcommand = interaction.options.getSubcommand(true) as
|
const subcommand = interaction.options.getSubcommand(true) as
|
||||||
| 'league'
|
| 'league'
|
||||||
| 'neighbors';
|
| 'neighbors';
|
||||||
const limit = interaction.options.getInteger('limit') ?? 10;
|
const limit = interaction.options.getInteger('limit') ?? DEFAULT_LIMIT;
|
||||||
const seasonOption = interaction.options.getString('season');
|
const seasonOption = interaction.options.getString('season');
|
||||||
const season = seasonOption
|
const season = seasonOption
|
||||||
? parseInt(seasonOption)
|
? parseInt(seasonOption)
|
||||||
@@ -224,26 +286,26 @@ export const ratingsCommand = new Promise<CommandRegistryPromisable>(
|
|||||||
let titleName: string;
|
let titleName: string;
|
||||||
let titleImage: string | undefined;
|
let titleImage: string | undefined;
|
||||||
let titleDescription: string;
|
let titleDescription: string;
|
||||||
let playersBefore: number;
|
|
||||||
let playersAfter: number;
|
let playersAfter: number;
|
||||||
let players: SimplifiedPlayer[] | undefined;
|
let players: SimplifiedPlayer[] | undefined;
|
||||||
let midnightLeaderboard: BlitzkriegRatingsLeaderboard | undefined;
|
let midnightLeaderboard: BkrlDiscriminatedEntries | null;
|
||||||
let playerId: number | undefined;
|
let playerId: number | undefined;
|
||||||
let regionRatingsInfo: RatingsInfo;
|
let regionRatingInfo: RatingInfo;
|
||||||
|
|
||||||
if (subcommand === 'league') {
|
if (subcommand === 'league') {
|
||||||
const leagueIndex = parseInt(
|
const leagueIndex = parseInt(
|
||||||
interaction.options.getString('league')!,
|
interaction.options.getString('league')!,
|
||||||
);
|
);
|
||||||
const region = interaction.options.getString('region') as Region;
|
const region = interaction.options.getString('region') as Region;
|
||||||
regionRatingsInfo = await (isCurrentSeason
|
regionRatingInfo = await (isCurrentSeason
|
||||||
? getRatingsInfo(region)
|
? getRatingInfo(region)
|
||||||
: getArchivedRatingsInfo(region, season!));
|
: getArchivedRatingInfo(region, season!));
|
||||||
|
|
||||||
if (regionRatingsInfo.detail !== undefined) return noOngoingSeason;
|
if (regionRatingInfo.detail !== undefined)
|
||||||
|
return t`bot.commands.rating_leaderboard.body.no_ongoing_season`;
|
||||||
|
|
||||||
const result = isCurrentSeason
|
const result = isCurrentSeason
|
||||||
? await getRatingsLeague(region, leagueIndex).then(async (result) =>
|
? await getRatingLeague(region, leagueIndex).then(async (result) =>
|
||||||
result.slice(0, limit).map(
|
result.slice(0, limit).map(
|
||||||
(player) =>
|
(player) =>
|
||||||
({
|
({
|
||||||
@@ -255,17 +317,17 @@ export const ratingsCommand = new Promise<CommandRegistryPromisable>(
|
|||||||
}) satisfies SimplifiedPlayer,
|
}) satisfies SimplifiedPlayer,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: await getArchivedRatingsLeaderboard(region, season!).then(
|
: await getArchivedRatingLeaderboard(region, season!).then(
|
||||||
async (players) => {
|
async (players) => {
|
||||||
const firstPlayerIndex =
|
const firstPlayerIndex =
|
||||||
leagueIndex === 0
|
leagueIndex === 0
|
||||||
? 0
|
? 0
|
||||||
: players.findIndex(
|
: players.entries.findIndex(
|
||||||
(player) =>
|
(player) =>
|
||||||
player.score < LEAGUES[leagueIndex - 1].minScore,
|
player.score < LEAGUES[leagueIndex - 1].minScore,
|
||||||
);
|
);
|
||||||
const lastPlayerIndex = firstPlayerIndex + limit - 1;
|
const lastPlayerIndex = firstPlayerIndex + limit - 1;
|
||||||
const trimmed = players.slice(
|
const trimmed = players.entries.slice(
|
||||||
firstPlayerIndex,
|
firstPlayerIndex,
|
||||||
lastPlayerIndex + 1,
|
lastPlayerIndex + 1,
|
||||||
);
|
);
|
||||||
@@ -284,42 +346,50 @@ export const ratingsCommand = new Promise<CommandRegistryPromisable>(
|
|||||||
clan: clanData[player.id]?.clan?.tag,
|
clan: clanData[player.id]?.clan?.tag,
|
||||||
nickname:
|
nickname:
|
||||||
clanData[index]?.account_name ??
|
clanData[index]?.account_name ??
|
||||||
`Deleted ${player.id}`,
|
translate(
|
||||||
|
'bot.commands.rating_leaderboard.body.deleted_player',
|
||||||
|
[`${player.id}`],
|
||||||
|
),
|
||||||
}) satisfies SimplifiedPlayer,
|
}) satisfies SimplifiedPlayer,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
const leagueInfo = regionRatingsInfo.leagues[leagueIndex];
|
const leagueInfo = regionRatingInfo.leagues[leagueIndex];
|
||||||
midnightLeaderboard = isCurrentSeason
|
midnightLeaderboard = isCurrentSeason
|
||||||
? await getArchivedRatingsMidnightLeaderboard(
|
? await getArchivedRatingMidnightLeaderboard(
|
||||||
region,
|
region,
|
||||||
regionRatingsInfo.current_season,
|
regionRatingInfo.current_season,
|
||||||
)
|
)
|
||||||
: await getArchivedRatingsMidnightLeaderboard(region, season!);
|
: await getArchivedRatingMidnightLeaderboard(region, season!);
|
||||||
|
|
||||||
players = result;
|
players = result;
|
||||||
playersBefore = result ? result[0].position - 1 : 0;
|
|
||||||
playersAfter =
|
playersAfter =
|
||||||
regionRatingsInfo.count - result[result.length - 1].position;
|
regionRatingInfo.count - result[result.length - 1].position;
|
||||||
titleName = `${
|
titleName = `${
|
||||||
leagueInfo ? leagueInfo.title : 'No Ongoing Season'
|
leagueInfo
|
||||||
} - ${REGION_NAMES_SHORT[region]}`;
|
? translate(`common.leagues.${LEAGUES[leagueInfo.index].name}`)
|
||||||
|
: ''
|
||||||
|
} - ${translate(`common.regions.short.${region}`)}`;
|
||||||
titleImage = leagueInfo.big_icon.startsWith('http')
|
titleImage = leagueInfo.big_icon.startsWith('http')
|
||||||
? leagueInfo.big_icon
|
? leagueInfo.big_icon
|
||||||
: `https:${leagueInfo.big_icon}`;
|
: `https:${leagueInfo.big_icon}`;
|
||||||
titleDescription = `Top ${limit} players`;
|
titleDescription = translate(
|
||||||
|
'bot.commands.rating_leaderboard.body.top_players',
|
||||||
|
[`${limit}`],
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
const { region, id } = await resolvePlayerFromCommand(interaction);
|
const { region, id } = await resolvePlayerFromCommand(interaction);
|
||||||
regionRatingsInfo = isCurrentSeason
|
regionRatingInfo = isCurrentSeason
|
||||||
? await getRatingsInfo(region)
|
? await getRatingInfo(region)
|
||||||
: await getArchivedRatingsInfo(region, season!);
|
: await getArchivedRatingInfo(region, season!);
|
||||||
|
|
||||||
if (regionRatingsInfo.detail !== undefined) return noOngoingSeason;
|
if (regionRatingInfo.detail !== undefined)
|
||||||
|
return t`bot.commands.rating_leaderboard.body.no_ongoing_season`;
|
||||||
|
|
||||||
const accountInfo = await getAccountInfo(region, id);
|
const accountInfo = await getAccountInfo(region, id);
|
||||||
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
||||||
const neighbors = isCurrentSeason
|
const neighbors = isCurrentSeason
|
||||||
? await getRatingsNeighbors(region, id, Math.round(limit / 2)).then(
|
? await getRatingNeighbors(region, id, Math.round(limit / 2)).then(
|
||||||
(players) =>
|
(players) =>
|
||||||
players.neighbors.map(
|
players.neighbors.map(
|
||||||
(player) =>
|
(player) =>
|
||||||
@@ -332,20 +402,23 @@ export const ratingsCommand = new Promise<CommandRegistryPromisable>(
|
|||||||
}) satisfies SimplifiedPlayer,
|
}) satisfies SimplifiedPlayer,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: await getArchivedRatingsLeaderboard(region, season!).then(
|
: await getArchivedRatingLeaderboard(region, season!).then(
|
||||||
async (players) => {
|
async (players) => {
|
||||||
const playerIndex = players.findIndex(
|
const playerIndex = players.entries.findIndex(
|
||||||
(player) => player.id === id,
|
(player) => player.id === id,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (playerIndex === -1) {
|
if (playerIndex === -1) {
|
||||||
throw new UserError(
|
throw new UserError(
|
||||||
`# ${markdownEscape(accountInfo.nickname)} didn't play ratings in season ${season}\nThis player did not participate in this season or did not get past calibration.`,
|
translate(
|
||||||
|
'bot.commands.rating_leaderboard.body.no_participation',
|
||||||
|
[markdownEscape(accountInfo.nickname), `${season}`],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const halfRange = Math.round(limit / 2);
|
const halfRange = Math.round(limit / 2);
|
||||||
const trimmed = players.slice(
|
const trimmed = players.entries.slice(
|
||||||
playerIndex - halfRange,
|
playerIndex - halfRange,
|
||||||
playerIndex + halfRange + 1,
|
playerIndex + halfRange + 1,
|
||||||
);
|
);
|
||||||
@@ -367,43 +440,31 @@ export const ratingsCommand = new Promise<CommandRegistryPromisable>(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
midnightLeaderboard = isCurrentSeason
|
midnightLeaderboard = isCurrentSeason
|
||||||
? await getArchivedRatingsMidnightLeaderboard(
|
? await getArchivedRatingMidnightLeaderboard(
|
||||||
region,
|
region,
|
||||||
regionRatingsInfo.current_season,
|
regionRatingInfo.current_season,
|
||||||
)
|
)
|
||||||
: await getArchivedRatingsMidnightLeaderboard(region, season!);
|
: await getArchivedRatingMidnightLeaderboard(region, season!);
|
||||||
|
|
||||||
players = neighbors;
|
players = neighbors;
|
||||||
titleImage = clan
|
titleImage = clan
|
||||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clan.emblem_set_id}.png`
|
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clan.emblem_set_id}.png`
|
||||||
: undefined;
|
: undefined;
|
||||||
titleName = neighbors
|
titleName = neighbors ? accountInfo.nickname : '';
|
||||||
? accountInfo.nickname
|
titleDescription = t`bot.commands.rating_leaderboard.body.neighbors`;
|
||||||
: `No Ongoing Season - ${REGION_NAMES_SHORT[region]}`;
|
|
||||||
titleDescription = 'Ratings neighbors';
|
|
||||||
playersBefore = neighbors ? neighbors[0].position - 1 : 0;
|
|
||||||
playersAfter =
|
playersAfter =
|
||||||
regionRatingsInfo.count - neighbors[neighbors.length - 1].position;
|
regionRatingInfo.count - neighbors[neighbors.length - 1].position;
|
||||||
playerId = id;
|
playerId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolvedRegionRatingsInfo: typeof regionRatingsInfo & {
|
|
||||||
detail: undefined;
|
|
||||||
} = regionRatingsInfo;
|
|
||||||
|
|
||||||
const items = players.map((player) => {
|
const items = players.map((player) => {
|
||||||
const reward = resolvedRegionRatingsInfo.rewards.find(
|
const midnightIndex = midnightLeaderboard?.entries.findIndex(
|
||||||
(reward) =>
|
|
||||||
player.position >= reward.from_position &&
|
|
||||||
player.position <= reward.to_position,
|
|
||||||
);
|
|
||||||
const midnightIndex = midnightLeaderboard?.findIndex(
|
|
||||||
(item) => item.id === player.id,
|
(item) => item.id === player.id,
|
||||||
);
|
);
|
||||||
const midnightScore =
|
const midnightScore =
|
||||||
midnightIndex === undefined
|
midnightIndex === undefined
|
||||||
? player.score
|
? player.score
|
||||||
: midnightLeaderboard![midnightIndex].score;
|
: midnightLeaderboard!.entries[midnightIndex].score;
|
||||||
const midnightPosition =
|
const midnightPosition =
|
||||||
midnightIndex === undefined ? player.position : midnightIndex + 1;
|
midnightIndex === undefined ? player.position : midnightIndex + 1;
|
||||||
|
|
||||||
@@ -413,7 +474,6 @@ export const ratingsCommand = new Promise<CommandRegistryPromisable>(
|
|||||||
score={player.score}
|
score={player.score}
|
||||||
position={player.position}
|
position={player.position}
|
||||||
clan={player.clan}
|
clan={player.clan}
|
||||||
reward={reward}
|
|
||||||
deltaScore={player.score - midnightScore}
|
deltaScore={player.score - midnightScore}
|
||||||
deltaPosition={midnightPosition - player.position}
|
deltaPosition={midnightPosition - player.position}
|
||||||
key={player.id}
|
key={player.id}
|
||||||
@@ -423,29 +483,27 @@ export const ratingsCommand = new Promise<CommandRegistryPromisable>(
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper>
|
<CommandWrapper>
|
||||||
<TitleBar
|
<TitleBar
|
||||||
name={titleName}
|
title={titleName}
|
||||||
image={titleImage}
|
image={titleImage}
|
||||||
description={titleDescription}
|
description={titleDescription}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{items && (
|
{items && (
|
||||||
<Leaderboard.Root>
|
<Leaderboard.Root>
|
||||||
{playersBefore > 0 && (
|
|
||||||
<Leaderboard.Gap
|
|
||||||
message={`+ ${playersBefore.toLocaleString()} more`}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{items}
|
{items}
|
||||||
{playersAfter > 0 && (
|
{playersAfter > 0 && (
|
||||||
<Leaderboard.Gap
|
<Leaderboard.Gap
|
||||||
message={`+ ${playersAfter.toLocaleString()} more`}
|
message={translate(
|
||||||
|
'bot.commands.rating_leaderboard.body.more',
|
||||||
|
[`${playersAfter.toLocaleString(interaction.locale)}`],
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Leaderboard.Root>
|
</Leaderboard.Root>
|
||||||
)}
|
)}
|
||||||
</Wrapper>
|
</CommandWrapper>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -0,0 +1,576 @@
|
|||||||
|
import { Locale, escapeMarkdown } from 'discord.js';
|
||||||
|
import CommandWrapper from '../components/CommandWrapper';
|
||||||
|
import TitleBar from '../components/TitleBar';
|
||||||
|
import { equipmentPriceMatrix } from '../constants/equipmentPrice';
|
||||||
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
|
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||||
|
import getTankStats from '../core/blitz/getTankStats';
|
||||||
|
import resolveTankId from '../core/blitz/resolveTankId';
|
||||||
|
import { asset } from '../core/blitzkrieg/asset';
|
||||||
|
import { buildTechTreeLine } from '../core/blitzkrieg/buildTechTreeLine';
|
||||||
|
import { emblemURL } from '../core/blitzkrieg/emblemURL';
|
||||||
|
import { webpToPng } from '../core/blitzkrieg/iconPng';
|
||||||
|
import { resolveAncestry } from '../core/blitzkrieg/resolveAncestry';
|
||||||
|
import { tankDefinitions } from '../core/blitzkrieg/tankDefinitions';
|
||||||
|
import {
|
||||||
|
TANK_ICONS,
|
||||||
|
TIER_ROMAN_NUMERALS,
|
||||||
|
} from '../core/blitzkrieg/tankDefinitions/constants';
|
||||||
|
import { tankIconPng } from '../core/blitzkrieg/tankIconPng';
|
||||||
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
|
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
||||||
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
|
import { localizationObject } from '../core/discord/localizationObject';
|
||||||
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||||
|
import { translator } from '../core/localization/translator';
|
||||||
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
import { theme } from '../stitches.config';
|
||||||
|
|
||||||
|
export const researchCommand = new Promise<CommandRegistry>((resolve) => {
|
||||||
|
const { t } = translator(Locale.EnglishUS);
|
||||||
|
|
||||||
|
resolve({
|
||||||
|
inProduction: true,
|
||||||
|
inPublic: true,
|
||||||
|
|
||||||
|
command: createLocalizedCommand('research')
|
||||||
|
.addStringOption((option) =>
|
||||||
|
option
|
||||||
|
.setName(t`bot.commands.research.options.target_tank`)
|
||||||
|
.setNameLocalizations(
|
||||||
|
localizationObject('bot.commands.research.options.target_tank'),
|
||||||
|
)
|
||||||
|
.setDescription(
|
||||||
|
t`bot.commands.research.options.target_tank.description`,
|
||||||
|
)
|
||||||
|
.setDescriptionLocalizations(
|
||||||
|
localizationObject(
|
||||||
|
'bot.commands.research.options.target_tank.description',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.setAutocomplete(true)
|
||||||
|
.setRequired(true),
|
||||||
|
)
|
||||||
|
.addStringOption((option) =>
|
||||||
|
option
|
||||||
|
.setName(t`bot.commands.research.options.starting_tank`)
|
||||||
|
.setNameLocalizations(
|
||||||
|
localizationObject('bot.commands.research.options.starting_tank'),
|
||||||
|
)
|
||||||
|
.setDescription(
|
||||||
|
t`bot.commands.research.options.starting_tank.description`,
|
||||||
|
)
|
||||||
|
.setDescriptionLocalizations(
|
||||||
|
localizationObject(
|
||||||
|
'bot.commands.research.options.starting_tank.description',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.setAutocomplete(true)
|
||||||
|
.setRequired(false),
|
||||||
|
)
|
||||||
|
.addStringOption(addUsernameChoices),
|
||||||
|
|
||||||
|
async handler(interaction) {
|
||||||
|
const { t, translate } = translator(interaction.locale);
|
||||||
|
const awaitedTankDefinitions = await tankDefinitions;
|
||||||
|
const targetTankId = await resolveTankId(
|
||||||
|
interaction.options.getString('target-tank', true),
|
||||||
|
interaction.locale,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
const startingTankRaw = interaction.options.getString('starting-tank');
|
||||||
|
const targetTank = awaitedTankDefinitions[targetTankId];
|
||||||
|
const { id, region } = await resolvePlayerFromCommand(interaction);
|
||||||
|
let startingTankId: number;
|
||||||
|
const targetTankAncestry = await resolveAncestry(targetTankId);
|
||||||
|
|
||||||
|
if (startingTankRaw) {
|
||||||
|
startingTankId = await resolveTankId(
|
||||||
|
startingTankRaw,
|
||||||
|
interaction.locale,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (targetTankId === startingTankId) {
|
||||||
|
return translate('bot.commands.research.errors.start_end_equal', [
|
||||||
|
escapeMarkdown(targetTank.name),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const startingTank = awaitedTankDefinitions[startingTankId];
|
||||||
|
|
||||||
|
if (startingTank.tier > targetTank.tier) {
|
||||||
|
return translate('bot.commands.research.errors.unordered', [
|
||||||
|
escapeMarkdown(startingTank.name),
|
||||||
|
escapeMarkdown(targetTank.name),
|
||||||
|
escapeMarkdown(targetTank.name),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!targetTankAncestry.includes(startingTankId)) {
|
||||||
|
return translate('bot.commands.research.errors.tanks_not_on_line', [
|
||||||
|
escapeMarkdown(targetTank.name),
|
||||||
|
escapeMarkdown(startingTank.name),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (targetTank.treeType !== 'researchable') {
|
||||||
|
return translate('bot.commands.research.errors.non_tech_tree', [
|
||||||
|
escapeMarkdown(targetTank.name),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetTank.tier === 1) {
|
||||||
|
return translate('bot.commands.research.errors.tier_1', [
|
||||||
|
escapeMarkdown(targetTank.name),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const tankStats = await getTankStats(region, id, interaction.locale);
|
||||||
|
|
||||||
|
if (tankStats.some(({ tank_id }) => tank_id === targetTankId)) {
|
||||||
|
return translate('bot.commands.research.errors.already_researched', [
|
||||||
|
escapeMarkdown(targetTank.name),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const foundAncestor = targetTankAncestry.find(
|
||||||
|
(id) =>
|
||||||
|
awaitedTankDefinitions[id].tier === 1 ||
|
||||||
|
tankStats.some(({ tank_id }) => tank_id === id),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (foundAncestor === undefined) {
|
||||||
|
throw new Error('No first owned tech tree found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
startingTankId = foundAncestor;
|
||||||
|
}
|
||||||
|
|
||||||
|
const techTreeLine = await buildTechTreeLine(
|
||||||
|
startingTankId,
|
||||||
|
targetTankId,
|
||||||
|
);
|
||||||
|
|
||||||
|
const line = [...techTreeLine, startingTankId].reverse();
|
||||||
|
const { nickname } = await getAccountInfo(region, id);
|
||||||
|
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
||||||
|
const clanImage = clan ? emblemURL(clan.emblem_set_id) : undefined;
|
||||||
|
const costs = await Promise.all(
|
||||||
|
line.map(async (id) => {
|
||||||
|
const tank = awaitedTankDefinitions[id];
|
||||||
|
const turretXps = new Map<number, number>();
|
||||||
|
const gunXps = new Map<number, number>();
|
||||||
|
const engineXps = new Map<number, number>();
|
||||||
|
const trackXps = new Map<number, number>();
|
||||||
|
|
||||||
|
tank.turrets.forEach((turret) => {
|
||||||
|
if (turret.xp !== undefined) {
|
||||||
|
turretXps.set(turret.id, turret.xp);
|
||||||
|
}
|
||||||
|
|
||||||
|
turret.guns.forEach((gun) => {
|
||||||
|
if (gun.xp !== undefined) {
|
||||||
|
gunXps.set(gun.id, gun.xp);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tank.engines.forEach((engine) => {
|
||||||
|
if (engine.xp !== undefined) {
|
||||||
|
engineXps.set(engine.id, engine.xp);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tank.tracks.forEach((track) => {
|
||||||
|
if (track.xp !== undefined) {
|
||||||
|
trackXps.set(track.id, track.xp);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let moduleXp = 0;
|
||||||
|
turretXps.forEach((value) => {
|
||||||
|
moduleXp += value;
|
||||||
|
});
|
||||||
|
gunXps.forEach((value) => {
|
||||||
|
moduleXp += value;
|
||||||
|
});
|
||||||
|
engineXps.forEach((value) => {
|
||||||
|
moduleXp += value;
|
||||||
|
});
|
||||||
|
trackXps.forEach((value) => {
|
||||||
|
moduleXp += value;
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
research: tank.xp,
|
||||||
|
upgrades: moduleXp,
|
||||||
|
purchase: tank.price.value,
|
||||||
|
equipment: equipmentPriceMatrix[tank.tier].reduce(
|
||||||
|
(a, b) => a + 3 * b,
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const image = (
|
||||||
|
<CommandWrapper>
|
||||||
|
<TitleBar
|
||||||
|
title={nickname}
|
||||||
|
image={clanImage}
|
||||||
|
description={`${t`bot.commands.research.body.subtitle`} • ${targetTank.name}`}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: 8,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
borderRadius: 4,
|
||||||
|
backgroundColor: theme.colors.appBackground2,
|
||||||
|
border: theme.borderStyles.subtle,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div style={{ width: 48 }}></div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
position: 'relative',
|
||||||
|
right: 24,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t`bot.commands.research.body.total`}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: 8,
|
||||||
|
padding: '16px 0',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
gap: 4,
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={await webpToPng(asset('icons/currencies/xp.webp'))}
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Experience:{' '}
|
||||||
|
{costs
|
||||||
|
.reduce((a, b) => a + (b.research ?? 0) + b.upgrades, 0)
|
||||||
|
.toLocaleString(interaction.locale)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
gap: 4,
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={await webpToPng(asset('icons/currencies/silver.webp'))}
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Purchase:{' '}
|
||||||
|
{costs
|
||||||
|
.reduce((a, b) => a + b.purchase, 0)
|
||||||
|
.toLocaleString(interaction.locale)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
gap: 4,
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={await webpToPng(asset('icons/currencies/silver.webp'))}
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Equipment:{' '}
|
||||||
|
{costs
|
||||||
|
.reduce((a, b) => a + b.equipment, 0)
|
||||||
|
.toLocaleString(interaction.locale)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{await Promise.all(
|
||||||
|
line.map(async (id, index) => {
|
||||||
|
const tank = awaitedTankDefinitions[id];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={id}
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
borderRadius: 4,
|
||||||
|
backgroundColor: theme.colors.appBackground2,
|
||||||
|
border: theme.borderStyles.subtle,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: 48,
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color: theme.colors.textLowContrast,
|
||||||
|
fontSize: 16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{TIER_ROMAN_NUMERALS[tank.tier]}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
display: 'flex',
|
||||||
|
position: 'relative',
|
||||||
|
right: '5%',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
height: 120,
|
||||||
|
width: 240,
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'flex-start',
|
||||||
|
left: '25%',
|
||||||
|
top: '5%',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={await tankIconPng(id)}
|
||||||
|
style={{
|
||||||
|
height: '100%',
|
||||||
|
position: 'absolute',
|
||||||
|
objectFit: 'contain',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
gap: 4,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
position: 'absolute',
|
||||||
|
bottom: 8,
|
||||||
|
left: '50%',
|
||||||
|
transform: 'translateX(-50%)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={TANK_ICONS[tank.class]}
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{tank.name}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: 8,
|
||||||
|
padding: '16px 0',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
gap: 4,
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={await webpToPng(
|
||||||
|
asset('icons/currencies/xp.webp'),
|
||||||
|
)}
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{translate('bot.commands.research.body.research', [
|
||||||
|
`${costs[index].research?.toLocaleString(
|
||||||
|
interaction.locale,
|
||||||
|
)}`,
|
||||||
|
])}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{costs[index].upgrades > 0 && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
gap: 4,
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={await webpToPng(
|
||||||
|
asset('icons/currencies/free-xp.webp'),
|
||||||
|
)}
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{translate('bot.commands.research.body.upgrades', [
|
||||||
|
costs[index].upgrades.toLocaleString(),
|
||||||
|
])}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
gap: 4,
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={await webpToPng(
|
||||||
|
asset('icons/currencies/silver.webp'),
|
||||||
|
)}
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{translate('bot.commands.research.body.purchase', [
|
||||||
|
costs[index].purchase.toLocaleString(
|
||||||
|
interaction.locale,
|
||||||
|
),
|
||||||
|
])}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
gap: 4,
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={await webpToPng(
|
||||||
|
asset('icons/currencies/silver.webp'),
|
||||||
|
)}
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{translate('bot.commands.research.body.equipment', [
|
||||||
|
costs[index].equipment.toLocaleString(
|
||||||
|
interaction.locale,
|
||||||
|
),
|
||||||
|
])}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</CommandWrapper>
|
||||||
|
);
|
||||||
|
|
||||||
|
return startingTankRaw
|
||||||
|
? image
|
||||||
|
: [t`bot.commands.research.body.estimation`, image];
|
||||||
|
},
|
||||||
|
|
||||||
|
autocomplete(interaction) {
|
||||||
|
autocompleteTanks(interaction, true, ['target-tank', 'starting-tank']);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
+60
-34
@@ -1,46 +1,72 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { Locale } from 'discord.js';
|
||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import { REGION_NAMES, Region } from '../constants/regions';
|
import { Region } from '../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
||||||
import fetchBlitz from '../core/blitz/fetchBlitz';
|
import fetchBlitz from '../core/blitz/fetchBlitz';
|
||||||
import addClanChoices from '../core/discord/addClanChoices';
|
import addClanChoices from '../core/discord/addClanChoices';
|
||||||
import addRegionChoices from '../core/discord/addRegionChoices';
|
import addRegionChoices from '../core/discord/addRegionChoices';
|
||||||
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
import embedInfo from '../core/discord/embedInfo';
|
import embedInfo from '../core/discord/embedInfo';
|
||||||
|
import { localizationObject } from '../core/discord/localizationObject';
|
||||||
|
import { translator } from '../core/localization/translator';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
import { ClanList } from '../types/clanList';
|
import { ClanList } from '../types/clanList';
|
||||||
|
|
||||||
export const searchClansCommand: CommandRegistry = {
|
const DEFAULT_LIMIT = 25;
|
||||||
inProduction: true,
|
|
||||||
inPublic: true,
|
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
export const searchClansCommand = new Promise<CommandRegistry>((resolve) => {
|
||||||
.setName('search-clans')
|
resolve({
|
||||||
.setDescription('Search clans')
|
inProduction: true,
|
||||||
.addStringOption(addRegionChoices)
|
inPublic: true,
|
||||||
.addStringOption((option) => addClanChoices(option).setAutocomplete(false))
|
|
||||||
.addIntegerOption((option) =>
|
|
||||||
option
|
|
||||||
.setName('limit')
|
|
||||||
.setDescription('The size of the search result (default: 25)')
|
|
||||||
.setMinValue(1)
|
|
||||||
.setMaxValue(100),
|
|
||||||
),
|
|
||||||
|
|
||||||
async handler(interaction) {
|
command: createLocalizedCommand('search-clans')
|
||||||
const server = interaction.options.getString('region') as Region;
|
.addStringOption(addRegionChoices)
|
||||||
const clan = interaction.options.getString('clan')!;
|
.addStringOption((option) =>
|
||||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
addClanChoices(option).setAutocomplete(false),
|
||||||
const clanList = await fetchBlitz<ClanList>(
|
)
|
||||||
`https://api.wotblitz.${server}/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${clan}&limit=${limit}`,
|
.addIntegerOption((option) => {
|
||||||
);
|
const { t, translate } = translator(Locale.EnglishUS);
|
||||||
|
|
||||||
return embedInfo(
|
return option
|
||||||
`Clan search for "${markdownEscape(clan)}" in ${REGION_NAMES[server]}`,
|
.setName(t`bot.commands.search_clans.options.limit`)
|
||||||
clanList.length === 0
|
.setNameLocalizations(
|
||||||
? 'No clans found.'
|
localizationObject('bot.commands.search_clans.options.limit'),
|
||||||
: `\`\`\`\n${clanList
|
)
|
||||||
.map((clan) => `${clan.name} [${clan.tag}]`)
|
.setDescription(
|
||||||
.join('\n')}\n\`\`\``,
|
translate('bot.commands.search_clans.options.limit.description', [
|
||||||
);
|
`${DEFAULT_LIMIT}`,
|
||||||
},
|
]),
|
||||||
};
|
)
|
||||||
|
.setDescriptionLocalizations(
|
||||||
|
localizationObject(
|
||||||
|
'bot.commands.search_clans.options.limit.description',
|
||||||
|
[`${DEFAULT_LIMIT}`],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.setMinValue(1)
|
||||||
|
.setMaxValue(100);
|
||||||
|
}),
|
||||||
|
|
||||||
|
async handler(interaction) {
|
||||||
|
const { translate } = translator(interaction.locale);
|
||||||
|
const server = interaction.options.getString('region') as Region;
|
||||||
|
const clan = interaction.options.getString('clan')!;
|
||||||
|
const limit = interaction.options.getInteger('limit') ?? DEFAULT_LIMIT;
|
||||||
|
const clanList = await fetchBlitz<ClanList>(
|
||||||
|
`https://api.wotblitz.${server}/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${clan}&limit=${limit}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
return embedInfo(
|
||||||
|
translate('bot.commands.search_clans.body.title', [
|
||||||
|
markdownEscape(clan),
|
||||||
|
translate(`common.regions.normal.${server}`),
|
||||||
|
]),
|
||||||
|
clanList.length === 0
|
||||||
|
? translate('bot.commands.search_clans.body.no_results')
|
||||||
|
: `\`\`\`\n${clanList
|
||||||
|
.map((clan) => `${clan.name} [${clan.tag}]`)
|
||||||
|
.join('\n')}\n\`\`\``,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,56 +1,78 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { Locale } from 'discord.js';
|
||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import { REGION_NAMES, Region } from '../constants/regions';
|
import { Region } from '../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
||||||
import fetchBlitz from '../core/blitz/fetchBlitz';
|
import fetchBlitz from '../core/blitz/fetchBlitz';
|
||||||
import {
|
import { AccountList } from '../core/blitz/searchPlayersAcrossRegions';
|
||||||
AccountList,
|
import { usernamePattern } from '../core/blitz/searchPlayersAcrossRegions/constants';
|
||||||
usernamePattern,
|
|
||||||
} from '../core/blitz/searchPlayersAcrossRegions';
|
|
||||||
import addRegionChoices from '../core/discord/addRegionChoices';
|
import addRegionChoices from '../core/discord/addRegionChoices';
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
import embedInfo from '../core/discord/embedInfo';
|
import embedInfo from '../core/discord/embedInfo';
|
||||||
|
import { localizationObject } from '../core/discord/localizationObject';
|
||||||
|
import { translator } from '../core/localization/translator';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|
||||||
export const searchPlayersCommand: CommandRegistry = {
|
const DEFAULT_LIMIT = 25;
|
||||||
inProduction: true,
|
|
||||||
inPublic: true,
|
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
export const searchPlayersCommand = new Promise<CommandRegistry>((resolve) => {
|
||||||
.setName('search-players')
|
const { t, translate } = translator(Locale.EnglishUS);
|
||||||
.setDescription('Search players in a Blitz server')
|
|
||||||
.addStringOption(addRegionChoices)
|
|
||||||
.addStringOption((option) =>
|
|
||||||
addUsernameChoices(option).setAutocomplete(false).setRequired(true),
|
|
||||||
)
|
|
||||||
.addIntegerOption((option) =>
|
|
||||||
option
|
|
||||||
.setName('limit')
|
|
||||||
.setDescription('The size of the search result (default: 25)')
|
|
||||||
.setMinValue(1)
|
|
||||||
.setMaxValue(100),
|
|
||||||
),
|
|
||||||
|
|
||||||
async handler(interaction) {
|
resolve({
|
||||||
const server = interaction.options.getString('region') as Region;
|
inProduction: true,
|
||||||
const name = interaction.options.getString('username')!;
|
inPublic: true,
|
||||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
|
||||||
const trimmedSearch = name.trim();
|
|
||||||
const players = usernamePattern.test(trimmedSearch)
|
|
||||||
? await fetchBlitz<AccountList>(
|
|
||||||
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodeURIComponent(
|
|
||||||
trimmedSearch,
|
|
||||||
)}&limit=${limit}`,
|
|
||||||
)
|
|
||||||
: [];
|
|
||||||
|
|
||||||
return embedInfo(
|
command: createLocalizedCommand('search-players')
|
||||||
`Player search for "${markdownEscape(name)}" in ${REGION_NAMES[server]}`,
|
.addStringOption(addRegionChoices)
|
||||||
`\`\`\`${
|
.addStringOption((option) =>
|
||||||
players.length === 0
|
addUsernameChoices(option).setAutocomplete(false).setRequired(true),
|
||||||
? 'No players found.'
|
)
|
||||||
: players.map((player) => player.nickname).join('\n')
|
.addIntegerOption((option) =>
|
||||||
}\`\`\``,
|
option
|
||||||
);
|
.setName(t`bot.commands.search_players.options.limit`)
|
||||||
},
|
.setNameLocalizations(
|
||||||
};
|
localizationObject('bot.commands.search_players.options.limit'),
|
||||||
|
)
|
||||||
|
.setDescription(
|
||||||
|
translate('bot.commands.search_players.options.limit.description', [
|
||||||
|
`${DEFAULT_LIMIT}`,
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
.setDescriptionLocalizations(
|
||||||
|
localizationObject(
|
||||||
|
'bot.commands.search_players.options.limit.description',
|
||||||
|
[`${DEFAULT_LIMIT}`],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.setMinValue(1)
|
||||||
|
.setMaxValue(100),
|
||||||
|
),
|
||||||
|
|
||||||
|
async handler(interaction) {
|
||||||
|
const { translate } = translator(interaction.locale);
|
||||||
|
const server = interaction.options.getString('region') as Region;
|
||||||
|
const name = interaction.options.getString('username')!;
|
||||||
|
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||||
|
const trimmedSearch = name.trim();
|
||||||
|
const players = usernamePattern.test(trimmedSearch)
|
||||||
|
? await fetchBlitz<AccountList>(
|
||||||
|
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodeURIComponent(
|
||||||
|
trimmedSearch,
|
||||||
|
)}&limit=${limit}`,
|
||||||
|
)
|
||||||
|
: [];
|
||||||
|
|
||||||
|
return embedInfo(
|
||||||
|
translate('bot.commands.search_players.body.title', [
|
||||||
|
markdownEscape(trimmedSearch),
|
||||||
|
translate(`common.regions.normal.${server}`),
|
||||||
|
]),
|
||||||
|
`\`\`\`${
|
||||||
|
players.length === 0
|
||||||
|
? translate('bot.commands.search_players.body.no_results')
|
||||||
|
: players.map((player) => player.nickname).join('\n')
|
||||||
|
}\`\`\``,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
+47
-36
@@ -1,40 +1,51 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
// _____ _____ _ _ _ _ _____ ____ __ __ ______ ____ _____ _ __
|
||||||
import { go } from 'fuzzysort';
|
// |_ _| / ____| | | | /\ | | | | / ____/ __ \| \/ | ____| | _ \ /\ / ____| |/ /
|
||||||
import markdownEscape from 'markdown-escape';
|
// | | | (___ | |__| | / \ | | | | | | | | | | \ / | |__ | |_) | / \ | | | ' /
|
||||||
import { tankNames } from '../core/blitzkrieg/tankDefinitions';
|
// | | \___ \| __ | / /\ \ | | | | | | | | | | |\/| | __| | _ < / /\ \| | | <
|
||||||
import addTankChoices from '../core/discord/addTankChoices';
|
// _| |_ ____) | | | |/ ____ \| |____| |____ | |___| |__| | | | | |____ | |_) / ____ \ |____| . \
|
||||||
import embedInfo from '../core/discord/embedInfo';
|
// |_____| |_____/|_| |_/_/ \_\______|______| \_____\____/|_| |_|______| |____/_/ \_\_____|_|\_\
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
|
||||||
|
|
||||||
export const searchTanksCommand: CommandRegistry = {
|
// import { SlashCommandBuilder } from 'discord.js';
|
||||||
inProduction: true,
|
// import { go } from 'fuzzysort';
|
||||||
inPublic: true,
|
// import markdownEscape from 'markdown-escape';
|
||||||
|
// import { tankNames } from '../core/blitzkrieg/tankDefinitions';
|
||||||
|
// import addTankChoices from '../core/discord/addTankChoices';
|
||||||
|
// import embedInfo from '../core/discord/embedInfo';
|
||||||
|
// import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
// export const searchTanksCommand = new Promise<CommandRegistry>((resolve) => {
|
||||||
.setName('search-tanks')
|
// resolve({
|
||||||
.setDescription('Search tanks')
|
// inProduction: true,
|
||||||
.addStringOption((option) => addTankChoices(option).setAutocomplete(false))
|
// inPublic: true,
|
||||||
.addIntegerOption((option) =>
|
|
||||||
option
|
|
||||||
.setName('limit')
|
|
||||||
.setDescription('The size of the search result (default: 25)')
|
|
||||||
.setMinValue(1)
|
|
||||||
.setMaxValue(100),
|
|
||||||
),
|
|
||||||
|
|
||||||
async handler(interaction) {
|
// command: new SlashCommandBuilder()
|
||||||
const tank = interaction.options.getString('tank')!;
|
// .setName('search-tanks')
|
||||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
// .setDescription('Search tanks')
|
||||||
const results = go(tank, await tankNames, {
|
// .addStringOption((option) =>
|
||||||
limit,
|
// addTankChoices(option).setAutocomplete(false),
|
||||||
keys: ['combined'],
|
// )
|
||||||
}).map((result) => result.obj.original);
|
// .addIntegerOption((option) =>
|
||||||
|
// option
|
||||||
|
// .setName('limit')
|
||||||
|
// .setDescription('The size of the search result (default: 25)')
|
||||||
|
// .setMinValue(1)
|
||||||
|
// .setMaxValue(100),
|
||||||
|
// ),
|
||||||
|
|
||||||
return embedInfo(
|
// async handler(interaction) {
|
||||||
`Tank search for "${markdownEscape(tank)}"`,
|
// const tank = interaction.options.getString('tank')!;
|
||||||
results.length === 0
|
// const limit = interaction.options.getInteger('limit') ?? 25;
|
||||||
? 'No tanks found.'
|
// const results = go(tank, await tankNames, {
|
||||||
: `\`\`\`\n${results.join('\n')}\n\`\`\``,
|
// limit,
|
||||||
);
|
// keys: ['combined'],
|
||||||
},
|
// }).map((result) => result.obj.original);
|
||||||
};
|
|
||||||
|
// return embedInfo(
|
||||||
|
// `Tank search for "${markdownEscape(tank)}"`,
|
||||||
|
// results.length === 0
|
||||||
|
// ? 'No tanks found.'
|
||||||
|
// : `\`\`\`\n${results.join('\n')}\n\`\`\``,
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// });
|
||||||
+60
-54
@@ -1,11 +1,11 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { Locale } from 'discord.js';
|
||||||
import AllStatsOverview from '../components/AllStatsOverview';
|
import AllStatsOverview from '../components/AllStatsOverview';
|
||||||
import NoData, { NoDataType } from '../components/NoData';
|
import CommandWrapper from '../components/CommandWrapper';
|
||||||
|
import NoData from '../components/NoData';
|
||||||
import TitleBar from '../components/TitleBar';
|
import TitleBar from '../components/TitleBar';
|
||||||
import Wrapper from '../components/Wrapper';
|
|
||||||
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||||
import { emblemIdToURL } from '../core/blitzkrieg/emblemIdToURL';
|
import { emblemURL } from '../core/blitzkrieg/emblemURL';
|
||||||
import { filtersToDescription } from '../core/blitzkrieg/filtersToDescription';
|
import { filtersToDescription } from '../core/blitzkrieg/filtersToDescription';
|
||||||
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||||
import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod';
|
import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod';
|
||||||
@@ -15,6 +15,7 @@ import autocompleteTanks from '../core/discord/autocompleteTanks';
|
|||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
import { buttonRefresh } from '../core/discord/buttonRefresh';
|
import { buttonRefresh } from '../core/discord/buttonRefresh';
|
||||||
import commandToURL from '../core/discord/commandToURL';
|
import commandToURL from '../core/discord/commandToURL';
|
||||||
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
||||||
import { getFiltersFromButton } from '../core/discord/getFiltersFromButton';
|
import { getFiltersFromButton } from '../core/discord/getFiltersFromButton';
|
||||||
import { getFiltersFromCommand } from '../core/discord/getFiltersFromCommand';
|
import { getFiltersFromCommand } from '../core/discord/getFiltersFromCommand';
|
||||||
@@ -27,80 +28,85 @@ import resolvePlayerFromCommand, {
|
|||||||
ResolvedPlayer,
|
ResolvedPlayer,
|
||||||
} from '../core/discord/resolvePlayerFromCommand';
|
} from '../core/discord/resolvePlayerFromCommand';
|
||||||
import { StatFilters, filterStats } from '../core/statistics/filterStats';
|
import { StatFilters, filterStats } from '../core/statistics/filterStats';
|
||||||
import { CommandRegistryPromisable } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|
||||||
async function render(
|
async function render(
|
||||||
{ region, id }: ResolvedPlayer,
|
{ region, id }: ResolvedPlayer,
|
||||||
{ start, end, name }: ResolvedPeriod,
|
{ start, end, name }: ResolvedPeriod,
|
||||||
filters: StatFilters,
|
filters: StatFilters,
|
||||||
|
locale: Locale,
|
||||||
) {
|
) {
|
||||||
const { nickname } = await getAccountInfo(region, id);
|
const { nickname } = await getAccountInfo(region, id);
|
||||||
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
||||||
const clanImage = clan ? emblemIdToURL(clan.emblem_set_id) : undefined;
|
const clanImage = clan ? emblemURL(clan.emblem_set_id) : undefined;
|
||||||
const diffedTankStats = await getStatsInPeriod(region, id, start, end);
|
const diffedTankStats = await getStatsInPeriod(
|
||||||
|
region,
|
||||||
|
id,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
locale,
|
||||||
|
);
|
||||||
const { stats, supplementary } = await filterStats(diffedTankStats, filters);
|
const { stats, supplementary } = await filterStats(diffedTankStats, filters);
|
||||||
const filterDescriptions = await filtersToDescription(filters);
|
const filterDescriptions = await filtersToDescription(filters, locale);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper>
|
<CommandWrapper>
|
||||||
<TitleBar
|
<TitleBar
|
||||||
name={nickname}
|
title={nickname}
|
||||||
image={clanImage}
|
image={clanImage}
|
||||||
description={`${name} • ${filterDescriptions}`}
|
description={`${name} • ${filterDescriptions}`}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{!stats.battles && <NoData type={NoDataType.BattlesInPeriod} />}
|
{!stats.battles && <NoData type="battles_in_period" locale={locale} />}
|
||||||
{stats.battles > 0 && (
|
{stats.battles > 0 && (
|
||||||
<AllStatsOverview stats={stats} supplementaryStats={supplementary} />
|
<AllStatsOverview
|
||||||
|
locale={locale}
|
||||||
|
stats={stats}
|
||||||
|
supplementaryStats={supplementary}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</Wrapper>
|
</CommandWrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const statsCommand = new Promise<CommandRegistryPromisable>(
|
export const statsCommand = new Promise<CommandRegistry>(async (resolve) => {
|
||||||
async (resolve) => {
|
resolve({
|
||||||
const command = await addPeriodicFilterOptions(
|
inProduction: true,
|
||||||
new SlashCommandBuilder()
|
inPublic: true,
|
||||||
.setName('stats')
|
|
||||||
.setDescription('Regular battles statistics'),
|
command: await addPeriodicFilterOptions(
|
||||||
|
createLocalizedCommand('stats'),
|
||||||
(option) => option.addStringOption(addUsernameChoices),
|
(option) => option.addStringOption(addUsernameChoices),
|
||||||
);
|
),
|
||||||
|
|
||||||
resolve({
|
async handler(interaction) {
|
||||||
inProduction: true,
|
const player = await resolvePlayerFromCommand(interaction);
|
||||||
inPublic: true,
|
const period = resolvePeriodFromCommand(player.region, interaction);
|
||||||
|
const filters = await getFiltersFromCommand(interaction);
|
||||||
|
const path = commandToURL(interaction, {
|
||||||
|
...player,
|
||||||
|
...getCustomPeriodParams(interaction),
|
||||||
|
...filters,
|
||||||
|
});
|
||||||
|
|
||||||
command,
|
return Promise.all([
|
||||||
|
render(player, period, filters, interaction.locale),
|
||||||
|
buttonRefresh(interaction, path),
|
||||||
|
getBlitzStarsLinkButton(player.region, player.id),
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
|
||||||
async handler(interaction) {
|
autocomplete: (interaction) => {
|
||||||
const player = await resolvePlayerFromCommand(interaction);
|
autocompleteUsername(interaction);
|
||||||
const period = resolvePeriodFromCommand(player.region, interaction);
|
autocompleteTanks(interaction);
|
||||||
const filters = await getFiltersFromCommand(interaction);
|
},
|
||||||
const path = commandToURL(interaction, {
|
|
||||||
...player,
|
|
||||||
...getCustomPeriodParams(interaction),
|
|
||||||
...filters,
|
|
||||||
});
|
|
||||||
|
|
||||||
return Promise.all([
|
async button(interaction) {
|
||||||
render(player, period, filters),
|
const player = await resolvePlayerFromButton(interaction);
|
||||||
buttonRefresh(interaction, path),
|
const period = resolvePeriodFromButton(player.region, interaction);
|
||||||
getBlitzStarsLinkButton(player.region, player.id),
|
const filters = getFiltersFromButton(interaction);
|
||||||
]);
|
|
||||||
},
|
|
||||||
|
|
||||||
autocomplete: (interaction) => {
|
return await render(player, period, filters, interaction.locale);
|
||||||
autocompleteUsername(interaction);
|
},
|
||||||
autocompleteTanks(interaction);
|
});
|
||||||
},
|
});
|
||||||
|
|
||||||
async button(interaction) {
|
|
||||||
const player = await resolvePlayerFromButton(interaction);
|
|
||||||
const period = resolvePeriodFromButton(player.region, interaction);
|
|
||||||
const filters = getFiltersFromButton(interaction);
|
|
||||||
|
|
||||||
return await render(player, period, filters);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
+45
-51
@@ -1,12 +1,12 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { NATIONS } from '../core/blitzkrieg/tankDefinitions';
|
||||||
import { encyclopediaInfo } from '../core/blitz/encyclopediaInfo';
|
|
||||||
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||||
import { addFilterOptions } from '../core/discord/addFilterOptions';
|
import { addFilterOptions } from '../core/discord/addFilterOptions';
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
import buttonPrimary from '../core/discord/buttonPrimary';
|
import { buttonRefresh } from '../core/discord/buttonRefresh';
|
||||||
import commandToURL from '../core/discord/commandToURL';
|
import commandToURL from '../core/discord/commandToURL';
|
||||||
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
||||||
import { getFiltersFromButton } from '../core/discord/getFiltersFromButton';
|
import { getFiltersFromButton } from '../core/discord/getFiltersFromButton';
|
||||||
import { getFiltersFromCommand } from '../core/discord/getFiltersFromCommand';
|
import { getFiltersFromCommand } from '../core/discord/getFiltersFromCommand';
|
||||||
@@ -14,58 +14,52 @@ import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
|||||||
import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand';
|
import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand';
|
||||||
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||||
import { CommandRegistryPromisable } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
import { renderBreakdown } from './breakdown';
|
import { renderBreakdown } from './breakdown/render';
|
||||||
|
|
||||||
export const todayCommand = new Promise<CommandRegistryPromisable>(
|
export const todayCommand = new Promise<CommandRegistry>(async (resolve) => {
|
||||||
async (resolve) => {
|
const nations = await NATIONS;
|
||||||
const awaitedEncyclopediaInfo = await encyclopediaInfo;
|
resolve({
|
||||||
const command = addFilterOptions(
|
inProduction: true,
|
||||||
new SlashCommandBuilder()
|
inPublic: true,
|
||||||
.setName('today')
|
|
||||||
.setDescription("Today's played tanks and statistics"),
|
|
||||||
awaitedEncyclopediaInfo,
|
|
||||||
).addStringOption(addUsernameChoices);
|
|
||||||
|
|
||||||
resolve({
|
command: addFilterOptions(
|
||||||
inProduction: true,
|
createLocalizedCommand('today'),
|
||||||
inPublic: true,
|
nations,
|
||||||
|
).addStringOption(addUsernameChoices),
|
||||||
|
|
||||||
command,
|
async handler(interaction) {
|
||||||
|
const player = await resolvePlayerFromCommand(interaction);
|
||||||
|
const period = resolvePeriodFromCommand(
|
||||||
|
player.region,
|
||||||
|
interaction,
|
||||||
|
'today',
|
||||||
|
);
|
||||||
|
const filters = await getFiltersFromCommand(interaction);
|
||||||
|
const path = commandToURL(interaction, {
|
||||||
|
...player,
|
||||||
|
...getCustomPeriodParams(interaction, true),
|
||||||
|
...filters,
|
||||||
|
});
|
||||||
|
|
||||||
async handler(interaction) {
|
return [
|
||||||
const player = await resolvePlayerFromCommand(interaction);
|
...(await renderBreakdown(player, period, filters, interaction.locale)),
|
||||||
const period = resolvePeriodFromCommand(
|
buttonRefresh(interaction, path),
|
||||||
player.region,
|
await getBlitzStarsLinkButton(player.region, player.id),
|
||||||
interaction,
|
];
|
||||||
'today',
|
},
|
||||||
);
|
|
||||||
const filters = await getFiltersFromCommand(interaction);
|
|
||||||
const path = commandToURL(interaction, {
|
|
||||||
...player,
|
|
||||||
...getCustomPeriodParams(interaction, true),
|
|
||||||
...filters,
|
|
||||||
});
|
|
||||||
|
|
||||||
return [
|
autocomplete: (interaction) => {
|
||||||
...(await renderBreakdown(player, period, filters)),
|
autocompleteUsername(interaction);
|
||||||
buttonPrimary(path, 'Refresh'),
|
autocompleteTanks(interaction);
|
||||||
await getBlitzStarsLinkButton(player.region, player.id),
|
},
|
||||||
];
|
|
||||||
},
|
|
||||||
|
|
||||||
autocomplete: (interaction) => {
|
async button(interaction) {
|
||||||
autocompleteUsername(interaction);
|
const player = await resolvePlayerFromButton(interaction);
|
||||||
autocompleteTanks(interaction);
|
const period = resolvePeriodFromButton(player.region, interaction);
|
||||||
},
|
const filters = getFiltersFromButton(interaction);
|
||||||
|
|
||||||
async button(interaction) {
|
return await renderBreakdown(player, period, filters, interaction.locale);
|
||||||
const player = await resolvePlayerFromButton(interaction);
|
},
|
||||||
const period = resolvePeriodFromButton(player.region, interaction);
|
});
|
||||||
const filters = getFiltersFromButton(interaction);
|
});
|
||||||
|
|
||||||
return await renderBreakdown(player, period, filters);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import { ComponentProps } from 'react';
|
||||||
|
|
||||||
|
export interface GlowProps extends ComponentProps<'div'> {
|
||||||
|
color: string;
|
||||||
|
direction?: 'default' | 'reverse';
|
||||||
|
rotation?: number;
|
||||||
|
startOpacity?: number;
|
||||||
|
endOpacity?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const width = 16;
|
||||||
|
|
||||||
|
export function Glow({
|
||||||
|
color,
|
||||||
|
direction = 'default',
|
||||||
|
rotation = 0,
|
||||||
|
style,
|
||||||
|
startOpacity = 0,
|
||||||
|
endOpacity = 1,
|
||||||
|
...props
|
||||||
|
}: GlowProps) {
|
||||||
|
const color1 = `${color}${Math.round(endOpacity * 255)
|
||||||
|
.toString(16)
|
||||||
|
.padStart(2, '0')}`;
|
||||||
|
const color2 = `${color}${Math.round(startOpacity * 255)
|
||||||
|
.toString(16)
|
||||||
|
.padStart(2, '0')}`;
|
||||||
|
const background = `linear-gradient(${
|
||||||
|
direction === 'default' ? 0 : 180
|
||||||
|
}deg, ${color1} 0%, ${color2} 100%)`;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: direction === 'default' ? 'flex-end' : 'flex-start',
|
||||||
|
justifyContent: 'center',
|
||||||
|
transform: `rotate(${rotation}deg)`,
|
||||||
|
...style,
|
||||||
|
}}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<div style={{ height: 54, width, background }} />
|
||||||
|
<div style={{ height: 72, width, background }} />
|
||||||
|
<div style={{ height: 80, width, background }} />
|
||||||
|
<div style={{ height: 72, width, background }} />
|
||||||
|
<div style={{ height: 54, width, background }} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
import { Locale } from 'discord.js';
|
||||||
|
import { Percentile } from '../../../../constants/percentiles';
|
||||||
|
import { SupplementaryStats } from '../../../../core/blitz/getAccountInfo';
|
||||||
|
import { translator } from '../../../../core/localization/translator';
|
||||||
|
import getWN8Percentile from '../../../../core/statistics/getWN8Percentile';
|
||||||
|
import { theme } from '../../../../stitches.config';
|
||||||
|
import { PERCENTILE_COLORS } from '../../../PercentileIndicator/constants';
|
||||||
|
import { Glow } from './components/Glow';
|
||||||
|
|
||||||
|
export interface WN8DisplayProps {
|
||||||
|
stats: SupplementaryStats;
|
||||||
|
locale: Locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function HeroStat({ stats, locale }: WN8DisplayProps) {
|
||||||
|
const { translate } = translator(locale);
|
||||||
|
|
||||||
|
const percentile =
|
||||||
|
stats.WN8 === undefined ? Percentile.VeryBad : getWN8Percentile(stats.WN8);
|
||||||
|
const color = PERCENTILE_COLORS[percentile];
|
||||||
|
const heroStat = stats.WN8 === undefined ? '--' : stats.WN8.toFixed(0);
|
||||||
|
const subtitle = translate(`common.wn8_percentile.${percentile}`);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: 128 * 2, // idk why twice the width turns into the correct width
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: -16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Glow color={color} />
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: 128,
|
||||||
|
height: 80,
|
||||||
|
backgroundColor: color,
|
||||||
|
borderRadius: 40,
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: -4,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontWeight: 900,
|
||||||
|
fontSize: 32,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{heroStat}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{subtitle}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Glow color={color} direction="reverse" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
export interface GlowProps {
|
|
||||||
color: string;
|
|
||||||
direction?: 'default' | 'reverse';
|
|
||||||
rotation?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function Glow({
|
|
||||||
color,
|
|
||||||
direction = 'default',
|
|
||||||
rotation = 0,
|
|
||||||
}: GlowProps) {
|
|
||||||
const color1 = color;
|
|
||||||
const color2 = `${color}00`;
|
|
||||||
|
|
||||||
const background = `linear-gradient(${
|
|
||||||
direction === 'default' ? 0 : 180
|
|
||||||
}deg, ${color1} 0%, ${color2} 100%)`;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: direction === 'default' ? 'flex-end' : 'flex-start',
|
|
||||||
justifyContent: 'center',
|
|
||||||
transform: `rotate(${rotation}deg)`,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ height: 54, width: 16, background }} />
|
|
||||||
<div style={{ height: 72, width: 16, background }} />
|
|
||||||
<div style={{ height: 80, width: 16, background }} />
|
|
||||||
<div style={{ height: 72, width: 16, background }} />
|
|
||||||
<div style={{ height: 54, width: 16, background }} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
import { Percentile } from '../../../../constants/percentiles';
|
|
||||||
import getWN8Percentile from '../../../../core/statistics/getWN8Percentile';
|
|
||||||
import { theme } from '../../../../stitches.config';
|
|
||||||
import { PERCENTILE_COLORS } from '../../../PercentileIndicator';
|
|
||||||
import { Glow } from './components/Glow';
|
|
||||||
|
|
||||||
export interface WN8DisplayProps {
|
|
||||||
WN8?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const PERCENTILE_NAMES = {
|
|
||||||
[Percentile.VeryBad]: 'Very Bad',
|
|
||||||
[Percentile.Bad]: 'Bad',
|
|
||||||
[Percentile.BelowAverage]: 'Below Average',
|
|
||||||
[Percentile.Average]: 'Average',
|
|
||||||
[Percentile.AboveAverage]: 'Above Average',
|
|
||||||
[Percentile.Good]: 'Good',
|
|
||||||
[Percentile.VeryGood]: 'Very Good',
|
|
||||||
[Percentile.Great]: 'Great',
|
|
||||||
[Percentile.Unicum]: 'Unicum',
|
|
||||||
[Percentile.SuperUnicum]: 'Super Unicum',
|
|
||||||
};
|
|
||||||
|
|
||||||
export function WN8Display({ WN8 }: WN8DisplayProps) {
|
|
||||||
const percentile =
|
|
||||||
WN8 === undefined ? Percentile.VeryBad : getWN8Percentile(WN8);
|
|
||||||
const color = PERCENTILE_COLORS[percentile];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: 128 * 2, // idk why twice the width turns into the correct width
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
gap: -16,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Glow color={color} />
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: 128,
|
|
||||||
height: 80,
|
|
||||||
backgroundColor: color,
|
|
||||||
borderRadius: 40,
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
gap: -4,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontWeight: 900,
|
|
||||||
fontSize: 32,
|
|
||||||
color: theme.colors.textHighContrast,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{WN8 === undefined ? '--' : WN8.toFixed(0)}
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: 16,
|
|
||||||
color: theme.colors.textHighContrast,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{PERCENTILE_NAMES[percentile]}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Glow color={color} direction="reverse" />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -34,7 +34,7 @@ export function WN8SurroundingStat({
|
|||||||
style={{
|
style={{
|
||||||
color: theme.colors.textHighContrast,
|
color: theme.colors.textHighContrast,
|
||||||
fontSize: 24,
|
fontSize: 24,
|
||||||
fontWeight: 'bold',
|
fontWeight: 700,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{value}
|
{value}
|
||||||
|
|||||||
@@ -1,23 +1,39 @@
|
|||||||
import { AllStats, SupplementaryStats } from '../../core/blitz/getAccountInfo';
|
import { Locale } from 'discord.js';
|
||||||
import { WN8Display } from './components/WN8Display';
|
import { SupplementaryStats } from '../../core/blitz/getAccountInfo';
|
||||||
|
import { translator } from '../../core/localization/translator';
|
||||||
|
import { HeroStat } from './components/HeroStat';
|
||||||
import {
|
import {
|
||||||
WN8SurroundingStat,
|
WN8SurroundingStat,
|
||||||
WN8SurroundingStatAlign,
|
WN8SurroundingStatAlign,
|
||||||
} from './components/WN8SurroundingStat';
|
} from './components/WN8SurroundingStat';
|
||||||
|
|
||||||
export interface AllStatsOverviewProps {
|
export interface AllStatsOverviewProps {
|
||||||
stats: AllStats;
|
stats: {
|
||||||
|
battles: number;
|
||||||
|
wins: number;
|
||||||
|
damage_dealt: number;
|
||||||
|
damage_received: number;
|
||||||
|
survived_battles: number;
|
||||||
|
hits: number;
|
||||||
|
shots: number;
|
||||||
|
frags: number;
|
||||||
|
};
|
||||||
supplementaryStats: SupplementaryStats;
|
supplementaryStats: SupplementaryStats;
|
||||||
|
locale: Locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function AllStatsOverview({
|
export default function AllStatsOverview({
|
||||||
stats,
|
stats,
|
||||||
|
locale,
|
||||||
supplementaryStats,
|
supplementaryStats,
|
||||||
}: AllStatsOverviewProps) {
|
}: AllStatsOverviewProps) {
|
||||||
|
const { t } = translator(locale);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
gap: -64,
|
gap: -64,
|
||||||
width: '100%',
|
width: '100%',
|
||||||
}}
|
}}
|
||||||
@@ -32,18 +48,18 @@ export default function AllStatsOverview({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<WN8SurroundingStat
|
<WN8SurroundingStat
|
||||||
label="Battles"
|
label={t`bot.common.hero_stats.battles`}
|
||||||
value={stats.battles.toLocaleString()}
|
value={stats.battles.toLocaleString()}
|
||||||
align={WN8SurroundingStatAlign.Right}
|
align={WN8SurroundingStatAlign.Right}
|
||||||
/>
|
/>
|
||||||
<WN8SurroundingStat
|
<WN8SurroundingStat
|
||||||
label="Winrate"
|
label={t`bot.common.hero_stats.winrate`}
|
||||||
value={`${(100 * (stats.wins / stats.battles)).toFixed(2)}%`}
|
value={`${(100 * (stats.wins / stats.battles)).toFixed(2)}%`}
|
||||||
align={WN8SurroundingStatAlign.Right}
|
align={WN8SurroundingStatAlign.Right}
|
||||||
padded
|
padded
|
||||||
/>
|
/>
|
||||||
<WN8SurroundingStat
|
<WN8SurroundingStat
|
||||||
label="Damage"
|
label={t`bot.common.hero_stats.damage`}
|
||||||
value={Math.round(
|
value={Math.round(
|
||||||
stats.damage_dealt / stats.battles,
|
stats.damage_dealt / stats.battles,
|
||||||
).toLocaleString()}
|
).toLocaleString()}
|
||||||
@@ -51,13 +67,13 @@ export default function AllStatsOverview({
|
|||||||
padded
|
padded
|
||||||
/>
|
/>
|
||||||
<WN8SurroundingStat
|
<WN8SurroundingStat
|
||||||
label="Dmg. ratio"
|
label={t`bot.common.hero_stats.damage_ratio`}
|
||||||
value={(stats.damage_dealt / stats.damage_received).toFixed(2)}
|
value={(stats.damage_dealt / stats.damage_received).toFixed(2)}
|
||||||
align={WN8SurroundingStatAlign.Right}
|
align={WN8SurroundingStatAlign.Right}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<WN8Display WN8={supplementaryStats.WN8} />
|
<HeroStat locale={locale} stats={supplementaryStats} />
|
||||||
|
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@@ -68,29 +84,26 @@ export default function AllStatsOverview({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<WN8SurroundingStat
|
<WN8SurroundingStat
|
||||||
label="Tier"
|
label={t`bot.common.hero_stats.tier`}
|
||||||
value={
|
value={
|
||||||
supplementaryStats.tier ? supplementaryStats.tier.toFixed(2) : '--'
|
supplementaryStats.tier ? supplementaryStats.tier.toFixed(2) : '--'
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<WN8SurroundingStat
|
<WN8SurroundingStat
|
||||||
label="Survival"
|
label={t`bot.common.hero_stats.survival`}
|
||||||
value={`${(100 * (stats.survived_battles / stats.battles)).toFixed(
|
value={`${(100 * (stats.survived_battles / stats.battles)).toFixed(
|
||||||
2,
|
2,
|
||||||
)}%`}
|
)}%`}
|
||||||
padded
|
padded
|
||||||
/>
|
/>
|
||||||
<WN8SurroundingStat
|
<WN8SurroundingStat
|
||||||
label="Accuracy"
|
label={t`bot.common.hero_stats.accuracy`}
|
||||||
value={`${(100 * (stats.hits / stats.shots)).toFixed(2)}%`}
|
value={`${(100 * (stats.hits / stats.shots)).toFixed(2)}%`}
|
||||||
padded
|
padded
|
||||||
/>
|
/>
|
||||||
<WN8SurroundingStat
|
<WN8SurroundingStat
|
||||||
label="Kill ratio"
|
label={t`bot.common.hero_stats.kills`}
|
||||||
value={(
|
value={(stats.frags / stats.battles).toFixed(2)}
|
||||||
stats.frags /
|
|
||||||
(stats.battles - stats.survived_battles)
|
|
||||||
).toFixed(2)}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
export function Analytics() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<script
|
||||||
|
async
|
||||||
|
src="https://www.googletagmanager.com/gtag/js?id=G-98NTMRHRP9"
|
||||||
|
/>
|
||||||
|
<script
|
||||||
|
dangerouslySetInnerHTML={{
|
||||||
|
__html: `
|
||||||
|
window.dataLayer = window.dataLayer || [];
|
||||||
|
function gtag(){dataLayer.push(arguments);}
|
||||||
|
gtag('js', new Date());
|
||||||
|
|
||||||
|
gtag('config', 'G-98NTMRHRP9');
|
||||||
|
`,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
+94
-88
@@ -1,28 +1,29 @@
|
|||||||
import { useEffect, useRef } from 'react';
|
import { memo, useEffect, useRef } from 'react';
|
||||||
import { Euler, Group, Mesh, Vector3 } from 'three';
|
import { Euler, Group, Vector3 } from 'three';
|
||||||
import { degToRad } from 'three/src/math/MathUtils';
|
import { degToRad } from 'three/src/math/MathUtils';
|
||||||
import { ArmorMesh } from '../../../../../../../../../components/ArmorMesh';
|
import { I_HAT, J_HAT, K_HAT } from '../../../constants/axis';
|
||||||
import { I_HAT, J_HAT, K_HAT } from '../../../../../../../../../constants/axis';
|
|
||||||
import {
|
import {
|
||||||
ModelTransformEventData,
|
ModelTransformEventData,
|
||||||
modelTransformEvent,
|
modelTransformEvent,
|
||||||
} from '../../../../../../../../../core/blitzkrieg/modelTransform';
|
} from '../../../core/blitzkrieg/modelTransform';
|
||||||
import { nameToArmorId } from '../../../../../../../../../core/blitzkrieg/nameToArmorId';
|
import { nameToArmorId } from '../../../core/blitzkrieg/nameToArmorId';
|
||||||
import { resolveArmor } from '../../../../../../../../../core/blitzkrieg/resolveThickness';
|
import { resolveArmor } from '../../../core/blitzkrieg/resolveThickness';
|
||||||
import { useArmor } from '../../../../../../../../../hooks/useArmor';
|
import { useArmor } from '../../../hooks/useArmor';
|
||||||
import { useModelDefinitions } from '../../../../../../../../../hooks/useModelDefinitions';
|
import { useModelDefinitions } from '../../../hooks/useModelDefinitions';
|
||||||
import { useDuel } from '../../../../../../../../../stores/duel';
|
import { useDuel } from '../../../stores/duel';
|
||||||
import { useTankopediaPersistent } from '../../../../../../../../../stores/tankopedia';
|
import { useTankopediaPersistent } from '../../../stores/tankopedia';
|
||||||
|
import { CoreArmorSceneComponent } from './CoreArmorSceneComponent';
|
||||||
|
|
||||||
export function ArmorHighlighting() {
|
export const CoreArmorScene = memo(() => {
|
||||||
const protagonist = useDuel((state) => state.protagonist!);
|
|
||||||
const wrapper = useRef<Group>(null);
|
const wrapper = useRef<Group>(null);
|
||||||
const modelDefinitions = useModelDefinitions();
|
const modelDefinitions = useModelDefinitions();
|
||||||
const gunContainer = useRef<Group>(null);
|
|
||||||
const turretContainer = useRef<Group>(null);
|
const turretContainer = useRef<Group>(null);
|
||||||
|
const gunContainer = useRef<Group>(null);
|
||||||
const initialTankopediaState = useTankopediaPersistent.getState();
|
const initialTankopediaState = useTankopediaPersistent.getState();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!modelDefinitions) return;
|
||||||
|
|
||||||
const hullOrigin = new Vector3(
|
const hullOrigin = new Vector3(
|
||||||
trackModelDefinition.origin[0],
|
trackModelDefinition.origin[0],
|
||||||
trackModelDefinition.origin[1],
|
trackModelDefinition.origin[1],
|
||||||
@@ -33,14 +34,17 @@ export function ArmorHighlighting() {
|
|||||||
tankModelDefinition.turretOrigin[1],
|
tankModelDefinition.turretOrigin[1],
|
||||||
-tankModelDefinition.turretOrigin[2],
|
-tankModelDefinition.turretOrigin[2],
|
||||||
).applyAxisAngle(I_HAT, Math.PI / 2);
|
).applyAxisAngle(I_HAT, Math.PI / 2);
|
||||||
|
const gunOrigin = new Vector3(
|
||||||
|
turretModelDefinition.gunOrigin[0],
|
||||||
|
turretModelDefinition.gunOrigin[1],
|
||||||
|
-turretModelDefinition.gunOrigin[2],
|
||||||
|
).applyAxisAngle(I_HAT, Math.PI / 2);
|
||||||
const turretPosition = new Vector3();
|
const turretPosition = new Vector3();
|
||||||
const turretRotation = new Euler();
|
const turretRotation = new Euler();
|
||||||
const gunPosition = new Vector3();
|
const gunPosition = new Vector3();
|
||||||
const gunRotation = new Euler();
|
const gunRotation = new Euler();
|
||||||
|
|
||||||
function handleModelTransform({ pitch, yaw }: ModelTransformEventData) {
|
function handleModelTransform({ yaw, pitch }: ModelTransformEventData) {
|
||||||
if (yaw === undefined) return;
|
|
||||||
|
|
||||||
gunPosition
|
gunPosition
|
||||||
.set(0, 0, 0)
|
.set(0, 0, 0)
|
||||||
.sub(hullOrigin)
|
.sub(hullOrigin)
|
||||||
@@ -53,6 +57,9 @@ export function ArmorHighlighting() {
|
|||||||
gunRotation.set(pitch, 0, 0);
|
gunRotation.set(pitch, 0, 0);
|
||||||
gunContainer.current?.position.copy(gunPosition);
|
gunContainer.current?.position.copy(gunPosition);
|
||||||
gunContainer.current?.rotation.copy(gunRotation);
|
gunContainer.current?.rotation.copy(gunRotation);
|
||||||
|
|
||||||
|
if (yaw === undefined) return;
|
||||||
|
|
||||||
turretPosition
|
turretPosition
|
||||||
.set(0, 0, 0)
|
.set(0, 0, 0)
|
||||||
.sub(hullOrigin)
|
.sub(hullOrigin)
|
||||||
@@ -80,6 +87,16 @@ export function ArmorHighlighting() {
|
|||||||
turretContainer.current?.position.copy(turretPosition);
|
turretContainer.current?.position.copy(turretPosition);
|
||||||
turretContainer.current?.rotation.copy(turretRotation);
|
turretContainer.current?.rotation.copy(turretRotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleModelTransform(useDuel.getState().protagonist!);
|
||||||
|
modelTransformEvent.on(handleModelTransform);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
modelTransformEvent.off(handleModelTransform);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
const unsubscribe = useTankopediaPersistent.subscribe(
|
const unsubscribe = useTankopediaPersistent.subscribe(
|
||||||
(state) => state.mode,
|
(state) => state.mode,
|
||||||
(mode) => {
|
(mode) => {
|
||||||
@@ -87,27 +104,24 @@ export function ArmorHighlighting() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
handleModelTransform(protagonist);
|
return unsubscribe;
|
||||||
modelTransformEvent.on(handleModelTransform);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
modelTransformEvent.off(handleModelTransform);
|
|
||||||
unsubscribe();
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const armorGltf = useArmor(protagonist.tank.id);
|
const tank = useDuel((state) => state.protagonist!.tank);
|
||||||
|
const track = useDuel((state) => state.protagonist!.track);
|
||||||
|
const turret = useDuel((state) => state.protagonist!.turret);
|
||||||
|
const gun = useDuel((state) => state.protagonist!.gun);
|
||||||
|
const armorGltf = useArmor(tank.id);
|
||||||
const armorNodes = Object.values(armorGltf.nodes);
|
const armorNodes = Object.values(armorGltf.nodes);
|
||||||
const tankModelDefinition = modelDefinitions[protagonist.tank.id];
|
const tankModelDefinition = modelDefinitions[tank.id];
|
||||||
const trackModelDefinition = tankModelDefinition.tracks[protagonist.track.id];
|
const trackModelDefinition = tankModelDefinition.tracks[track.id];
|
||||||
const turretModelDefinition =
|
const turretModelDefinition = tankModelDefinition.turrets[turret.id];
|
||||||
tankModelDefinition.turrets[protagonist.turret.id];
|
const gunModelDefinition = turretModelDefinition.guns[gun.id];
|
||||||
const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id];
|
|
||||||
const hullOrigin = new Vector3(
|
const hullOrigin = new Vector3(
|
||||||
trackModelDefinition.origin[0],
|
trackModelDefinition.origin[0],
|
||||||
trackModelDefinition.origin[1],
|
trackModelDefinition.origin[1],
|
||||||
-trackModelDefinition.origin[2],
|
-trackModelDefinition.origin[2],
|
||||||
);
|
).applyAxisAngle(I_HAT, Math.PI / 2);
|
||||||
const turretOrigin = new Vector3(
|
const turretOrigin = new Vector3(
|
||||||
tankModelDefinition.turretOrigin[0],
|
tankModelDefinition.turretOrigin[0],
|
||||||
tankModelDefinition.turretOrigin[1],
|
tankModelDefinition.turretOrigin[1],
|
||||||
@@ -118,96 +132,88 @@ export function ArmorHighlighting() {
|
|||||||
turretModelDefinition.gunOrigin[1],
|
turretModelDefinition.gunOrigin[1],
|
||||||
-turretModelDefinition.gunOrigin[2],
|
-turretModelDefinition.gunOrigin[2],
|
||||||
).applyAxisAngle(I_HAT, Math.PI / 2);
|
).applyAxisAngle(I_HAT, Math.PI / 2);
|
||||||
const maxThickness = Math.max(
|
|
||||||
trackModelDefinition.thickness,
|
|
||||||
gunModelDefinition.thickness,
|
|
||||||
...armorNodes
|
|
||||||
.map((node) => {
|
|
||||||
const armorId = nameToArmorId(node.name);
|
|
||||||
return resolveArmor(tankModelDefinition.armor, armorId).thickness;
|
|
||||||
})
|
|
||||||
.filter(Boolean),
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<group
|
<group
|
||||||
ref={wrapper}
|
ref={wrapper}
|
||||||
rotation={[-Math.PI / 2, 0, 0]}
|
rotation={[-Math.PI / 2, 0, 0]}
|
||||||
visible={initialTankopediaState.mode === 'armor'}
|
visible={initialTankopediaState.mode === 'armor'}
|
||||||
position={hullOrigin}
|
|
||||||
>
|
>
|
||||||
{armorNodes.map((node) => {
|
<group position={hullOrigin}>
|
||||||
const isHull = node.name.startsWith('hull_');
|
|
||||||
const isVisible = isHull;
|
|
||||||
const armorId = nameToArmorId(node.name);
|
|
||||||
const { spaced, thickness } = resolveArmor(
|
|
||||||
tankModelDefinition.armor,
|
|
||||||
armorId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isVisible || thickness === undefined || spaced) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ArmorMesh
|
|
||||||
maxThickness={maxThickness}
|
|
||||||
key={node.uuid}
|
|
||||||
geometry={(node as Mesh).geometry}
|
|
||||||
thickness={thickness}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
|
|
||||||
<group ref={turretContainer}>
|
|
||||||
{armorNodes.map((node) => {
|
{armorNodes.map((node) => {
|
||||||
const isCurrentTurret = node.name.startsWith(
|
const isHull = node.name.startsWith('hull_');
|
||||||
`turret_${turretModelDefinition.model.toString().padStart(2, '0')}`,
|
const isVisible = isHull;
|
||||||
);
|
|
||||||
const isVisible = isCurrentTurret;
|
|
||||||
const armorId = nameToArmorId(node.name);
|
const armorId = nameToArmorId(node.name);
|
||||||
const { spaced, thickness } = resolveArmor(
|
const { spaced, thickness } = resolveArmor(
|
||||||
turretModelDefinition.armor,
|
tankModelDefinition.armor,
|
||||||
armorId,
|
armorId,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!isVisible || thickness === undefined || spaced) return null;
|
if (!isVisible || spaced || thickness === undefined) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ArmorMesh
|
<CoreArmorSceneComponent
|
||||||
maxThickness={maxThickness}
|
|
||||||
key={node.uuid}
|
key={node.uuid}
|
||||||
geometry={(node as Mesh).geometry}
|
|
||||||
position={turretOrigin}
|
|
||||||
thickness={thickness}
|
thickness={thickness}
|
||||||
|
node={node}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</group>
|
||||||
|
|
||||||
<group ref={gunContainer}>
|
<group ref={turretContainer}>
|
||||||
|
<group position={hullOrigin}>
|
||||||
{armorNodes.map((node) => {
|
{armorNodes.map((node) => {
|
||||||
const isCurrentGun = node.name.startsWith(
|
const isCurrentTurret = node.name.startsWith(
|
||||||
`gun_${gunModelDefinition.model.toString().padStart(2, '0')}`,
|
`turret_${turretModelDefinition.model.toString().padStart(2, '0')}`,
|
||||||
);
|
);
|
||||||
const isVisible = isCurrentGun;
|
const isVisible = isCurrentTurret;
|
||||||
const armorId = nameToArmorId(node.name);
|
const armorId = nameToArmorId(node.name);
|
||||||
const { spaced, thickness } = resolveArmor(
|
const { spaced, thickness } = resolveArmor(
|
||||||
gunModelDefinition.armor,
|
turretModelDefinition.armor,
|
||||||
armorId,
|
armorId,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!isVisible || thickness === undefined || spaced) return null;
|
if (!isVisible || spaced || thickness === undefined) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ArmorMesh
|
<group key={node.uuid} position={turretOrigin}>
|
||||||
maxThickness={maxThickness}
|
<CoreArmorSceneComponent
|
||||||
key={node.uuid}
|
key={node.uuid}
|
||||||
geometry={(node as Mesh).geometry}
|
thickness={thickness}
|
||||||
position={turretOrigin.clone().add(gunOrigin)}
|
node={node}
|
||||||
thickness={thickness}
|
/>
|
||||||
/>
|
</group>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</group>
|
</group>
|
||||||
|
<group ref={gunContainer}>
|
||||||
|
<group position={hullOrigin}>
|
||||||
|
{armorNodes.map((node) => {
|
||||||
|
const isCurrentGun = node.name.startsWith(
|
||||||
|
`gun_${gunModelDefinition.model.toString().padStart(2, '0')}`,
|
||||||
|
);
|
||||||
|
const isVisible = isCurrentGun;
|
||||||
|
const armorId = nameToArmorId(node.name);
|
||||||
|
const { spaced, thickness } = resolveArmor(
|
||||||
|
gunModelDefinition.armor,
|
||||||
|
armorId,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isVisible || spaced || thickness === undefined) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<group
|
||||||
|
key={node.uuid}
|
||||||
|
position={turretOrigin.clone().add(gunOrigin)}
|
||||||
|
>
|
||||||
|
<CoreArmorSceneComponent thickness={thickness} node={node} />
|
||||||
|
</group>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
import { useFrame } from '@react-three/fiber';
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import { MeshBasicMaterial, Object3D, ShaderMaterial, Vector2 } from 'three';
|
||||||
|
import { degToRad } from 'three/src/math/MathUtils';
|
||||||
|
import { canSplash } from '../../../../core/blitz/canSplash';
|
||||||
|
import { isExplosive } from '../../../../core/blitz/isExplosive';
|
||||||
|
import { resolveNearPenetration } from '../../../../core/blitz/resolveNearPenetration';
|
||||||
|
import { hasEquipment } from '../../../../core/blitzkrieg/hasEquipment';
|
||||||
|
import { jsxTree } from '../../../../core/blitzkrieg/jsxTree';
|
||||||
|
import { ShellDefinition } from '../../../../core/blitzkrieg/tankDefinitions';
|
||||||
|
import { EquipmentMatrix, useDuel } from '../../../../stores/duel';
|
||||||
|
import {
|
||||||
|
TankopediaPersistent,
|
||||||
|
useTankopediaPersistent,
|
||||||
|
} from '../../../../stores/tankopedia';
|
||||||
|
import fragmentShader from './shaders/fragment.glsl';
|
||||||
|
import vertexShader from './shaders/vertex.glsl';
|
||||||
|
import { spacedArmorRenderTarget } from './target';
|
||||||
|
|
||||||
|
interface CoreArmorSceneComponentProps {
|
||||||
|
thickness: number;
|
||||||
|
node: Object3D;
|
||||||
|
}
|
||||||
|
|
||||||
|
const excludeMaterial = new MeshBasicMaterial({
|
||||||
|
colorWrite: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
export function CoreArmorSceneComponent({
|
||||||
|
node,
|
||||||
|
thickness,
|
||||||
|
}: CoreArmorSceneComponentProps) {
|
||||||
|
const material = new ShaderMaterial({
|
||||||
|
fragmentShader,
|
||||||
|
vertexShader,
|
||||||
|
|
||||||
|
transparent: true,
|
||||||
|
|
||||||
|
uniforms: {
|
||||||
|
thickness: { value: null },
|
||||||
|
penetration: { value: null },
|
||||||
|
caliber: { value: null },
|
||||||
|
ricochet: { value: null },
|
||||||
|
normalization: { value: null },
|
||||||
|
isExplosive: { value: null },
|
||||||
|
canSplash: { value: null },
|
||||||
|
damage: { value: null },
|
||||||
|
explosionRadius: { value: null },
|
||||||
|
greenPenetration: { value: null },
|
||||||
|
opaque: { value: null },
|
||||||
|
useSpacedArmor: { value: null },
|
||||||
|
|
||||||
|
inverseProjectionMatrix: { value: null },
|
||||||
|
resolution: { value: new Vector2() },
|
||||||
|
spacedArmorBuffer: { value: null },
|
||||||
|
spacedArmorDepth: { value: null },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function handleShellChange(shell: ShellDefinition) {
|
||||||
|
material.uniforms.caliber.value = shell.caliber;
|
||||||
|
material.uniforms.ricochet.value = degToRad(shell.ricochet ?? 90);
|
||||||
|
material.uniforms.normalization.value = degToRad(
|
||||||
|
shell.normalization ?? 0,
|
||||||
|
);
|
||||||
|
material.uniforms.isExplosive.value = isExplosive(shell.type);
|
||||||
|
material.uniforms.canSplash.value = canSplash(shell.type);
|
||||||
|
material.uniforms.damage.value = shell.damage.armor;
|
||||||
|
material.uniforms.explosionRadius.value = shell.explosionRadius;
|
||||||
|
|
||||||
|
const duel = useDuel.getState();
|
||||||
|
await handleProtagonistEquipmentChange(duel.protagonist!.equipment);
|
||||||
|
await handleAntagonistEquipmentChange(duel.antagonist!.equipment);
|
||||||
|
}
|
||||||
|
function handleVisualChange(
|
||||||
|
visual: TankopediaPersistent['model']['visual'],
|
||||||
|
) {
|
||||||
|
material.uniforms.greenPenetration.value = visual.greenPenetration;
|
||||||
|
material.uniforms.opaque.value = visual.opaque || visual.wireframe;
|
||||||
|
material.uniforms.useSpacedArmor.value = visual.showSpacedArmor;
|
||||||
|
material.wireframe = visual.wireframe;
|
||||||
|
}
|
||||||
|
async function handleProtagonistEquipmentChange(
|
||||||
|
equipment: EquipmentMatrix,
|
||||||
|
) {
|
||||||
|
const hasEnhancedArmor = await hasEquipment(110, false, equipment);
|
||||||
|
material.uniforms.thickness.value = hasEnhancedArmor
|
||||||
|
? thickness * 1.04
|
||||||
|
: thickness;
|
||||||
|
}
|
||||||
|
async function handleAntagonistEquipmentChange(equipment: EquipmentMatrix) {
|
||||||
|
const shell = useDuel.getState().antagonist!.shell;
|
||||||
|
const penetration = resolveNearPenetration(shell.penetration);
|
||||||
|
const hasCalibratedShells = await hasEquipment(103, true, equipment);
|
||||||
|
|
||||||
|
material.uniforms.penetration.value = hasCalibratedShells
|
||||||
|
? penetration * (isExplosive(shell.type) ? 1.1 : 1.05)
|
||||||
|
: penetration;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleShellChange(useDuel.getState().antagonist!.shell);
|
||||||
|
handleVisualChange(useTankopediaPersistent.getState().model.visual);
|
||||||
|
handleProtagonistEquipmentChange(useDuel.getState().protagonist!.equipment);
|
||||||
|
handleAntagonistEquipmentChange(useDuel.getState().antagonist!.equipment);
|
||||||
|
|
||||||
|
const unsubscribes = [
|
||||||
|
useDuel.subscribe((state) => state.antagonist!.shell, handleShellChange),
|
||||||
|
useTankopediaPersistent.subscribe(
|
||||||
|
(state) => state.model.visual,
|
||||||
|
handleVisualChange,
|
||||||
|
),
|
||||||
|
useDuel.subscribe(
|
||||||
|
(state) => state.protagonist!.equipment,
|
||||||
|
handleProtagonistEquipmentChange,
|
||||||
|
),
|
||||||
|
useDuel.subscribe(
|
||||||
|
(state) => state.antagonist!.equipment,
|
||||||
|
handleAntagonistEquipmentChange,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
unsubscribes.forEach((unsubscribe) => unsubscribe());
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useFrame(({ gl, camera }) => {
|
||||||
|
gl.getSize(material.uniforms.resolution.value).multiplyScalar(
|
||||||
|
gl.getPixelRatio(),
|
||||||
|
);
|
||||||
|
material.uniforms.spacedArmorBuffer.value = spacedArmorRenderTarget.texture;
|
||||||
|
material.uniforms.spacedArmorDepth.value =
|
||||||
|
spacedArmorRenderTarget.depthTexture;
|
||||||
|
material.uniforms.inverseProjectionMatrix.value =
|
||||||
|
camera.projectionMatrixInverse;
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{jsxTree(node, {
|
||||||
|
renderOrder: 0,
|
||||||
|
material: excludeMaterial,
|
||||||
|
})}
|
||||||
|
{jsxTree(node, {
|
||||||
|
renderOrder: 1,
|
||||||
|
material,
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
varying vec3 vNormal;
|
||||||
|
varying vec3 vViewPosition;
|
||||||
|
|
||||||
|
uniform float thickness;
|
||||||
|
uniform float penetration;
|
||||||
|
uniform float caliber;
|
||||||
|
uniform float ricochet;
|
||||||
|
uniform float normalization;
|
||||||
|
uniform vec2 resolution;
|
||||||
|
uniform bool isExplosive;
|
||||||
|
uniform bool canSplash;
|
||||||
|
uniform float damage;
|
||||||
|
uniform float explosionRadius;
|
||||||
|
uniform bool greenPenetration;
|
||||||
|
uniform bool opaque;
|
||||||
|
uniform bool useSpacedArmor;
|
||||||
|
uniform mat4 inverseProjectionMatrix;
|
||||||
|
|
||||||
|
uniform highp sampler2D spacedArmorBuffer;
|
||||||
|
uniform highp sampler2D spacedArmorDepth;
|
||||||
|
|
||||||
|
float depthToDistance(float depth) {
|
||||||
|
vec4 clipPosition = vec4(gl_FragCoord.xy / resolution * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
|
||||||
|
vec4 eyePosition = inverseProjectionMatrix * clipPosition;
|
||||||
|
return length(eyePosition.xyz / eyePosition.w);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
float penetrationChance = -1.0;
|
||||||
|
float splashChance = -1.0;
|
||||||
|
|
||||||
|
vec2 screenCoordinates = gl_FragCoord.xy / resolution;
|
||||||
|
float angle = acos(dot(vNormal, -vViewPosition) / length(vViewPosition));
|
||||||
|
|
||||||
|
vec4 spacedArmorBufferFragment = texture2D(spacedArmorBuffer, screenCoordinates);
|
||||||
|
bool isUnderSpacedArmor = spacedArmorBufferFragment.a != 0.0;
|
||||||
|
|
||||||
|
bool threeCalibersRule = caliber > thickness * 3.0 || isUnderSpacedArmor;
|
||||||
|
if (!threeCalibersRule && angle >= ricochet) {
|
||||||
|
penetrationChance = 0.0;
|
||||||
|
} else {
|
||||||
|
bool twoCalibersRule = caliber > thickness * 2.0 && thickness > 0.0;
|
||||||
|
float finalNormalization = twoCalibersRule ? ((1.4 * normalization * caliber) / (2.0 * thickness)) : normalization;
|
||||||
|
float finalThickness = thickness / cos(max(0.0, angle - finalNormalization));
|
||||||
|
|
||||||
|
// world space in meters
|
||||||
|
vec4 spacedArmorDepthFragment = texture2D(spacedArmorDepth, screenCoordinates);
|
||||||
|
float spacedArmorDistance = depthToDistance(spacedArmorDepthFragment.r);
|
||||||
|
float coreArmorDistance = depthToDistance(gl_FragCoord.z);
|
||||||
|
float distanceFromSpacedArmor = coreArmorDistance - spacedArmorDistance;
|
||||||
|
|
||||||
|
if (canSplash && useSpacedArmor && isUnderSpacedArmor) {
|
||||||
|
float spacedArmorThickness = spacedArmorBufferFragment.r * penetration;
|
||||||
|
float finalDamage = 0.5 * damage * (1.0 - distanceFromSpacedArmor / explosionRadius) - 1.1 * (finalThickness + spacedArmorThickness);
|
||||||
|
|
||||||
|
penetrationChance = 0.0;
|
||||||
|
splashChance = finalDamage > 0.0 ? 1.0 : 0.0;
|
||||||
|
} else {
|
||||||
|
float remainingPenetration = penetration;
|
||||||
|
|
||||||
|
if (useSpacedArmor && isUnderSpacedArmor) {
|
||||||
|
float spacedArmorThickness = spacedArmorBufferFragment.r * penetration;
|
||||||
|
remainingPenetration -= spacedArmorThickness;
|
||||||
|
|
||||||
|
if (isExplosive && remainingPenetration > 0.0) {
|
||||||
|
remainingPenetration -= 0.5 * remainingPenetration * distanceFromSpacedArmor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
remainingPenetration = max(0.0, remainingPenetration);
|
||||||
|
float delta = finalThickness - remainingPenetration;
|
||||||
|
float randomization = remainingPenetration * 0.05;
|
||||||
|
penetrationChance = clamp(1.0 - (delta + randomization) / (2.0 * randomization), 0.0, 1.0);
|
||||||
|
|
||||||
|
if (canSplash) {
|
||||||
|
float splashDamage = 0.5 * damage - 1.1 * finalThickness;
|
||||||
|
splashChance = splashDamage > 0.0 ? 1.0 : 0.0;
|
||||||
|
} else {
|
||||||
|
splashChance = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float alpha = opaque ? 1.0 : 0.5;
|
||||||
|
vec3 color = vec3(1.0, splashChance * 0.392, 0.0);
|
||||||
|
if (greenPenetration) {
|
||||||
|
// non-trigonometric red-green mixing: https://www.desmos.com/calculator/ceo1oq7l67
|
||||||
|
float falling = -pow(penetrationChance, 2.0) + 1.0;
|
||||||
|
float gaining = -pow(penetrationChance - 1.0, 2.0) + 1.0;
|
||||||
|
gl_FragColor = vec4(falling * color + gaining * vec3(0.0, 1.0, 0.0), alpha);
|
||||||
|
} else {
|
||||||
|
gl_FragColor = vec4(color, (1.0 - penetrationChance) * alpha);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loaded 100 of 280 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user