From 7f815baeb59be02bb4f1f75ae92005e3f550deab Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sat, 26 Mar 2022 16:24:45 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=84=B4=20=EC=84=A0=ED=83=9D=EA=B8=B0?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=ED=81=B4=EB=A6=BD=EB=B3=B4=EB=93=9C,=20?= =?UTF-8?q?=EC=84=A0=ED=83=9D=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC?= =?UTF-8?q?=EB=A5=BC=20=EC=83=81=ED=83=9C=20=EA=B4=80=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/ts/PartialReservedCommand.vue | 8 +++---- hwe/ts/components/CommandSelectForm.vue | 30 ++++++++++++++++++++----- hwe/ts/util/StoredActionsHelper.ts | 28 ++++++++++++++++++++++- 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/hwe/ts/PartialReservedCommand.vue b/hwe/ts/PartialReservedCommand.vue index 64a31151..87b7ab7f 100644 --- a/hwe/ts/PartialReservedCommand.vue +++ b/hwe/ts/PartialReservedCommand.vue @@ -281,6 +281,7 @@ queryActionHelper.selectTurn(...$event); anchor=".commandSelectFormAnchor" ref="commandSelectForm" @on-close="chooseCommand($event)" + v-model:activatedCategory="activatedCategory" /> @@ -673,6 +675,7 @@ const storedActionsHelper = new StoredActionsHelper(staticValues.serverNick, 'ge const recentActions = storedActionsHelper.recentActions; const storedActions = storedActionsHelper.storedActions; +const activatedCategory = storedActionsHelper.activatedCategory; async function eraseSelectedTurnList(releaseSelect = true): Promise { const result = await reserveCommandDirect([[ @@ -685,10 +688,7 @@ async function eraseSelectedTurnList(releaseSelect = true): Promise { return result; } - - - -const clipboard = ref<[number[], TurnObj][] | undefined>(undefined); +const clipboard = storedActionsHelper.clipboard; async function clipboardCut(releaseSelect = true) { clipboardCopy(false); diff --git a/hwe/ts/components/CommandSelectForm.vue b/hwe/ts/components/CommandSelectForm.vue index 4affe6d3..369f6387 100644 --- a/hwe/ts/components/CommandSelectForm.vue +++ b/hwe/ts/components/CommandSelectForm.vue @@ -69,9 +69,6 @@ import type { CommandItem } from "@/defs"; import { BButton } from "bootstrap-vue-3"; import { ref, defineProps, defineEmits, defineExpose, type PropType, watch, onMounted } from "vue"; -const chosenCategory = ref("-"); -const chosenSubList = ref([]); - interface CategoryDecoration { name: string, altName?: string, @@ -101,9 +98,23 @@ const props = defineProps({ type: Boolean, required: false, default: true, + }, + activatedCategory: { + type: String, + required: false, + default: "", } }) +const chosenCategory = ref('-'); +const chosenSubList = ref([]); + +const categories = new Set(props.commandList.map(({category})=>category)); + +watch(()=>props.activatedCategory, (newValue)=>{ + chosenCategory.value = newValue; +}) + const showForm = ref(false); function convCategoryDeco(category: string): CategoryDecoration { @@ -140,17 +151,25 @@ 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; + if(props.activatedCategory !== category){ + emits('update:activatedCategory', category); + } }); onMounted(() => { - chosenCategory.value = props.commandList[0].category; + if(!categories.has(props.activatedCategory)){ + chosenCategory.value = props.commandList[0].category; + } + else{ + chosenCategory.value = props.activatedCategory; + } + }); function show(): void { @@ -171,6 +190,7 @@ function close(category?: string): void { const emits = defineEmits<{ (event: 'onClose', command?: string): void, + (event: 'update:activatedCategory', category: string): void, }>(); defineExpose({ diff --git a/hwe/ts/util/StoredActionsHelper.ts b/hwe/ts/util/StoredActionsHelper.ts index 70f3cf87..c91b3ad3 100644 --- a/hwe/ts/util/StoredActionsHelper.ts +++ b/hwe/ts/util/StoredActionsHelper.ts @@ -1,18 +1,44 @@ import type { TurnObj } from '@/defs'; -import { ref } from 'vue'; +import { ref, watch } from 'vue'; export class StoredActionsHelper { public readonly recentActions = ref([]); public readonly storedActions = ref(new Map()); + public readonly clipboard = ref<[number[], TurnObj][] | undefined>(undefined); + public readonly activatedCategory = ref(""); + public readonly recentActionsKey: string; public readonly storedActionsKey: string; + public readonly clipboardKey: string; + public readonly activatedCategoryKey: string; constructor(protected serverNick: string, protected type: 'general' | 'nation', protected mapName: string, protected unitSet: string, protected maxRecent = 10) { this.recentActionsKey = `${serverNick}_${mapName}_${unitSet}_${type}RecentActions`; this.storedActionsKey = `${serverNick}_${mapName}_${unitSet}_${type}StoredActions`; + this.clipboardKey = `${serverNick}_${mapName}_${unitSet}_${type}Clipboard`; + this.activatedCategoryKey = `${serverNick}_${mapName}_${unitSet}_${type}ActivatedCategory`; this.loadRecentActions(); this.loadStoredActions(); + + const rawClipboard = localStorage.getItem(this.clipboardKey); + if(rawClipboard !== null){ + this.clipboard.value = JSON.parse(rawClipboard); + } + + const rawActivatedCategory = localStorage.getItem(this.activatedCategoryKey); + if(rawActivatedCategory !== null){ + this.activatedCategory.value = JSON.parse(rawActivatedCategory); + } + + watch(this.clipboard, (newValue)=>{ + console.log(newValue); + localStorage.setItem(this.clipboardKey, JSON.stringify(newValue)); + }); + + watch(this.activatedCategory, (newValue)=>{ + localStorage.setItem(this.activatedCategoryKey, JSON.stringify(newValue)); + }); } loadRecentActions() {