兩個角色 skill 空殼(sao-asuna、sao-suguha)、userConfig(預設角色、強度、稱呼)、 設定解析與測試,並登錄到 marketplace。 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { CHARACTERS, isCharacterCode, type CharacterCode } from './characters'
|
|
|
|
export type Intensity = 0 | 1 | 2 | 3
|
|
|
|
export type Config = {
|
|
character: CharacterCode | null
|
|
intensity: Intensity
|
|
address: string | null
|
|
}
|
|
|
|
export const DEFAULT_INTENSITY: Intensity = 2
|
|
|
|
function toIntensity(value: unknown): Intensity {
|
|
const n = typeof value === 'number' ? value : Number(value)
|
|
return n === 0 || n === 1 || n === 2 || n === 3 ? n : DEFAULT_INTENSITY
|
|
}
|
|
|
|
// 缺失或無效的值一律退回預設,不讓設定錯誤擋住載入。
|
|
export function resolveConfig(options: Readonly<Record<string, unknown>>): Config {
|
|
const address = typeof options.address === 'string' ? options.address.trim() : ''
|
|
return {
|
|
character: isCharacterCode(options.defaultCharacter) ? options.defaultCharacter : null,
|
|
intensity: toIntensity(options.intensity),
|
|
address: address === '' ? null : address,
|
|
}
|
|
}
|
|
|
|
// 使用者的覆寫優先,否則用角色在原作中對使用者的稱呼。
|
|
export function addressFor(config: Config, character: CharacterCode): string {
|
|
return config.address ?? CHARACTERS[character].address
|
|
}
|