Skip to content

Commit

Permalink
Adding hud command
Browse files Browse the repository at this point in the history
  • Loading branch information
DaanV2 committed Apr 27, 2024
1 parent 539748d commit e47d8e7
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 8 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
"typescript": "^5.2.2"
},
"dependencies": {
"bc-minecraft-bedrock-types": "^1.20.71-1"
"bc-minecraft-bedrock-types": "^1.20.73"
}
}
2 changes: 2 additions & 0 deletions src/Lib/Data/CommandData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -99,6 +100,7 @@ export namespace CommandData {
gamemode,
gamerule,
give,
hud,
inputpermission,
kick,
kill,
Expand Down
16 changes: 16 additions & 0 deletions src/Lib/Data/Vanilla/hud.ts
Original file line number Diff line number Diff line change
@@ -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 },
],
},
];
2 changes: 2 additions & 0 deletions src/Lib/Types/Command/Functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ const Matches: Partial<Record<ParameterType, (item: string) => 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),
Expand Down
4 changes: 4 additions & 0 deletions src/Lib/Types/ParameterType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
126 changes: 126 additions & 0 deletions test/Export/export.test.ts
Original file line number Diff line number Diff line change
@@ -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<Parameter>;
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, string> = {

Check failure on line 68 in test/Export/export.test.ts

View workflow job for this annotation

GitHub Actions / 📋 Test on ubuntu-latest

Type '{ 0: string; 1: string; 2: string; 3: string; 4: string; 5: string; 6: string; 7: string; 8: string; 9: string; 10: string; 11: string; 12: string; 13: string; 14: string; 15: string; 16: string; 17: string; 18: string; ... 37 more ...; 58: string; }' is missing the following properties from type 'Record<ParameterType, string>': 20, 21

Check failure on line 68 in test/Export/export.test.ts

View workflow job for this annotation

GitHub Actions / 📋 Test on macOS-latest

Type '{ 0: string; 1: string; 2: string; 3: string; 4: string; 5: string; 6: string; 7: string; 8: string; 9: string; 10: string; 11: string; 12: string; 13: string; 14: string; 15: string; 16: string; 17: string; 18: string; ... 37 more ...; 58: string; }' is missing the following properties from type 'Record<ParameterType, string>': 20, 21
[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",
}

0 comments on commit e47d8e7

Please sign in to comment.