From d8d55dfcdfba57bf374a558168bb8f22e4cbd3b7 Mon Sep 17 00:00:00 2001 From: Damian-I Date: Sat, 8 Feb 2025 15:26:20 +0000 Subject: [PATCH 1/2] Refactor container interaction and unlocking logic - Modify item collection process to prevent automatic collection - Add alert when container is unlocked - Simplify handling of unlocked containers with contents - Improve state management for locked and unlocked items --- index.html | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/index.html b/index.html index 3e6f92a..50c5456 100644 --- a/index.html +++ b/index.html @@ -1403,22 +1403,10 @@ } const data = sprite.scenarioData; - let message = `${data.name}\n\n`; - message += `Observations: ${data.observations}\n\n`; - // Check for locked state in scenarioData - if (data.locked === true) { - console.log('Item is locked:', data); - handleUnlock(sprite, 'item'); - return; - } - - if (data.readable && data.text) { - message += `Text: ${data.text}\n\n`; - } - - if (data.contents && data.contents.length > 0) { - message += `You found the following items:\n`; + // Check if this is an unlocked container that hasn't been collected yet + if (data.isUnlockedButNotCollected && data.contents) { + let message = `You found the following items:\n`; data.contents.forEach(item => { message += `- ${item.name}\n`; }); @@ -1434,12 +1422,27 @@ addToInventory(contentSprite); } }); - + // Clear contents after adding to inventory data.contents = []; + data.isUnlockedButNotCollected = false; return; } + // Check for locked state in scenarioData + if (data.locked === true) { + console.log('Item is locked:', data); + handleUnlock(sprite, 'item'); + return; + } + + let message = `${data.name}\n\n`; + message += `Observations: ${data.observations}\n\n`; + + if (data.readable && data.text) { + message += `Text: ${data.text}\n\n`; + } + if (data.takeable) { message += `This item can be taken\n\n`; @@ -1836,7 +1839,7 @@ } } - // Generic unlock function + // Modify the unlockTarget function function unlockTarget(lockable, type, layer) { if (type === 'door') { if (!layer) { @@ -1851,23 +1854,17 @@ // Set new state for containers with contents if (lockable.scenarioData.contents) { lockable.scenarioData.isUnlockedButNotCollected = true; + alert('Container unlocked! You can now collect its contents.'); + return; // Return early to prevent automatic collection } } else { lockable.locked = false; if (lockable.contents) { lockable.isUnlockedButNotCollected = true; + alert('Container unlocked! You can now collect its contents.'); + return; // Return early to prevent automatic collection } } - - // If the item has contents, make them accessible - if (lockable.scenarioData?.contents) { - lockable.scenarioData.contents.forEach(item => { - const sprite = createInventorySprite(item); - if (sprite) { - addToInventory(sprite); - } - }); - } } } From 41a7372ce769ebb41ac793bd3404d66c781f737a Mon Sep 17 00:00:00 2001 From: Damian-I Date: Sat, 8 Feb 2025 15:31:30 +0000 Subject: [PATCH 2/2] Remove container unlock alerts - Eliminate redundant alert messages when unlocking containers - Preserve the existing logic for preventing automatic item collection - Simplify user interaction by removing unnecessary pop-up notifications --- index.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/index.html b/index.html index 50c5456..f793cca 100644 --- a/index.html +++ b/index.html @@ -1854,14 +1854,12 @@ // Set new state for containers with contents if (lockable.scenarioData.contents) { lockable.scenarioData.isUnlockedButNotCollected = true; - alert('Container unlocked! You can now collect its contents.'); return; // Return early to prevent automatic collection } } else { lockable.locked = false; if (lockable.contents) { lockable.isUnlockedButNotCollected = true; - alert('Container unlocked! You can now collect its contents.'); return; // Return early to prevent automatic collection } }