From 9dbc57991d6c8ab62032b3c8d7c09174b1f282c4 Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Mon, 13 May 2024 17:43:32 +0200 Subject: [PATCH] working principle, one console per jxr snippet (temporary visible toggling on execution) --- index.html | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++- jxr-core.js | 21 +++++++++++++++++-- 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 80d1517..f52f80a 100644 --- a/index.html +++ b/index.html @@ -4,15 +4,64 @@ + - + diff --git a/jxr-core.js b/jxr-core.js index 87b0592..8a26ce1 100644 --- a/jxr-core.js +++ b/jxr-core.js @@ -129,8 +129,11 @@ AFRAME.registerComponent('pinchsecondary', { this.el.addEventListener('pinchended', function (event) { selectedElement = getClosestTargetElement( event.detail.position ) selectedElements.push({element:selectedElement, timestamp:Date.now(), primary:false}) + // could push on pinchstarted instead // if close enough to a target among a list of potential targets, unselect previous target then select new - if (selectedElement) interpretJXR( selectedElement.getAttribute("value") ) + if (selectedElement) interpretJXR( selectedElement.getAttribute("value"), selectedElement ) + // if (selectedElement) selectedElement.emit('released', {element:selectedElement, timestamp:Date.now(), primary:false}) + // would be coherent BUT so far NOT testing on e.detail.primary thus probably getting unexpected behaviors selectedElement = null }); this.el.addEventListener('pinchmoved', function (event) { @@ -477,7 +480,7 @@ function parseJXR( code ){ return newcode } -function interpretJXR( code ){ +function interpretJXR( code, sourceElement ){ if (!code) return if (code.length == 1) { // special case of being a single character, thus keyboard if (code == ">") { // Enter equivalent @@ -502,6 +505,20 @@ function interpretJXR( code ){ commandhistory.push( {date: +Date.now(), uninterpreted: uninterpreted, interpreted: parseCode} ) console.log( parseCode ) + if (sourceElement){ + let consoleEl = sourceElement.querySelector("a-console") + if (consoleEl === null){ + consoleEl = document.createElement("a-console") + consoleEl.setAttribute("position","1 -.4 0") + consoleEl.setAttribute("font-size","30") + consoleEl.setAttribute("height",".4") + consoleEl.setAttribute("width","2") + consoleEl.setAttribute("skip-intro",true) + sourceElement.appendChild(consoleEl) + } + consoleEl.setAttribute("visible", "true") + setTimeout( _ => consoleEl.setAttribute("visible", "false") , 10000) + } try { eval( parseCode ) } catch (error) {