refactor
This commit is contained in:
@@ -22,18 +22,17 @@ export class AuthenticationScene extends Scene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @param {Player} player */
|
/** @param {Player} player */
|
||||||
usernameAccepted(player) {
|
usernameSuccess(player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.session.sendSystemMessage("salt", player.salt);
|
this.session.sendSystemMessage("salt", player.salt);
|
||||||
this.show(PasswordPrompt);
|
this.show(PasswordPrompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
passwordAccepted() {
|
passwordSuccess() {
|
||||||
this.player.loggedIn = true;
|
this.player.loggedIn = true;
|
||||||
|
|
||||||
this.session.setPlayer(this.player);
|
this.session.setPlayer(this.player);
|
||||||
this.session.sendText(["= Success!", "((but I don't know what to do now...))"]);
|
this.session.setScene(new GameScene(this.session));
|
||||||
this.session.setScene(new GameScene());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,6 +45,18 @@ export class AuthenticationScene extends Scene {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// _ _
|
||||||
|
// | | | |___ ___ _ __ _ __ __ _ _ __ ___ ___
|
||||||
|
// | | | / __|/ _ \ '__| '_ \ / _` | '_ ` _ \ / _ \
|
||||||
|
// | |_| \__ \ __/ | | | | | (_| | | | | | | __/
|
||||||
|
// \___/|___/\___|_| |_| |_|\__,_|_| |_| |_|\___|
|
||||||
|
//
|
||||||
|
// ____ _
|
||||||
|
// | _ \ _ __ ___ _ __ ___ _ __ | |_
|
||||||
|
// | |_) | '__/ _ \| '_ ` _ \| '_ \| __|
|
||||||
|
// | __/| | | (_) | | | | | | |_) | |_
|
||||||
|
// |_| |_| \___/|_| |_| |_| .__/ \__|
|
||||||
|
// |_|
|
||||||
class UsernamePrompt extends Prompt {
|
class UsernamePrompt extends Prompt {
|
||||||
//
|
//
|
||||||
promptText = [
|
promptText = [
|
||||||
@@ -96,10 +107,23 @@ class UsernamePrompt extends Prompt {
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Tell daddy that we're done
|
// Tell daddy that we're done
|
||||||
this.scene.usernameAccepted(player);
|
this.scene.usernameSuccess(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// ____ _
|
||||||
|
// | _ \ __ _ ___ _____ _____ _ __ __| |
|
||||||
|
// | |_) / _` / __/ __\ \ /\ / / _ \| '__/ _` |
|
||||||
|
// | __/ (_| \__ \__ \\ V V / (_) | | | (_| |
|
||||||
|
// |_| \__,_|___/___/ \_/\_/ \___/|_| \__,_|
|
||||||
|
//
|
||||||
|
// ____ _
|
||||||
|
// | _ \ _ __ ___ _ __ ___ _ __ | |_
|
||||||
|
// | |_) | '__/ _ \| '_ ` _ \| '_ \| __|
|
||||||
|
// | __/| | | (_) | | | | | | |_) | |_
|
||||||
|
// |_| |_| \___/|_| |_| |_| .__/ \__|
|
||||||
|
// |_|
|
||||||
class PasswordPrompt extends Prompt {
|
class PasswordPrompt extends Prompt {
|
||||||
//
|
//
|
||||||
promptText = "Please enter your password";
|
promptText = "Please enter your password";
|
||||||
@@ -174,7 +198,6 @@ class PasswordPrompt extends Prompt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Password was correct, go to main game
|
// Password was correct, go to main game
|
||||||
// this.scene.passwordAccepted();
|
this.scene.passwordSuccess();
|
||||||
this.scene.passwordAccepted();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,39 +6,7 @@ import { Scene } from "../scene.js";
|
|||||||
* It's here we listen for player commands.
|
* It's here we listen for player commands.
|
||||||
*/
|
*/
|
||||||
export class GameScene extends Scene {
|
export class GameScene extends Scene {
|
||||||
introText = "= Welcome";
|
introText = `
|
||||||
|
|
||||||
onReady() {
|
|
||||||
//
|
|
||||||
// Find out which state the player and their characters are in
|
|
||||||
// Find out where we are
|
|
||||||
// Re-route to the relevant scene if necessary.
|
|
||||||
//
|
|
||||||
// IF player has stored state THEN
|
|
||||||
// restore it and resume [main flow]
|
|
||||||
// END
|
|
||||||
//
|
|
||||||
// IF player has no characters THEN
|
|
||||||
// go to createCharacterScene
|
|
||||||
// END
|
|
||||||
//
|
|
||||||
// set player's current location = Hovedstad
|
|
||||||
// display the welcome to Hovedstad stuff, and
|
|
||||||
// await the player's commands.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// IDEA:
|
|
||||||
// Does a player have a previous state?
|
|
||||||
// The state that was on the previous session?
|
|
||||||
//
|
|
||||||
// If player does not have a previous session
|
|
||||||
// then we start in the Adventurers Guild in the Hovedstad
|
|
||||||
//
|
|
||||||
this.showBasicPrompt(this.castle);
|
|
||||||
}
|
|
||||||
|
|
||||||
get castle() {
|
|
||||||
return `
|
|
||||||
▄
|
▄
|
||||||
█▐▀▀▀▌▄
|
█▐▀▀▀▌▄
|
||||||
█ ▐▀▀▀▌▌▓▌
|
█ ▐▀▀▀▌▌▓▌
|
||||||
@@ -78,6 +46,36 @@ export class GameScene extends Scene {
|
|||||||
▓░ ▓░ ▐▌ ▀▌ ▐▌ ▐█
|
▓░ ▓░ ▐▌ ▀▌ ▐▌ ▐█
|
||||||
▀▌▄▄ ▓▄▄ ▐█ ▓▌ ▄▄▄▐▌ ▄▄▄▀
|
▀▌▄▄ ▓▄▄ ▐█ ▓▌ ▄▄▄▐▌ ▄▄▄▀
|
||||||
▐▐▐▀▀▀▀▐▐▐ ▐▐▀▀▀▀▀▀▐▐
|
▐▐▐▀▀▀▀▐▐▐ ▐▐▀▀▀▀▀▀▐▐
|
||||||
|
|
||||||
|
|
||||||
|
= Welcome to Hovedstad
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
onReady() {
|
||||||
|
//
|
||||||
|
// Find out which state the player and their characters are in
|
||||||
|
// Find out where we are
|
||||||
|
// Re-route to the relevant scene if necessary.
|
||||||
|
//
|
||||||
|
// IF player has stored state THEN
|
||||||
|
// restore it and resume [main flow]
|
||||||
|
// END
|
||||||
|
//
|
||||||
|
// IF player has no characters THEN
|
||||||
|
// go to createCharacterScene
|
||||||
|
// END
|
||||||
|
//
|
||||||
|
// set player's current location = Hovedstad
|
||||||
|
// display the welcome to Hovedstad stuff, and
|
||||||
|
// await the player's commands.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// IDEA:
|
||||||
|
// Does a player have a previous state?
|
||||||
|
// The state that was on the previous session?
|
||||||
|
//
|
||||||
|
// If player does not have a previous session
|
||||||
|
// then we start in the Adventurers Guild in the Hovedstad
|
||||||
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,9 +64,7 @@ export class Scene {
|
|||||||
throw new Error("Abstract method must be implemented by subclass");
|
throw new Error("Abstract method must be implemented by subclass");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @param {Prompt} prompt */
|
||||||
* @param {Prompt} prompt
|
|
||||||
*/
|
|
||||||
showPrompt(prompt) {
|
showPrompt(prompt) {
|
||||||
this.#currentPrompt = prompt;
|
this.#currentPrompt = prompt;
|
||||||
prompt.execute();
|
prompt.execute();
|
||||||
@@ -82,12 +80,14 @@ export class Scene {
|
|||||||
*
|
*
|
||||||
* We route that message to the current prompt.
|
* We route that message to the current prompt.
|
||||||
*
|
*
|
||||||
* It should not be necessary to override this function
|
* You SHOULD NOT:
|
||||||
|
* - call this method directly
|
||||||
|
* - override this method
|
||||||
*
|
*
|
||||||
* @param {WebsocketMessage} message
|
* @param {WebsocketMessage} message
|
||||||
*/
|
*/
|
||||||
onReply(message) {
|
onReply(message) {
|
||||||
console.log("REPLY", {
|
console.debug("REPLY", {
|
||||||
message,
|
message,
|
||||||
type: typeof message,
|
type: typeof message,
|
||||||
});
|
});
|
||||||
@@ -99,11 +99,12 @@ export class Scene {
|
|||||||
*
|
*
|
||||||
* We route that message to the current prompt.
|
* We route that message to the current prompt.
|
||||||
*
|
*
|
||||||
* It should may be necessary to override this method
|
* It may be necessary to override this method in
|
||||||
* in case you want to trigger specific behavior before
|
* case you want to trigger specific behavior before
|
||||||
* quitting.
|
* quitting.
|
||||||
*
|
*
|
||||||
* Default behavior is to route this message to the current prompt.
|
* You SHOULD NOT:
|
||||||
|
* - call this method directly
|
||||||
*/
|
*/
|
||||||
onQuit() {
|
onQuit() {
|
||||||
this.currentPrompt.onQuit();
|
this.currentPrompt.onQuit();
|
||||||
@@ -120,6 +121,9 @@ export class Scene {
|
|||||||
* many prompts, so handling this behavior inside the prompt
|
* many prompts, so handling this behavior inside the prompt
|
||||||
* should be the primary choice.
|
* should be the primary choice.
|
||||||
*
|
*
|
||||||
|
* You SHOULD NOT:
|
||||||
|
* - call this method directly
|
||||||
|
*
|
||||||
* @param {WebsocketMessage} message
|
* @param {WebsocketMessage} message
|
||||||
*/
|
*/
|
||||||
onHelp(message) {
|
onHelp(message) {
|
||||||
|
|||||||
47
test.js
47
test.js
@@ -1,26 +1,25 @@
|
|||||||
let cnt = 0;
|
class TestParent {
|
||||||
|
someString = "foo";
|
||||||
|
|
||||||
let val = Math.floor(Math.random() * 5);
|
constructor() {
|
||||||
|
console.log(this.someString);
|
||||||
switch (val) {
|
|
||||||
case cnt++:
|
|
||||||
console.log("zero");
|
|
||||||
break;
|
|
||||||
case cnt++:
|
|
||||||
console.log("one");
|
|
||||||
break;
|
|
||||||
case cnt++:
|
|
||||||
console.log("two");
|
|
||||||
break;
|
|
||||||
case cnt++:
|
|
||||||
console.log("three");
|
|
||||||
break;
|
|
||||||
case cnt++:
|
|
||||||
console.log("four");
|
|
||||||
break;
|
|
||||||
case cnt++:
|
|
||||||
console.log("five");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
console.log("waaat", { val });
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestChild extends TestParent {
|
||||||
|
get someString() {
|
||||||
|
return "bar";
|
||||||
|
}
|
||||||
|
|
||||||
|
set someString(_val) {
|
||||||
|
console.log("was I called?");
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.someString = "baz";
|
||||||
|
console.log(this.someString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(new TestChild());
|
||||||
|
|||||||
Reference in New Issue
Block a user