Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 36x 36x 36x 1x 1x 1x 1x 1x 1x 1x 1x 45x 45x 1x 1x 1x 1x 1x 1x 1x 21x 20x 21x 1x 1x 1x 1x 21x 1x 1x 1x 1x 1x 1x 1x 1x 15x 2x 2x 15x 15x 1x 1x 1x 1x 1x 1x 1x 1x 28x 28x 1x 1x 1x | "use strict";
import Conversation from "./conversation.js";
/**
* Per-player conversation memory.
*
* Each player gets their own conversation history so context does not leak
* between players.
*
* @class
*/
class Memory {
/**
* Initializes a new Memory instance.
*
* @param {number} [historySize=20] - Maximum messages stored per player.
*/
constructor(historySize) {
this.conversations = {};
this.historySize = historySize || 20;
}
/**
* Check if a conversation exists for a player.
*
* @param {string} player - Player name or id.
* @returns {boolean} True when the player exists in memory.
*/
exists(player) {
return player in this.conversations;
}
/**
* Initialize a conversation for a player.
*
* @param {string} player - Player name or id.
*/
initialize(player) {
if (!this.exists(player)) {
this.conversations[player] = new Conversation(this.historySize);
} else {
console.info(
`Memory for player ${player} already exists. Nothing to initialize.`,
);
}
}
/**
* Retrieve the conversation for a player, creating it if needed.
*
* @param {string} player - Player name or id.
* @returns {Conversation} Player conversation.
*/
retrieve(player) {
if (!this.exists(player)) {
this.initialize(player);
}
return this.conversations[player];
}
/**
* Register a new message for a player.
*
* @param {string} player - Player name or id.
* @param {Message} message - Message to register.
*/
register(player, message) {
this.conversations[player].addMessage(message);
}
}
export { Memory as default };
|