fix(game-ui): 턴 입력기 모드를 서버별로 기억한다
This commit is contained in:
@@ -30,6 +30,7 @@ const props = withDefaults(
|
||||
commandTable: CommandTable | null;
|
||||
loading: boolean;
|
||||
storageKey: string;
|
||||
editModeStorageKey?: string;
|
||||
maxPushTurn?: number;
|
||||
compact?: boolean;
|
||||
mobile?: boolean;
|
||||
@@ -41,6 +42,7 @@ const props = withDefaults(
|
||||
autonomousUntil?: string | null;
|
||||
}>(),
|
||||
{
|
||||
editModeStorageKey: undefined,
|
||||
maxPushTurn: 6,
|
||||
compact: false,
|
||||
mobile: false,
|
||||
@@ -82,20 +84,20 @@ const editorElement = ref<HTMLElement | null>(null);
|
||||
const pickerElement = ref<HTMLElement | null>(null);
|
||||
const collapsedRowCount = 15;
|
||||
|
||||
const loadStorage = (key: string) => {
|
||||
storage.value = new CommandStorage(key);
|
||||
const loadStorage = (key: string, editModeKey: string | undefined) => {
|
||||
storage.value = new CommandStorage(key, { editModeKey });
|
||||
editMode.value = storage.value.editMode;
|
||||
activeCategory.value = storage.value.activeCategory;
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
loadStorage(props.storageKey);
|
||||
loadStorage(props.storageKey, props.editModeStorageKey);
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.storageKey,
|
||||
(key, previousKey) => {
|
||||
if (key !== previousKey) loadStorage(key);
|
||||
() => [props.storageKey, props.editModeStorageKey] as const,
|
||||
([key, editModeKey], [previousKey, previousEditModeKey]) => {
|
||||
if (key !== previousKey || editModeKey !== previousEditModeKey) loadStorage(key, editModeKey);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -95,6 +95,18 @@ export const moveQueueRange = (
|
||||
return next.map((entry, index) => ({ turnList: [index], ...entry }));
|
||||
};
|
||||
|
||||
export const generalTurnEditorModeStorageKey = (profile: string | undefined, appBasePath: string): string => {
|
||||
const runtimeProfile = profile?.trim().split(':', 1)[0];
|
||||
const basePathProfile = appBasePath.split('/').find((segment) => segment.length > 0);
|
||||
const profileId = runtimeProfile || basePathProfile || 'default';
|
||||
return `core2026:profile:${encodeURIComponent(profileId)}:general-turn-editor`;
|
||||
};
|
||||
|
||||
interface CommandStorageOptions {
|
||||
maxRecent?: number;
|
||||
editModeKey?: string;
|
||||
}
|
||||
|
||||
export class CommandStorage {
|
||||
readonly recent = new Map<string, CommandPatternEntry>();
|
||||
readonly templates = new Map<string, CommandPatternEntry[]>();
|
||||
@@ -102,11 +114,13 @@ export class CommandStorage {
|
||||
editMode = false;
|
||||
activeCategory = '';
|
||||
private readonly key: string;
|
||||
private readonly editModeKey: string;
|
||||
private readonly maxRecent: number;
|
||||
|
||||
constructor(key: string, maxRecent = 10) {
|
||||
constructor(key: string, options: CommandStorageOptions = {}) {
|
||||
this.key = key;
|
||||
this.maxRecent = maxRecent;
|
||||
this.editModeKey = options.editModeKey ?? key;
|
||||
this.maxRecent = options.maxRecent ?? 10;
|
||||
this.load();
|
||||
}
|
||||
|
||||
@@ -126,12 +140,18 @@ export class CommandStorage {
|
||||
this.templates.set(name, entries);
|
||||
}
|
||||
this.clipboard = this.read<CommandPatternEntry[] | undefined>('clipboard', undefined);
|
||||
this.editMode = localStorage.getItem(`${this.key}:editMode`) === '1';
|
||||
const editModeStorageKey = `${this.editModeKey}:editMode`;
|
||||
let storedEditMode = localStorage.getItem(editModeStorageKey);
|
||||
if (storedEditMode === null && this.editModeKey !== this.key) {
|
||||
storedEditMode = localStorage.getItem(`${this.key}:editMode`);
|
||||
if (storedEditMode !== null) localStorage.setItem(editModeStorageKey, storedEditMode);
|
||||
}
|
||||
this.editMode = storedEditMode === '1';
|
||||
this.activeCategory = this.read('category', '');
|
||||
}
|
||||
|
||||
saveState(): void {
|
||||
localStorage.setItem(`${this.key}:editMode`, this.editMode ? '1' : '0');
|
||||
localStorage.setItem(`${this.editModeKey}:editMode`, this.editMode ? '1' : '0');
|
||||
localStorage.setItem(`${this.key}:category`, JSON.stringify(this.activeCategory));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user