선택 메뉴
Pixi’VN에서 인터랙티브 선택 메뉴를 구현하고 커스터마이즈하는 방법을 설명합니다. 플레이어가 스토리에 영향을 미치는 결정을 내릴 수 있게 합니다.
UI 화면
선택 메뉴 UI 화면의 예시는 인터페이스 예시 섹션에서 찾을 수 있습니다.
ink
이 메서드는 ink 문법과 함께 사용할 수 있습니다. 여기에서 더 알아보세요.
비주얼 노벨에서 선택 메뉴는 플레이어가 스토리에 영향을 미치는 결정을 내릴 수 있게 합니다.
Pixi’VN에서 플레이어에게 선택을 요청할 수 있습니다. 각 선택은 내러티브 노드 (label)를 시작하거나 선택 메뉴를 닫을 수 있습니다.
플레이어에게 선택 요구하기
플레이어에게 선택을 요구하려면 narration.choices를 StoredChoiceInterface 배열로 설정하세요. StoredChoiceInterface 객체를 생성하려면 다음을 사용하세요:
import {
newChoiceOption,
newCloseChoiceOption,
narration,
newLabel,
} from "@drincs/pixi-vn";
export const startLabel = newLabel("start", [
async () => {
narration.dialogue = "Choose a fruit:";
narration.choices = [
newChoiceOption("Orange", orangeLabel, {}), // by default, the label will be called with "call"
newChoiceOption("Banana", bananaLabel, {}, { type: "jump" }),
newChoiceOption(
"Apple",
appleLabel,
{ quantity: 5 },
{ type: "call" },
),
newCloseChoiceOption("Cancel"),
];
},
() => {
narration.dialogue = "Restart";
},
async (props) => await narration.jump("start", props),
]);가져오기
현재 선택 메뉴를 가져오려면 narration.choices.list를 사용하세요. StoredChoiceInterface 배열을 반환합니다.
const menuOptions: StoredChoiceInterface[] = narration.choices.list;요청
선택을 선택하려면 narration.choices.select를 사용하세요.
const item = narration.choices.list![0]; // get the first item
narration.choices
.select(item, {
// Add StepLabelProps here
navigate: navigate, // example
// And the props to pass to the label
...item.props,
})
.then(() => {
// ...
})
.catch((e) => {
// ...
});제거
선택 옵션을 지우려면 narration.choices = undefined로 설정하세요.
narration.choices = undefined;기타 기능
현재 내러티브 단계 (step)에서 이미 한 선택을 가져오려면 narration.queries.alreadyCurrentStepMadeChoices를 사용하세요.
import { INTERFACE_DATA_USE_QUERY_KEY } from "@/constants";
import { narration } from "@drincs/pixi-vn";
import { useQuery } from "@tanstack/react-query";
const CHOICE_MENU_OPTIONS_USE_QUERY_KEY = "choice_menu_options_use_query_key";
export function useQueryChoiceMenuOptions() {
return useQuery({
queryKey: [
INTERFACE_DATA_USE_QUERY_KEY,
CHOICE_MENU_OPTIONS_USE_QUERY_KEY,
],
queryFn: async () =>
narration.choices.list?.map((option) => ({
...option,
text:
typeof option.text === "string"
? option.text
: option.text.map((text) => text).join(" "),
alreadyChosen:
narration.queries.alreadyCurrentStepMadeChoices?.find(
(index) => index === option.choiceIndex,
) !== undefined,
})) || [],
});
}ChoiceInterface 인터페이스에 속성을 추가하여 선택 메뉴 옵션을 커스터마이즈할 수 있습니다. 예를 들어, 아이콘을 표시하기 위해 icon 속성을 추가하세요.
.d.ts 파일에서 ChoiceInterface 인터페이스를 재정의하세요:
declare module "@drincs/pixi-vn" {
interface ChoiceInterface {
icon?: string;
}
}