fix: preserve rpg custom world detail profiles
This commit is contained in:
@@ -21,6 +21,11 @@ import {
|
||||
unpublishRpgEntryWorldProfile,
|
||||
} from '../../services/rpg-entry/rpgEntryLibraryClient';
|
||||
import type { CustomWorldProfile } from '../../types';
|
||||
import {
|
||||
countCustomWorldProfileAssetSlots,
|
||||
countCustomWorldProfileDetailSlots,
|
||||
countCustomWorldProfileStructuredSlots,
|
||||
} from './rpgProfileCompleteness';
|
||||
import { resolveRpgEntryErrorMessage } from './rpgEntryShared';
|
||||
import type {
|
||||
CustomWorldAutoSaveState,
|
||||
@@ -86,6 +91,46 @@ function isMissingRpgEntryAgentSessionError(error: unknown) {
|
||||
);
|
||||
}
|
||||
|
||||
function shouldKeepSelectedDetailProfile(
|
||||
selectedEntry: CustomWorldLibraryEntry<CustomWorldProfile>,
|
||||
nextOwnedEntry: CustomWorldLibraryEntry<CustomWorldProfile>,
|
||||
) {
|
||||
if (
|
||||
selectedEntry.ownerUserId !== nextOwnedEntry.ownerUserId ||
|
||||
selectedEntry.profileId !== nextOwnedEntry.profileId
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const selectedDetailCount = countCustomWorldProfileDetailSlots(
|
||||
selectedEntry.profile,
|
||||
);
|
||||
const nextDetailCount = countCustomWorldProfileDetailSlots(
|
||||
nextOwnedEntry.profile,
|
||||
);
|
||||
const selectedAssetSlotCount = countCustomWorldProfileAssetSlots(
|
||||
selectedEntry.profile,
|
||||
);
|
||||
const nextAssetSlotCount = countCustomWorldProfileAssetSlots(
|
||||
nextOwnedEntry.profile,
|
||||
);
|
||||
const selectedStructuredSlotCount =
|
||||
countCustomWorldProfileStructuredSlots(selectedEntry.profile);
|
||||
const nextStructuredSlotCount = countCustomWorldProfileStructuredSlots(
|
||||
nextOwnedEntry.profile,
|
||||
);
|
||||
const expectedRuntimeCount =
|
||||
nextOwnedEntry.playableNpcCount + nextOwnedEntry.landmarkCount;
|
||||
|
||||
// 作品架列表只保证卡片摘要,不能在详情接口已经拿到完整运行态字段后覆盖详情。
|
||||
return (
|
||||
(selectedDetailCount > nextDetailCount &&
|
||||
expectedRuntimeCount > nextDetailCount) ||
|
||||
selectedAssetSlotCount > nextAssetSlotCount ||
|
||||
selectedStructuredSlotCount > nextStructuredSlotCount
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 负责平台详情、创作作品入口和结果页打开路径。
|
||||
* 平台壳层只消费“打开哪个面板”的结果,不再自己拼接恢复流程细节。
|
||||
@@ -136,6 +181,10 @@ export function useRpgEntryLibraryDetail(
|
||||
entry.profileId === selectedDetailEntry.profileId,
|
||||
);
|
||||
if (nextOwnedEntry && nextOwnedEntry !== selectedDetailEntry) {
|
||||
if (shouldKeepSelectedDetailProfile(selectedDetailEntry, nextOwnedEntry)) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSelectedDetailEntry(nextOwnedEntry);
|
||||
}
|
||||
}, [savedCustomWorldEntries, selectedDetailEntry, setSelectedDetailEntry]);
|
||||
|
||||
Reference in New Issue
Block a user