-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.vue
178 lines (158 loc) · 5.29 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<script lang="ts" setup>
import { invoke } from "@tauri-apps/api/core";
import { useIntervalFn } from '@vueuse/core'
import { getKV } from "~/composables/store/kv";
import parseDatetime from "~/utils/parse.datetime";
import convertMatchGroup from "~/utils/convert.matchgroup";
import type {GameData, Vehicle} from "~/types/GameData";
import { SettingsNeededSettingsModal } from '#components';
import {saveBattleHistory} from "~/composables/store/battle_history";
import checkServerValidity from "~/utils/check.server";
const modal = useModal()
const toast = useToast()
const checkModal = ref(false)
function openNeededSettingsModal() {
toast.add({
title: "请正确设置游戏目录"
})
checkModal.value = true
modal.open(SettingsNeededSettingsModal, {
un: 1,
onSuccess: async () => {
checkModal.value = false
}
})
}
useIntervalFn(async () => {
// 如果模态框打开,则不执行
if (checkModal.value) {return}
// 如果游戏目录为空,则从数据库中获取,如果依然为空,则打开模态框
let gameDirSet = await getKV("gameDir")
let gameServerSet = await getKV("gameServer")
let clanEnemyServerSet = await getKV("clanEnemyServer")
if (gameDirSet === '' || gameServerSet === '') {openNeededSettingsModal()}
// 获取游戏目录下的战斗信息
invoke('get_replays_temp_info', {gameDir: gameDirSet})
.then(async (res: any) => {
let gameDataParse: GameData
if (typeof res === "string") {
gameDataParse = JSON.parse(res)
} else {
throw new Error('数据解析失败')
}
let playersInfo: Vehicle[] = [];
for (let i = 0; i < gameDataParse.vehicles.length; i++) {
let getShipInfo = await convertShipid(String(gameDataParse.vehicles[i].shipId))
if (getShipInfo) {
playersInfo.push({
...gameDataParse.vehicles[i],
shipInfo: getShipInfo
})
}
}
let player: Vehicle | undefined
player = playersInfo.find(item => item.relation === 0)
if (!player) {
toast.add({
title: "出现意外错误!请联系开发者!",
})
throw new Error('无法获取玩家信息')
}
let teammateServer = 'unknown';
let enemyServer = 'unknown';
try {
if (gameServerSet === 'auto') {
const res = await invoke('get_selected_realm', { gameDir: gameDirSet });
if (typeof res === 'string') {
if (checkServerValidity(res)) {
teammateServer = res;
} else {
toast.add({
title: "错误:该服务器暂不支持!",
});
}
}
} else {
teammateServer = gameServerSet;
}
if (gameDataParse.matchGroup.toUpperCase() === 'CLAN') {
enemyServer = clanEnemyServerSet === 'sync' ? teammateServer : clanEnemyServerSet;
} else {
enemyServer = teammateServer;
}
} catch (err) {
console.log(err);
}
if (teammateServer === 'unknown' || enemyServer === 'unknown') {
toast.add({
title: "错误:未获取到服务器信息!可能无法自动检测,请尝试手动选择服务器!",
});
throw new Error('teamServer or enemyServer is unknown')
}
if (!(checkServerValidity(teammateServer) && checkServerValidity(enemyServer))) {
toast.add({
title: "错误:服务器信息不正确!",
});
throw new Error('teamServer or enemyServer is invalid')
}
await saveBattleHistory({
timestamp: parseDatetime(gameDataParse.dateTime).getTime(),
kokomi_battle_id: 0,
start_time: parseDatetime(gameDataParse.dateTime),
match_group: convertMatchGroup(gameDataParse.matchGroup).name,
game_mode: gameDataParse.gameMode,
map_display_name: convertMapid(gameDataParse.mapId).name,
map_id: gameDataParse.mapId,
players_per_team: gameDataParse.playersPerTeam,
teams_count: gameDataParse.teamsCount,
duration: gameDataParse.duration,
player_name: player.name,
player_vehicle: (player.shipInfo ? player.shipInfo.ship_name.zh_sg : '不认识这艘船捏'),
scenario: gameDataParse.scenario,
teammate_server: teammateServer,
enemy_server: enemyServer,
tire: (player.shipInfo ? player.shipInfo.tier : -1),
raw_data: res
})
})
.catch((err) => {
console.log(err);
if (err === '1002') {
toast.add({
title: "错误:游戏目录下没有找到replays文件夹,请检查游戏目录是否正确!",
})
}
})
}, 5000)
</script>
<template>
<NuxtLoadingIndicator />
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
<UModals />
<UNotifications />
</template>
<style>
.page-enter-active,
.page-leave-active {
transition: all 0.4s;
}
.page-enter-from,
.page-leave-to {
opacity: 0;
filter: blur(1rem);
}
.layout-enter-active,
.layout-leave-active {
transition: all 0.4s;
}
.layout-enter-from,
.layout-leave-to {
opacity: 0;
filter: blur(1rem);
}
html.dark{
color-scheme: dark;
}
</style>