refactor
This commit is contained in:
@@ -398,14 +398,14 @@ class MUDClient {
|
|||||||
// prompted.
|
// prompted.
|
||||||
// In fact, we should ALWAYS be in a state of just-having-been-prompted.
|
// In fact, we should ALWAYS be in a state of just-having-been-prompted.
|
||||||
handlePromptMessage(data) {
|
handlePromptMessage(data) {
|
||||||
let [promptText, options = {}] = data;
|
let [prompt, options = {}] = data;
|
||||||
|
|
||||||
this.shouldReply = true;
|
this.shouldReply = true;
|
||||||
|
|
||||||
this.promptOptions = { ...{ class: "prompt" }, ...options };
|
this.promptOptions = { ...{ class: "prompt" }, ...options };
|
||||||
|
|
||||||
//
|
//
|
||||||
this.writeToOutput(promptText, this.promptOptions);
|
this.writeToOutput(prompt, this.promptOptions);
|
||||||
|
|
||||||
//
|
//
|
||||||
// The server has asked for a password, so we set the
|
// The server has asked for a password, so we set the
|
||||||
|
|||||||
@@ -148,6 +148,6 @@ h2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.faint {
|
.faint {
|
||||||
opacity: 0.42;
|
opacity: 0.6;
|
||||||
color: #44f;
|
color: #44f;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { gGame } from "../../models/globals.js";
|
|||||||
|
|
||||||
/** @typedef {import("../../models/player.js").Player} Player */
|
/** @typedef {import("../../models/player.js").Player} Player */
|
||||||
|
|
||||||
/** @property {Session} session */
|
|
||||||
export class AuthenticationScene extends Scene {
|
export class AuthenticationScene extends Scene {
|
||||||
/** @type {Player} */
|
/** @type {Player} */
|
||||||
player;
|
player;
|
||||||
@@ -54,25 +53,24 @@ export class AuthenticationScene extends Scene {
|
|||||||
// | __/| | | (_) | | | | | | |_) | |_
|
// | __/| | | (_) | | | | | | |_) | |_
|
||||||
// |_| |_| \___/|_| |_| |_| .__/ \__|
|
// |_| |_| \___/|_| |_| |_| .__/ \__|
|
||||||
// |_|
|
// |_|
|
||||||
|
/** @property {AuthenticationScene} scene */
|
||||||
class UsernamePrompt extends Prompt {
|
class UsernamePrompt extends Prompt {
|
||||||
//
|
//
|
||||||
promptText = [
|
message = [
|
||||||
"Please enter your username:", //
|
"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
|
// When player types :help
|
||||||
helpText = [
|
help = [
|
||||||
"This is where you log in.",
|
"Enter your username to proceed with loggin in",
|
||||||
"If you don't already have a player profile on this server, you can type *:create* to create one",
|
"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 };
|
||||||
|
|
||||||
//
|
/** @returns {AuthenticationScene} workaround for proper type hinting */
|
||||||
// Let the client know that we're asking for a username
|
|
||||||
promptOptions = { username: true };
|
|
||||||
|
|
||||||
/** @returns {AuthenticationScene} */
|
|
||||||
get scene() {
|
get scene() {
|
||||||
return this._scene;
|
return this._scene;
|
||||||
}
|
}
|
||||||
@@ -123,12 +121,8 @@ class UsernamePrompt extends Prompt {
|
|||||||
// |_|
|
// |_|
|
||||||
class PasswordPrompt extends Prompt {
|
class PasswordPrompt extends Prompt {
|
||||||
//
|
//
|
||||||
promptText = "Please enter your password";
|
message = "Please enter your password";
|
||||||
|
options = { password: true };
|
||||||
//
|
|
||||||
// Let the client know that we're asking for a password
|
|
||||||
// so it can set <input type="password">
|
|
||||||
promptOptions = { password: true };
|
|
||||||
|
|
||||||
get player() {
|
get player() {
|
||||||
return this.scene.player;
|
return this.scene.player;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export class GameScene extends Scene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class GameScenePlaceholderPrompt extends Prompt {
|
class GameScenePlaceholderPrompt extends Prompt {
|
||||||
promptText = `
|
message = `
|
||||||
▄
|
▄
|
||||||
█▐▀▀▀▌▄
|
█▐▀▀▀▌▄
|
||||||
█ ▐▀▀▀▌▌▓▌
|
█ ▐▀▀▀▌▌▓▌
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import { Config } from "../../config.js";
|
|||||||
|
|
||||||
export class CreatePasswordPrompt extends Prompt {
|
export class CreatePasswordPrompt extends Prompt {
|
||||||
//
|
//
|
||||||
promptText = ["Enter a password"];
|
message = ["Enter a password"];
|
||||||
|
|
||||||
//
|
//
|
||||||
// Let the client know that we're asking for a password
|
// Let the client know that we're asking for a password
|
||||||
// so it can set <input type="password">
|
// so it can set <input type="password">
|
||||||
promptOptions = { password: true };
|
options = { password: true };
|
||||||
|
|
||||||
get player() {
|
get player() {
|
||||||
return this.scene.player;
|
return this.scene.player;
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ import { gGame } from "../../models/globals.js";
|
|||||||
|
|
||||||
export class CreateUsernamePrompt extends Prompt {
|
export class CreateUsernamePrompt extends Prompt {
|
||||||
//
|
//
|
||||||
promptText = [
|
message = [
|
||||||
"Enter your username", //
|
"Enter your username", //
|
||||||
"((type *:help* for more info))", //
|
"((type *:help* for more info))", //
|
||||||
];
|
];
|
||||||
|
|
||||||
//
|
//
|
||||||
// When player types :help
|
// When player types :help
|
||||||
helpText = [
|
help = [
|
||||||
"Your username.",
|
"Your username.",
|
||||||
"It's used, along with your password, when you log in.",
|
"It's used, along with your password, when you log in.",
|
||||||
"Other players can see it.",
|
"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
|
// Let the client know that we're asking for a username
|
||||||
promptOptions = { username: true };
|
options = { username: true };
|
||||||
|
|
||||||
/** @protected @type {PlayerCreationScene} */
|
/** @protected @type {PlayerCreationScene} */
|
||||||
_scene;
|
_scene;
|
||||||
|
|||||||
@@ -30,19 +30,24 @@ export class Prompt {
|
|||||||
* Values: string containing the help text
|
* Values: string containing the help text
|
||||||
*
|
*
|
||||||
* If you want truly custom help texts, you must override the onHelpFallback function,
|
* 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.
|
* dictionary entirely.
|
||||||
*
|
*
|
||||||
* @constant
|
* @constant
|
||||||
* @readonly
|
* @readonly
|
||||||
* @type {Record<string, string|string[]>}
|
* @type {Record<string, string|string[]>}
|
||||||
*/
|
*/
|
||||||
helpText = {
|
help = {};
|
||||||
"": "Sorry, no help available. Figure it out yourself, adventurer", // default help text
|
|
||||||
};
|
|
||||||
|
|
||||||
/** @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
|
"Please enter some very important info", // Silly placeholder text
|
||||||
"((or type :quit to run away))", // strings in double parentheses is rendered shaded/faintly
|
"((or type :quit to run away))", // strings in double parentheses is rendered shaded/faintly
|
||||||
];
|
];
|
||||||
@@ -51,12 +56,12 @@ export class Prompt {
|
|||||||
/* @example
|
/* @example
|
||||||
*
|
*
|
||||||
* // if the prompt expects a username
|
* // if the prompt expects a username
|
||||||
* promptOptions = { username : true };
|
* options = { username : true };
|
||||||
*
|
*
|
||||||
* // if the prompt expects a password
|
* // if the prompt expects a password
|
||||||
* promptOptions = { password : true };
|
* options = { password : true };
|
||||||
*/
|
*/
|
||||||
promptOptions = {};
|
options = {};
|
||||||
|
|
||||||
/** @type {Session} */
|
/** @type {Session} */
|
||||||
get session() {
|
get session() {
|
||||||
@@ -74,27 +79,36 @@ export class Prompt {
|
|||||||
* It's here you want to send the prompt text via the sendPrompt() method
|
* It's here you want to send the prompt text via the sendPrompt() method
|
||||||
*/
|
*/
|
||||||
execute() {
|
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]` */
|
/** Triggered when user types `:help [some optional topic]` */
|
||||||
onHelp(topic) {
|
onHelp(topic) {
|
||||||
//
|
if (!this.help) {
|
||||||
// Fix data formatting shorthand
|
this.sendText("No help available at this moment - figure it out yourself, adventurer");
|
||||||
// So lazy dev set property helpText = "fooo" instead of helpText = { "": "fooo" }.
|
return;
|
||||||
//
|
}
|
||||||
if (typeof this.helpText === "string" || Array.isArray(this.helpText)) {
|
|
||||||
this.helpText = { "": this.helpText };
|
if (this.help[topic]) {
|
||||||
}
|
this.sendText(this.help[topic]);
|
||||||
|
|
||||||
if (this.helpText[topic]) {
|
|
||||||
this.sendText(this.helpText[topic]);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log({
|
|
||||||
ht: this.helpText,
|
|
||||||
topic,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.onHelpFallback(topic);
|
this.onHelpFallback(topic);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ const opcodes = [
|
|||||||
["___", "___", "<span class='underline'>$1</span>"], // ___underline___
|
["___", "___", "<span class='underline'>$1</span>"], // ___underline___
|
||||||
["(?:[,]{3})", "(?:[,]{3})", "<span class='undercurl'>$1</span>"], // ,,,undercurl,,,
|
["(?:[,]{3})", "(?:[,]{3})", "<span class='undercurl'>$1</span>"], // ,,,undercurl,,,
|
||||||
["(?:[(]{2})", "(?:[)]{2})", "<span class='faint'>$1</span>"], // ((faint text))
|
["(?:[(]{2})", "(?:[)]{2})", "<span class='faint'>$1</span>"], // ((faint text))
|
||||||
|
["(?:_\\*)", "(?:\\*_)", "<span class='bold italic'>$1</span>"], // _*bold and italic*_
|
||||||
|
["(?:\\*_)", "(?:_\\*)", "<span class='bold italic'>$1</span>"], // *_bold and italic_*
|
||||||
["_", "_", "<span class='italic'>$1</span>"], // _italic_
|
["_", "_", "<span class='italic'>$1</span>"], // _italic_
|
||||||
["\\*", "\\*", "<span class='bold'>$1</span>"], // *bold*
|
["\\*", "\\*", "<span class='bold'>$1</span>"], // *bold*
|
||||||
["\\[\\[([a-zA-Z0-9_ ]+)\\[\\[", "\\]\\]", "<span class='$1'>$2</span>"], // [[custom_class[[text with custom class]]
|
["\\[\\[([a-zA-Z0-9_ ]+)\\[\\[", "\\]\\]", "<span class='$1'>$2</span>"], // [[custom_class[[text with custom class]]
|
||||||
|
|||||||
Reference in New Issue
Block a user