diff --git a/scenes/playerCreation/createUsernamePrompt.js b/scenes/playerCreation/createUsernamePrompt.js index 71056d2..ebfb6ad 100755 --- a/scenes/playerCreation/createUsernamePrompt.js +++ b/scenes/playerCreation/createUsernamePrompt.js @@ -25,12 +25,8 @@ export class CreateUsernamePrompt extends Prompt { // Let the client know that we're asking for a username promptOptions = { username: true }; - /** - * @returns {PlayerCreationScene} - */ - get scene() { - return this._scene; - } + /** @protected @type {PlayerCreationScene} */ + _scene; onReply(username) { // @@ -56,7 +52,7 @@ export class CreateUsernamePrompt extends Prompt { } // - // Tell daddy that we're done - this.scene.usernameAccepted(username); + // Tell owner that we're done + this._scene.usernameAccepted(username); } } diff --git a/scenes/prompt.js b/scenes/prompt.js index bf11234..8c26da1 100755 --- a/scenes/prompt.js +++ b/scenes/prompt.js @@ -16,7 +16,7 @@ * - onColon(...) */ export class Prompt { - /** @type {Scene} */ + /** @protected @type {Scene} */ _scene; /** @type {Scene} */ @@ -66,13 +66,6 @@ export class Prompt { /** @param {Scene} scene */ constructor(scene) { this._scene = scene; - - // - // Fix data formatting shorthand - // So lazy dev set property helpText = "fooo" instead of helpText = { "": "fooo" }. - if (typeof this.helpText === "string" || Array.isArray(this.helpText)) { - this.helpText = { "": this.helpText }; - } } /** @@ -86,10 +79,22 @@ export class Prompt { /** Triggered when user types `:help [some optional topic]` */ onHelp(topic) { + // + // Fix data formatting shorthand + // So lazy dev set property helpText = "fooo" instead of helpText = { "": "fooo" }. + // + if (typeof this.helpText === "string" || Array.isArray(this.helpText)) { + this.helpText = { "": this.helpText }; + } + if (this.helpText[topic]) { this.sendText(this.helpText[topic]); return; } + console.log({ + ht: this.helpText, + topic, + }); this.onHelpFallback(topic); } diff --git a/utils/messages.js b/utils/messages.js index 75f2b3b..667c4a5 100755 --- a/utils/messages.js +++ b/utils/messages.js @@ -83,12 +83,15 @@ export const MessageType = Object.freeze({ * @property {any[]} args */ export class WebsocketMessage { - /** @protected @type {any[]} _arr The array that contains the message data */ + /** @protected @type {any[]} The array that contains the message data */ _data; - /** @constant @readonly @type {string} _arr The array that contains the message data */ + /** @constant @readonly @type {string} The array that contains the message data */ type; + /** @constant @readonly @type {string?} the text payload (if any) of the decoded message */ + text; + /** * @param {string} msgData the raw text data in the websocket message. */ @@ -98,13 +101,12 @@ export class WebsocketMessage { "Could not create client message. Attempting to parse json, but data was not even a string, it was a " + typeof msgData, ); - return; } let data; try { data = JSON.parse(msgData); - } catch (_) { + } catch { throw new Error( `Could not create client message. Attempting to parse json, but data was invalid json: >>> ${msgData} <<<`, );