Add automatic inventory item removal when adding notes

This commit is contained in:
Damian-I
2025-03-08 04:24:24 +00:00
parent 0e0442acdc
commit 31b74e16b9

View File

@@ -2233,6 +2233,16 @@
// Only show notification if a new note was actually added (not a duplicate)
if (addedNote) {
gameAlert(`Added "${data.name}" to your notes.`, 'info', 'Note Added', 3000);
// If this is a note in the inventory, remove it after adding to notes list
if (isInventoryItem && data.type === 'notes') {
// Remove from inventory after a short delay to allow the player to see the message
setTimeout(() => {
if (removeFromInventory(sprite)) {
gameAlert(`Removed "${data.name}" from inventory after recording in notes.`, 'success', 'Inventory Updated', 3000);
}
}, 1000);
}
}
}
}
@@ -4561,6 +4571,52 @@
}
}
// removes an item from the inventory
function removeFromInventory(sprite) {
if (!sprite || !inventory.items) {
return false;
}
try {
// Find the index of the sprite in the inventory
const index = inventory.items.indexOf(sprite);
if (index === -1) {
return false; // Item not found in inventory
}
// Remove from container
inventory.container.remove(sprite);
// Remove from items array
inventory.items.splice(index, 1);
// Destroy the sprite
sprite.destroy();
// Rearrange remaining items
rearrangeInventoryItems();
// Log the removal
debugLog('INVENTORY ITEM REMOVED', {
name: sprite.name,
totalItems: inventory.items.length
}, 2);
return true;
} catch (error) {
console.error('Error removing item from inventory:', error);
return false;
}
}
// Rearrange inventory items after removal
function rearrangeInventoryItems() {
inventory.items.forEach((item, index) => {
item.x = index * 60 + 100;
});
}
</script>
</body>
</html>