66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
import type { MedievalNpcVisualOverride } from '../data/medievalNpcVisuals';
|
|
import {
|
|
buildEditorJsonApiPath,
|
|
EDITOR_JSON_RESOURCE_IDS,
|
|
} from '../editor/shared/editorApiClient';
|
|
import { saveJsonObject } from '../editor/shared/jsonClient';
|
|
import {
|
|
buildNpcVisualSavePayload,
|
|
type EditableNpcVisualState,
|
|
} from './npcVisualEditorModel';
|
|
import { cloneNpcLayoutConfig, type NpcLayoutConfig } from './npcVisualShared';
|
|
|
|
export const NPC_VISUAL_OVERRIDES_API_PATH = buildEditorJsonApiPath(
|
|
EDITOR_JSON_RESOURCE_IDS.npcVisualOverrides,
|
|
);
|
|
export const NPC_LAYOUT_CONFIG_API_PATH = buildEditorJsonApiPath(
|
|
EDITOR_JSON_RESOURCE_IDS.npcLayoutConfig,
|
|
);
|
|
|
|
type SaveEditorJsonFn = typeof saveJsonObject;
|
|
|
|
export async function persistNpcVisualOverrides(params: {
|
|
overrideMap: Record<string, MedievalNpcVisualOverride>;
|
|
npcId: string;
|
|
editorState: EditableNpcVisualState;
|
|
saveJson?: SaveEditorJsonFn;
|
|
}) {
|
|
const {
|
|
overrideMap,
|
|
npcId,
|
|
editorState,
|
|
saveJson = saveJsonObject,
|
|
} = params;
|
|
const nextOverrideMap = buildNpcVisualSavePayload(overrideMap, npcId, editorState);
|
|
|
|
await saveJson(
|
|
NPC_VISUAL_OVERRIDES_API_PATH,
|
|
nextOverrideMap,
|
|
'保存角色形象覆盖配置失败',
|
|
);
|
|
|
|
return {
|
|
nextOverrideMap,
|
|
saveMessage: '已将角色形象覆盖配置保存到 src/data/npcVisualOverrides.json。',
|
|
};
|
|
}
|
|
|
|
export async function persistNpcLayoutConfig(params: {
|
|
layoutDraft: NpcLayoutConfig;
|
|
saveJson?: SaveEditorJsonFn;
|
|
}) {
|
|
const { layoutDraft, saveJson = saveJsonObject } = params;
|
|
const nextLayout = cloneNpcLayoutConfig(layoutDraft);
|
|
|
|
await saveJson(
|
|
NPC_LAYOUT_CONFIG_API_PATH,
|
|
nextLayout,
|
|
'保存角色布局配置失败',
|
|
);
|
|
|
|
return {
|
|
nextLayout,
|
|
saveMessage: '已保存共享角色布局配置。',
|
|
};
|
|
}
|