diff --git a/index.html b/index.html index 4dca04f..ec0edc8 100644 --- a/index.html +++ b/index.html @@ -112,10 +112,11 @@ const url = "https://fabien.benetou.fr/PIMVRdata/CabinData?action=" var primarySide = 0 const sides = ["right", "left"] var generators = "line-link-entities link screenstack dynamic-view selectionboxonpinches keyboard " - + "commands-from-external-json glossary timeline issues web-url background-via-url observableui hidableenvironmentfot fot" + + "commands-from-external-json glossary timeline issues web-url background-via-url observableui hidableenvironmentfot fot webdav" // could be an array proper completed on each relevant component registration var heightAdjustableClasses = ["commands-from-external-json"] const webdavURL = "https://webdav.benetou.fr"; +var webdavClient // could add a dedicated MakeyMakey mode with a fixed camera, e.g bird eye view, and an action based on some physical input that others, thanks to NAF, could see or even use. // ?inputmode=makeymakey @@ -796,7 +797,7 @@ AFRAME.registerComponent('pinchsecondary', { this.el.addEventListener('pinchended', function (event) { selectedElement = getClosestTargetElement( event.detail.position ) // 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 ) selectedElement = null if (setupMode) setupBBox["B"] = event.detail.position if ( setupBBox["A"] && setupBBox["B"] ) { @@ -1192,7 +1193,7 @@ function parseJXR( code ){ return newcode } -function interpretJXR( code ){ +function interpretJXR( code, sourceElement = null ){ if (code.length == 1) { // special case of being a single character, thus keyboard if (code == ">") { // Enter equivalent addNewNote( hudTextEl.getAttribute("value") ) @@ -1203,13 +1204,22 @@ function interpretJXR( code ){ appendToHUD( code ) } } - if (!code.match(/^jxr /)) return + if (!code.match(/^jxr /)) { + if (sourceElement && sourceElement.className && generators.includes(sourceElement.className) ) + handleFromGenerator(sourceElement) + return + } var uninterpreted = code var parseCode = "" code.split("\n").map( lineOfCode => parseCode += parseJXR( lineOfCode ) + ";" ) // could ignore meta code e.g showhistory / saveHistoryAsCompoundSnippet commandhistory.push( {date: +Date.now(), uninterpreted: uninterpreted, interpreted: parseCode} ) + // examples to test via the console without putting the headset on: + /* + selectedElement = document.querySelectorAll(".commands-from-external-json")[1] ; + interpretJXR( selectedElement.getAttribute("value"), selectedElement ); + */ console.log( parseCode ) try { eval( parseCode ) @@ -1221,6 +1231,23 @@ function interpretJXR( code ){ // opt re-run it by moving the corresponding text in target volume } +function handleFromGenerator(el){ + let value = el.getAttribute("value") + let generatorName = el.className // hijacking classes, could rely on a dedicated attribute instead, e.g generator + console.log("trying to get", value, "from generator", generatorName) + if (generatorName == "webdav"){ + console.log("webdav generator, trying to handle files and directories") + webdavClient.stat(value).then( s => { + console.log("webdav stat", s) + if ( s.type == "directory") + webdavClient.getDirectoryContents(value).then( d => d.map( (c,i) => addNewNote( c.filename , "-1 "+(i/10+1)+" -1", undefined, undefined, generatorName) ) ) + else + console.log("it's a file of MIME", s.mime) + }) + // assume its a directory, not a file. If file, no error though.... but no content either. + } +} + AFRAME.registerComponent('toolbox', { // ununsed init: function(){ var el = this.el @@ -1348,13 +1375,12 @@ AFRAME.registerComponent('dynamic-view', { AFRAME.registerComponent('webdav', { init:function(){ // could become a parameter instead with optional credentials - const client = window.WebDAV.createClient(webdavURL); + webdavClient = window.WebDAV.createClient(webdavURL); let generatorName = this.attrName - async function getDirectory(path = "/"){ - return await client.getDirectoryContents(path); - } - getDirectory().then( d => d.map( (c,i) => addNewNote( c.filename , "-1 "+(i/10+1)+" -1", undefined, undefined, generatorName) ) ) + webdavClient.getDirectoryContents("/").then( d => d.map( (c,i) => addNewNote( c.filename , "-1 "+(i/10+1)+" -1", undefined, undefined, generatorName) ) ) // null doesn't fallback to default parameter. Fine when truly optional but fails otherwise, so prefer undefined. + // on the impact of provenance https://git.benetou.fr/utopiah/text-code-xr-engine/issues/52#issuecomment-209 + // see interpretJXR and parseJXR, arguably others, e.g keyboard, could be used instead on specific tests, e.g length }, });