11
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
2026-04-16 21:47:20 +08:00
parent 2456c10c63
commit 09d4c0c31b
79 changed files with 11873 additions and 2341 deletions

View File

@@ -28,6 +28,7 @@ import {
CustomWorldPlayableNpc,
CustomWorldProfile,
CustomWorldRoleInitialItem,
CustomWorldRoleRelation,
CustomWorldRoleSkill,
EquipmentSlotId,
ItemAttributeResonance,
@@ -39,8 +40,8 @@ import {
SceneNarrativeResidue,
ThemePack,
ThreadContract,
WorldType,
WorldStoryGraph,
WorldType,
} from '../types';
import {
AFFINITY_BACKSTORY_CHAPTER_THRESHOLDS,
@@ -330,6 +331,35 @@ function buildFallbackRoleSkills(source: CustomWorldRoleFallbackSource) {
] satisfies CustomWorldRoleSkill[];
}
function normalizeRoleRelations(value: unknown, fallbackHooks: string[]) {
const normalized = Array.isArray(value)
? value
.filter(isRecord)
.map(
(entry, index) =>
({
id: toText(entry.id, `saved-role-relation-${index + 1}`),
targetRoleId: toText(entry.targetRoleId),
summary: toText(entry.summary),
}) satisfies CustomWorldRoleRelation,
)
.filter((entry) => entry.summary)
.slice(0, 8)
: [];
if (normalized.length > 0) {
return normalized;
}
return fallbackHooks
.map((summary, index) => ({
id: `saved-role-relation-${index + 1}`,
targetRoleId: '',
summary,
}))
.slice(0, 8);
}
function normalizeRoleSkills(
value: unknown,
fallbackSource: CustomWorldRoleFallbackSource,
@@ -344,6 +374,10 @@ function normalizeRoleSkills(
name: toText(entry.name),
summary: toText(entry.summary, toText(entry.description)),
style: toText(entry.style, toText(entry.category, '常用')),
actionPromptText: toText(entry.actionPromptText) || undefined,
actionPreviewConfig:
normalizeCharacterAnimationConfig(entry.actionPreviewConfig) ??
undefined,
}) satisfies CustomWorldRoleSkill,
)
.filter((entry) => entry.name)
@@ -424,6 +458,7 @@ function normalizeRoleInitialItems(
: 'rare',
description: toText(entry.description),
tags: toStringArray(entry.tags),
iconSrc: toText(entry.iconSrc) || undefined,
}) satisfies CustomWorldRoleInitialItem,
)
.filter((entry) => entry.name)
@@ -587,6 +622,11 @@ function normalizePlayableNpc(
const title = toText(value.title, toText(value.role, '未命名角色'));
const role = toText(value.role, title);
const relationshipHooks = toStringArray(value.relationshipHooks);
const relations = normalizeRoleRelations(value.relations, relationshipHooks);
const relationSummaries = relations
.map((entry) => entry.summary)
.filter(Boolean)
.slice(0, 8);
const tags = toStringArray(value.tags);
const fallbackSource = {
name,
@@ -616,7 +656,11 @@ function normalizePlayableNpc(
value.initialAffinity,
DEFAULT_PLAYABLE_INITIAL_AFFINITY,
),
relationshipHooks: fallbackSource.relationshipHooks,
relationshipHooks:
relationSummaries.length > 0
? relationSummaries
: fallbackSource.relationshipHooks,
relations,
tags: fallbackSource.tags,
backstoryReveal: normalizeBackstoryReveal(
value.backstoryReveal,
@@ -650,6 +694,11 @@ function normalizeStoryNpc(
const title = toText(value.title, toText(value.role, '未命名场景角色'));
const role = toText(value.role, title);
const relationshipHooks = toStringArray(value.relationshipHooks);
const relations = normalizeRoleRelations(value.relations, relationshipHooks);
const relationSummaries = relations
.map((entry) => entry.summary)
.filter(Boolean)
.slice(0, 8);
const tags = toStringArray(value.tags);
const fallbackSource = {
name,
@@ -679,7 +728,11 @@ function normalizeStoryNpc(
value.initialAffinity,
DEFAULT_STORY_NPC_INITIAL_AFFINITY,
),
relationshipHooks: fallbackSource.relationshipHooks,
relationshipHooks:
relationSummaries.length > 0
? relationSummaries
: fallbackSource.relationshipHooks,
relations,
tags: fallbackSource.tags,
backstoryReveal: normalizeBackstoryReveal(
value.backstoryReveal,