82 lines
3.1 KiB
TypeScript
82 lines
3.1 KiB
TypeScript
import { reactive } from 'vue'
|
|
import type { SubjectFormAsset } from '../subject-images/types'
|
|
import type {
|
|
CharacterCastingItem,
|
|
CharacterCastingStatus,
|
|
IdentityImage,
|
|
IdentityReceipt,
|
|
IdentitySubject
|
|
} from './types'
|
|
|
|
/** 视角名称保持与后端四种固定值对应。 */
|
|
export const identityViewLabels = {
|
|
primary: '身份母版',
|
|
front: '正面',
|
|
'three-quarter': '三分之四侧面',
|
|
'full-body': '全身'
|
|
} as const
|
|
|
|
/** 将同一主体的多个形态归并成一条,避免为每个形态重复创建 Identity。 */
|
|
export function groupIdentitySubjects(forms: SubjectFormAsset[]): IdentitySubject[] {
|
|
const subjects = new Map<string, IdentitySubject>()
|
|
for (const form of forms) {
|
|
if (form.subjectId !== form.subject.id) throw new Error('形态与主体 ID 不匹配,请刷新后重试。')
|
|
const subject = subjects.get(form.subjectId) ?? { ...form.subject, forms: [] }
|
|
subject.forms.push(form)
|
|
subjects.set(form.subjectId, subject)
|
|
}
|
|
return [...subjects.values()]
|
|
}
|
|
|
|
/** 将选角就绪接口中的无形态 Character 补入主体目录,确保选角早于 Form 生图也可操作。 */
|
|
export function mergeCastingSubjects(
|
|
subjects: IdentitySubject[],
|
|
casting: CharacterCastingItem[],
|
|
projectId: string
|
|
): IdentitySubject[] {
|
|
const rows = new Map(subjects.map(subject => [subject.id, subject]))
|
|
for (const item of casting) {
|
|
if (!rows.has(item.subjectId)) {
|
|
rows.set(item.subjectId, {
|
|
id: item.subjectId,
|
|
projectId,
|
|
ref: item.subjectRef,
|
|
name: item.subjectName,
|
|
module: 'character',
|
|
forms: []
|
|
})
|
|
}
|
|
}
|
|
return [...rows.values()].toSorted((a, b) => a.ref.localeCompare(b.ref))
|
|
}
|
|
|
|
/** 角色选角状态中文标签。 */
|
|
export function castingStatusLabel(status: CharacterCastingStatus): string {
|
|
const labels: Record<CharacterCastingStatus, string> = {
|
|
missing_identity: '缺少身份文本',
|
|
missing_anchor: '缺少候选图',
|
|
candidate_pending: '等待确认演员',
|
|
unlocked: '演员尚未锁定',
|
|
ready: '选角已完成'
|
|
}
|
|
return labels[status]
|
|
}
|
|
|
|
/** 只有成功且有图片的 primary 候选可成为母版;停用候选也允许重新启用。 */
|
|
export function canBeAnchor(image: IdentityImage): boolean {
|
|
return image.viewType === 'primary' && image.status === 'completed' && !!image.imageUrl
|
|
}
|
|
|
|
/** 使用后端明确的 isAnchor 标记,并校验图片已完成且为 primary 视角。 */
|
|
export function currentAnchor(images: IdentityImage[]): IdentityImage | undefined {
|
|
return images.find(image => image.isAnchor && canBeAnchor(image))
|
|
}
|
|
|
|
/** 批量回执按项目保存在当前会话,切页不丢失,刷新浏览器后不伪造恢复。 */
|
|
const sessions = reactive<Record<string, { receipt: IdentityReceipt | null }>>({})
|
|
|
|
/** 取得指定项目的身份文本或选角候选批量回执。 */
|
|
export function getIdentitySession(projectId: string) {
|
|
return (sessions[projectId] ??= { receipt: null })
|
|
}
|