mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-20 13:50:46 +00:00
Enhance inventory item uniqueness check with item identifier
This commit is contained in:
12
index.html
12
index.html
@@ -2886,10 +2886,16 @@
|
||||
}
|
||||
|
||||
try {
|
||||
// Check if the item is already in the inventory
|
||||
const isAlreadyInInventory = inventory.items.some(item => item.name === sprite.name);
|
||||
// Check if the item is already in the inventory using the unique identifier
|
||||
const itemIdentifier = createItemIdentifier(sprite.scenarioData);
|
||||
console.log(`Checking if item ${itemIdentifier} is already in inventory`);
|
||||
|
||||
const isAlreadyInInventory = inventory.items.some(item =>
|
||||
createItemIdentifier(item.scenarioData) === itemIdentifier
|
||||
);
|
||||
|
||||
if (isAlreadyInInventory) {
|
||||
console.log(`Item ${sprite.name} is already in inventory, not adding again`);
|
||||
console.log(`Item ${itemIdentifier} is already in inventory, not adding again`);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user