wip: GetFrontInfo

This commit is contained in:
2023-03-09 02:20:11 +09:00
parent 7425722c39
commit 8b78055fcf
4 changed files with 739 additions and 96 deletions
+69 -16
View File
@@ -27,7 +27,15 @@
<div class="reservedCommandZone">예턴</div>
<div class="cityInfo">도시 정보</div>
<div class="nationInfo">국가 정보</div>
<div class="generalInfo">장수 정보</div>
<div v-if="frontInfo && generalInfo && nationStaticInfo" class="generalInfo">
<GeneralBasicCard
:general="generalInfo"
:nation="nationStaticInfo"
:troopInfo="frontInfo.general.troopInfo"
:turnTerm="frontInfo.global.turnterm"
:lastExecuted="lastExecuted"
/>
</div>
<div class="generalCommandToolbar">국가 툴바</div>
<div class="actionMiniPlate">갱신/로비 버튼</div>
<div class="PublicRecord">
@@ -87,8 +95,11 @@ import { parseTime } from "./util/parseTime";
import { unwrap } from "./util/unwrap";
import Denque from "denque";
import { formatLog } from "@/utilGame/formatLog";
import type { ExecuteResponse } from "./defs/API/Global";
import type { ExecuteResponse, GetFrontInfoResponse } from "./defs/API/Global";
import { delay } from "./util/delay";
import GeneralBasicCard from "./components/GeneralBasicCard.vue";
import type { GeneralListItemP1 } from "./defs/API/Nation";
import type { NationStaticItem } from "./defs";
const { serverName, serverNick, serverID } = staticValues;
@@ -115,21 +126,19 @@ async function tryRefresh() {
}
try {
responseLock = true;
const responseP = SammoAPI.Global.ExecuteEngine({ serverID }, true).then(
(response) => {
if (response.result) {
lastExecuted.value = parseTime(response.lastExecuted);
serverLocked.value = response.locked;
}
return response;
const responseP = SammoAPI.Global.ExecuteEngine({ serverID }, true).then((response) => {
if (response.result) {
lastExecuted.value = parseTime(response.lastExecuted);
serverLocked.value = response.locked;
}
);
return response;
});
//TODO: 갱신 알림 띄우기
const response = await Promise.race([delay(3000), responseP]);
responseLock = false;
if(response === undefined){
if (response === undefined) {
//timeout이지만 일단 갱신한다.
refreshCounter.value += 1;
return;
@@ -179,7 +188,7 @@ const worldHistory = ref(new Denque<[number, string]>());
let recordLock = false;
watch(refreshCounter, async () => {
if(recordLock){
if (recordLock) {
return;
}
try {
@@ -215,11 +224,10 @@ watch(refreshCounter, async () => {
if (!generalRecords.value.isEmpty() && id <= unwrap(generalRecords.value.get(0))[0]) {
continue;
}
if(generalRecords.value.length >= 15) {
if (generalRecords.value.length >= 15) {
generalRecords.value.pop();
}
generalRecords.value.unshift([id, record]);
}
while (response.global.length) {
@@ -227,7 +235,7 @@ watch(refreshCounter, async () => {
if (!globalRecords.value.isEmpty() && id <= unwrap(globalRecords.value.get(0))[0]) {
continue;
}
if(globalRecords.value.length >= 15) {
if (globalRecords.value.length >= 15) {
globalRecords.value.pop();
}
globalRecords.value.unshift([id, record]);
@@ -238,7 +246,7 @@ watch(refreshCounter, async () => {
if (!worldHistory.value.isEmpty() && id <= unwrap(worldHistory.value.get(0))[0]) {
continue;
}
if(worldHistory.value.length >= 15) {
if (worldHistory.value.length >= 15) {
worldHistory.value.pop();
}
worldHistory.value.unshift([id, record]);
@@ -252,6 +260,51 @@ watch(refreshCounter, async () => {
});
}
});
const frontInfo = ref<GetFrontInfoResponse>();
const generalInfo = ref<GeneralListItemP1>();
const nationStaticInfo = ref<NationStaticItem>();
let generalInfoLock = false;
watch(refreshCounter, async () => {
if (generalInfoLock) {
return;
}
try {
generalInfoLock = true;
const response = await SammoAPI.General.GetFrontInfo();
generalInfoLock = false;
frontInfo.value = response;
generalInfo.value = response.general;
const newLastExecuted = parseTime(response.global.lastExecuted);
if(newLastExecuted.getTime() > lastExecuted.value.getTime()){
lastExecuted.value = newLastExecuted;
}
const rawNation = response.nation;
nationStaticInfo.value = {
nation: rawNation.id,
name: rawNation.name,
color: rawNation.color,
type: rawNation.type.raw,
level: rawNation.level,
capital: rawNation.capital,
gennum: rawNation.gennum,
power: rawNation.power,
};
} catch (e) {
recordLock = false;
console.error(e);
toasts.danger({
title: "최근 정보 갱신 실패",
body: `${e}`,
});
}
});
</script>
<style lang="scss" scoped>
@import "@scss/common/break_500px.scss";