UNPKG

bedrock-development

Version:

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

47 lines (46 loc) 2.59 kB
var _a; import { Option } from "commander"; import { getFiles, setFiles } from "../../file_manager.js"; import { ServerEntity } from "../../types/index.js"; import { NameData, implementConfig } from "../../utils.js"; import { CommandMap } from "../command_map.js"; CommandMap.addCommand("root.entity.property", { parent: (_a = CommandMap.getCommandEntry("root.entity")) === null || _a === void 0 ? void 0 : _a.command, commandOptions(command) { command .name("property") .description("adds a property to entities") .argument("<names...>", 'property names as "namespace:property"') .option("-t, --type <family type...>", "filter entities by family type") .addOption(new Option("-f, --file [file]", "the entity files that should be modified").makeOptionMandatory().preset("**/*.json")) .addOption(new Option("-p, --property <property type>", "the type of property").choices(["bool", "enum", "float", "int"]).default("bool")) .option("-v, --values <values...>", "the values, either a list of enum values or a min-max") .option("-d, --default <default>", "the default value") .option("-c, --client", "should use client_sync") .option("-e, --event", "automatically generate events for the values"); }, commandAction: triggerEntityAddProperty, }); function triggerEntityAddProperty(names, options) { implementConfig(); // const default_value: any = options.property === "float" || options.property === "int" ? Number(options.default) : options.property === "bool" ? Boolean(options.default) : options.default; const values = options.property === "enum" ? options.values : undefined; const range = options.property === "float" || options.property === "int" ? options.values.map(value => Number(value)) : undefined; const files = []; const entities = getFiles(ServerEntity.DirectoryPath + options.file).map(file => ServerEntity.fromFile(ServerEntity, file)).filter(entity => entity.hasFamilyTypes(...options.type)); entities.forEach(entity => { names.forEach(name => { entity.setProperties({ [new NameData(name).fullname]: { type: options.property, client_sync: options.client, default: options.default, values, range, } }, "overwrite", { createEvents: options.event }); }); files.push(entity.toFile("overwrite")); }); setFiles(files); }