This commit is contained in:
2026-04-24 17:59:48 +08:00
parent 929febb4fe
commit 6cb3efae61
55 changed files with 2373 additions and 435 deletions

View File

@@ -64,6 +64,7 @@ function buildDefaultAnimationPromptTextByKey(defaultText: string) {
function pickCachedAnimationPromptTextByKey(
cache: CharacterAssetWorkflowCache,
fallbackText: string,
preferFreshRoleText: boolean,
) {
const fromCache = cache.animationPromptTextByKey ?? {};
@@ -73,8 +74,9 @@ function pickCachedAnimationPromptTextByKey(
const legacyText = cache.animationPromptText?.trim();
return {
...result,
[action.animation]:
cachedText && !isLegacyGeneratedActionDescription(cachedText)
[action.animation]: preferFreshRoleText
? fallbackText
: cachedText && !isLegacyGeneratedActionDescription(cachedText)
? cachedText
: legacyText && !isLegacyGeneratedActionDescription(legacyText)
? legacyText
@@ -487,6 +489,7 @@ function buildAnimationPreviewCharacter(params: {
export interface RpgCreationRoleAssetStudioModalProps {
role: EditableCustomWorldRole;
roleKind: 'playable' | 'story';
cacheScopeId?: string;
onApply?: (nextRole: EditableCustomWorldRole) => void;
onPublishSuccess?: (
payload: {
@@ -509,6 +512,7 @@ export interface RpgCreationRoleAssetStudioModalProps {
export function RpgCreationRoleAssetStudioModal({
role,
roleKind,
cacheScopeId,
onApply,
onPublishSuccess,
onClose,
@@ -746,13 +750,16 @@ export function RpgCreationRoleAssetStudioModal({
setSaveStatus(null);
setIsHydratingCache(true);
void fetchCharacterWorkflowCache(baseRole.id)
void fetchCharacterWorkflowCache(baseRole.id, cacheScopeId)
.then((result) => {
if (cancelled || !result.cache) {
return;
}
const cache = result.cache;
if (cacheScopeId && cache.cacheScopeId !== cacheScopeId) {
return;
}
const nextRole = mergeRole(baseRole, {
imageSrc: cache.imageSrc ?? baseRole.imageSrc,
generatedVisualAssetId:
@@ -765,7 +772,8 @@ export function RpgCreationRoleAssetStudioModal({
});
setWorkingRole(nextRole);
setVisualPromptText(
cache.visualPromptText &&
!baseRole.visualDescription?.trim() &&
cache.visualPromptText &&
!isLegacyGeneratedVisualDescription(cache.visualPromptText)
? cache.visualPromptText
: initialPromptBundle.visualPromptText,
@@ -774,6 +782,7 @@ export function RpgCreationRoleAssetStudioModal({
pickCachedAnimationPromptTextByKey(
cache,
initialPromptBundle.animationPromptText,
Boolean(baseRole.actionDescription?.trim()),
),
);
setVisualDrafts(cache.visualDrafts ?? []);
@@ -798,7 +807,7 @@ export function RpgCreationRoleAssetStudioModal({
return () => {
cancelled = true;
};
}, [baseRole, initialPromptBundle, roleSnapshotKey]);
}, [baseRole, cacheScopeId, initialPromptBundle, roleSnapshotKey]);
useEffect(() => {
if (isHydratingCache) {
@@ -808,8 +817,10 @@ export function RpgCreationRoleAssetStudioModal({
const timer = window.setTimeout(() => {
const payload: CharacterAssetWorkflowCache = {
characterId: workingRole.id,
cacheScopeId,
visualPromptText,
animationPromptText,
animationPromptTextByKey,
visualDrafts,
selectedVisualDraftId,
selectedAnimation,
@@ -829,9 +840,11 @@ export function RpgCreationRoleAssetStudioModal({
};
}, [
animationPromptText,
animationPromptTextByKey,
isHydratingCache,
selectedAnimation,
selectedVisualDraftId,
cacheScopeId,
visualDrafts,
visualPromptText,
workingRole.animationMap,
@@ -1137,7 +1150,12 @@ export function RpgCreationRoleAssetStudioModal({
workingRoleGeneratedVisualAssetId={workingRole.generatedVisualAssetId}
workingRoleImageSrc={workingRole.imageSrc}
workingRoleName={workingRole.name}
onAnimationPromptChange={setAnimationPromptText}
onAnimationPromptChange={(value) => {
setAnimationPromptTextByKey((current) => ({
...current,
[selectedAnimation]: value,
}));
}}
onGenerateAnimation={() => {
void handleGenerateAnimation();
}}