feat: 턴 조작기, 보관함 기능

This commit is contained in:
2022-03-23 20:12:59 +09:00
parent 39ac64b837
commit b8542b6bce
2 changed files with 46 additions and 10 deletions
+11 -4
View File
@@ -1,4 +1,5 @@
import type { TurnObj } from '@/defs';
import { clone } from 'lodash';
import { ref } from 'vue';
@@ -8,7 +9,7 @@ export class StoredActionsHelper {
public readonly recentActionsKey: string;
public readonly storedActionsKey: string;
constructor(protected serverNick: string, protected type: 'general'|'nation', protected maxRecent = 10) {
constructor(protected serverNick: string, protected type: 'general' | 'nation', protected maxRecent = 10) {
this.recentActionsKey = `${serverNick}_${type}RecentActions`;
this.storedActionsKey = `${serverNick}_${type}StoredActions`;
this.loadRecentActions();
@@ -21,7 +22,7 @@ export class StoredActionsHelper {
pushRecentActions(action: TurnObj) {
this.recentActions.value.unshift(action);
if(this.recentActions.value.length > this.maxRecent){
if (this.recentActions.value.length > this.maxRecent) {
this.recentActions.value.pop();
}
this.saveRecentActions();
@@ -32,12 +33,15 @@ export class StoredActionsHelper {
}
loadStoredActions() {
const rawValue: [string, [number[], TurnObj][]][] = JSON.parse(localStorage.getItem(this.storedActionsKey) ?? '[]');
const rawValue: [string, [number[], TurnObj][]][] = JSON.parse(
localStorage.getItem(this.storedActionsKey) ?? '[]'
);
this.storedActions.value = new Map(rawValue);
}
setStoredActions(actionKey: string, actions: [number[], TurnObj][]) {
this.storedActions.value.set(actionKey, actions);
console.log(this.storedActions.value);
this.saveStoredActions();
}
@@ -48,7 +52,10 @@ export class StoredActionsHelper {
}
saveStoredActions() {
localStorage.setItem(this.storedActionsKey, JSON.stringify(Object.entries(this.storedActions.value)));
localStorage.setItem(
this.storedActionsKey,
JSON.stringify(Array.from(this.storedActions.value.entries()))
);
}
}