feat: 턴 조작기, 보관함 기능
This commit is contained in:
@@ -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()))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user