Tweaks and fixes

This commit is contained in:
Kim Ravn Hansen
2025-10-22 00:09:10 +02:00
parent 9de5140e47
commit 3ce96deeea
3 changed files with 23 additions and 20 deletions

View File

@@ -25,12 +25,8 @@ export class CreateUsernamePrompt extends Prompt {
// Let the client know that we're asking for a username // Let the client know that we're asking for a username
promptOptions = { username: true }; promptOptions = { username: true };
/** /** @protected @type {PlayerCreationScene} */
* @returns {PlayerCreationScene} _scene;
*/
get scene() {
return this._scene;
}
onReply(username) { onReply(username) {
// //
@@ -56,7 +52,7 @@ export class CreateUsernamePrompt extends Prompt {
} }
// //
// Tell daddy that we're done // Tell owner that we're done
this.scene.usernameAccepted(username); this._scene.usernameAccepted(username);
} }
} }

View File

@@ -16,7 +16,7 @@
* - onColon(...) * - onColon(...)
*/ */
export class Prompt { export class Prompt {
/** @type {Scene} */ /** @protected @type {Scene} */
_scene; _scene;
/** @type {Scene} */ /** @type {Scene} */
@@ -66,13 +66,6 @@ export class Prompt {
/** @param {Scene} scene */ /** @param {Scene} scene */
constructor(scene) { constructor(scene) {
this._scene = 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]` */ /** Triggered when user types `:help [some optional topic]` */
onHelp(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]) { if (this.helpText[topic]) {
this.sendText(this.helpText[topic]); this.sendText(this.helpText[topic]);
return; return;
} }
console.log({
ht: this.helpText,
topic,
});
this.onHelpFallback(topic); this.onHelpFallback(topic);
} }

View File

@@ -83,12 +83,15 @@ export const MessageType = Object.freeze({
* @property {any[]} args * @property {any[]} args
*/ */
export class WebsocketMessage { 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; _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; 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. * @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 " + "Could not create client message. Attempting to parse json, but data was not even a string, it was a " +
typeof msgData, typeof msgData,
); );
return;
} }
let data; let data;
try { try {
data = JSON.parse(msgData); data = JSON.parse(msgData);
} catch (_) { } catch {
throw new Error( throw new Error(
`Could not create client message. Attempting to parse json, but data was invalid json: >>> ${msgData} <<<`, `Could not create client message. Attempting to parse json, but data was invalid json: >>> ${msgData} <<<`,
); );