vanilladocs
vanillapunch.com
API / misc/dialogue

misc/dialogue

대사 진행기.

Dialogue runner.

DialogueRunnerextends Object

짝Counterpart: vanilla-engine DialogueRunner

대사 진행기.

  • {speaker, text} 대사와 선택지 / 라벨 / 점프로 이루어진 대본을 순서대로 해석한다. 비주얼노벨 / RPG 대화 / 튜토리얼이 제각각 만들던 상태기계를 표준화했다.
  • 대본 항목 형식: { speaker: "이름", text: "대사" } { label: "이름표" } { jump: "이름표" } { choice: [{ text: "보기", jump: "이름표" }, ...] } { end: true }
  • 사용: runner.setScript(entries); runner.start(); runner.getCurrent() → { kind: "line" | "choice" | "finished", ... } 대사에서 runner.advance(), 선택지에서 runner.choose(index).

Dialogue runner.

  • Interprets in order a script made of {speaker, text} lines and choices / labels / jumps. Standardizes the state machine that visual novels / RPG dialogues / tutorials each built.
  • Script entry format: { speaker: "name", text: "line" } { label: "tag" } { jump: "tag" } { choice: [{ text: "option", jump: "tag" }, ...] } { end: true }
  • Usage: runner.setScript(entries); runner.start(); runner.getCurrent() → { kind: "line" | "choice" | "finished", ... } runner.advance() on a line, runner.choose(index) on a choice.
예제Example대사를 넘기고 선택지로 갈라지기Advance lines and branch on a choice
import { DialogueRunner } from "./build/vanilla.js";

const dialogueRunner = new DialogueRunner();
dialogueRunner.setScript([
	{ speaker: "Guide", text: "Welcome, traveler." },
	{ choice: [{ text: "Tell me more", jump: "more" }, { text: "Bye", jump: "bye" }] },
	{ label: "more" },
	{ speaker: "Guide", text: "This village is old." },
	{ end: true },
	{ label: "bye" },
	{ speaker: "Guide", text: "Safe travels." },
]);
dialogueRunner.start();
let current = dialogueRunner.getCurrent();
console.log(current.kind, current.speaker, current.text);

dialogueRunner.advance();
current = dialogueRunner.getCurrent();
console.log(current.kind, current.options.length);

dialogueRunner.choose(1);
current = dialogueRunner.getCurrent();
console.log(current.kind, current.text);

dialogueRunner.advance();
console.log(dialogueRunner.isFinished());
생성자constructorconstructor()#0.3.0 부터since 0.3.0소스source

생성.

Constructor.

짝Counterpart: vanilla-engine DialogueRunner.new

메서드methodsetScript(entryList)#0.3.0 부터since 0.3.0소스source

대본 설정.

Sets the script.

entryListobject[]
대본 항목 목록. (null 이면 빈 대본)List of script entries. (an empty script if null)

짝Counterpart: vanilla-engine DialogueRunner.set_script

메서드methodstart(labelName = null)#0.3.0 부터since 0.3.0소스source

시작. (라벨을 넘기면 그 지점부터)

Start. (from that point if a label is passed)

labelNamestring | null
시작할 이름표. (null 이거나 없는 이름표면 처음부터)Label to start from. (from the beginning if null or an unknown label)

짝Counterpart: vanilla-engine DialogueRunner.start

메서드methodgetCurrent()#0.3.0 부터since 0.3.0소스source

현재 항목 반환.

  • { kind: "line", speaker, text } | { kind: "choice", options: [{text}] } | { kind: "finished" }

Returns the current entry.

  • { kind: "line", speaker, text } | { kind: "choice", options: [{text}] } | { kind: "finished" }

반환Returnsobject 지금 보여 줄 항목.Entry to show now.

짝Counterpart: vanilla-engine DialogueRunner.get_current

메서드methodadvance()#0.3.0 부터since 0.3.0소스source

다음으로. (대사 항목에서 부른다, 선택지 위에서는 무시)

Advances. (called on a line entry, ignored on a choice)

짝Counterpart: vanilla-engine DialogueRunner.advance

메서드methodchoose(optionIndex)#0.3.0 부터since 0.3.0소스source

선택. (선택지 항목에서 부른다)

Chooses. (called on a choice entry)

optionIndexnumber
고를 보기 번호. (0 부터, 없는 번호면 무시)Index of the option to choose. (from 0, ignored if out of range)

짝Counterpart: vanilla-engine DialogueRunner.choose

메서드methodisFinished()#0.3.0 부터since 0.3.0소스source

종료 여부.

Whether ended.

반환Returnsboolean 대본이 끝났으면 참. (start 전에도 참)True when the script has ended. (also true before start)

짝Counterpart: vanilla-engine DialogueRunner.is_finished

DialogueScriptParserextends Object

짝Counterpart: vanilla-engine DialogueScriptParser

대본 파서.

  • 한 줄 명령어 텍스트를 DialogueRunner 대본으로 바꾼다. 형식: /label 이름표 /jump 이름표 /speaker 화자이름 (이후 /say 의 기본 화자) /say 대사 내용 /option 보기 텍스트 -> 이름표 (연달아 쓴 /option 은 하나의 선택지로 묶인다) /end "/" 로 시작하지 않는 줄은 직전 화자의 /say 로 본다. "//" 는 주석.

Script parser.

  • Converts one-line command text into a DialogueRunner script. Format: /label tag /jump tag /speaker speakerName (default speaker for subsequent /say) /say line text /option option text -> tag (consecutive /option lines are grouped into one choice) /end Lines not starting with "/" are treated as /say by the previous speaker. "//" is a comment.
예제Example명령어 대본을 읽어 진행기에 넣기Parse a command script and feed it to the runner
import { DialogueScriptParser, DialogueRunner } from "./build/vanilla.js";

const scriptText = [
	"/speaker Guide",
	"/say Welcome, traveler.",
	"Need a hand?",
	"/option Yes -> help",
	"/option No -> bye",
	"/label help",
	"/say Follow the river.",
	"/end",
	"/label bye",
	"/say Safe travels.",
].join("\n");
const entryList = DialogueScriptParser.parse(scriptText);
console.log(entryList.length);

const dialogueRunner = new DialogueRunner();
dialogueRunner.setScript(entryList);
dialogueRunner.start("help");
const current = dialogueRunner.getCurrent();
console.log(current.speaker, current.text);
정적staticstatic parse(scriptText)#0.3.0 부터since 0.3.0소스source

파싱. (정적)

Parse. (static)

scriptTextstring
명령어 대본 글. (줄마다 명령 하나)Command script text. (one command per line)

반환Returnsobject[] DialogueRunner 대본.DialogueRunner script.

짝Counterpart: vanilla-engine DialogueScriptParser.parse