diff --git a/index.html b/index.html
index cfc1628..3e6f92a 100644
--- a/index.html
+++ b/index.html
@@ -1406,52 +1406,35 @@
let message = `${data.name}\n\n`;
message += `Observations: ${data.observations}\n\n`;
- if (distanceSq > INTERACTION_RANGE_SQ) {
+ // Check for locked state in scenarioData
+ if (data.locked === true) {
+ console.log('Item is locked:', data);
+ handleUnlock(sprite, 'item');
return;
}
- }
-
- 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`;
- }
-
- // Only handle contents if they exist and haven't been collected yet
- if (data.contents && data.contents.length > 0) {
- message += `You found the following items:\n`;
- data.contents.forEach(item => {
- message += `- ${item.name}\n`;
- });
- alert(message);
- // Add all contents to inventory
- data.contents.forEach(item => {
- const contentSprite = createInventorySprite({
- ...item,
- type: item.type.toLowerCase()
+ 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`;
+ data.contents.forEach(item => {
+ message += `- ${item.name}\n`;
});
-
alert(message);
// Add all contents to inventory
data.contents.forEach(item => {
- // Ensure the item type matches the preloaded asset name
- const contentSprite = createInventorySprite(item);
+ const contentSprite = createInventorySprite({
+ ...item,
+ type: item.type.toLowerCase()
+ });
if (contentSprite) {
addToInventory(contentSprite);
}
});
-
+
// Clear contents after adding to inventory
data.contents = [];
return;
@@ -1875,24 +1858,17 @@
lockable.isUnlockedButNotCollected = true;
}
}
- }
- }
-
- function collectContainerContents(container) {
- if (!container.scenarioData?.contents ||
- !container.scenarioData?.isUnlockedButNotCollected) {
- return;
- }
-
- container.scenarioData.contents.forEach(item => {
- const sprite = createInventorySprite(item);
- if (sprite) {
- addToInventory(sprite);
+
+ // 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);
+ }
+ });
}
- });
-
- container.scenarioData.isUnlockedButNotCollected = false;
- alert('You collected the items from the container.');
+ }
}
// Helper function to create inventory sprites for unlocked container contents
@@ -2071,6 +2047,23 @@
};
}
+ function collectContainerContents(container) {
+ if (!container.scenarioData?.contents ||
+ !container.scenarioData?.isUnlockedButNotCollected) {
+ return;
+ }
+
+ container.scenarioData.contents.forEach(item => {
+ const sprite = createInventorySprite(item);
+ if (sprite) {
+ addToInventory(sprite);
+ }
+ });
+
+ container.scenarioData.isUnlockedButNotCollected = false;
+ alert('You collected the items from the container.');
+ }
+