-
+
-
+
@@ -269,16 +311,12 @@ import { mb_strwidth } from "@util/mb_strwidth";
import { parseTime } from "@util/parseTime";
import { parseYearMonth } from "@util/parseYearMonth";
import DragSelect from "@/components/DragSelect.vue";
-import { SammoAPI } from "./SammoAPI";
-import type { CommandItem } from "@/defs";
+import { SammoAPI, type InvalidResponse } from "./SammoAPI";
+import type { CommandItem, ReserveCommandResponse } from "@/defs";
import CommandSelectForm from "@/components/CommandSelectForm.vue";
import { BButton, BButtonGroup, BDropdownItem, BDropdown, BDropdownText, BDropdownDivider } from "bootstrap-vue-3";
-
-type TurnObj = {
- action: string;
- brief: string;
- arg: null | [] | Record;
-};
+import { StoredActionsHelper } from "./util/StoredActionsHelper";
+import type { TurnObj } from '@/defs';
type TurnObjWithTime = TurnObj & {
time: string;
@@ -362,7 +400,7 @@ setTimeout(() => {
const emptyTurn: TurnObjWithTime[] = Array.from({
length: staticValues.maxTurn,
}).fill({
- arg: null,
+ arg: {},
brief: "",
action: "",
year: undefined,
@@ -375,17 +413,20 @@ const editModeKey = `sammo_edit_mode_key`;
const prevTurnList = ref(new Set([0]));
const turnList = ref(new Set());
const reservedCommandList = ref(emptyTurn);
-const isEditMode = ref(localStorage.getItem(editModeKey)==='1');
+const isEditMode = ref(localStorage.getItem(editModeKey) === '1');
-const flippedMaxTurn = 15;
+const flippedMaxTurn = 14;
+
+const editModeRowHeight = 29.35;
+const basicModeRowHeight = 34.4;
const viewMaxTurn = ref(flippedMaxTurn);
const rowGridStyle = ref({
display: "grid",
- gridTemplateRows: `repeat(${viewMaxTurn.value}, 29.4px)`,
+ gridTemplateRows: `repeat(${viewMaxTurn.value}, ${isEditMode.value ? editModeRowHeight : basicModeRowHeight}px)`,
});
-watch(viewMaxTurn, (val) => {
- rowGridStyle.value.gridTemplateRows = `repeat(${val}, 29.4px)`;
+watch([isEditMode, viewMaxTurn], ([isEditMode, maxTurn]) => {
+ rowGridStyle.value.gridTemplateRows = `repeat(${maxTurn}, ${isEditMode ? editModeRowHeight : basicModeRowHeight}px)`;
});
const isDragSingle = ref(false);
@@ -484,12 +525,15 @@ async function pushGeneralCommand(amount: number) {
await reloadCommandList();
}
-/*
+
function pushGeneralCommandSingle(e: Event) {
//NOTE: split 구현에 버그가 있어서, 수동으로 구분해야함
if (isDropdownChildren(e)) {
return;
}
+ if (!isEditMode.value) {
+ return;
+ }
void pushGeneralCommand(1);
}
@@ -498,9 +542,12 @@ function pullGeneralCommandSingle(e: Event) {
if (isDropdownChildren(e)) {
return;
}
+ if (!isEditMode.value) {
+ return;
+ }
void pushGeneralCommand(-1);
}
-*/
+
async function reloadCommandList() {
let result: ReservedCommandResponse;
@@ -563,6 +610,41 @@ async function reloadCommandList() {
timeDiff.value = serverNow.value.getTime() - clientNow.value.getTime();
}
+async function reserveCommandDirect(args: [number[], TurnObj][], reload = true): Promise {
+ const waiterList: Promise[] = [];
+ for (const [turnList, { action, arg }] of args) {
+ waiterList.push(
+ SammoAPI.Command.ReserveCommand({
+ turnList,
+ action,
+ arg,
+ }, true)
+ );
+ }
+
+ let success = true;
+ for (const [idx, waiter] of waiterList.entries()) {
+ try {
+ const response = await waiter;
+ if (!response.result) {
+ const message = `${args[idx][0].join(',')}을 예약하지 못했습니다: ${response.reason}`
+ console.error(message, args[idx][1]);
+ alert(message);
+ success = false;
+ }
+ }
+ catch (e) {
+ const message = `${args[idx][0].join(',')}을 예약하지 못했습니다: ${e}`
+ console.error(message, args[idx][1]);
+ success = false;
+ }
+ }
+ if (reload) {
+ await reloadCommandList();
+ }
+ return success;
+}
+
async function reserveCommand() {
let reqTurnList: number[];
if (turnList.value.size == 0) {
@@ -589,11 +671,17 @@ async function reserveCommand() {
}
try {
- await SammoAPI.Command.ReserveCommand({
+ const result = await SammoAPI.Command.ReserveCommand({
turnList: reqTurnList,
action: commandName,
});
+ storedActionsHelper.pushRecentActions({
+ action: commandName,
+ brief: result.brief,
+ arg: {}
+ });
+
if (turnList.value.size > 0) {
prevTurnList.value.clear();
for (const v of turnList.value) {
@@ -614,6 +702,7 @@ function chooseCommand(val?: string) {
return;
}
selectedCommand.value = invCommandMap[val];
+ void reserveCommand();
}
const commandQuickReserveForm = ref | null>(null);
@@ -637,13 +726,9 @@ function toggleQuickReserveForm(turnIdx: number) {
commandQuickReserveForm.value?.show();
}
-onMounted(() => {
- void reloadCommandList();
-});
-
watch(isEditMode, newEditMode => {
- localStorage.setItem(editModeKey, newEditMode?'1':'0');
+ localStorage.setItem(editModeKey, newEditMode ? '1' : '0');
if (newEditMode) {
commandQuickReserveForm.value?.close();
currentQuickReserveTarget.value = -1;
@@ -653,6 +738,15 @@ watch(isEditMode, newEditMode => {
}
});
+const storedActionsHelper = new StoredActionsHelper(staticValues.serverNick, 'general');
+
+const recentActions = storedActionsHelper.recentActions;
+const storedActions = storedActionsHelper.storedActions;
+
+onMounted(() => {
+ void reloadCommandList();
+});
+