feat(WIP): 턴 선택기를 multiselect에서 modal form으로 변경

This commit is contained in:
2022-03-23 20:12:59 +09:00
parent f6c59ad1f5
commit 70401d9567
9 changed files with 521 additions and 440 deletions
+6 -2
View File
@@ -203,9 +203,13 @@ $nations = $history['nations'];
<td><?= banner() ?> </td> <td><?= banner() ?> </td>
</tr> </tr>
</table> </table>
<?= WebUtil::printStaticValues([
'staticValues' => [
'serverNick' => DB::prefix(),
'serverID' => UniqueConst::$serverID,
]
])?>
<script> <script>
window.serverNick = '<?= DB::prefix() ?>';
window.serverID = '<?= UniqueConst::$serverID ?>';
<?php if($isCurrent): ?> <?php if($isCurrent): ?>
reloadWorldMap({ reloadWorldMap({
showMe: false, showMe: false,
+6 -2
View File
@@ -98,9 +98,13 @@ $neutralStateCharMap = [
<?= WebUtil::printCSS('css/map.css') ?> <?= WebUtil::printCSS('css/map.css') ?>
<?= WebUtil::printCSS('css/history.css') ?> <?= WebUtil::printCSS('css/history.css') ?>
<?= WebUtil::printDist('ts', ['common', 'map']) ?> <?= WebUtil::printDist('ts', ['common', 'map']) ?>
<?= WebUtil::printStaticValues([
'staticValues' => [
'serverNick' => DB::prefix(),
'serverID' => UniqueConst::$serverID
],
]) ?>
<script> <script>
window.serverNick = '<?= DB::prefix() ?>';
window.serverID = '<?= UniqueConst::$serverID ?>';
$(function() { $(function() {
reloadWorldMap({ reloadWorldMap({
+14 -1
View File
@@ -126,6 +126,19 @@ if (!$otherTextInfo) {
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css" /> <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css" />
<?= WebUtil::printCSS('css/map.css') ?> <?= WebUtil::printCSS('css/map.css') ?>
<?= WebUtil::printStaticValues([ <?= WebUtil::printStaticValues([
//deprecated, staticValues를 이용할 것
'serverName' => $serverName,
'serverCnt' => $serverCnt,
'serverNick' => DB::prefix(),
'serverID' => UniqueConst::$serverID,
'maxTurn' => GameConst::$maxTurn,
'maxPushTurn' => 12,
'serverNow' => TimeUtil::now(false),
'lastExecuted' => $gameStor->turntime,
'isLocked' => $plock,
'isTournamentActive' => $isTournamentActive,
'isBettingActive' => $isBettingActive,
'staticValues' => [
'serverName' => $serverName, 'serverName' => $serverName,
'serverCnt' => $serverCnt, 'serverCnt' => $serverCnt,
'serverNick' => DB::prefix(), 'serverNick' => DB::prefix(),
@@ -134,11 +147,11 @@ if (!$otherTextInfo) {
'maxPushTurn' => 12, 'maxPushTurn' => 12,
'commandList' => getCommandTable($generalObj), 'commandList' => getCommandTable($generalObj),
'serverNow' => TimeUtil::now(false), 'serverNow' => TimeUtil::now(false),
'baseColor2' => GameConst::$basecolor2,
'lastExecuted' => $gameStor->turntime, 'lastExecuted' => $gameStor->turntime,
'isLocked' => $plock, 'isLocked' => $plock,
'isTournamentActive' => $isTournamentActive, 'isTournamentActive' => $isTournamentActive,
'isBettingActive' => $isBettingActive 'isBettingActive' => $isBettingActive
]
]) ?> ]) ?>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous"> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
</head> </head>
+2
View File
@@ -16,8 +16,10 @@ include "func.php";
<title>최근 지도</title> <title>최근 지도</title>
<?= WebUtil::printJS('../d_shared/common_path.js') ?> <?= WebUtil::printJS('../d_shared/common_path.js') ?>
<?= WebUtil::printStaticValues([ <?= WebUtil::printStaticValues([
'staticValues' => [
'serverNick' => DB::prefix(), 'serverNick' => DB::prefix(),
'serverID' => UniqueConst::$serverID 'serverID' => UniqueConst::$serverID
],
]) ?> ]) ?>
<?= WebUtil::printJS('d_shared/base_map.js') ?> <?= WebUtil::printJS('d_shared/base_map.js') ?>
+196 -284
View File
@@ -6,26 +6,26 @@
<div class="row gx-1"> <div class="row gx-1">
<div class="col d-grid"> <div class="col d-grid">
<b-dropdown left text="턴 선택"> <BDropdown left text="턴 선택">
<b-dropdown-item @click="selectTurn()">해제</b-dropdown-item> <BDropdownItem @click="selectTurn()">해제</BDropdownItem>
<b-dropdown-item @click="selectAll(true)">모든턴</b-dropdown-item> <BDropdownItem @click="selectAll(true)">모든턴</BDropdownItem>
<b-dropdown-item @click="selectStep(0, 2)">홀수턴</b-dropdown-item> <BDropdownItem @click="selectStep(0, 2)">홀수턴</BDropdownItem>
<b-dropdown-item @click="selectStep(1, 2)">짝수턴</b-dropdown-item> <BDropdownItem @click="selectStep(1, 2)">짝수턴</BDropdownItem>
<b-dropdown-divider></b-dropdown-divider> <BDropdownDivider></BDropdownDivider>
<b-dropdown-text v-for="spanIdx in [3, 4, 5, 6, 7]" :key="spanIdx"> <BDropdownText v-for="spanIdx in [3, 4, 5, 6, 7]" :key="spanIdx">
{{ spanIdx }} 간격<br /> {{ spanIdx }} 간격
<b-button-group> <br />
<b-button <BButtonGroup>
<BButton
class="ignoreMe" class="ignoreMe"
v-for="beginIdx in spanIdx" v-for="beginIdx in spanIdx"
:key="beginIdx" :key="beginIdx"
@click="selectStep(beginIdx - 1, spanIdx)" @click="selectStep(beginIdx - 1, spanIdx)"
>{{ beginIdx }}</b-button >{{ beginIdx }}</BButton>
> </BButtonGroup>
</b-button-group> </BDropdownText>
</b-dropdown-text> </BDropdown>
</b-dropdown>
</div> </div>
<div <div
class="col alert alert-primary m-0 p-0" class="col alert alert-primary m-0 p-0"
@@ -35,18 +35,15 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
" "
> >{{ formatTime(serverNow, "HH:mm:ss") }}</div>
{{ serverNow }}
</div>
<div class="col d-grid"> <div class="col d-grid">
<b-dropdown right text="반복"> <BDropdown right text="반복">
<b-dropdown-item <BDropdownItem
v-for="turnIdx in maxPushTurn" v-for="turnIdx in maxPushTurn"
:key="turnIdx" :key="turnIdx"
@click="repeatGeneralCommand(turnIdx)" @click="repeatGeneralCommand(turnIdx)"
>{{ turnIdx }} >{{ turnIdx }}</BDropdownItem>
</b-dropdown-item> </BDropdown>
</b-dropdown>
</div> </div>
</div> </div>
@@ -70,7 +67,7 @@
:key="turnIdx" :key="turnIdx"
class="idx_pad center d-grid" class="idx_pad center d-grid"
> >
<b-button <BButton
size="sm" size="sm"
:variant=" :variant="
(isDragToggle && selected.has(`${turnIdx}`)) ? 'light' : (isDragToggle && selected.has(`${turnIdx}`)) ? 'light' :
@@ -80,8 +77,7 @@
? 'success' ? 'success'
: 'primary' : 'primary'
" "
>{{ turnIdx + 1 }}</b-button >{{ turnIdx + 1 }}</BButton>
>
</div> </div>
</DragSelect> </DragSelect>
<DragSelect <DragSelect
@@ -131,9 +127,7 @@
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
overflow: 'hidden', overflow: 'hidden',
}" }"
> >{{ turnObj.time }}</div>
{{ turnObj.time }}
</div>
</div> </div>
<div :style="rowGridStyle"> <div :style="rowGridStyle">
<div <div
@@ -157,130 +151,73 @@
</div> </div>
<div class="row gx-1"> <div class="row gx-1">
<div class="col d-grid"> <div class="col d-grid">
<b-dropdown right split text="당기기" @click="pullGeneralCommandSingle"> <BDropdown right split text="당기기" @click="pullGeneralCommandSingle">
<b-dropdown-item <BDropdownItem
v-for="turnIdx in maxPushTurn" v-for="turnIdx in maxPushTurn"
:key="turnIdx" :key="turnIdx"
@click="pushGeneralCommand(-turnIdx)" @click="pushGeneralCommand(-turnIdx)"
>{{ turnIdx }}턴 >{{ turnIdx }}턴</BDropdownItem>
</b-dropdown-item> </BDropdown>
</b-dropdown>
</div> </div>
<div class="col d-grid"> <div class="col d-grid">
<b-dropdown right split text="미루기" @click="pushGeneralCommandSingle"> <BDropdown right split text="미루기" @click="pushGeneralCommandSingle">
<b-dropdown-item <BDropdownItem
v-for="turnIdx in maxPushTurn" v-for="turnIdx in maxPushTurn"
:key="turnIdx" :key="turnIdx"
@click="pushGeneralCommand(turnIdx)" @click="pushGeneralCommand(turnIdx)"
>{{ turnIdx }}턴 >{{ turnIdx }}턴</BDropdownItem>
</b-dropdown-item> </BDropdown>
</b-dropdown>
</div> </div>
<div class="col d-grid"> <div class="col d-grid">
<b-button @click="toggleViewMaxTurn">{{ <BButton @click="toggleViewMaxTurn">
{{
flippedMaxTurn == viewMaxTurn ? "펼치기" : "접기" flippedMaxTurn == viewMaxTurn ? "펼치기" : "접기"
}}</b-button> }}
</BButton>
</div> </div>
</div> </div>
<div class="row gx-0"> <div class="row gx-0">
<div class="col-2 d-grid"> <div class="col-2 d-grid"></div>
<b-button
:pressed="searchModeOn"
@click="toggleSearchCommand()"
:variant="searchModeOn ? 'info' : 'primary'"
v-b-tooltip.hover
title="검색 기능을 활성화합니다."
><i class="bi bi-search"></i
></b-button>
</div>
<div class="col-7"> <div class="col-7">
<v-multiselect <BButton @click="commandSelectForm?.show()">{{ selectedCommand.title }}</BButton>
v-model="selectedCommand"
:allow-empty="false"
:options="commandList"
:group-select="false"
group-values="values"
group-label="category"
label="searchText"
track-by="value"
open-direction="top"
:show-labels="false"
selectLabel="선택(엔터)"
selectGroupLabel=""
selectedLabel="선택됨"
deselectLabel="해제(엔터)"
deselectGroupLabel=""
placeholder="턴 선택"
:maxHeight="400"
:searchable="searchModeOn"
>
<template v-slot:noResult>검색 결과가 없습니다.</template>
<template v-slot:option="props"
><!--FIXME: 카테고리-->
<template v-if="props.option.title">
<span
class="compensatePositive"
v-if="props.option.compensation > 0"
>▲</span
>
<span
class="compensateNegative"
v-else-if="props.option.compensation < 0"
>▼</span
>
<span class="compensateNeutral" v-else></span>
<span :class="[props.option.possible ? '' : 'commandImpossible']">
{{ props.option.title }}
</span>
</template>
<template v-else-if="props.option.category">
{{ props.option.category }}
</template>
</template>
<template v-slot:singleLabel="props">
{{ props.option.simpleName }}
</template>
</v-multiselect>
</div> </div>
<div class="col-3 d-grid"> <div class="col-3 d-grid">
<b-button @click="reserveCommand()" variant="primary">실행</b-button> <BButton @click="reserveCommand()" variant="primary">실행</BButton>
</div> </div>
</div> </div>
</div> </div>
<CommandSelectForm :commandList="commandList" ref="commandSelectForm" @on-close="chooseCommand($event)" />
</template> </template>
<script lang="ts"> <script lang="ts">
declare const staticValues: {
maxTurn: number,
maxPushTurn: number,
commandList: {
category: string;
values: CommandItem[];
}[],
serverNow: string,
}
</script>
<script lang="ts" setup>
import addMilliseconds from "date-fns/esm/addMilliseconds"; import addMilliseconds from "date-fns/esm/addMilliseconds";
import addMinutes from "date-fns/esm/addMinutes"; import addMinutes from "date-fns/esm/addMinutes";
import { isString, range } from "lodash"; import { isString, range } from "lodash";
import { stringifyUrl } from "query-string"; import { stringifyUrl } from "query-string";
import { defineComponent, ref, watch } from "vue"; import { onMounted, ref, watch } from "vue";
import { formatTime } from "@util/formatTime"; import { formatTime } from "@util/formatTime";
import { joinYearMonth } from "@util/joinYearMonth"; import { joinYearMonth } from "@util/joinYearMonth";
import { mb_strwidth } from "@util/mb_strwidth"; import { mb_strwidth } from "@util/mb_strwidth";
import { parseTime } from "@util/parseTime"; import { parseTime } from "@util/parseTime";
import { parseYearMonth } from "@util/parseYearMonth"; import { parseYearMonth } from "@util/parseYearMonth";
import { convertSearch초성 } from "./util/convertSearch초성";
import DragSelect from "@/components/DragSelect.vue"; import DragSelect from "@/components/DragSelect.vue";
import { SammoAPI } from "./SammoAPI"; import { SammoAPI } from "./SammoAPI";
import type { CommandItem } from "@/defs";
import CommandSelectForm from "@/components/CommandSelectForm.vue";
import { BButton, BButtonGroup, BDropdownItem, BDropdown, BDropdownText, BDropdownDivider } from "bootstrap-vue-3";
type commandItem = {
value: string;
title: string;
compensation: number;
simpleName: string;
possible: boolean;
reqArg: boolean;
searchText?: string;
};
declare const maxTurn: number;
declare const maxPushTurn: number;
declare const commandList: {
category: string;
values: commandItem[];
}[];
declare const serverNow: string;
type TurnObj = { type TurnObj = {
action: string; action: string;
brief: string; brief: string;
@@ -306,7 +243,21 @@ type ReservedCommandResponse = {
autorun_limit: null | number; autorun_limit: null | number;
}; };
const {
maxTurn,
maxPushTurn,
commandList,
} = staticValues;
const listReqArgCommand = new Set<string>(); const listReqArgCommand = new Set<string>();
const serverNow = ref(parseTime(staticValues.serverNow));
const clientNow = ref(new Date());
const timeDiff = ref(serverNow.value.getTime() - clientNow.value.getTime());
const selectedCommand = ref(staticValues.commandList[0].values[0]);
const commandSelectForm = ref<InstanceType<typeof CommandSelectForm> | null>(null);
for (const commandCategories of commandList) { for (const commandCategories of commandList) {
if (!commandCategories.values) { if (!commandCategories.values) {
continue; continue;
@@ -336,73 +287,113 @@ function isDropdownChildren(e?: Event): boolean {
return false; return false;
} }
const searchModeKey = `sammo_searchModeOn`;
export default defineComponent({
name: "PartialReservedCommand",
components: {
DragSelect,
},
methods: {
updateNow() {
const serverNow = addMilliseconds(new Date(), this.timeDiff);
this.serverNow = formatTime(serverNow, "HH:mm:ss");
setTimeout(() => { setTimeout(() => {
this.updateNow(); updateNow();
}, 1000 - serverNow.getMilliseconds()); }, 1000 - serverNow.value.getMilliseconds());
},
toggleTurn(...turnList: number[] | string[]) {
for (let turnIdx of turnList) { const emptyTurn: TurnObjWithTime[] = Array.from<TurnObjWithTime>({
length: staticValues.maxTurn,
}).fill({
arg: null,
brief: "",
action: "",
year: undefined,
month: undefined,
time: "",
});
const prevTurnList = ref(new Set([0]));
const turnList = ref(new Set<number>());
const reservedCommandList = ref(emptyTurn);
const flippedMaxTurn = 15;
const viewMaxTurn = ref(flippedMaxTurn);
const rowGridStyle = ref({
display: "grid",
gridTemplateRows: `repeat(${viewMaxTurn.value}, 29.4px)`,
});
watch(viewMaxTurn, (val) => {
rowGridStyle.value.gridTemplateRows = `repeat(${val}, 29.4px)`;
});
const isDragSingle = ref(false);
const isDragToggle = ref(false);
const invCommandMap: Record<string, CommandItem> = {};
for (const category of commandList) {
for (const command of category.values) {
invCommandMap[command.value] = command;
}
}
function updateNow() {
serverNow.value = addMilliseconds(new Date(), timeDiff.value);
setTimeout(() => {
updateNow();
}, 1000 - serverNow.value.getMilliseconds());
}
function toggleTurn(...reqTurnList: number[] | string[]) {
for (let turnIdx of reqTurnList) {
if (isString(turnIdx)) { if (isString(turnIdx)) {
turnIdx = parseInt(turnIdx); turnIdx = parseInt(turnIdx);
} }
if (this.turnList.has(turnIdx)) { if (turnList.value.has(turnIdx)) {
this.turnList.delete(turnIdx); turnList.value.delete(turnIdx);
} else { } else {
this.turnList.add(turnIdx); turnList.value.add(turnIdx);
} }
} }
}, }
selectTurn(...turnList: number[] | string[]) {
this.turnList.clear(); function selectTurn(...reqTurnList: number[] | string[]) {
for (const turnIdx of turnList) { turnList.value.clear();
for (const turnIdx of reqTurnList) {
if (isString(turnIdx)) { if (isString(turnIdx)) {
this.turnList.add(parseInt(turnIdx)); turnList.value.add(parseInt(turnIdx));
} else { } else {
this.turnList.add(turnIdx); turnList.value.add(turnIdx);
} }
} }
}, }
selectAll(e: Event | true) {
function selectAll(e: Event | true) {
//NOTE: split 구현에 버그가 있어서, 수동으로 구분해야함 //NOTE: split 구현에 버그가 있어서, 수동으로 구분해야함
if (e !== true && isDropdownChildren(e)) { if (e !== true && isDropdownChildren(e)) {
return; return;
} }
if (this.turnList.size * 3 > this.maxTurn) { if (turnList.value.size * 3 > maxTurn) {
this.turnList.clear(); turnList.value.clear();
} else { } else {
for (let i = 0; i < this.maxTurn; i++) { for (let i = 0; i < maxTurn; i++) {
this.turnList.add(i); turnList.value.add(i);
} }
} }
}, }
selectStep(begin: number, step: number) {
this.turnList.clear(); function selectStep(begin: number, step: number) {
turnList.value.clear();
for (const idx of range(0, maxTurn)) { for (const idx of range(0, maxTurn)) {
if ((idx - begin) % step == 0) { if ((idx - begin) % step == 0) {
this.turnList.add(idx); turnList.value.add(idx);
} }
} }
}, }
toggleViewMaxTurn() {
if (this.viewMaxTurn == this.flippedMaxTurn) { function toggleViewMaxTurn() {
this.viewMaxTurn = this.maxTurn; if (viewMaxTurn.value == flippedMaxTurn) {
viewMaxTurn.value = maxTurn;
} else { } else {
this.viewMaxTurn = this.flippedMaxTurn; viewMaxTurn.value = flippedMaxTurn;
} }
}, }
async repeatGeneralCommand(amount: number) {
async function repeatGeneralCommand(amount: number) {
try { try {
await SammoAPI.Command.RepeatCommand({ amount }); await SammoAPI.Command.RepeatCommand({ amount });
} catch (e) { } catch (e) {
@@ -410,9 +401,10 @@ export default defineComponent({
alert(`실패했습니다: ${e}`); alert(`실패했습니다: ${e}`);
return; return;
} }
await this.reloadCommandList(); await reloadCommandList();
}, }
async pushGeneralCommand(amount: number) {
async function pushGeneralCommand(amount: number) {
try { try {
await SammoAPI.Command.PushCommand({ amount }); await SammoAPI.Command.PushCommand({ amount });
} catch (e) { } catch (e) {
@@ -420,23 +412,26 @@ export default defineComponent({
alert(`실패했습니다: ${e}`); alert(`실패했습니다: ${e}`);
return; return;
} }
await this.reloadCommandList(); await reloadCommandList();
}, }
pushGeneralCommandSingle(e: Event) {
function pushGeneralCommandSingle(e: Event) {
//NOTE: split 구현에 버그가 있어서, 수동으로 구분해야함 //NOTE: split 구현에 버그가 있어서, 수동으로 구분해야함
if (isDropdownChildren(e)) { if (isDropdownChildren(e)) {
return; return;
} }
void this.pushGeneralCommand(1); void pushGeneralCommand(1);
}, }
pullGeneralCommandSingle(e: Event) {
function pullGeneralCommandSingle(e: Event) {
//NOTE: split 구현에 버그가 있어서, 수동으로 구분해야함 //NOTE: split 구현에 버그가 있어서, 수동으로 구분해야함
if (isDropdownChildren(e)) { if (isDropdownChildren(e)) {
return; return;
} }
void this.pushGeneralCommand(-1); void pushGeneralCommand(-1);
}, }
async reloadCommandList() {
async function reloadCommandList() {
let result: ReservedCommandResponse; let result: ReservedCommandResponse;
try { try {
result = await SammoAPI.Command.GetReservedCommand(); result = await SammoAPI.Command.GetReservedCommand();
@@ -446,7 +441,6 @@ export default defineComponent({
return; return;
} }
const reservedCommandList: TurnObjWithTime[] = [];
let yearMonth = joinYearMonth(result.year, result.month); let yearMonth = joinYearMonth(result.year, result.month);
const turnTime = parseTime(result.turnTime); const turnTime = parseTime(result.turnTime);
@@ -457,6 +451,7 @@ export default defineComponent({
autorunLimitYearMonth autorunLimitYearMonth
); );
reservedCommandList.value = [];
for (const obj of result.turn) { for (const obj of result.turn) {
const [year, month] = parseYearMonth(yearMonth); const [year, month] = parseYearMonth(yearMonth);
let tooltip: string[] = []; let tooltip: string[] = [];
@@ -479,7 +474,7 @@ export default defineComponent({
tooltip.push(brief); tooltip.push(brief);
} }
reservedCommandList.push({ reservedCommandList.value.push({
...obj, ...obj,
year, year,
month, month,
@@ -491,33 +486,32 @@ export default defineComponent({
yearMonth += 1; yearMonth += 1;
nextTurnTime = addMinutes(nextTurnTime, result.turnTerm); nextTurnTime = addMinutes(nextTurnTime, result.turnTerm);
} }
this.reservedCommandList = reservedCommandList;
const serverNowObj = parseTime(result.date); serverNow.value = parseTime(result.date);
const clientNowObj = new Date(); clientNow.value = new Date();
const timeDiff = serverNowObj.getTime() - clientNowObj.getTime(); timeDiff.value = serverNow.value.getTime() - clientNow.value.getTime();
this.timeDiff = timeDiff; }
},
async reserveCommand() { async function reserveCommand() {
let turnList: number[]; let reqTurnList: number[];
if (this.turnList.size == 0) { if (turnList.value.size == 0) {
turnList = Array.from(this.prevTurnList.values()); reqTurnList = Array.from(prevTurnList.value.values());
} else { } else {
turnList = Array.from(this.turnList.values()); reqTurnList = Array.from(turnList.value.values());
} }
if (turnList.length == 0) { if (reqTurnList.length == 0) {
turnList.push(0); reqTurnList.push(0);
} }
const commandName = this.selectedCommand.value; const commandName = selectedCommand.value.value;
if (listReqArgCommand.has(commandName)) { if (listReqArgCommand.has(commandName)) {
document.location.href = stringifyUrl({ document.location.href = stringifyUrl({
url: "v_processing.php", url: "v_processing.php",
query: { query: {
command: commandName, command: commandName,
turnList: turnList.join("_"), turnList: reqTurnList.join("_"),
}, },
}); });
return; return;
@@ -529,114 +523,32 @@ export default defineComponent({
action: commandName, action: commandName,
}); });
if (this.turnList.size > 0) { if (turnList.value.size > 0) {
this.prevTurnList.clear(); prevTurnList.value.clear();
for (const v of this.turnList) { for (const v of turnList.value) {
this.prevTurnList.add(v); prevTurnList.value.add(v);
} }
this.turnList.clear(); turnList.value.clear();
} }
} catch (e) { } catch (e) {
console.error(e); console.error(e);
alert(`실패했습니다: ${e}`); alert(`실패했습니다: ${e}`);
return; return;
} }
await this.reloadCommandList(); await reloadCommandList();
},
toggleSearchCommand() {
const searchModeOn = !this.searchModeOn;
this.searchModeOn = searchModeOn;
localStorage.setItem(searchModeKey, searchModeOn ? "1" : "0");
},
chooseCommand(val: string){
this.selectedCommand = this.invCommandMap[val];
}
},
data() {
const serverNowObj = parseTime(serverNow);
const clientNowObj = new Date();
const timeDiff = serverNowObj.getTime() - clientNowObj.getTime();
setTimeout(() => {
this.updateNow();
}, 1000 - serverNowObj.getMilliseconds());
const selectedCommand = commandList[0].values[0];
for (const subCategory of commandList) {
for (const command of subCategory.values) {
if (command.searchText) {
continue;
}
command.searchText = convertSearch초성(command.simpleName).join("|");
}
} }
const searchModeOn = (localStorage.getItem(searchModeKey) ?? "0") != "0"; function chooseCommand(val?: string) {
if(!val){
return;
}
selectedCommand.value = invCommandMap[val];
}
const emptyTurn: TurnObjWithTime[] = Array.from<TurnObjWithTime>({ onMounted(() => {
length: maxTurn, void reloadCommandList();
}).fill({
arg: null,
brief: "",
action: "",
year: undefined,
month: undefined,
time: "",
}); });
const prevTurnList = new Set([0]);
const turnList = new Set<number>();
return {
maxTurn,
maxPushTurn,
commandList,
serverNow: formatTime(serverNowObj, "HH:mm:ss"),
timeDiff,
prevTurnList,
turnList,
selectedCommand,
reservedCommandList: emptyTurn,
autorun_limit: null as null | number,
searchModeOn,
};
},
setup() {
const flippedMaxTurn = 15;
const viewMaxTurn = ref(flippedMaxTurn);
const rowGridStyle = ref({
display: "grid",
gridTemplateRows: `repeat(${viewMaxTurn.value}, 29.4px)`,
});
watch(viewMaxTurn, (val) => {
rowGridStyle.value.gridTemplateRows = `repeat(${val}, 29.4px)`;
});
const isDragSingle = ref(false);
const isDragToggle = ref(false);
const invCommandMap: Record<string, commandItem> = {};
for(const category of commandList){
for(const command of category.values){
invCommandMap[command.value] = command;
}
}
return {
isDragSingle,
isDragToggle,
flippedMaxTurn,
viewMaxTurn,
rowGridStyle,
invCommandMap,
};
},
mounted() {
void this.reloadCommandList();
},
});
</script> </script>
<style lang="scss"> <style lang="scss">
@use "sass:color"; @use "sass:color";
+135
View File
@@ -0,0 +1,135 @@
<template>
<teleport to="body">
<div v-if="showForm">
<div class="commandCategory">
<div
class="categoryItem"
v-for="[categoryKey, { deco: categoryDeco }] of commandList"
:key="categoryKey"
><BButton @click="chosenCategory=categoryKey">{{ categoryDeco.altName ?? categoryDeco.name }}</BButton></div>
</div>
<div class="commandList">
<div
class="commandItem"
v-for="commandItem of chosenSubList"
:key="commandItem.value"
@click="close(commandItem.value)"
>
{{ commandItem.simpleName }}
<br />
<small>{{ commandItem.title }}</small>
</div>
</div>
<div class="commandBottom">
<BButton @click="close()">닫기</BButton>
</div>
</div>
</teleport>
</template>
<script setup lang="ts">
/*
<template v-if="props.option.title">
<span class="compensatePositive" v-if="props.option.compensation > 0">▲</span>
<span class="compensateNegative" v-else-if="props.option.compensation < 0">▼</span>
<span class="compensateNeutral" v-else></span>
<span
:class="[props.option.possible ? '' : 'commandImpossible']"
>{{ props.option.title }}</span>
</template>
<template v-else-if="props.option.category">{{ props.option.category }}</template>
</template>
<template v-slot:singleLabel="props">{{ props.option.simpleName }}</template>
*/
import type { CommandItem } from "@/defs";
import { BButton } from "bootstrap-vue-3";
import { ref, defineProps, defineEmits, defineExpose, type PropType, watch } from "vue";
const chosenCategory = ref<string>("");
const chosenSubList = ref<CommandItem[]>([]);
interface CategoryDecoration {
name: string,
altName?: string,
//icon?: string,
//color?: string,
//backgroundColor?: string,
}
const props = defineProps({
categoryInfo: {
type: Object as PropType<Record<string, Omit<CategoryDecoration, 'name'>>>,
required: false,
},
commandList: {
type: Object as PropType<{
category: string;
values: CommandItem[];
}[]>,
required: true,
}
})
const showForm = ref(false);
function convCategoryDeco(category: string): CategoryDecoration {
const itemInfo = props.categoryInfo?.[category];
if (!itemInfo) {
return {
name: category,
}
}
return {
name: category,
...itemInfo
};
}
const commandList = ref(new Map<string, {
deco: CategoryDecoration,
values: CommandItem[],
}>());
function updateCommandList(rawCommandList: typeof props.commandList) {
commandList.value.clear();
for (const { category, values } of rawCommandList) {
commandList.value.set(category, {
deco: convCategoryDeco(category),
values
});
}
}
watch(() => props.commandList, updateCommandList);
updateCommandList(props.commandList);
watch(chosenCategory, (category) => {
console.log('sel', category);
const itemInfo = commandList.value?.get(category);
if (itemInfo === undefined) {
console.error(`category 없음: ${category}`);
return;
}
chosenSubList.value = itemInfo.values;
});
function show(): void {
showForm.value = true;
}
function close(category?: string): void {
showForm.value = false;
emits('onClose', category);
}
const emits = defineEmits<{
(event: 'onClose', command?: string): void,
}>();
defineExpose({
show,
close
})
</script>
+6 -2
View File
@@ -9,8 +9,12 @@ import { exportWindow } from '@util/exportWindow';
import { htmlReady } from './util/htmlReady'; import { htmlReady } from './util/htmlReady';
import { initTooltip } from './legacy/initTooltip'; import { initTooltip } from './legacy/initTooltip';
declare const serverNick: string; declare const staticValues: {
declare const serverID: string; serverNick: string;
serverID: string;
}
const { serverNick, serverID } = staticValues;
type CityPositionMap = { type CityPositionMap = {
[cityID: number]: [string, number, number]; [cityID: number]: [string, number, number];
+7
View File
@@ -76,6 +76,7 @@ if (!$commandObj->hasPermissionToReserve()) {
<?= WebUtil::printJS('../d_shared/common_path.js') ?> <?= WebUtil::printJS('../d_shared/common_path.js') ?>
<?= WebUtil::printJS('d_shared/base_map.js') ?> <?= WebUtil::printJS('d_shared/base_map.js') ?>
<?= WebUtil::printStaticValues([ <?= WebUtil::printStaticValues([
'staticValues' => [
'serverNick' => DB::prefix(), 'serverNick' => DB::prefix(),
'serverID' => UniqueConst::$serverID, 'serverID' => UniqueConst::$serverID,
'commandName' => $commandObj->getName(), 'commandName' => $commandObj->getName(),
@@ -83,6 +84,12 @@ if (!$commandObj->hasPermissionToReserve()) {
'currentCity' => $general->getCityID(), 'currentCity' => $general->getCityID(),
'currentNation' => $general->getNationID(), 'currentNation' => $general->getNationID(),
'entryInfo' => [$isChiefTurn?'Nation':'General', $commandType] 'entryInfo' => [$isChiefTurn?'Nation':'General', $commandType]
],
'commandName' => $commandObj->getName(),
'turnList' => $turnList,
'currentCity' => $general->getCityID(),
'currentNation' => $general->getNationID(),
'entryInfo' => [$isChiefTurn?'Nation':'General', $commandType]
])?> ])?>
<?= WebUtil::printStaticValues($commandObj->exportJSVars(), false) ?> <?= WebUtil::printStaticValues($commandObj->exportJSVars(), false) ?>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css" /> <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css" />