feat(npc): Enhance message handling by adding metadata support in addMessage method

This commit is contained in:
Z. Cliffe Schreuders
2025-11-01 10:42:37 +00:00
parent 2a5eed9963
commit 1bd037d969

View File

@@ -104,7 +104,7 @@ export default class NPCManager {
this.barkSystem = barkSystem;
}
// Add a message to conversation history
// Add a message to conversation history (internal method)
addMessageToHistory(npcId, type, text) {
if (!this.conversationHistory.has(npcId)) {
this.conversationHistory.set(npcId, []);
@@ -118,6 +118,21 @@ export default class NPCManager {
this._log('debug', `Added ${type} message to ${npcId} history:`, text);
}
// Public API: Add a message with full metadata (used by external systems)
addMessage(npcId, type, text, metadata = {}) {
if (!this.conversationHistory.has(npcId)) {
this.conversationHistory.set(npcId, []);
}
this.conversationHistory.get(npcId).push({
type,
text,
timestamp: Date.now(),
read: type === 'player', // Player messages are automatically marked as read
...metadata
});
this._log('debug', `Added ${type} message to ${npcId}:`, text);
}
// Get conversation history for an NPC
getConversationHistory(npcId) {
return this.conversationHistory.get(npcId) || [];