1
This commit is contained in:
@@ -23,6 +23,10 @@ export type PendingGeneratedEntity = {
|
||||
|
||||
export type RecentGeneratedIds = Record<EntityGenerationKind, string[]>;
|
||||
|
||||
export type AgentEntityGenerationResult = {
|
||||
profile?: CustomWorldProfile | null;
|
||||
};
|
||||
|
||||
function getCreateTargetByTab(
|
||||
activeTab: ResultTab,
|
||||
): RpgCreationEditorTarget | null {
|
||||
@@ -99,6 +103,15 @@ function prependLandmark(
|
||||
} satisfies CustomWorldProfile;
|
||||
}
|
||||
|
||||
function getEntityCountByKind(
|
||||
profile: CustomWorldProfile,
|
||||
kind: EntityGenerationKind,
|
||||
) {
|
||||
if (kind === 'playable') return profile.playableNpcs.length;
|
||||
if (kind === 'story') return profile.storyNpcs.length;
|
||||
return profile.landmarks.length;
|
||||
}
|
||||
|
||||
function removeStoryNpcsFromProfile(
|
||||
profile: CustomWorldProfile,
|
||||
ids: string[],
|
||||
@@ -144,6 +157,9 @@ function removeLandmarksFromProfile(
|
||||
|
||||
export function useRpgCreationResultActions(params: {
|
||||
activeTab: ResultTab;
|
||||
agentEntityGenerator?:
|
||||
| ((kind: EntityGenerationKind) => Promise<AgentEntityGenerationResult | void>)
|
||||
| undefined;
|
||||
isGenerating: boolean;
|
||||
onProfileChange: (profile: CustomWorldProfile) => void;
|
||||
profile: CustomWorldProfile;
|
||||
@@ -152,6 +168,7 @@ export function useRpgCreationResultActions(params: {
|
||||
}) {
|
||||
const {
|
||||
activeTab,
|
||||
agentEntityGenerator,
|
||||
isGenerating,
|
||||
onProfileChange,
|
||||
profile,
|
||||
@@ -242,7 +259,16 @@ export function useRpgCreationResultActions(params: {
|
||||
startPendingProgress(kind);
|
||||
|
||||
try {
|
||||
if (kind === 'playable') {
|
||||
if (agentEntityGenerator) {
|
||||
const previousCount = getEntityCountByKind(profile, kind);
|
||||
const generationResult = await agentEntityGenerator(kind);
|
||||
const currentCount = generationResult?.profile
|
||||
? getEntityCountByKind(generationResult.profile, kind)
|
||||
: previousCount;
|
||||
if (currentCount <= previousCount) {
|
||||
throw new Error('生成请求已完成,但结果页未收到新增内容,请返回创作页重新打开草稿后重试。');
|
||||
}
|
||||
} else if (kind === 'playable') {
|
||||
const nextNpc = await rpgCreationAssetClient.generatePlayableNpc({
|
||||
profile,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user