Skip to content

Commit

Permalink
feat(RawJSONBuilder): enums
Browse files Browse the repository at this point in the history
  • Loading branch information
egorprnn committed May 9, 2021
1 parent 2e28bb5 commit 42837f7
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 44 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"types": "./lib/interfaces.d.ts",
"scripts": {
"build": "tsc",
"postbuild": "node --experimental-modules --es-module-specifier-resolution=node scripts/cleanUpBuild.mjs",
"pretest": "npm run-script build",
"test": "mocha --reporter spec",
"eslint:check": "eslint ./src/**/*",
Expand Down
18 changes: 0 additions & 18 deletions scripts/cleanUpBuild.mjs

This file was deleted.

8 changes: 7 additions & 1 deletion src/RawJSONBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as minecraftProtocolChatParser from "minecraft-protocol-chat-parser";
import { inspectable } from "inspectable";

import { IKeybind, ITranslate, IClickEvent, NBT, IText, IScore, ISelector, RawJSON, RawJSONBuilderOptions } from "./interfaces";
import { IKeybind, ITranslate, IClickEvent, NBT, IText, IScore, ISelector, RawJSON, RawJSONBuilderOptions, HoverAction, ClickAction, Color } from "./interfaces";

const parser = minecraftProtocolChatParser(735);

Expand Down Expand Up @@ -206,3 +206,9 @@ inspectable(RawJSONBuilder, {
`${context.stylize(instance.constructor.name, "special")} ${context.inspect(payload)}`
)
});

export {
Color,
HoverAction,
ClickAction
};
3 changes: 2 additions & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export * from "./interfaces/clickEvent";
export * from "./interfaces/formatting";
export * from "./interfaces/nbt";
export * from "./interfaces/hoverEvent";
export * from "./RawJSONBuilder";

export { RawJSONBuilder } from "./RawJSONBuilder";
13 changes: 12 additions & 1 deletion src/interfaces/clickEvent.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import { IFormatting } from "./formatting";

export enum ClickAction {
OPEN_URL = "open_url",
OPEN_FILE = "open_file",
RUN_COMMAND = "run_command",
SUGGEST_COMMAND = "suggest_command",
CHANGE_PAGE = "change_page",
COPY_TO_CLIPBOARD = "copy_to_clipboard"
}

export type ClickActionUnion = "open_url" | "open_file" | "run_command" | "suggest_command" | "change_page" | "copy_to_clipboard";

export interface IClickEvent extends IFormatting {
insertion?: string;
clickEvent?: {
action: "open_url" | "open_file" | "run_command" | "suggest_command" | "change_page" | "copy_to_clipboard";
action: ClickAction | ClickActionUnion;
value: string;
}
}
58 changes: 39 additions & 19 deletions src/interfaces/formatting.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
export interface IFormatting {
color?: "black"
| "dark_blue"
| "dark_green"
| "dark_aqua"
| "dark_red"
| "dark_purple"
| "gold"
| "gray"
| "dark_gray"
| "blue"
| "green"
| "aqua"
| "red"
| "light_purple"
| "yellow"
| "white"
| "reset"
| string;
export enum Color {
BLACK = "black",
DARK_BLUE = "dark_blue",
DARK_GREEN = "dark_green",
DARK_AQUA = "dark_aqua",
DARK_RED = "dark_red",
DARK_PURPLE = "dark_purple",
GOLD = "gold",
GRAY = "gray",
DARK_GRAY = "dark_gray",
BLUE = "blue",
GREEN = "green",
AQUA = "aqua",
RED = "red",
LIGHT_PURPLE = "light_purple",
YELLOW = "yellow",
WHITE = "white",
RESET = "reset"
}

export type ColorUnion = "black"
| "dark_blue"
| "dark_green"
| "dark_aqua"
| "dark_red"
| "dark_purple"
| "gold"
| "gray"
| "dark_gray"
| "blue"
| "green"
| "aqua"
| "red"
| "light_purple"
| "yellow"
| "white"
| "reset";

export interface IFormatting {
color?: Color | ColorUnion | string;
font?: string;
bold?: boolean;
italic?: boolean;
Expand Down
12 changes: 9 additions & 3 deletions src/interfaces/hoverEvent.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { RawJSONBuilder } from "../RawJSONBuilder";
import { IClickEvent } from "./clickEvent";

export enum HoverAction {
SHOW_TEXT = "show_text",
SHOW_ITEM = "show_item",
SHOW_ENTITY = "show_entity"
}

export interface IHoverEvent extends IClickEvent {
hoverEvent?: IShowTextHoverEvent | IShowItemHoverEvent | IShowEntityHoverEvent;
}

export interface IShowTextHoverEvent {
action: "show_text";
action: HoverAction.SHOW_TEXT | "show_text";
value?: RawJSONBuilder;
contents?: RawJSONBuilder;
}

export interface IShowItemHoverEvent {
action: "show_item";
action: HoverAction.SHOW_ITEM | "show_item";
value?: string;
contents?: {
id: string;
Expand All @@ -22,7 +28,7 @@ export interface IShowItemHoverEvent {
}

export interface IShowEntityHoverEvent {
action?: "show_entity";
action?: HoverAction.SHOW_ENTITY | "show_entity";
value?: {
name?: RawJSONBuilder;
type?: string;
Expand Down

0 comments on commit 42837f7

Please sign in to comment.