improve transcripts function for reuse
This commit is contained in:
parent
a93e128f26
commit
f6e7178dc3
src/3rd/js
|
@ -262,6 +262,7 @@ chatComponent.css = `
|
||||||
max-width: 20px;
|
max-width: 20px;
|
||||||
border-radius: 20px 0px 0px 20px;
|
border-radius: 20px 0px 0px 20px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
margin:0;
|
||||||
}
|
}
|
||||||
#chatbar input{
|
#chatbar input{
|
||||||
border:none;
|
border:none;
|
||||||
|
|
|
@ -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']}` :'') )
|
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 ){
|
//if( e.key == 'Enter' && objects[cache.current]?.userData.href ){
|
||||||
xrf.navigator.to( objects[cache.current].userData.href )
|
// xrf.navigator.to( objects[cache.current].userData.href )
|
||||||
}
|
//}
|
||||||
|
|
||||||
// increment to next
|
// increment to next
|
||||||
cache.current = (cache.current + 1) % objects.length
|
cache.current = (cache.current + 1) % objects.length
|
||||||
|
|
|
@ -20,12 +20,7 @@ document.addEventListener('chat.command.help', (e) => {
|
||||||
|
|
||||||
const listExits = (scene) => {
|
const listExits = (scene) => {
|
||||||
let message = ''
|
let message = ''
|
||||||
let destinations = {}
|
let destinations = xrf.sceneListExits(scene, true)
|
||||||
scene.traverse( (n) => {
|
|
||||||
if( n.userData && n.userData.href && n.userData.href.match(/pos=/) ){
|
|
||||||
destinations[n.name] = n.userData['aria-label'] || n.userData.href
|
|
||||||
}
|
|
||||||
})
|
|
||||||
for( let destination in destinations ){
|
for( let destination in destinations ){
|
||||||
message += `<br><b class="badge">${destination}</b> ${destinations[destination]}`
|
message += `<br><b class="badge">${destination}</b> ${destinations[destination]}`
|
||||||
}
|
}
|
||||||
|
@ -56,8 +51,13 @@ document.addEventListener('chat.input', (e) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if( e.detail.message.trim() == 'look' ){
|
if( e.detail.message.trim() == 'look' ){
|
||||||
let scene = xrf.frag.pos.last ? xrf.scene.getObjectByName(xrf.frag.pos.last) : xrf.scene
|
let transcript = xrf.sceneToTranscript(false,false,true)
|
||||||
let message = `<div class="transcript">${xrf.sceneToTranscript(scene)}</div><br>possible destinations in this area:${listExits(scene)}`
|
.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
|
e.detail.halt = true // dont print command to screen
|
||||||
$chat.send({message})
|
$chat.send({message})
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,13 @@ window.frontend = (opts) => new Proxy({
|
||||||
}
|
}
|
||||||
let root = data.mesh.portal ? data.mesh.portal.stencilObject : data.mesh
|
let root = data.mesh.portal ? data.mesh.portal.stencilObject : data.mesh
|
||||||
let transcript = xrf.sceneToTranscript(root,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 (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
|
if( !html ) return
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,23 @@
|
||||||
xrf.sceneToTranscript = (scene, ignoreMesh ) => {
|
xrf.sceneToTranscript = (scene, node, currentPosition ) => {
|
||||||
let transcript = ''
|
let items = []
|
||||||
|
scene = currentPosition && xrf.frag.pos.last ? xrf.scene.getObjectByName(xrf.frag.pos.last) : scene || xrf.scene
|
||||||
scene.traverse( (n) => {
|
scene.traverse( (n) => {
|
||||||
let isSRC = false
|
let isSRC = false
|
||||||
n.traverseAncestors( (m) => m.userData.src ? isSRC = true : false )
|
n.traverseAncestors( (m) => m.userData.src ? isSRC = true : false )
|
||||||
if( !isSRC && n.userData['aria-description'] && (!ignoreMesh || n.uuid != ignoreMesh.uuid) ){
|
if( !isSRC && n.userData['aria-description'] && (!node || n.uuid != node.uuid) ){
|
||||||
transcript += `<b>#${n.name}</b> ${n.userData['aria-description']}. `
|
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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue