UNPKG

bedrock-development

Version:

APIs for creating and editing files related to Minecraft Bedrock development.

57 lines (56 loc) 2.2 kB
import { Directories } from "../../file_manager.js"; import { currentFormatVersion } from "../../utils.js"; import { MinecraftDataType } from "../minecraft.js"; export class ServerDialogue extends MinecraftDataType { static get DirectoryPath() { return Directories.BEHAVIOR_PATH + 'dialogue/'; } constructor(filepath, template) { super(filepath, template); this.format_version = template.format_version; this["minecraft:npc_dialogue"] = template["minecraft:npc_dialogue"]; } static createFromTemplate(nameData) { return new ServerDialogue(this.createFilePath(nameData), { format_version: currentFormatVersion, "minecraft:npc_dialogue": { scenes: [] } }); } addScene(scene) { this["minecraft:npc_dialogue"].scenes.push(scene); } addButtonToAllScenes(button) { this["minecraft:npc_dialogue"].scenes.forEach(scene => { var _a; scene.buttons = (_a = scene.buttons) !== null && _a !== void 0 ? _a : []; scene.buttons.push(button); }); } addToAllCloseCommands(...commands) { this["minecraft:npc_dialogue"].scenes.forEach(scene => { var _a; scene.on_close_commands = (_a = scene.on_close_commands) !== null && _a !== void 0 ? _a : []; scene.on_close_commands.push(...commands); }); } addToAllOpenCommands(...commands) { this["minecraft:npc_dialogue"].scenes.forEach(scene => { var _a; scene.on_open_commands = (_a = scene.on_open_commands) !== null && _a !== void 0 ? _a : []; scene.on_open_commands.push(...commands); }); } addToAllButtonCommands(...commands) { this["minecraft:npc_dialogue"].scenes.forEach(scene => { var _a; scene.buttons = (_a = scene.buttons) !== null && _a !== void 0 ? _a : []; scene.buttons.forEach(button => { var _a; button.commands = (_a = button.commands) !== null && _a !== void 0 ? _a : []; button.commands.push(...commands); }); }); } }