From f6e7178dc361ab59c22b006c6f5b1f07518d8219 Mon Sep 17 00:00:00 2001 From: Leon van Kammen <leonvankammen@gmail.com> Date: Mon, 10 Feb 2025 15:53:41 +0100 Subject: [PATCH] improve transcripts function for reuse --- src/3rd/js/plugin/frontend/$chat.js | 1 + src/3rd/js/plugin/frontend/accessibility.js | 6 ++--- src/3rd/js/plugin/frontend/chatcommand/mud.js | 16 +++++++------- src/3rd/js/plugin/frontend/frontend.js | 8 ++++++- src/3rd/js/three/util/transcript.js | 22 ++++++++++++++----- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/3rd/js/plugin/frontend/$chat.js b/src/3rd/js/plugin/frontend/$chat.js index 535f31c..5d6e2e6 100644 --- a/src/3rd/js/plugin/frontend/$chat.js +++ b/src/3rd/js/plugin/frontend/$chat.js @@ -262,6 +262,7 @@ chatComponent.css = ` max-width: 20px; border-radius: 20px 0px 0px 20px; overflow: hidden; + margin:0; } #chatbar input{ border:none; diff --git a/src/3rd/js/plugin/frontend/accessibility.js b/src/3rd/js/plugin/frontend/accessibility.js index 1760f6d..7b90cf3 100644 --- a/src/3rd/js/plugin/frontend/accessibility.js +++ b/src/3rd/js/plugin/frontend/accessibility.js @@ -116,9 +116,9 @@ window.accessibility = (opts) => new Proxy({ notify(`${n.userData['aria-description']||''}` + (n.userData.href ? `<br><b>name:</b> ${n.name}<br><b>href:</b> ${n.userData['href']}` :'') ) } - if( e.key == 'Enter' && objects[cache.current].userData.href ){ - xrf.navigator.to( objects[cache.current].userData.href ) - } + //if( e.key == 'Enter' && objects[cache.current]?.userData.href ){ + // xrf.navigator.to( objects[cache.current].userData.href ) + //} // increment to next cache.current = (cache.current + 1) % objects.length diff --git a/src/3rd/js/plugin/frontend/chatcommand/mud.js b/src/3rd/js/plugin/frontend/chatcommand/mud.js index f4e066a..6fd7886 100644 --- a/src/3rd/js/plugin/frontend/chatcommand/mud.js +++ b/src/3rd/js/plugin/frontend/chatcommand/mud.js @@ -20,12 +20,7 @@ document.addEventListener('chat.command.help', (e) => { const listExits = (scene) => { let message = '' - let destinations = {} - scene.traverse( (n) => { - if( n.userData && n.userData.href && n.userData.href.match(/pos=/) ){ - destinations[n.name] = n.userData['aria-label'] || n.userData.href - } - }) + let destinations = xrf.sceneListExits(scene, true) for( let destination in destinations ){ message += `<br><b class="badge">${destination}</b> ${destinations[destination]}` } @@ -56,8 +51,13 @@ document.addEventListener('chat.input', (e) => { } if( e.detail.message.trim() == 'look' ){ - let scene = xrf.frag.pos.last ? xrf.scene.getObjectByName(xrf.frag.pos.last) : xrf.scene - let message = `<div class="transcript">${xrf.sceneToTranscript(scene)}</div><br>possible destinations in this area:${listExits(scene)}` + let transcript = xrf.sceneToTranscript(false,false,true) + .map( (n) => `<b>${n.name}</b> ${n.description}` ) + .join(". ") + let exits = xrf.listExits(false,true) + .map( (n) => `<b>${n.name}</b>` ) + .join("<br>") + let message = `<div class="transcript">${transcript}</div><br>possible destinations in this area:<br>${exits}` e.detail.halt = true // dont print command to screen $chat.send({message}) } diff --git a/src/3rd/js/plugin/frontend/frontend.js b/src/3rd/js/plugin/frontend/frontend.js index 033c94e..038b97d 100644 --- a/src/3rd/js/plugin/frontend/frontend.js +++ b/src/3rd/js/plugin/frontend/frontend.js @@ -128,7 +128,13 @@ window.frontend = (opts) => new Proxy({ } let root = data.mesh.portal ? data.mesh.portal.stencilObject : data.mesh let transcript = xrf.sceneToTranscript(root,data.mesh) - if( transcript.length ) html += `<br><b>transcript:</b><br><div class="transcript">${transcript}</div>` + console.dir(transcript) + if( transcript.length ){ + transcript = xrf.sceneToTranscript(false,false,true) + .map( (n) => `<b>${n.name}</b> ${n.description}` ) + .join(". ") + html += `<br><b>transcript:</b><br><div class="transcript">${transcript}</div>` + } if (hasMeta && !data.mesh.portal && metadata.XRF.src ) html += `<br><br><a class="btn" style="float:right" onclick="xrf.navigator.to('${data.mesh.userData.href}')">Visit embedded scene</a>` if( !html ) return diff --git a/src/3rd/js/three/util/transcript.js b/src/3rd/js/three/util/transcript.js index 194d52e..536a78f 100644 --- a/src/3rd/js/three/util/transcript.js +++ b/src/3rd/js/three/util/transcript.js @@ -1,11 +1,23 @@ -xrf.sceneToTranscript = (scene, ignoreMesh ) => { - let transcript = '' +xrf.sceneToTranscript = (scene, node, currentPosition ) => { + let items = [] + scene = currentPosition && xrf.frag.pos.last ? xrf.scene.getObjectByName(xrf.frag.pos.last) : scene || xrf.scene scene.traverse( (n) => { let isSRC = false n.traverseAncestors( (m) => m.userData.src ? isSRC = true : false ) - if( !isSRC && n.userData['aria-description'] && (!ignoreMesh || n.uuid != ignoreMesh.uuid) ){ - transcript += `<b>#${n.name}</b> ${n.userData['aria-description']}. ` + if( !isSRC && n.userData['aria-description'] && (!node || n.uuid != node.uuid) ){ + items.push({name: n.name, description: n.userData['aria-description']}) } }) - return transcript + return items +} + +xrf.listExits = (scene, currentPosition ) => { + let destinations = [] + scene = currentPosition && xrf.frag.pos.last ? xrf.scene.getObjectByName(xrf.frag.pos.last) : scene || xrf.scene + scene.traverse( (n) => { + if( n.userData && n.userData.href && n.userData.href.match(/pos=/) ){ + destinations.push({name: n.name, destination: n.userData['aria-label'] || n.userData.href}) + } + }) + return destinations }