feat: rebuild Ref-compatible command editors
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
|
||||
const props = withDefaults(defineProps<{ disabled?: boolean; attribute?: string }>(), {
|
||||
disabled: false,
|
||||
attribute: 'data-turn-index',
|
||||
});
|
||||
const emit = defineEmits<{ (event: 'drag-start'): void; (event: 'drag-done', selected: Set<number>): void }>();
|
||||
const root = ref<HTMLElement | null>(null);
|
||||
const preview = ref(new Set<number>());
|
||||
let dragging = false;
|
||||
let startX = 0;
|
||||
let startY = 0;
|
||||
let box: HTMLDivElement | null = null;
|
||||
let activePointerId: number | null = null;
|
||||
|
||||
const intersects = (left: DOMRect, right: DOMRect) =>
|
||||
left.left <= right.right && left.right >= right.left && left.top <= right.bottom && left.bottom >= right.top;
|
||||
|
||||
const update = (clientX: number, clientY: number) => {
|
||||
if (!root.value || !box) return;
|
||||
const rootRect = root.value.getBoundingClientRect();
|
||||
const x = clientX - rootRect.left;
|
||||
const y = clientY - rootRect.top;
|
||||
box.style.left = `${Math.min(startX, x)}px`;
|
||||
box.style.top = `${Math.min(startY, y)}px`;
|
||||
box.style.width = `${Math.abs(x - startX)}px`;
|
||||
box.style.height = `${Math.abs(y - startY)}px`;
|
||||
const boxRect = box.getBoundingClientRect();
|
||||
const next = new Set<number>();
|
||||
for (const element of root.value.children) {
|
||||
if (element === box || !intersects(boxRect, element.getBoundingClientRect())) continue;
|
||||
const raw = element.getAttribute(props.attribute);
|
||||
if (raw !== null) next.add(Number(raw));
|
||||
}
|
||||
preview.value = next;
|
||||
};
|
||||
|
||||
const pointerMove = (event: PointerEvent) =>
|
||||
dragging && event.pointerId === activePointerId && update(event.clientX, event.clientY);
|
||||
const pointerUp = (event: PointerEvent) => {
|
||||
if (event.pointerId !== activePointerId) return;
|
||||
if (!dragging) return;
|
||||
dragging = false;
|
||||
if (root.value?.hasPointerCapture(event.pointerId)) root.value.releasePointerCapture(event.pointerId);
|
||||
activePointerId = null;
|
||||
box?.remove();
|
||||
box = null;
|
||||
emit('drag-done', new Set(preview.value));
|
||||
preview.value = new Set();
|
||||
};
|
||||
const pointerDown = (event: PointerEvent) => {
|
||||
if (props.disabled || !root.value || event.button !== 0) return;
|
||||
event.preventDefault();
|
||||
const rect = root.value.getBoundingClientRect();
|
||||
startX = event.clientX - rect.left;
|
||||
startY = event.clientY - rect.top;
|
||||
box = document.createElement('div');
|
||||
box.className = 'drag-selection-box';
|
||||
root.value.append(box);
|
||||
dragging = true;
|
||||
activePointerId = event.pointerId;
|
||||
root.value.setPointerCapture(event.pointerId);
|
||||
update(event.clientX, event.clientY);
|
||||
emit('drag-start');
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
root.value?.addEventListener('pointerdown', pointerDown);
|
||||
root.value?.addEventListener('pointermove', pointerMove);
|
||||
root.value?.addEventListener('pointerup', pointerUp);
|
||||
root.value?.addEventListener('pointercancel', pointerUp);
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
root.value?.removeEventListener('pointerdown', pointerDown);
|
||||
root.value?.removeEventListener('pointermove', pointerMove);
|
||||
root.value?.removeEventListener('pointerup', pointerUp);
|
||||
root.value?.removeEventListener('pointercancel', pointerUp);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="root" class="drag-select"><slot :selected="preview" /></div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.drag-select {
|
||||
position: relative;
|
||||
min-width: 0;
|
||||
user-select: none;
|
||||
}
|
||||
.drag-select :deep(.drag-selection-box) {
|
||||
position: absolute;
|
||||
z-index: 30;
|
||||
border: 1px solid #7ee8ff;
|
||||
background: rgb(0 180 255 / 28%);
|
||||
pointer-events: none;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,926 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, shallowRef, watch } from 'vue';
|
||||
import CommandArgumentForm from '../main/CommandArgumentForm.vue';
|
||||
import CommandSelectForm from '../main/CommandSelectForm.vue';
|
||||
import DragSelect from './DragSelect.vue';
|
||||
import {
|
||||
amplifyPattern,
|
||||
CommandStorage,
|
||||
extractPattern,
|
||||
moveQueueRange,
|
||||
normalizedSelection,
|
||||
selectStep,
|
||||
} from './commandQueue';
|
||||
import type { CommandAvailability, CommandPatternEntry, CommandTable, ReservedCommandRow } from './types';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
scope: 'general' | 'nation';
|
||||
rows: ReservedCommandRow[];
|
||||
commandTable: CommandTable | null;
|
||||
loading: boolean;
|
||||
storageKey: string;
|
||||
maxPushTurn?: number;
|
||||
compact?: boolean;
|
||||
mobile?: boolean;
|
||||
title?: string;
|
||||
name?: string | null;
|
||||
currentTime?: string;
|
||||
}>(),
|
||||
{ maxPushTurn: 6, compact: false, mobile: false, title: '', name: null, currentTime: '--:--' }
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
(event: 'reserve-bulk', entries: CommandPatternEntry[]): void;
|
||||
(event: 'shift', amount: number): void;
|
||||
(event: 'repeat', amount: number): void;
|
||||
}>();
|
||||
|
||||
const storage = shallowRef<CommandStorage | null>(null);
|
||||
const editMode = ref(false);
|
||||
const activeCategory = ref('');
|
||||
const selected = ref(new Set<number>());
|
||||
const previousSelected = ref(new Set<number>([0]));
|
||||
const dragKind = ref<'replace' | 'toggle' | null>(null);
|
||||
const quickTarget = ref<number | null>(null);
|
||||
const pickerOpen = ref(false);
|
||||
const selectedCommand = ref<CommandAvailability | null>(null);
|
||||
const commandArgs = ref<Record<string, unknown>>({});
|
||||
const commandArgsValid = ref(false);
|
||||
const expanded = ref(false);
|
||||
const menuRevision = ref(0);
|
||||
const pendingReservation = ref<CommandPatternEntry | null>(null);
|
||||
|
||||
const loadStorage = (key: string) => {
|
||||
storage.value = new CommandStorage(key);
|
||||
editMode.value = storage.value.editMode;
|
||||
activeCategory.value = storage.value.activeCategory;
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
loadStorage(props.storageKey);
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.storageKey,
|
||||
(key, previousKey) => {
|
||||
if (key !== previousKey) loadStorage(key);
|
||||
}
|
||||
);
|
||||
|
||||
watch([editMode, activeCategory], () => {
|
||||
if (!storage.value) return;
|
||||
storage.value.editMode = editMode.value;
|
||||
storage.value.activeCategory = activeCategory.value;
|
||||
storage.value.saveState();
|
||||
if (editMode.value) quickTarget.value = null;
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.rows,
|
||||
(rows) => {
|
||||
const pending = pendingReservation.value;
|
||||
if (!pending) return;
|
||||
const saved = pending.turnList.every((index) => {
|
||||
const row = rows[index];
|
||||
return row?.action === pending.action && JSON.stringify(row.args ?? {}) === JSON.stringify(pending.args);
|
||||
});
|
||||
if (!saved) return;
|
||||
storage.value?.pushRecent({ ...pending, turnList: [0] });
|
||||
pendingReservation.value = null;
|
||||
releaseSelection();
|
||||
closePicker();
|
||||
},
|
||||
{ deep: true }
|
||||
);
|
||||
|
||||
const scopedTable = computed<CommandTable | null>(() => {
|
||||
if (!props.commandTable) return null;
|
||||
return {
|
||||
...props.commandTable,
|
||||
general: props.scope === 'general' ? props.commandTable.general : [],
|
||||
nation: props.scope === 'nation' ? props.commandTable.nation : [],
|
||||
};
|
||||
});
|
||||
const labelMap = computed(() => {
|
||||
const map = new Map<string, string>([['휴식', '휴식']]);
|
||||
const groups = props.commandTable?.[props.scope] ?? [];
|
||||
for (const group of groups) for (const command of group.values) map.set(command.key, command.name);
|
||||
return map;
|
||||
});
|
||||
const displayRows = computed(() => props.rows.slice(0, expanded.value || props.compact ? props.rows.length : 14));
|
||||
const selectedIndices = () => normalizedSelection(selected.value, previousSelected.value, props.rows.length);
|
||||
const pattern = () => extractPattern(props.rows, selectedIndices());
|
||||
const touchMenus = () => (menuRevision.value += 1);
|
||||
|
||||
const releaseSelection = () => {
|
||||
if (selected.value.size) previousSelected.value = new Set(selected.value);
|
||||
selected.value = new Set();
|
||||
};
|
||||
const setSelection = (next: Set<number>) => (selected.value = new Set(next));
|
||||
const toggleSelection = (next: Set<number>) => {
|
||||
const result = new Set(selected.value);
|
||||
for (const index of next) {
|
||||
if (result.has(index)) result.delete(index);
|
||||
else result.add(index);
|
||||
}
|
||||
selected.value = result;
|
||||
};
|
||||
const finishDrag = (next: Set<number>) => {
|
||||
if (dragKind.value === 'toggle') toggleSelection(next);
|
||||
else setSelection(next);
|
||||
dragKind.value = null;
|
||||
};
|
||||
|
||||
const openPicker = (turnIndex?: number) => {
|
||||
quickTarget.value = turnIndex ?? null;
|
||||
pickerOpen.value = true;
|
||||
selectedCommand.value = null;
|
||||
commandArgs.value = {};
|
||||
commandArgsValid.value = false;
|
||||
};
|
||||
const closePicker = () => {
|
||||
pickerOpen.value = false;
|
||||
quickTarget.value = null;
|
||||
selectedCommand.value = null;
|
||||
};
|
||||
const selectCommand = (commandKey: string) => {
|
||||
const command = props.commandTable?.[props.scope]
|
||||
.flatMap((group) => group.values)
|
||||
.find((entry) => entry.key === commandKey);
|
||||
if (!command) return;
|
||||
selectedCommand.value = command;
|
||||
commandArgs.value = {};
|
||||
commandArgsValid.value = !command.reqArg;
|
||||
if (!command.reqArg) submitCommand();
|
||||
};
|
||||
const submitCommand = () => {
|
||||
const command = selectedCommand.value;
|
||||
if (!command || !commandArgsValid.value) return;
|
||||
const turnList = quickTarget.value === null ? selectedIndices() : [quickTarget.value];
|
||||
const entry = { turnList, action: command.key, args: { ...commandArgs.value }, label: command.name };
|
||||
emit('reserve-bulk', [entry]);
|
||||
pendingReservation.value = entry;
|
||||
};
|
||||
|
||||
const applyPattern = (raw: CommandPatternEntry[] | undefined) => {
|
||||
if (!raw?.length) return;
|
||||
const entries = amplifyPattern(raw, selectedIndices(), props.rows.length);
|
||||
if (entries.length) emit('reserve-bulk', entries);
|
||||
releaseSelection();
|
||||
};
|
||||
const copy = () => {
|
||||
storage.value?.saveClipboard(pattern());
|
||||
releaseSelection();
|
||||
touchMenus();
|
||||
};
|
||||
const cut = () => {
|
||||
storage.value?.saveClipboard(pattern());
|
||||
clearSelection();
|
||||
touchMenus();
|
||||
};
|
||||
const paste = () => applyPattern(storage.value?.clipboard);
|
||||
const clearSelection = () => {
|
||||
emit('reserve-bulk', [{ turnList: selectedIndices(), action: '휴식', args: {}, label: '휴식' }]);
|
||||
releaseSelection();
|
||||
};
|
||||
const repeatPattern = () => {
|
||||
const indexes = selectedIndices();
|
||||
if (!indexes.length) return;
|
||||
const first = indexes[0] ?? 0;
|
||||
const last = indexes.at(-1) ?? first;
|
||||
const anchors: number[] = [];
|
||||
for (let index = first; index < props.rows.length; index += last - first + 1) anchors.push(index);
|
||||
const entries = amplifyPattern(pattern(), anchors, props.rows.length);
|
||||
if (entries.length) emit('reserve-bulk', entries);
|
||||
releaseSelection();
|
||||
previousSelected.value = new Set(Array.from({ length: last - first + 1 }, (_, i) => first + i));
|
||||
};
|
||||
const rearrange = (direction: 'pull' | 'push') => {
|
||||
emit('reserve-bulk', moveQueueRange(props.rows, selectedIndices(), direction));
|
||||
releaseSelection();
|
||||
};
|
||||
const textCopy = async () => {
|
||||
const lines = selectedIndices().map((index) => {
|
||||
const row = props.rows[index];
|
||||
return `${index + 1}턴 ${row?.label ?? labelMap.value.get(row?.action ?? '') ?? row?.action ?? ''}`;
|
||||
});
|
||||
await navigator.clipboard.writeText(lines.join('\n'));
|
||||
releaseSelection();
|
||||
};
|
||||
const saveTemplate = () => {
|
||||
const raw = pattern();
|
||||
const fallback = raw
|
||||
.flatMap((entry) =>
|
||||
entry.turnList.map((index) => [index, (entry.label ?? entry.action).replace(/^che_|^cr_/, '')[0] ?? ''])
|
||||
)
|
||||
.sort((a, b) => Number(a[0]) - Number(b[0]))
|
||||
.map((entry) => entry[1])
|
||||
.join('');
|
||||
const name = window.prompt('선택한 턴들의 별명을 지어주세요', fallback)?.trim();
|
||||
if (!name) return;
|
||||
storage.value?.setTemplate(name, raw);
|
||||
releaseSelection();
|
||||
touchMenus();
|
||||
};
|
||||
|
||||
const clickOutsideMenu = (event: Event) => {
|
||||
const details = (event.currentTarget as HTMLElement).closest('details');
|
||||
if (details instanceof HTMLDetailsElement) details.open = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<article
|
||||
class="reserved-command-editor"
|
||||
:class="{ compact: props.compact, mobile: props.mobile, 'edit-mode': editMode, 'picker-open': pickerOpen }"
|
||||
:data-command-scope="props.scope"
|
||||
>
|
||||
<header v-if="props.compact && !props.mobile" class="identity legacy-bg1">
|
||||
<span>{{ props.title }} :</span><strong>{{ props.name ?? '-' }}</strong>
|
||||
</header>
|
||||
|
||||
<div class="editor-layout">
|
||||
<aside class="control-pad">
|
||||
<div v-if="props.mobile && props.compact" class="mobile-identity legacy-bg1">
|
||||
<strong>{{ props.name ?? '-' }}</strong
|
||||
><span>{{ props.title }}</span>
|
||||
</div>
|
||||
<div class="clock">{{ props.currentTime }}</div>
|
||||
<button type="button" @click="editMode = !editMode">{{ editMode ? '일반 모드' : '고급 모드' }}</button>
|
||||
<details class="legacy-menu">
|
||||
<summary>반복</summary>
|
||||
<div class="menu-items">
|
||||
<button
|
||||
v-for="amount in props.maxPushTurn"
|
||||
:key="amount"
|
||||
@click="
|
||||
emit('repeat', amount);
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
{{ amount }}턴
|
||||
</button>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<template v-if="editMode">
|
||||
<details class="legacy-menu range-menu">
|
||||
<summary>범위</summary>
|
||||
<div class="menu-items">
|
||||
<button
|
||||
@click="
|
||||
setSelection(new Set());
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
해제
|
||||
</button>
|
||||
<button
|
||||
@click="
|
||||
setSelection(new Set(props.rows.map((_, i) => i)));
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
모든턴
|
||||
</button>
|
||||
<button
|
||||
@click="
|
||||
setSelection(selectStep(props.rows.length, 0, 2));
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
홀수턴
|
||||
</button>
|
||||
<button
|
||||
@click="
|
||||
setSelection(selectStep(props.rows.length, 1, 2));
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
짝수턴
|
||||
</button>
|
||||
<template v-for="step in [3, 4, 5, 6, 7]" :key="step">
|
||||
<small>{{ step }}턴 간격</small>
|
||||
<div class="step-buttons">
|
||||
<button
|
||||
v-for="begin in step"
|
||||
:key="begin"
|
||||
@click="
|
||||
setSelection(selectStep(props.rows.length, begin - 1, step));
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
{{ begin }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</details>
|
||||
<details class="legacy-menu">
|
||||
<summary>보관함</summary>
|
||||
<div :key="`templates:${menuRevision}`" class="menu-items">
|
||||
<div
|
||||
v-for="[templateName, entries] in storage?.templates"
|
||||
:key="`${menuRevision}:${templateName}`"
|
||||
class="template-row"
|
||||
>
|
||||
<button
|
||||
@click="
|
||||
applyPattern(entries);
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
{{ templateName }}
|
||||
</button>
|
||||
<button
|
||||
aria-label="보관 명령 삭제"
|
||||
@click="
|
||||
storage?.deleteTemplate(templateName);
|
||||
touchMenus();
|
||||
"
|
||||
>
|
||||
삭제
|
||||
</button>
|
||||
</div>
|
||||
<span v-if="!storage?.templates.size" class="empty-menu">비어 있음</span>
|
||||
</div>
|
||||
</details>
|
||||
<details class="legacy-menu">
|
||||
<summary>최근{{ props.compact ? '' : ' 실행' }}</summary>
|
||||
<div :key="`recent:${menuRevision}`" class="menu-items">
|
||||
<button
|
||||
v-for="entry in [...(storage?.recent.values() ?? [])].reverse()"
|
||||
:key="JSON.stringify([entry.action, entry.args])"
|
||||
@click="
|
||||
applyPattern([entry]);
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
{{ entry.label ?? labelMap.get(entry.action) ?? entry.action }}
|
||||
</button>
|
||||
<span v-if="!storage?.recent.size" class="empty-menu">비어 있음</span>
|
||||
</div>
|
||||
</details>
|
||||
</template>
|
||||
|
||||
<details class="legacy-menu">
|
||||
<summary>당기기</summary>
|
||||
<div class="menu-items">
|
||||
<button
|
||||
v-for="amount in props.maxPushTurn"
|
||||
:key="amount"
|
||||
@click="
|
||||
emit('shift', -amount);
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
{{ amount }}턴
|
||||
</button>
|
||||
</div>
|
||||
</details>
|
||||
<details class="legacy-menu">
|
||||
<summary>미루기</summary>
|
||||
<div class="menu-items">
|
||||
<button
|
||||
v-for="amount in props.maxPushTurn"
|
||||
:key="amount"
|
||||
@click="
|
||||
emit('shift', amount);
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
{{ amount }}턴
|
||||
</button>
|
||||
</div>
|
||||
</details>
|
||||
</aside>
|
||||
|
||||
<div class="queue-area">
|
||||
<div class="queue-grid" :class="{ advanced: editMode }">
|
||||
<DragSelect
|
||||
v-if="editMode"
|
||||
v-slot="{ selected: draggingSelection }"
|
||||
class="index-column"
|
||||
@drag-start="dragKind = 'toggle'"
|
||||
@drag-done="finishDrag"
|
||||
>
|
||||
<button
|
||||
v-for="row in displayRows"
|
||||
:key="row.index"
|
||||
type="button"
|
||||
:data-turn-index="row.index"
|
||||
:class="{
|
||||
selected: selected.has(row.index),
|
||||
previous: !selected.size && previousSelected.has(row.index),
|
||||
preview: draggingSelection.has(row.index),
|
||||
}"
|
||||
>
|
||||
{{ row.index + 1 }}
|
||||
</button>
|
||||
</DragSelect>
|
||||
<DragSelect
|
||||
v-slot="{ selected: draggingSelection }"
|
||||
class="date-column"
|
||||
:disabled="!editMode"
|
||||
@drag-start="dragKind = 'replace'"
|
||||
@drag-done="finishDrag"
|
||||
>
|
||||
<div
|
||||
v-for="row in displayRows"
|
||||
:key="row.index"
|
||||
:data-turn-index="row.index"
|
||||
:class="{ preview: draggingSelection.has(row.index) }"
|
||||
>
|
||||
<template v-if="props.compact">{{ row.time ?? '--:--' }}</template>
|
||||
<template v-else>{{ row.year ? `${row.year}年 ${row.month}月` : '' }}</template>
|
||||
</div>
|
||||
</DragSelect>
|
||||
<div v-if="!props.compact" class="time-column">
|
||||
<div v-for="row in displayRows" :key="row.index">{{ row.time ?? '--:--' }}</div>
|
||||
</div>
|
||||
<div class="action-column">
|
||||
<div
|
||||
v-for="row in displayRows"
|
||||
:key="row.index"
|
||||
:title="row.label ?? labelMap.get(row.action) ?? row.action"
|
||||
>
|
||||
{{ row.label ?? labelMap.get(row.action) ?? row.action }}
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!editMode" class="edit-column">
|
||||
<button
|
||||
v-for="row in displayRows"
|
||||
:key="row.index"
|
||||
type="button"
|
||||
:aria-label="`${row.index + 1}턴 명령 입력`"
|
||||
@click="openPicker(row.index)"
|
||||
>
|
||||
✎
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="editMode" class="advanced-actions">
|
||||
<details class="legacy-menu selected-menu">
|
||||
<summary>선택한 턴을</summary>
|
||||
<div class="menu-items">
|
||||
<button
|
||||
@click="
|
||||
cut();
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
잘라내기
|
||||
</button>
|
||||
<button
|
||||
@click="
|
||||
copy();
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
복사하기
|
||||
</button>
|
||||
<button
|
||||
@click="
|
||||
paste();
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
붙여넣기
|
||||
</button>
|
||||
<button
|
||||
@click="
|
||||
textCopy();
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
텍스트 복사
|
||||
</button>
|
||||
<button
|
||||
@click="
|
||||
saveTemplate();
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
보관하기
|
||||
</button>
|
||||
<button
|
||||
@click="
|
||||
repeatPattern();
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
반복하기
|
||||
</button>
|
||||
<button
|
||||
@click="
|
||||
clearSelection();
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
비우기
|
||||
</button>
|
||||
<button
|
||||
@click="
|
||||
rearrange('pull');
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
지우고 당기기
|
||||
</button>
|
||||
<button
|
||||
@click="
|
||||
rearrange('push');
|
||||
clickOutsideMenu($event);
|
||||
"
|
||||
>
|
||||
뒤로 밀기
|
||||
</button>
|
||||
</div>
|
||||
</details>
|
||||
<button type="button" class="select-command" @click="openPicker()">명령 선택 ▾</button>
|
||||
</div>
|
||||
|
||||
<div v-if="!props.compact" class="bottom-actions">
|
||||
<button type="button" @click="emit('shift', -1)">당기기</button>
|
||||
<button type="button" @click="emit('shift', 1)">미루기</button>
|
||||
<button type="button" @click="expanded = !expanded">{{ expanded ? '접기' : '펼치기' }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="pickerOpen" class="command-picker" data-testid="command-picker">
|
||||
<header>
|
||||
<strong>{{ quickTarget === null ? '선택한 턴' : `${quickTarget + 1}턴` }} 명령 입력</strong
|
||||
><button type="button" aria-label="명령 입력 닫기" @click="closePicker">×</button>
|
||||
</header>
|
||||
<CommandSelectForm
|
||||
v-if="!selectedCommand"
|
||||
:command-table="scopedTable"
|
||||
:loading="props.loading"
|
||||
:scope="props.scope"
|
||||
:active-category="activeCategory"
|
||||
:allow-blocked="true"
|
||||
@update:active-category="activeCategory = $event"
|
||||
@select="selectCommand"
|
||||
/>
|
||||
<template v-else>
|
||||
<div class="selected-command">
|
||||
<strong>{{ selectedCommand.name }}</strong>
|
||||
<small v-if="selectedCommand.reason"
|
||||
>현재 상태: {{ selectedCommand.reason }} · 예약 입력은 가능합니다.</small
|
||||
>
|
||||
</div>
|
||||
<CommandArgumentForm
|
||||
v-if="selectedCommand.reqArg && props.commandTable"
|
||||
:command-key="selectedCommand.key"
|
||||
:fields="selectedCommand.inputFields"
|
||||
:options="props.commandTable.inputOptions"
|
||||
@update:args="commandArgs = $event"
|
||||
@update:valid="commandArgsValid = $event"
|
||||
/>
|
||||
<div class="picker-actions">
|
||||
<button :disabled="Boolean(pendingReservation)" @click="selectedCommand = null">
|
||||
명령 다시 선택</button
|
||||
><button :disabled="!commandArgsValid || Boolean(pendingReservation)" @click="submitCommand">
|
||||
{{ pendingReservation ? '저장 중' : '입력' }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.reserved-command-editor {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
color: #fff;
|
||||
background: #1d1d1d;
|
||||
font: 14px/1.05 var(--sammo-font-sans);
|
||||
}
|
||||
.reserved-command-editor.picker-open {
|
||||
z-index: 50;
|
||||
}
|
||||
.identity {
|
||||
box-sizing: border-box;
|
||||
height: 24px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
font-size: 16.8px;
|
||||
font-weight: 400;
|
||||
}
|
||||
.identity strong {
|
||||
font-weight: 400;
|
||||
}
|
||||
.editor-layout {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.control-pad {
|
||||
order: 0;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 4px;
|
||||
padding: 3px 0;
|
||||
}
|
||||
.control-pad > button,
|
||||
.clock,
|
||||
.legacy-menu > summary,
|
||||
.bottom-actions button,
|
||||
.select-command {
|
||||
box-sizing: border-box;
|
||||
min-height: 34px;
|
||||
border: 0;
|
||||
border-radius: 4px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 4px;
|
||||
background: #444;
|
||||
color: #fff;
|
||||
font: inherit;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
list-style: none;
|
||||
}
|
||||
.clock {
|
||||
background: #345c85;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.legacy-menu {
|
||||
position: relative;
|
||||
min-width: 0;
|
||||
}
|
||||
.legacy-menu > summary::-webkit-details-marker {
|
||||
display: none;
|
||||
}
|
||||
.menu-items {
|
||||
position: absolute;
|
||||
z-index: 60;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
min-width: 130px;
|
||||
max-height: 330px;
|
||||
overflow: auto;
|
||||
padding: 4px;
|
||||
border: 1px solid #777;
|
||||
background: #292929;
|
||||
box-shadow: 0 4px 12px #000;
|
||||
}
|
||||
.menu-items > button,
|
||||
.template-row button {
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-height: 30px;
|
||||
border: 0;
|
||||
padding: 5px 8px;
|
||||
background: transparent;
|
||||
color: #fff;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
.menu-items > button:hover,
|
||||
.template-row button:hover {
|
||||
background: #147a64;
|
||||
}
|
||||
.menu-items small,
|
||||
.empty-menu {
|
||||
display: block;
|
||||
padding: 5px 8px;
|
||||
color: #bbb;
|
||||
}
|
||||
.step-buttons,
|
||||
.template-row {
|
||||
display: flex;
|
||||
}
|
||||
.step-buttons button {
|
||||
flex: 1;
|
||||
min-width: 28px;
|
||||
min-height: 28px;
|
||||
}
|
||||
.template-row button:first-child {
|
||||
flex: 1;
|
||||
}
|
||||
.template-row button:last-child {
|
||||
width: auto;
|
||||
color: #ffaaa0;
|
||||
}
|
||||
.queue-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 75px 40px minmax(0, 1fr) 38px;
|
||||
}
|
||||
.queue-grid.advanced {
|
||||
grid-template-columns: 34px 75px 40px minmax(0, 1fr);
|
||||
}
|
||||
.index-column,
|
||||
.date-column,
|
||||
.time-column,
|
||||
.action-column,
|
||||
.edit-column {
|
||||
display: grid;
|
||||
grid-auto-rows: 34.4px;
|
||||
min-width: 0;
|
||||
}
|
||||
.edit-mode .index-column,
|
||||
.edit-mode .date-column,
|
||||
.edit-mode .time-column,
|
||||
.edit-mode .action-column {
|
||||
grid-auto-rows: 29.35px;
|
||||
}
|
||||
.index-column button,
|
||||
.date-column > div,
|
||||
.time-column > div,
|
||||
.action-column > div,
|
||||
.edit-column button {
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
border: 0;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
overflow: hidden;
|
||||
padding: 2px;
|
||||
color: #fff;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.index-column button {
|
||||
margin: 2px;
|
||||
border-radius: 3px;
|
||||
background: #006f98;
|
||||
}
|
||||
.index-column button.selected {
|
||||
background: #18a9ce;
|
||||
color: #00151d;
|
||||
}
|
||||
.index-column button.previous {
|
||||
background: #168e58;
|
||||
}
|
||||
.index-column button.preview {
|
||||
background: #eefcff;
|
||||
color: #00151d;
|
||||
}
|
||||
.date-column > div {
|
||||
background: #153c68;
|
||||
}
|
||||
.date-column > div.preview {
|
||||
color: #00ffff;
|
||||
}
|
||||
.time-column > div {
|
||||
background: #000;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.action-column > div {
|
||||
background: #0c1a41;
|
||||
}
|
||||
.action-column > div:nth-child(even) {
|
||||
background: #071638;
|
||||
}
|
||||
.edit-column button {
|
||||
background: #444;
|
||||
cursor: pointer;
|
||||
}
|
||||
.advanced-actions {
|
||||
display: grid;
|
||||
grid-template-columns: 5fr 7fr;
|
||||
}
|
||||
.advanced-actions > * {
|
||||
border-radius: 0 !important;
|
||||
}
|
||||
.bottom-actions {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 4px;
|
||||
padding-top: 3px;
|
||||
}
|
||||
.command-picker {
|
||||
position: absolute;
|
||||
z-index: 80;
|
||||
inset: 38px 0 auto 0;
|
||||
box-sizing: border-box;
|
||||
max-height: calc(100% - 38px);
|
||||
overflow: auto;
|
||||
padding: 6px;
|
||||
border: 1px solid #888;
|
||||
background: #303030;
|
||||
box-shadow: 0 6px 16px #000;
|
||||
}
|
||||
.command-picker > header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
min-height: 32px;
|
||||
}
|
||||
.command-picker > header button {
|
||||
width: 32px;
|
||||
height: 28px;
|
||||
}
|
||||
.selected-command {
|
||||
display: grid;
|
||||
gap: 3px;
|
||||
padding: 6px;
|
||||
background: #0d204d;
|
||||
}
|
||||
.selected-command small {
|
||||
color: #ffe0a0;
|
||||
}
|
||||
.picker-actions {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 6px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
.picker-actions button {
|
||||
min-height: 34px;
|
||||
}
|
||||
|
||||
.compact .editor-layout {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.compact .queue-area {
|
||||
order: 1;
|
||||
}
|
||||
.compact .control-pad {
|
||||
order: 2;
|
||||
min-height: 79px;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
.compact .queue-grid {
|
||||
grid-template-columns: 40px minmax(0, 1fr) 38px;
|
||||
}
|
||||
.compact .queue-grid.advanced {
|
||||
grid-template-columns: 40px 32px minmax(0, 1fr);
|
||||
}
|
||||
.compact .date-column,
|
||||
.compact .action-column,
|
||||
.compact .edit-column,
|
||||
.compact .index-column {
|
||||
grid-auto-rows: 30px;
|
||||
}
|
||||
.compact .advanced-actions {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
bottom: 82px;
|
||||
left: 0;
|
||||
z-index: 15;
|
||||
}
|
||||
.compact .command-picker {
|
||||
top: 54px;
|
||||
height: 344px;
|
||||
max-height: 344px;
|
||||
}
|
||||
|
||||
@media (min-width: 1025px) {
|
||||
.compact:not(.mobile) .command-picker {
|
||||
position: fixed;
|
||||
z-index: 1000;
|
||||
top: 86px;
|
||||
right: auto;
|
||||
left: calc(50% - 476px);
|
||||
width: 238px;
|
||||
}
|
||||
}
|
||||
|
||||
.mobile.compact .editor-layout {
|
||||
height: 360px;
|
||||
display: grid;
|
||||
grid-template-columns: 109px 391px;
|
||||
}
|
||||
.mobile.compact .control-pad {
|
||||
order: initial;
|
||||
min-height: 0;
|
||||
padding: 0;
|
||||
grid-template-columns: 1fr;
|
||||
align-content: start;
|
||||
}
|
||||
.mobile.compact .queue-area {
|
||||
order: initial;
|
||||
padding-top: 10px;
|
||||
}
|
||||
.mobile.compact .queue-grid {
|
||||
grid-template-columns: 74px minmax(0, 1fr) 53px;
|
||||
}
|
||||
.mobile.compact .queue-grid.advanced {
|
||||
grid-template-columns: 74px 53px minmax(0, 1fr);
|
||||
}
|
||||
.mobile-identity {
|
||||
min-height: 60px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
.mobile.compact .command-picker {
|
||||
top: 30px;
|
||||
left: 130px;
|
||||
width: 370px;
|
||||
height: 327px;
|
||||
}
|
||||
.mobile.compact .advanced-actions {
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 109px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,164 @@
|
||||
import type { CommandPatternEntry, ReservedCommandRow } from './types';
|
||||
|
||||
const jsonClone = <T>(value: T): T => JSON.parse(JSON.stringify(value)) as T;
|
||||
|
||||
const cloneArgs = (value: unknown): Record<string, unknown> => {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) return {};
|
||||
return jsonClone(value as Record<string, unknown>);
|
||||
};
|
||||
|
||||
export const normalizedSelection = (
|
||||
selected: ReadonlySet<number>,
|
||||
previous: ReadonlySet<number>,
|
||||
maxTurns: number
|
||||
): number[] => {
|
||||
const source = selected.size ? selected : previous.size ? previous : new Set([0]);
|
||||
return [...source].filter((index) => index >= 0 && index < maxTurns).sort((left, right) => left - right);
|
||||
};
|
||||
|
||||
export const selectStep = (maxTurns: number, begin: number, step: number): Set<number> => {
|
||||
const result = new Set<number>();
|
||||
for (let index = 0; index < maxTurns; index += 1) {
|
||||
if ((index - begin) % step === 0) result.add(index);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
export const extractPattern = (rows: ReservedCommandRow[], selection: number[]): CommandPatternEntry[] => {
|
||||
if (!selection.length) return [];
|
||||
const first = selection[0] ?? 0;
|
||||
const grouped = new Map<string, CommandPatternEntry>();
|
||||
for (const index of selection) {
|
||||
const row = rows[index];
|
||||
if (!row) continue;
|
||||
const args = cloneArgs(row.args);
|
||||
const key = JSON.stringify([row.action, args]);
|
||||
const relative = index - first;
|
||||
const existing = grouped.get(key);
|
||||
if (existing) {
|
||||
existing.turnList.push(relative);
|
||||
} else {
|
||||
grouped.set(key, { turnList: [relative], action: row.action, args, label: row.label });
|
||||
}
|
||||
}
|
||||
return [...grouped.values()];
|
||||
};
|
||||
|
||||
export const amplifyPattern = (
|
||||
pattern: CommandPatternEntry[],
|
||||
targets: number[],
|
||||
maxTurns: number
|
||||
): CommandPatternEntry[] => {
|
||||
if (!pattern.length || !targets.length) return [];
|
||||
const offsets = pattern.flatMap((entry) => entry.turnList);
|
||||
if (!offsets.length) return [];
|
||||
const minOffset = Math.min(...offsets);
|
||||
const width = Math.max(...offsets) - minOffset + 1;
|
||||
const anchors: number[] = [];
|
||||
for (const target of [...targets].sort((a, b) => a - b)) {
|
||||
const last = anchors.at(-1);
|
||||
if (last === undefined || target >= last + width) anchors.push(target);
|
||||
}
|
||||
return pattern
|
||||
.map((entry) => ({
|
||||
...entry,
|
||||
args: cloneArgs(entry.args),
|
||||
turnList: entry.turnList
|
||||
.flatMap((offset) => anchors.map((anchor) => anchor + offset - minOffset))
|
||||
.filter((index) => index >= 0 && index < maxTurns),
|
||||
}))
|
||||
.filter((entry) => entry.turnList.length > 0);
|
||||
};
|
||||
|
||||
export const moveQueueRange = (
|
||||
rows: ReservedCommandRow[],
|
||||
selection: number[],
|
||||
direction: 'pull' | 'push',
|
||||
restAction = '휴식'
|
||||
): CommandPatternEntry[] => {
|
||||
if (!selection.length) return [];
|
||||
const first = selection[0] ?? 0;
|
||||
const last = selection.at(-1) ?? first;
|
||||
const width = last - first + 1;
|
||||
const next = rows.map((row) => ({ action: row.action, args: cloneArgs(row.args), label: row.label }));
|
||||
if (direction === 'pull') {
|
||||
for (let index = first; index < rows.length - width; index += 1) next[index] = next[index + width]!;
|
||||
for (let index = Math.max(first, rows.length - width); index < rows.length; index += 1) {
|
||||
next[index] = { action: restAction, args: {}, label: '휴식' };
|
||||
}
|
||||
} else {
|
||||
for (let index = rows.length - 1; index >= first + width; index -= 1) next[index] = next[index - width]!;
|
||||
for (let index = first; index < Math.min(rows.length, first + width); index += 1) {
|
||||
next[index] = { action: restAction, args: {}, label: '휴식' };
|
||||
}
|
||||
}
|
||||
return next.map((entry, index) => ({ turnList: [index], ...entry }));
|
||||
};
|
||||
|
||||
export class CommandStorage {
|
||||
readonly recent = new Map<string, CommandPatternEntry>();
|
||||
readonly templates = new Map<string, CommandPatternEntry[]>();
|
||||
clipboard: CommandPatternEntry[] | undefined;
|
||||
editMode = false;
|
||||
activeCategory = '';
|
||||
private readonly key: string;
|
||||
private readonly maxRecent: number;
|
||||
|
||||
constructor(key: string, maxRecent = 10) {
|
||||
this.key = key;
|
||||
this.maxRecent = maxRecent;
|
||||
this.load();
|
||||
}
|
||||
|
||||
private read<T>(suffix: string, fallback: T): T {
|
||||
try {
|
||||
return JSON.parse(localStorage.getItem(`${this.key}:${suffix}`) ?? '') as T;
|
||||
} catch {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
private load(): void {
|
||||
for (const entry of this.read<CommandPatternEntry[]>('recent', [])) {
|
||||
this.recent.set(JSON.stringify([entry.action, entry.args]), entry);
|
||||
}
|
||||
for (const [name, entries] of this.read<Array<[string, CommandPatternEntry[]]>>('templates', [])) {
|
||||
this.templates.set(name, entries);
|
||||
}
|
||||
this.clipboard = this.read<CommandPatternEntry[] | undefined>('clipboard', undefined);
|
||||
this.editMode = localStorage.getItem(`${this.key}:editMode`) === '1';
|
||||
this.activeCategory = this.read('category', '');
|
||||
}
|
||||
|
||||
saveState(): void {
|
||||
localStorage.setItem(`${this.key}:editMode`, this.editMode ? '1' : '0');
|
||||
localStorage.setItem(`${this.key}:category`, JSON.stringify(this.activeCategory));
|
||||
}
|
||||
|
||||
saveClipboard(pattern: CommandPatternEntry[]): void {
|
||||
this.clipboard = jsonClone(pattern);
|
||||
localStorage.setItem(`${this.key}:clipboard`, JSON.stringify(this.clipboard));
|
||||
}
|
||||
|
||||
pushRecent(entry: CommandPatternEntry): void {
|
||||
const key = JSON.stringify([entry.action, entry.args]);
|
||||
this.recent.delete(key);
|
||||
this.recent.set(key, jsonClone(entry));
|
||||
while (this.recent.size > this.maxRecent) this.recent.delete(this.recent.keys().next().value as string);
|
||||
localStorage.setItem(`${this.key}:recent`, JSON.stringify([...this.recent.values()]));
|
||||
}
|
||||
|
||||
setTemplate(name: string, entries: CommandPatternEntry[]): void {
|
||||
this.templates.set(name, jsonClone(entries));
|
||||
this.saveTemplates();
|
||||
}
|
||||
|
||||
deleteTemplate(name: string): void {
|
||||
this.templates.delete(name);
|
||||
this.saveTemplates();
|
||||
}
|
||||
|
||||
private saveTemplates(): void {
|
||||
localStorage.setItem(`${this.key}:templates`, JSON.stringify([...this.templates.entries()]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
export type CommandOption = { value: string | number; label: string; color?: string };
|
||||
|
||||
export type CommandInputField = {
|
||||
key: string;
|
||||
label: string;
|
||||
kind: 'text' | 'number' | 'boolean' | 'select' | 'numberTuple' | 'hidden';
|
||||
required: boolean;
|
||||
min?: number;
|
||||
max?: number;
|
||||
step?: number;
|
||||
constValue?: string | number;
|
||||
options?: CommandOption[];
|
||||
optionSource?: 'cities' | 'nations' | 'generals' | 'crewTypes' | 'armTypes' | 'nationTypes' | 'colors' | 'items';
|
||||
tupleLabels?: string[];
|
||||
};
|
||||
|
||||
export type CommandAvailability = {
|
||||
key: string;
|
||||
name: string;
|
||||
reqArg: boolean;
|
||||
status: 'available' | 'blocked' | 'needsInput' | 'unknown';
|
||||
possible: boolean;
|
||||
reason?: string;
|
||||
inputFields: CommandInputField[];
|
||||
};
|
||||
|
||||
export type CommandGroup = { category: string; values: CommandAvailability[] };
|
||||
|
||||
export type CommandTable = {
|
||||
general: CommandGroup[];
|
||||
nation: CommandGroup[];
|
||||
inputOptions: {
|
||||
cities: CommandOption[];
|
||||
nations: CommandOption[];
|
||||
generals: CommandOption[];
|
||||
crewTypes: CommandOption[];
|
||||
armTypes: CommandOption[];
|
||||
nationTypes: CommandOption[];
|
||||
colors: CommandOption[];
|
||||
items: Record<string, CommandOption[]>;
|
||||
};
|
||||
};
|
||||
|
||||
export type ReservedCommandRow = {
|
||||
index: number;
|
||||
action: string;
|
||||
args: unknown;
|
||||
label?: string;
|
||||
time?: string;
|
||||
year?: number;
|
||||
month?: number;
|
||||
};
|
||||
|
||||
export type CommandPatternEntry = {
|
||||
turnList: number[];
|
||||
action: string;
|
||||
args: Record<string, unknown>;
|
||||
label?: string;
|
||||
};
|
||||
Reference in New Issue
Block a user