From 0919c1c13ccc13bb86d82a735c66bf1356f6f10a Mon Sep 17 00:00:00 2001 From: Erik Date: Mon, 10 Aug 2020 18:53:50 -0400 Subject: [PATCH] Ported files from other projects and made some modifications. --- .gitignore | 105 +---------- AliasedAction.ts | 51 ++++++ Button.ts | 56 ++++++ Screen.ts | 79 ++++++++ actions/Action.ts | 83 +++++++++ actions/ActionBus.ts | 75 ++++++++ actions/Resolver.ts | 127 +++++++++++++ .../clientbound/AuthBeginHandshakeAction.ts | 28 +++ actions/clientbound/AuthCompleteAction.ts | 33 ++++ actions/clientbound/DisableModAction.ts | 30 +++ actions/clientbound/EnableModAction.ts | 18 ++ actions/clientbound/OpenGuiAction.ts | 38 ++++ actions/clientbound/OpenScreenAction.ts | 30 +++ actions/clientbound/RefreshCacheAction.ts | 20 ++ actions/clientbound/ResetConfigAction.ts | 18 ++ actions/clientbound/SendChatCommandAction.ts | 35 ++++ .../clientbound/SendChatComponentAction.ts | 31 ++++ actions/clientbound/SetAliasedActionAction.ts | 35 ++++ actions/clientbound/SetButtonAction.ts | 39 ++++ actions/clientbound/SetCurrentServerAction.ts | 35 ++++ actions/clientbound/SetGlyphForUserAction.ts | 47 +++++ actions/clientbound/SetKeybindsAction.ts | 32 ++++ actions/clientbound/SetPremiumAboutAction.ts | 31 ++++ actions/clientbound/SetScreenAction.ts | 43 +++++ actions/clientbound/SetTranslationAction.ts | 36 ++++ actions/clientbound/SystemOutAction.ts | 27 +++ actions/serverbound/AuthEndHandshakeAction.ts | 31 ++++ actions/serverbound/ButtonPressedAction.ts | 31 ++++ actions/serverbound/ExceptionThrownAction.ts | 68 +++++++ .../HypixelLocationChangedAction.ts | 31 ++++ actions/serverbound/InitializeClientAction.ts | 66 +++++++ actions/serverbound/LanguageChangedAction.ts | 31 ++++ actions/serverbound/MigrateKeybindsAction.ts | 33 ++++ actions/serverbound/ServerJoinedAction.ts | 35 ++++ actions/serverbound/ServerLeftAction.ts | 19 ++ chat-components/ChatComponent.ts | 171 ++++++++++++++++++ chat-components/ChatFormatting.ts | 20 ++ chat-components/ClickEvent.ts | 78 ++++++++ chat-components/HoverEvent.ts | 75 ++++++++ chat-components/Message.ts | 31 ++++ index.ts | 86 +++++++++ package-lock.json | 33 ++++ package.json | 36 ++++ tsconfig.json | 73 ++++++++ 44 files changed, 2027 insertions(+), 103 deletions(-) create mode 100644 AliasedAction.ts create mode 100644 Button.ts create mode 100644 Screen.ts create mode 100644 actions/Action.ts create mode 100644 actions/ActionBus.ts create mode 100644 actions/Resolver.ts create mode 100644 actions/clientbound/AuthBeginHandshakeAction.ts create mode 100644 actions/clientbound/AuthCompleteAction.ts create mode 100644 actions/clientbound/DisableModAction.ts create mode 100644 actions/clientbound/EnableModAction.ts create mode 100644 actions/clientbound/OpenGuiAction.ts create mode 100644 actions/clientbound/OpenScreenAction.ts create mode 100644 actions/clientbound/RefreshCacheAction.ts create mode 100644 actions/clientbound/ResetConfigAction.ts create mode 100644 actions/clientbound/SendChatCommandAction.ts create mode 100644 actions/clientbound/SendChatComponentAction.ts create mode 100644 actions/clientbound/SetAliasedActionAction.ts create mode 100644 actions/clientbound/SetButtonAction.ts create mode 100644 actions/clientbound/SetCurrentServerAction.ts create mode 100644 actions/clientbound/SetGlyphForUserAction.ts create mode 100644 actions/clientbound/SetKeybindsAction.ts create mode 100644 actions/clientbound/SetPremiumAboutAction.ts create mode 100644 actions/clientbound/SetScreenAction.ts create mode 100644 actions/clientbound/SetTranslationAction.ts create mode 100644 actions/clientbound/SystemOutAction.ts create mode 100644 actions/serverbound/AuthEndHandshakeAction.ts create mode 100644 actions/serverbound/ButtonPressedAction.ts create mode 100644 actions/serverbound/ExceptionThrownAction.ts create mode 100644 actions/serverbound/HypixelLocationChangedAction.ts create mode 100644 actions/serverbound/InitializeClientAction.ts create mode 100644 actions/serverbound/LanguageChangedAction.ts create mode 100644 actions/serverbound/MigrateKeybindsAction.ts create mode 100644 actions/serverbound/ServerJoinedAction.ts create mode 100644 actions/serverbound/ServerLeftAction.ts create mode 100644 chat-components/ChatComponent.ts create mode 100644 chat-components/ChatFormatting.ts create mode 100644 chat-components/ClickEvent.ts create mode 100644 chat-components/HoverEvent.ts create mode 100644 chat-components/Message.ts create mode 100644 index.ts create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index 6704566..c4de136 100644 --- a/.gitignore +++ b/.gitignore @@ -1,104 +1,3 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# TypeScript v1 declaration files -typings/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test - -# parcel-bundler cache (https://parceljs.org/) -.cache - -# Next.js build output -.next - -# Nuxt.js build / generate output -.nuxt dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and *not* Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port +node_modules +.npmrc diff --git a/AliasedAction.ts b/AliasedAction.ts new file mode 100644 index 0000000..83d6ff4 --- /dev/null +++ b/AliasedAction.ts @@ -0,0 +1,51 @@ +import Action from './actions/Action' +import Resolver from './actions/Resolver' + +/** + * AliasedActions are the lowest level of user-facing elements. Actions are executed by the user and are simply + * a wrapper to reference an Action and it's arguments. + */ +class AliasedAction { + + /** + * The key of this AliasedAction. Should probably be CAPS_SNAKE_CASE. + */ + key: string + /** + * Array of server identifiers that this AliasedAction is available on. + */ + availableOn: string[] = [] + /** + * The Action which this AliasedAction is a wrapper for. + */ + action: Action + + /** + * Constructor + * @param key {string} The key of this item. + */ + constructor (key: string) { + this.key = key + + } + + /** + * Deserialize a JSON-stringified AliasedAction into an AliasedAction object. + * @param json {string} The JSON to deserialize. + * @return {Promise} The AliasedAction that was deserialized. + */ + static async deserialize(json: string) : Promise { + const obj = JSON.parse(json) + const aa = new AliasedAction(obj.key) + for(const prop in obj) { + if(!obj.hasOwnProperty(prop)) { + continue + } + aa[prop] = obj[prop] + } + aa.action = await Resolver.deserialize(JSON.stringify(obj.action)) + return aa + } +} + +export default AliasedAction diff --git a/Button.ts b/Button.ts new file mode 100644 index 0000000..50e728a --- /dev/null +++ b/Button.ts @@ -0,0 +1,56 @@ +/** + * Buttons are the median user-facing element, between AliasedActions and Screens. Screens contain a list of + * Buttons, and Buttons contain a list of AliasedActions. + */ +class Button { + + /** + * The key of this Button. Unique identifier, should probably be CAPS_SNAKE_CASE + */ + key: string + /** + * Array of server identifiers that this Button is available on. + */ + availableOn: string[] = [] + /** + * Array of AliasedAction keys which this Button executes. AliasedAction objects are not used directly to reduce + * Action size, remove redundant references to AliasedActions, and due to the async nature in how AliasedActions are + * handled by the client. + */ + actions: string[] = [] + /** + * The URL to the image which can be displayed as this Button, specifically on "IMAGES" type Screens. + */ + imageURL = '' + /** + * The translation key for this Button's title. + */ + translationKey = '' + + /** + * Constructor + * @param key {string} The key/ID of this item. + */ + constructor (key: string) { + this.key = key + } + + /** + * Deserialize a JSON-stringified Button into an Button object. + * @param json {string} The JSON to deserialize. + * @return {Promise