句子
组合对白文本与 `Word` 的 `Sentence` 类,支持复制与运行时元数据
句子是角色的一部分。它用于构建对话
构建句子:
import { Sentence } from 'narraleaf-react';
const character = new Character("character 1");
const sentence = new Sentence([
"Hello, ",
Word.color("world", "#f00") // words can be colored,
], {
character,
});或
const sentence = new Sentence("Hello, world");或
const sentence = new Sentence([
"Hello, ", persis.get("playerName"), "!"
]);
公共方法
constructor
text: SentencePrompt- 参见 SentencePromptconfig?: Partial<SentenceUserConfig>- SentenceUserConfig
copy
复制句子
const sentence = new Sentence("你好,世界");
const sentence2 = sentence.copy();- 返回值:
Sentence
getMetadata
返回配置中的运行时 metadata(见 SentenceConfig);未设置时返回 undefined。元数据不会写入存档
const sentence = new Sentence("你好", {
metadata: { uiHint: "emphasis" },
});
sentence.getMetadata(); // { uiHint: "emphasis" }- 返回值:
SentenceMetadata | undefined