Stuff and things

This commit is contained in:
Kim Ravn Hansen
2025-10-13 15:58:34 +02:00
parent 2fe8f7149c
commit 00d55d638c
5 changed files with 36 additions and 30 deletions

View File

@@ -1,4 +1,4 @@
import { Session } from "../models/session.js"; /** @typedef {import("../models/session.js").Session} Session */
const castle = ` const castle = `

View File

@@ -5,6 +5,18 @@ import { frameText } from "../utils/tui.js";
import { Config } from "../config.js"; import { Config } from "../config.js";
import { State } from "./state.js"; import { State } from "./state.js";
// _____ ___ ____ ___ ____ _ _____
// |_ _/ _ \| _ \ / _ \ _ / ___|___ _ ____ _____ _ __| |_ |_ _|__
// | || | | | | | | | | (_) | | / _ \| '_ \ \ / / _ \ '__| __| | |/ _ \
// | || |_| | |_| | |_| |_ | |__| (_) | | | \ V / __/ | | |_ | | (_) |
// |_| \___/|____/ \___/(_) \____\___/|_| |_|\_/ \___|_| \__| |_|\___/
//
// ____
// / ___| ___ ___ _ __ ___ ___
// \___ \ / __/ _ \ '_ \ / _ \/ __|
// ___) | (_| __/ | | | __/\__ \
// |____/ \___\___|_| |_|\___||___/
export class PartyCreationState extends State { export class PartyCreationState extends State {
/** /**
* @proteted * @proteted
@@ -16,7 +28,7 @@ export class PartyCreationState extends State {
/** @param {Session} session */ /** @param {Session} session */
constructor(session) { constructor(session) {
/** @type {Session} */ super();
this.session = session; this.session = session;
} }
@@ -32,11 +44,7 @@ export class PartyCreationState extends State {
this.sendText(createPartyLogo, { preformatted: true }); this.sendText(createPartyLogo, { preformatted: true });
this.session.sendText([ this.session.sendText(["", `Current party size: ${charCount}`, `Max party size: ${Config.maxPartySize}`]);
"",
`Current party size: ${charCount}`,
`Max party size: ${Config.maxPartySize}`,
]);
const min = 1; const min = 1;
const max = Config.maxPartySize - charCount; const max = Config.maxPartySize - charCount;
const prompt = [ const prompt = [
@@ -46,32 +54,32 @@ export class PartyCreationState extends State {
this.sendText(`You can create a party with ${min} - ${max} characters, how big should your party be?`); this.sendText(`You can create a party with ${min} - ${max} characters, how big should your party be?`);
/** @param {WebsocketMessage} message */ /** @param {WebsocketMessage} m */
this.sendPrompt(prompt, (m) => this.receivePlayerCount(m)); this.sendPrompt(prompt, (m) => this.receiveCharacterCount(m));
} }
/** @param {WebsocketMessage} m */ /** @param {WebsocketMessage} m */
receivePlayerCount(m) { receiveCharacterCount(m) {
if (m.isHelpRequest()) { if (m.isHelpRequest()) {
return this.partySizeHelp(); return this.partySizeHelp();
} }
if (!m.isInteger()) { if (!m.isInteger()) {
this.sendError("You didn't enter an integer"); this.sendError("You didn't enter an integer");
this.sendPrompt(prompt, (m) => this.receivePlayerCount(m)); this.sendPrompt(prompt, (m) => this.receiveCharacterCount(m));
return; return;
} }
const numCharactersToCreate = Number(message.text); const numCharactersToCreate = Number(m.text);
if (numCharactersToCreate > max) { if (numCharactersToCreate > Config.maxPartySize) {
this.sendError("Number too high"); this.sendError("Number too high");
this.sendPrompt(prompt, (m) => this.receivePlayerCount(m)); this.sendPrompt(prompt, (m) => this.receiveCharacterCount(m));
return; return;
} }
if (numCharactersToCreate < min) { if (numCharactersToCreate < 1) {
this.sendError("Number too low"); this.sendError("Number too low");
this.sendPrompt(prompt, (m) => this.receivePlayerCount(m)); this.sendPrompt(prompt, (m) => this.receiveCharacterCount(m));
return; return;
} }
@@ -80,7 +88,7 @@ export class PartyCreationState extends State {
partySizeHelp() { partySizeHelp() {
this.sendText([ this.sendText([
`Your party can consist of 1 to ${mps} characters.`, `Your party can consist of 1 to ${Config.maxPartySize} characters.`,
"", "",
"* Large parties tend live longer", "* Large parties tend live longer",
`* If you have fewer than ${Config.maxPartySize} characters, you can`, `* If you have fewer than ${Config.maxPartySize} characters, you can`,
@@ -95,3 +103,7 @@ export class PartyCreationState extends State {
return; return;
} }
} }
if (Math.PI < 0 && Session && WebsocketMessage) {
("STFU Linda");
}

0
scenes/playerCreation/createUasswprdPrompt.js Normal file → Executable file
View File

View File

@@ -1,5 +1,6 @@
import { Config } from "../../config.js"; import { Config } from "../../config.js";
import { gGame } from "../../models/globals.js"; import { gGame } from "../../models/globals.js";
import { generateHash } from "../../utils/security.js";
import { Scene } from "../scene.js"; import { Scene } from "../scene.js";
import { CreateUsernamePrompt } from "./createUsernamePrompt.js"; import { CreateUsernamePrompt } from "./createUsernamePrompt.js";
@@ -47,6 +48,6 @@ export class PlayerCreationScene extends Scene {
passwordAccepted(password) { passwordAccepted(password) {
this.password = password; this.password = password;
this.session.sendText("*_Success_* ✅ You will now be asked to log in again, sorry for that ;)"); this.session.sendText("*_Success_* ✅ You will now be asked to log in again, sorry for that ;)");
this.player.setPasswordHash(security.generateHash(this.password)); this.player.setPasswordHash(generateHash(this.password));
} }
} }

View File

@@ -1,11 +1,8 @@
import figlet from "figlet";
import { gGame } from "../models/globals.js";
import { Session } from "../models/session.js";
import { Scene } from "./scene.js"; import { Scene } from "./scene.js";
import { MessageType, WebsocketMessage } from "../utils/messages.js";
import { mustBe, mustBeString } from "../utils/mustbe.js";
import { sprintf } from "sprintf-js";
/** @typedef {import("../models/session.js").Session} Session */
/** @typedef {import("../utils/message.js").WebsocketMessage} WebsocketMessage */
/** @typedef {import("../utils/message.js").MessageType} MessageType */
/** /**
* @typedef {object} PromptMethods * @typedef {object} PromptMethods
* @property {function(...any): any} [onColon_*] - Any method starting with "onColon_" * @property {function(...any): any} [onColon_*] - Any method starting with "onColon_"
@@ -27,10 +24,6 @@ export class Prompt {
return this._scene; return this._scene;
} }
//
// Extra info about the prompt we send to the client.
promptOptions = undefined;
/** /**
* Dictionary of help topics. * Dictionary of help topics.
* Keys: string matching /^[a-z]+$/ (topic name) * Keys: string matching /^[a-z]+$/ (topic name)
@@ -159,7 +152,7 @@ export class Prompt {
* *
* @param {WebsocketMessage} message The incoming reply * @param {WebsocketMessage} message The incoming reply
*/ */
onReply(message) {} onReply() {}
/** /**
* @overload * @overload
@@ -202,7 +195,7 @@ export class Prompt {
* @param {string} errorMessage * @param {string} errorMessage
*/ */
calamity(...args) { calamity(...args) {
this.session.calamity(); this.session.calamity(...args);
} }
// //