bedrock-development
Version:
APIs for creating and editing files related to Minecraft Bedrock development.
37 lines (36 loc) • 1.62 kB
JavaScript
var _a;
import { Option } from "commander";
import { setFiles } from "../../file_manager.js";
import { ServerAnimation } from "../../types/index.js";
import { NameData, implementConfig } from "../../utils.js";
import { CommandMap } from "../command_map.js";
CommandMap.addCommand("root.new.anim", {
parent: (_a = CommandMap.getCommandEntry("root.new")) === null || _a === void 0 ? void 0 : _a.command,
commandOptions(command) {
command
.name("anim")
.description('creates new bedrock behavior animations')
.argument('<names...>', 'animation names names as "entity.anim"')
.option('-l, --loop', 'should the animation loop')
.addOption(new Option('-c, --commands <commands...>', 'the commands to play').default(['/say anim_name']))
.addOption(new Option('-t, --time <time>', 'the animation length').default(1.0).argParser(parseFloat));
},
commandAction: triggerCreateNewAnimation,
});
function triggerCreateNewAnimation(names, options) {
implementConfig();
names.forEach((name) => {
const nameData = new NameData(name);
const files = [];
const animation = ServerAnimation.createFromTemplate(nameData);
animation.animations[`animation.${nameData.namespace}.${nameData.shortname}`] = {
animation_length: options.time,
loop: options.loop,
timeline: {
["0.0"]: options.commands.map(string => string.replace('anim_name', nameData.shortname)),
}
};
files.push(animation.toFile());
setFiles(files);
});
}