From 03cc85685d01db2d4bd647fd695d7683c988fd6c Mon Sep 17 00:00:00 2001 From: Damian-I Date: Sun, 9 Mar 2025 17:02:00 +0000 Subject: [PATCH] Refactor CryptoWorkstation interaction and remove redundant inventory item --- assets/scenarios/biometric_breach.json | 7 -- index.html | 119 ++++++++++++------------- 2 files changed, 58 insertions(+), 68 deletions(-) diff --git a/assets/scenarios/biometric_breach.json b/assets/scenarios/biometric_breach.json index 2fe3d07..6250131 100644 --- a/assets/scenarios/biometric_breach.json +++ b/assets/scenarios/biometric_breach.json @@ -46,13 +46,6 @@ "takeable": true, "inInventory": true, "observations": "A tool for picking locks" - }, - { - "type": "workstation", - "name": "Crypto Analysis Station", - "takeable": true, - "inInventory": true, - "observations": "A powerful workstation for cryptographic analysis" } ] }, diff --git a/index.html b/index.html index 2b6f6c6..29a1487 100644 --- a/index.html +++ b/index.html @@ -1549,56 +1549,6 @@ workstationSprite.scenarioData = objectData; workstationSprite.setInteractive({ useHandCursor: true }); - // Override the default handleObjectInteraction for this specific item - workstationSprite.openCryptoWorkstation = function() { - // Create popup - let popup = document.getElementById('laptop-popup'); - if (!popup) { - popup = document.createElement('div'); - popup.id = 'laptop-popup'; - popup.innerHTML = ` - -
-
-
- CryptoWorkstation - -
-
-
-
- `; - document.body.appendChild(popup); - - // Find the CyberChef file - fetch('assets/cyberchef/') - .then(response => response.text()) - .then(html => { - // Use regex to find the CyberChef filename - const match = html.match(/CyberChef_v[0-9.]+\.html/); - if (match) { - const cyberchefPath = `assets/cyberchef/${match[0]}`; - // Create and append the iframe with the found path - const iframe = document.createElement('iframe'); - iframe.src = cyberchefPath; - iframe.frameBorder = "0"; - document.getElementById('cyberchef-container').appendChild(iframe); - } else { - console.error('Could not find CyberChef file'); - } - }) - .catch(error => { - console.error('Error loading CyberChef:', error); - }); - - popup.querySelector('.close-btn').addEventListener('click', () => { - popup.style.display = 'none'; - }); - } - popup.style.display = 'flex'; - return true; - }; - return workstationSprite; } @@ -2702,19 +2652,20 @@ // Only log detailed object interactions at debug level 2+ debugLog('OBJECT INTERACTION', { name: sprite.name, - hasWorkstation: !!sprite.openCryptoWorkstation + type: sprite.scenarioData?.type }, 2); - if (sprite.openCryptoWorkstation && sprite.openCryptoWorkstation()) { - debugLog('WORKSTATION OPENED', null, 1); - return; - } - if (!sprite || !sprite.scenarioData) { console.warn('Invalid sprite or missing scenario data'); return; } + // Handle the Crypto Workstation + if (sprite.scenarioData.type === "workstation") { + openCryptoWorkstation(); + return; + } + // Skip range check for inventory items const isInventoryItem = inventory.items.includes(sprite); if (!isInventoryItem) { @@ -2919,11 +2870,6 @@ }; inventorySprite.name = sprite.name; - // Copy over the custom interaction if it exists - if (sprite.openCryptoWorkstation) { - inventorySprite.openCryptoWorkstation = sprite.openCryptoWorkstation; - } - // Set depth higher than container inventorySprite.setDepth(2003); @@ -6459,6 +6405,57 @@ initializeToggleButtons(); }); + // Function to open the crypto workstation + function openCryptoWorkstation() { + debugLog('OPENING CRYPTO WORKSTATION', null, 1); + + // Create popup + let popup = document.getElementById('laptop-popup'); + if (!popup) { + popup = document.createElement('div'); + popup.id = 'laptop-popup'; + popup.innerHTML = ` + +
+
+
+ CryptoWorkstation + +
+
+
+
+ `; + document.body.appendChild(popup); + + // Find the CyberChef file + fetch('assets/cyberchef/') + .then(response => response.text()) + .then(html => { + // Use regex to find the CyberChef filename + const match = html.match(/CyberChef_v[0-9.]+\.html/); + if (match) { + const cyberchefPath = `assets/cyberchef/${match[0]}`; + // Create and append the iframe with the found path + const iframe = document.createElement('iframe'); + iframe.src = cyberchefPath; + iframe.frameBorder = "0"; + document.getElementById('cyberchef-container').appendChild(iframe); + } else { + console.error('Could not find CyberChef file'); + } + }) + .catch(error => { + console.error('Error loading CyberChef:', error); + }); + + popup.querySelector('.close-btn').addEventListener('click', () => { + popup.style.display = 'none'; + }); + } + popup.style.display = 'flex'; + } + \ No newline at end of file