refac: General/GetFrontInfo 정보 추가

- Global/GetRecentRecord 항목 포함
This commit is contained in:
2023-03-09 02:20:23 +09:00
parent 53569e3f12
commit 6395f73f6a
4 changed files with 148 additions and 62 deletions
+39 -60
View File
@@ -306,65 +306,6 @@ void Promise.all([storeP, tryRefresh()]).then(() => {
asyncReady.value = true;
});
const lastGeneralRecordID = ref(0);
const lastWorldHistoryID = ref(0);
const generalRecords = ref(new Denque<[number, string]>());
const globalRecords = ref(new Denque<[number, string]>());
const worldHistory = ref(new Denque<[number, string]>());
let recordLock = false;
watch(refreshCounter, async () => {
if (recordLock) {
return;
}
try {
recordLock = true;
const response = await SammoAPI.Global.GetRecentRecord({
lastGeneralRecordID: lastGeneralRecordID.value,
lastWorldHistoryID: lastWorldHistoryID.value,
});
recordLock = false;
const recordIter = [
['flushGeneral', generalRecords, 'general'],
['flushGlobal', globalRecords, 'global'],
['flushHistory', worldHistory, 'history'],
] as const;
for(const [flushKey, recordRef, recordKey] of recordIter) {
if (response[flushKey]) {
recordRef.value = new Denque<[number, string]>();
}
if (response[recordKey].length) {
lastGeneralRecordID.value = Math.max(lastGeneralRecordID.value, response[recordKey][0][0]);
}
const subRecord = response[recordKey];
while(subRecord.length){
const [id, record] = unwrap(subRecord.pop());
if(!recordRef.value.isEmpty() && id <= unwrap(recordRef.value.get(0))[0]){
continue;
}
if(recordRef.value.length >= 15){
recordRef.value.pop();
}
recordRef.value.unshift([id, formatLog(record)]);
}
}
} catch (e) {
recordLock = false;
console.error(e);
toasts.danger({
title: "최근 기록 갱신 실패",
body: `${e}`,
});
}
});
const globalMenu = ref<GetMenuResponse["menu"]>();
onMounted(async () => {
try {
@@ -387,6 +328,14 @@ const generalInfo = ref<GetFrontInfoResponse["general"]>();
const nationStaticInfo = ref<NationStaticItem>();
const nationInfo = ref<GetFrontInfoResponse["nation"]>();
const lastGeneralRecordID = ref(0);
const lastWorldHistoryID = ref(0);
const generalRecords = ref(new Denque<[number, string]>());
const globalRecords = ref(new Denque<[number, string]>());
const worldHistory = ref(new Denque<[number, string]>());
let generalInfoLock = false;
watch(refreshCounter, async () => {
@@ -395,7 +344,10 @@ watch(refreshCounter, async () => {
}
try {
generalInfoLock = true;
const response = await SammoAPI.General.GetFrontInfo();
const response = await SammoAPI.General.GetFrontInfo({
lastGeneralRecordID: lastGeneralRecordID.value,
lastWorldHistoryID: lastWorldHistoryID.value,
});
generalInfoLock = false;
frontInfo.value = response;
@@ -419,6 +371,33 @@ watch(refreshCounter, async () => {
gennum: rawNation.gennum,
power: rawNation.power,
};
const recentRecord = response.recentRecord;
const recordIter = [
['flushGeneral', generalRecords, 'general'],
['flushGlobal', globalRecords, 'global'],
['flushHistory', worldHistory, 'history'],
] as const;
for(const [flushKey, recordRef, recordKey] of recordIter) {
if (recentRecord[flushKey]) {
recordRef.value = new Denque<[number, string]>();
}
if (recentRecord[recordKey].length) {
lastGeneralRecordID.value = Math.max(lastGeneralRecordID.value, recentRecord[recordKey][0][0]);
}
const subRecord = recentRecord[recordKey];
while(subRecord.length){
const [id, record] = unwrap(subRecord.pop());
if(!recordRef.value.isEmpty() && id <= unwrap(recordRef.value.get(0))[0]){
continue;
}
if(recordRef.value.length >= 15){
recordRef.value.pop();
}
recordRef.value.unshift([id, formatLog(record)]);
}
}
} catch (e) {
generalInfoLock = false;
console.error(e);
+5 -1
View File
@@ -133,7 +133,11 @@ const apiRealPath = {
DieOnPrestart: POST as APICallT<undefined>,
BuildNationCandidate: POST as APICallT<undefined>,
GetCommandTable: GET as APICallT<undefined, CommandTableResponse>,
GetFrontInfo: GET as APICallT<undefined, GetFrontInfoResponse>,
GetFrontInfo: GET as APICallT<{
lastNationNoticeDate?: string,
lastGeneralRecordID?: number,
lastWorldHistoryID?: number,
}, GetFrontInfoResponse>,
},
Global: {
GeneralList: GET as APICallT<undefined, GeneralListResponse>,
+1
View File
@@ -103,6 +103,7 @@ export type AutorunUserMode = "develop" | "warp" | "recruit" | "recruit_high" |
export type GetFrontInfoResponse = {
result: true;
recentRecord: Omit<GetRecentRecordResponse, "result">;
global: {
scenarioText: string;
extendedGeneral: 1 | 0;