This commit is contained in:
Kim Ravn Hansen
2025-10-22 10:09:50 +02:00
parent 3ce96deeea
commit 6a25b15530
8 changed files with 60 additions and 50 deletions

View File

@@ -8,7 +8,6 @@ import { gGame } from "../../models/globals.js";
/** @typedef {import("../../models/player.js").Player} Player */
/** @property {Session} session */
export class AuthenticationScene extends Scene {
/** @type {Player} */
player;
@@ -54,25 +53,24 @@ export class AuthenticationScene extends Scene {
// | __/| | | (_) | | | | | | |_) | |_
// |_| |_| \___/|_| |_| |_| .__/ \__|
// |_|
/** @property {AuthenticationScene} scene */
class UsernamePrompt extends Prompt {
//
promptText = [
message = [
"Please enter your username:", //
"(((type *:create* if you want to create a new user)))", //
"((type _*:help*_ to see your other options))",
];
//
// When player types :help
helpText = [
"This is where you log in.",
"If you don't already have a player profile on this server, you can type *:create* to create one",
help = [
"Enter your username to proceed with loggin in",
"Type _*:create*_ if you are not already registered, and want to create a new account",
"Only a username and password is required - not your email",
];
options = { username: true };
//
// Let the client know that we're asking for a username
promptOptions = { username: true };
/** @returns {AuthenticationScene} */
/** @returns {AuthenticationScene} workaround for proper type hinting */
get scene() {
return this._scene;
}
@@ -123,12 +121,8 @@ class UsernamePrompt extends Prompt {
// |_|
class PasswordPrompt extends Prompt {
//
promptText = "Please enter your password";
//
// Let the client know that we're asking for a password
// so it can set <input type="password">
promptOptions = { password: true };
message = "Please enter your password";
options = { password: true };
get player() {
return this.scene.player;

View File

@@ -38,7 +38,7 @@ export class GameScene extends Scene {
}
class GameScenePlaceholderPrompt extends Prompt {
promptText = `
message = `
█▐▀▀▀▌▄
█ ▐▀▀▀▌▌▓▌

View File

@@ -4,12 +4,12 @@ import { Config } from "../../config.js";
export class CreatePasswordPrompt extends Prompt {
//
promptText = ["Enter a password"];
message = ["Enter a password"];
//
// Let the client know that we're asking for a password
// so it can set <input type="password">
promptOptions = { password: true };
options = { password: true };
get player() {
return this.scene.player;

View File

@@ -6,14 +6,14 @@ import { gGame } from "../../models/globals.js";
export class CreateUsernamePrompt extends Prompt {
//
promptText = [
message = [
"Enter your username", //
"((type *:help* for more info))", //
];
//
// When player types :help
helpText = [
help = [
"Your username.",
"It's used, along with your password, when you log in.",
"Other players can see it.",
@@ -23,7 +23,7 @@ export class CreateUsernamePrompt extends Prompt {
//
// Let the client know that we're asking for a username
promptOptions = { username: true };
options = { username: true };
/** @protected @type {PlayerCreationScene} */
_scene;

View File

@@ -30,19 +30,24 @@ export class Prompt {
* Values: string containing the help text
*
* If you want truly custom help texts, you must override the onHelpFallback function,
* but overriding the onHelp() function gives you more control and skips this helpText
* but overriding the onHelp() function gives you more control and skips this help
* dictionary entirely.
*
* @constant
* @readonly
* @type {Record<string, string|string[]>}
*/
helpText = {
"": "Sorry, no help available. Figure it out yourself, adventurer", // default help text
};
help = {};
/** @type {string|string[]} Default prompt text to send if we don't want to send something in the execute() call. */
promptText = [
/**
* Default prompt text to send if we don't want to send something in the execute() call.
*
* Array values will be converted to multiline strings with newlines between each string
* in the array.
*
* @type {string|string[]}
*/
message = [
"Please enter some very important info", // Silly placeholder text
"((or type :quit to run away))", // strings in double parentheses is rendered shaded/faintly
];
@@ -51,12 +56,12 @@ export class Prompt {
/* @example
*
* // if the prompt expects a username
* promptOptions = { username : true };
* options = { username : true };
*
* // if the prompt expects a password
* promptOptions = { password : true };
* options = { password : true };
*/
promptOptions = {};
options = {};
/** @type {Session} */
get session() {
@@ -74,27 +79,36 @@ export class Prompt {
* It's here you want to send the prompt text via the sendPrompt() method
*/
execute() {
this.sendPrompt(this.promptText, this.promptOptions);
this.prepareProperties();
this.sendPrompt(this.message, this.options);
}
/**
* Normalize / massage the properties of the Prompt.
*
* This function cannot be called from the Prompt base constructor, as the
* properties of the child class have not been set yet.
*/
prepareProperties() {
//
// Lazy dev set property help = "fooo" instead of help = { "": "fooo" }.
if (this.help && (typeof this.help === "string" || Array.isArray(this.help))) {
this.help = { "": this.help };
}
}
/** 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]);
if (!this.help) {
this.sendText("No help available at this moment - figure it out yourself, adventurer");
return;
}
if (this.help[topic]) {
this.sendText(this.help[topic]);
return;
}
console.log({
ht: this.helpText,
topic,
});
this.onHelpFallback(topic);
}