고급 레이블 기능
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);
},
];
}
});