From 403a3d345eb20733b14960caf73b3110a61c7ff5 Mon Sep 17 00:00:00 2001 From: Damian Idzinski <45018439+Damian-I@users.noreply.github.com> Date: Sun, 2 Feb 2025 01:31:21 +0000 Subject: [PATCH] Add files via upload Fixed bug causing game to not load, #10 needs to be semi re-implemented --- index.html | 95 +++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 51 deletions(-) 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.'); + } + \ No newline at end of file