refac: isEditMode를 state 관리자로 이동
This commit is contained in:
@@ -7,38 +7,46 @@ export class StoredActionsHelper {
|
||||
public readonly storedActions = ref(new Map<string, [number[], TurnObj][]>());
|
||||
public readonly clipboard = ref<[number[], TurnObj][] | undefined>(undefined);
|
||||
public readonly activatedCategory = ref<string>("");
|
||||
public readonly isEditMode = ref(false);
|
||||
|
||||
public readonly recentActionsKey: string;
|
||||
public readonly storedActionsKey: string;
|
||||
public readonly clipboardKey: string;
|
||||
public readonly activatedCategoryKey: string;
|
||||
public readonly editModeKey: 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`;
|
||||
const typeKey = `${serverNick}_${mapName}_${unitSet}_${type}`;
|
||||
this.recentActionsKey = `${typeKey}RecentActions`;
|
||||
this.storedActionsKey = `${typeKey}StoredActions`;
|
||||
this.clipboardKey = `${typeKey}Clipboard`;
|
||||
this.activatedCategoryKey = `${typeKey}ActivatedCategory`;
|
||||
this.editModeKey = `${serverNick}_${type}_isEditMode`;
|
||||
|
||||
this.loadRecentActions();
|
||||
this.loadStoredActions();
|
||||
|
||||
const rawClipboard = localStorage.getItem(this.clipboardKey);
|
||||
if(rawClipboard !== null){
|
||||
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)=>{
|
||||
watch(this.clipboard, (newValue) => {
|
||||
console.log(newValue);
|
||||
localStorage.setItem(this.clipboardKey, JSON.stringify(newValue));
|
||||
});
|
||||
|
||||
watch(this.activatedCategory, (newValue)=>{
|
||||
const rawActivatedCategory = localStorage.getItem(this.activatedCategoryKey);
|
||||
if (rawActivatedCategory !== null) {
|
||||
this.activatedCategory.value = JSON.parse(rawActivatedCategory);
|
||||
}
|
||||
watch(this.activatedCategory, (newValue) => {
|
||||
localStorage.setItem(this.activatedCategoryKey, JSON.stringify(newValue));
|
||||
});
|
||||
|
||||
this.isEditMode.value = localStorage.getItem(this.editModeKey) === '1';
|
||||
watch(this.isEditMode, (newValue) => {
|
||||
localStorage.setItem(this.editModeKey, newValue ? '1' : '0')
|
||||
})
|
||||
}
|
||||
|
||||
loadRecentActions() {
|
||||
|
||||
Reference in New Issue
Block a user