From e47d8e789c22089027f72d41ea4011ea3ae1be32 Mon Sep 17 00:00:00 2001 From: DaanV2 Date: Sat, 27 Apr 2024 12:29:44 +0200 Subject: [PATCH] Adding hud command --- package-lock.json | 14 ++-- package.json | 2 +- src/Lib/Data/CommandData.ts | 2 + src/Lib/Data/Vanilla/hud.ts | 16 ++++ src/Lib/Types/Command/Functions.ts | 2 + src/Lib/Types/ParameterType.ts | 4 + test/Export/export.test.ts | 126 +++++++++++++++++++++++++++++ 7 files changed, 158 insertions(+), 8 deletions(-) create mode 100644 src/Lib/Data/Vanilla/hud.ts create mode 100644 test/Export/export.test.ts diff --git a/package-lock.json b/package-lock.json index 2651c60..48bae97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.20.71-1", "license": "BSD-3-Clause", "dependencies": { - "bc-minecraft-bedrock-types": "^1.20.71-1" + "bc-minecraft-bedrock-types": "^1.20.73" }, "devDependencies": { "@types/chai": "^4.3.8", @@ -305,9 +305,9 @@ "dev": true }, "node_modules/bc-minecraft-bedrock-types": { - "version": "1.20.71-1", - "resolved": "https://registry.npmjs.org/bc-minecraft-bedrock-types/-/bc-minecraft-bedrock-types-1.20.71-1.tgz", - "integrity": "sha512-APMS/TJ1Wn1T6QO2WL72fYOW3OFyZ6ZINo8X1DLCJNWFUP7X1Q39S1ScSRajZ2ysEpBTHCbxt+/A7WahBE48iw==" + "version": "1.20.73", + "resolved": "https://registry.npmjs.org/bc-minecraft-bedrock-types/-/bc-minecraft-bedrock-types-1.20.73.tgz", + "integrity": "sha512-JOEY1hIU+E4OSUX70ntOGu5WTOzTL3auMVomag18WXNpaqK43V1QVmP94664HQZvmDMEmdYeCV1PoCN7Hs1ysQ==" }, "node_modules/binary-extensions": { "version": "2.2.0", @@ -1797,9 +1797,9 @@ "dev": true }, "bc-minecraft-bedrock-types": { - "version": "1.20.71-1", - "resolved": "https://registry.npmjs.org/bc-minecraft-bedrock-types/-/bc-minecraft-bedrock-types-1.20.71-1.tgz", - "integrity": "sha512-APMS/TJ1Wn1T6QO2WL72fYOW3OFyZ6ZINo8X1DLCJNWFUP7X1Q39S1ScSRajZ2ysEpBTHCbxt+/A7WahBE48iw==" + "version": "1.20.73", + "resolved": "https://registry.npmjs.org/bc-minecraft-bedrock-types/-/bc-minecraft-bedrock-types-1.20.73.tgz", + "integrity": "sha512-JOEY1hIU+E4OSUX70ntOGu5WTOzTL3auMVomag18WXNpaqK43V1QVmP94664HQZvmDMEmdYeCV1PoCN7Hs1ysQ==" }, "binary-extensions": { "version": "2.2.0", diff --git a/package.json b/package.json index a2264fb..ba9264d 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,6 @@ "typescript": "^5.2.2" }, "dependencies": { - "bc-minecraft-bedrock-types": "^1.20.71-1" + "bc-minecraft-bedrock-types": "^1.20.73" } } diff --git a/src/Lib/Data/CommandData.ts b/src/Lib/Data/CommandData.ts index 137ae73..c1e846b 100644 --- a/src/Lib/Data/CommandData.ts +++ b/src/Lib/Data/CommandData.ts @@ -23,6 +23,7 @@ import { Function } from "./Vanilla/function"; import { gamemode } from "./Vanilla/gamemode"; import { gamerule } from "./Vanilla/gamerule"; import { give } from "./Vanilla/give"; +import { hud } from "./Vanilla/hud"; import { immutableworld } from "./Edu/immutableworld"; import { inputpermission } from './Vanilla/inputpermission'; import { kick } from "./Vanilla/kick"; @@ -99,6 +100,7 @@ export namespace CommandData { gamemode, gamerule, give, + hud, inputpermission, kick, kill, diff --git a/src/Lib/Data/Vanilla/hud.ts b/src/Lib/Data/Vanilla/hud.ts new file mode 100644 index 0000000..3aee70b --- /dev/null +++ b/src/Lib/Data/Vanilla/hud.ts @@ -0,0 +1,16 @@ +import { ParameterType } from "../../Types/ParameterType"; +import { CommandInfo } from "../CommandInfo"; + +/**The hud command */ +export const hud: CommandInfo[] = [ + { + name: "hud", + documentation: "Configures whether elements of the on-screen display (alternately known as the 'heads up display', or 'HUD') are visible on the screen.", + parameters: [ + { text: "hud", type: ParameterType.keyword, required: true }, + { text: "target", type: ParameterType.selector, required: true, options: { playerOnly: true } }, + { text: "visible", type: ParameterType.hudVisibility, required: true }, + { text: "hud_element", type: ParameterType.hudElement, required: false }, + ], + }, +]; diff --git a/src/Lib/Types/Command/Functions.ts b/src/Lib/Types/Command/Functions.ts index 816f9c6..ca9a515 100644 --- a/src/Lib/Types/Command/Functions.ts +++ b/src/Lib/Types/Command/Functions.ts @@ -105,6 +105,8 @@ const Matches: Partial boolean>> = { [ParameterType.float]: (item) => General.Float.is(item), [ParameterType.gamemode]: (item) => Modes.Gamemode.isValue(item), [ParameterType.handType]: (item) => Modes.HandType.isValue(item), + [ParameterType.hudElement]: (item) => Modes.HudElement.isValue(item), + [ParameterType.hudVisibility]: (item) => Modes.HudVisibility.isValue(item), [ParameterType.integer]: (item) => General.Integer.is(item), [ParameterType.jsonItem]: (item) => General.Json.isObject(item), [ParameterType.jsonRawText]: (item) => General.Json.isObject(item), diff --git a/src/Lib/Types/ParameterType.ts b/src/Lib/Types/ParameterType.ts index 7c2a223..d756a5a 100644 --- a/src/Lib/Types/ParameterType.ts +++ b/src/Lib/Types/ParameterType.ts @@ -40,6 +40,10 @@ export enum ParameterType { gamemode, /** The type of hand: mainhand or offhand */ handType, + /** The type of hud visibility */ + hudVisibility, + /** The type of hud element */ + hudElement, /** Integer numbers */ integer, /** Integer range numbers */ diff --git a/test/Export/export.test.ts b/test/Export/export.test.ts new file mode 100644 index 0000000..c6f5eb5 --- /dev/null +++ b/test/Export/export.test.ts @@ -0,0 +1,126 @@ +import { CommandData } from "../../src/Lib/Data/CommandData"; +import { CommandInfo, ParameterInfo } from "../../src/Lib/Data/CommandInfo"; +import { ParameterType } from '../../src/Lib/Types/ParameterType'; +import { writeFileSync } from 'fs'; + +interface Parameter { + text: string; + type: string; + required: boolean; + options?: any; +} + +interface Command { + name: string; + parameters: Array; + documentation: string; +} + +interface ExportData { + vanilla: Command[]; + edu: Command[]; +} + +describe.skip("Export", () => { + const { Vanilla, Edu } = CommandData; + + it("exported", () => { + const out: ExportData = { + vanilla: [], + edu: [], + }; + + Object.getOwnPropertyNames(Vanilla) + .map((key) => Vanilla[key]) + .map(exportCommands) + .forEach((commands) => out.vanilla.push(...commands)); + + Object.getOwnPropertyNames(Edu) + .map((key) => Edu[key]) + .map(exportCommands) + .forEach((commands) => out.edu.push(...commands)); + + writeFileSync('./out.json', JSON.stringify(out, null, 2)); + }); +}); + +function exportCommands(data: CommandInfo[]): Command[] { + return data.map(convertCommand); +} + +function convertCommand(c: CommandInfo): Command { + return { + name: c.name, + documentation: c.documentation, + parameters: c.parameters.map(convertParameter), + }; +} + +function convertParameter(p: ParameterInfo): Parameter { + return { + text: p.text, + type: ptype[p.type], + required: p.required, + options: p.options, + }; +} + +const ptype: Record = { + [ParameterType.animation]: "animation", + [ParameterType.block]: "block", + [ParameterType.blockStates]: "blockStates", + [ParameterType.boolean]: "boolean", + [ParameterType.causeType]: "causeType", + [ParameterType.cameraShakeType]: "cameraShakeType", + [ParameterType.cloneMode]: "cloneMode", + [ParameterType.command]: "command", + [ParameterType.coordinate]: "coordinate", + [ParameterType.difficulty]: "difficulty", + [ParameterType.dimension]: "dimension", + [ParameterType.effect]: "effect", + [ParameterType.entity]: "entity", + [ParameterType.executeSubcommand]: "executeSubcommand", + [ParameterType.event]: "event", + [ParameterType.fillMode]: "fillMode", + [ParameterType.function]: "function", + [ParameterType.float]: "float", + [ParameterType.gamemode]: "gamemode", + [ParameterType.handType]: "handType", + [ParameterType.integer]: "integer", + [ParameterType.integer_range]: "integer_range", + [ParameterType.item]: "item", + [ParameterType.jsonItem]: "jsonItem", + [ParameterType.jsonRawText]: "jsonRawText", + [ParameterType.keyword]: "keyword", + [ParameterType.lootTable]: "lootTable", + [ParameterType.locateFeature]: "locateFeature", + [ParameterType.message]: "message", + [ParameterType.maskMode]: "maskMode", + [ParameterType.mirror]: "mirror", + [ParameterType.musicRepeatMode]: "musicRepeatMode", + [ParameterType.objective]: "objective", + [ParameterType.oldBlockMode]: "oldBlockMode", + [ParameterType.operation]: "operation", + [ParameterType.particle]: "particle", + [ParameterType.permission]: "permission", + [ParameterType.permissionState]: "permissionState", + [ParameterType.replaceMode]: "replaceMode", + [ParameterType.rideRules]: "rideRules", + [ParameterType.ridefillMode]: "ridefillMode", + [ParameterType.rotation]: "rotation", + [ParameterType.saveMode]: "saveMode", + [ParameterType.scanMode]: "scanMode", + [ParameterType.selector]: "selector", + [ParameterType.slotType]: "slotType", + [ParameterType.slotID]: "slotID", + [ParameterType.sound]: "sound", + [ParameterType.string]: "string", + [ParameterType.structure]: "structure", + [ParameterType.structureAnimationMode]: "structureAnimationMode", + [ParameterType.tag]: "tag", + [ParameterType.teleportRules]: "teleportRules", + [ParameterType.tickingarea]: "tickingarea", + [ParameterType.time]: "time", + [ParameterType.unknown]: "unknown", + [ParameterType.xp]: "xp", +} \ No newline at end of file