feat: 턴 선택기에서 클립보드, 선택 카테고리를 상태 관리

This commit is contained in:
2022-03-26 21:37:04 +09:00
parent 162f0ff38a
commit 7f815baeb5
3 changed files with 56 additions and 10 deletions
+27 -1
View File
@@ -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<TurnObj[]>([]);
public readonly storedActions = ref(new Map<string, [number[], TurnObj][]>());
public readonly clipboard = ref<[number[], TurnObj][] | undefined>(undefined);
public readonly activatedCategory = ref<string>("");
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() {