高度なラベル機能
Pixi'VN における高度なラベルオプション(onLoadingLabel、onStepStart、onStepEnd、動的ステップリストなど)を説明します。
このセクションでは、高度なナラティブノード機能について説明します。基本的なゲームを作成するために必須ではありませんが、より複雑でインタラクティブな体験を構築するのに役立ちます。
onLoadingLabel は、ナラティブステップ(step)インデックスが 0 の場合に onStepStart 内で実行される関数で、ユーザーがセーブファイルをロードしたときにも実行されます。
セーブファイルがロードされると、narration.labels.opened のすべての onLoadingLabel 関数(現在のナラティブノード(label)およびスタック内のすべてのナラティブノード(labels))が実行されます。
たとえば、ナラティブノード(label)が開始する前に、そのナラティブノード(label)で使用するすべての画像をキャッシュするために役立ちます。
この関数は、ナラティブノード(label)オプションの onLoadingLabel プロパティに渡すことで設定できます。
const startLabel = newLabel(
"start",
[
async () => {
await showImage("image1", "path/to/image1.png");
await showImage("image2", "path/to/image2.png");
},
],
{
onLoadingLabel: async (stepIndex, label) => {
await Assets.load("path/to/image1.png");
await Assets.load("path/to/image2.png");
},
},
);Game.onLoadingLabel を使用して、すべてのナラティブノード(labels)のロードをグローバルにインターセプトすることもできます。
import { Game } from "@drincs/pixi-vn";
Game.onLoadingLabel((_stepId, label) => {
Assets.backgroundLoadBundle(label.id);
}); onStepStart は、ナラティブノード(label)の各ナラティブステップ(step)の前に実行される関数です。ナラティブノード(label)オプションの onStepStart プロパティを使用して設定します。
const startLabel = newLabel(
"start",
[
() => {
narration.dialogue = "Step 1";
},
() => {
narration.dialogue = "Step 2";
},
],
{
onStepStart: (stepIndex, label) => {
console.log(`Step ${stepIndex} started`);
},
},
);Game.onStepStart を使用して、任意のナラティブノード(label)内の任意のナラティブステップ(step)の開始をインターセプトすることもできます。
import { Game } from "@drincs/pixi-vn";
Game.onStepStart((stepIndex, label) => {
console.log(`Step ${stepIndex} started`);
}); onStepEnd は、ナラティブノード(label)の各ナラティブステップ(step)の後に実行される関数です。ナラティブノード(label)オプションの onStepEnd プロパティを使用して設定します。
const startLabel = newLabel(
"start",
[
() => {
narration.dialogue = "Step 1";
},
() => {
narration.dialogue = "Step 2";
},
],
{
onStepEnd: (stepIndex, label) => {
console.log(`Step ${stepIndex} ended`);
},
},
);Game.onStepEnd を使用して、任意のナラティブノード(label)内の任意のナラティブステップ(step)の終了をインターセプトすることもできます。
import { Game } from "@drincs/pixi-vn";
Game.onStepEnd((stepIndex, label) => {
console.log(`Step ${stepIndex} ended`);
}); 新しいナラティブノード(label)を作成する際、そのナラティブノード(label)のナラティブステップ(steps)を返す関数を渡すことができます。これにより、条件に基づいてナラティブステップ(step)リストを動的に変更できます。
import { storage, narration, newLabel } from "@drincs/pixi-vn";
export const startLabel = newLabel("start", () => {
let condition = storage.flags.get("condition");
if (condition) {
return [
() => {
narration.dialogue = "Step 2";
},
() => {
narration.dialogue = "Restart";
},
];
} else {
return [
() => {
narration.dialogue = "Step 1";
},
async (props, { labelId }) => {
storage.flags.set("condition", true);
return await narration.jump(labelId, props);
},
];
}
});