This commit is contained in:
Kim Ravn Hansen
2025-10-21 12:15:17 +02:00
parent a39a2d1b61
commit 15f648535c
4 changed files with 96 additions and 72 deletions

View File

@@ -22,18 +22,17 @@ export class AuthenticationScene extends Scene {
}
/** @param {Player} player */
usernameAccepted(player) {
usernameSuccess(player) {
this.player = player;
this.session.sendSystemMessage("salt", player.salt);
this.show(PasswordPrompt);
}
passwordAccepted() {
passwordSuccess() {
this.player.loggedIn = true;
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.setScene(new GameScene(this.session));
}
/**
@@ -46,6 +45,18 @@ export class AuthenticationScene extends Scene {
}
}
// _ _
// | | | |___ ___ _ __ _ __ __ _ _ __ ___ ___
// | | | / __|/ _ \ '__| '_ \ / _` | '_ ` _ \ / _ \
// | |_| \__ \ __/ | | | | | (_| | | | | | | __/
// \___/|___/\___|_| |_| |_|\__,_|_| |_| |_|\___|
//
// ____ _
// | _ \ _ __ ___ _ __ ___ _ __ | |_
// | |_) | '__/ _ \| '_ ` _ \| '_ \| __|
// | __/| | | (_) | | | | | | |_) | |_
// |_| |_| \___/|_| |_| |_| .__/ \__|
// |_|
class UsernamePrompt extends Prompt {
//
promptText = [
@@ -96,10 +107,23 @@ class UsernamePrompt extends Prompt {
//
// Tell daddy that we're done
this.scene.usernameAccepted(player);
this.scene.usernameSuccess(player);
}
}
//
// ____ _
// | _ \ __ _ ___ _____ _____ _ __ __| |
// | |_) / _` / __/ __\ \ /\ / / _ \| '__/ _` |
// | __/ (_| \__ \__ \\ V V / (_) | | | (_| |
// |_| \__,_|___/___/ \_/\_/ \___/|_| \__,_|
//
// ____ _
// | _ \ _ __ ___ _ __ ___ _ __ | |_
// | |_) | '__/ _ \| '_ ` _ \| '_ \| __|
// | __/| | | (_) | | | | | | |_) | |_
// |_| |_| \___/|_| |_| |_| .__/ \__|
// |_|
class PasswordPrompt extends Prompt {
//
promptText = "Please enter your password";
@@ -174,7 +198,6 @@ class PasswordPrompt extends Prompt {
}
// Password was correct, go to main game
// this.scene.passwordAccepted();
this.scene.passwordAccepted();
this.scene.passwordSuccess();
}
}

View File

@@ -6,39 +6,7 @@ import { Scene } from "../scene.js";
* It's here we listen for player commands.
*/
export class GameScene extends Scene {
introText = "= Welcome";
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 `
introText = `
█▐▀▀▀▌▄
█ ▐▀▀▀▌▌▓▌
@@ -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
//
}
}

View File

@@ -64,9 +64,7 @@ export class Scene {
throw new Error("Abstract method must be implemented by subclass");
}
/**
* @param {Prompt} prompt
*/
/** @param {Prompt} prompt */
showPrompt(prompt) {
this.#currentPrompt = prompt;
prompt.execute();
@@ -82,12 +80,14 @@ export class Scene {
*
* 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
*/
onReply(message) {
console.log("REPLY", {
console.debug("REPLY", {
message,
type: typeof message,
});
@@ -99,11 +99,12 @@ export class Scene {
*
* We route that message to the current prompt.
*
* It should may be necessary to override this method
* in case you want to trigger specific behavior before
* It may be necessary to override this method in
* case you want to trigger specific behavior before
* quitting.
*
* Default behavior is to route this message to the current prompt.
* You SHOULD NOT:
* - call this method directly
*/
onQuit() {
this.currentPrompt.onQuit();
@@ -120,6 +121,9 @@ export class Scene {
* many prompts, so handling this behavior inside the prompt
* should be the primary choice.
*
* You SHOULD NOT:
* - call this method directly
*
* @param {WebsocketMessage} message
*/
onHelp(message) {

47
test.js
View File

@@ -1,26 +1,25 @@
let cnt = 0;
class TestParent {
someString = "foo";
let val = Math.floor(Math.random() * 5);
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 });
constructor() {
console.log(this.someString);
}
}
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());