diff --git a/src/myverse/tronverse/tronverse-icosagallery.jpg b/src/myverse/tronverse/tronverse-icosagallery.jpg new file mode 100644 index 0000000..d1b6d42 Binary files /dev/null and b/src/myverse/tronverse/tronverse-icosagallery.jpg differ diff --git a/src/page/dir.html b/src/page/dir.html index beecce1..ddb1d51 100644 --- a/src/page/dir.html +++ b/src/page/dir.html @@ -39,7 +39,7 @@ end}
{if items then - function getURL(url) + function getURL(url, item) if app.arg[1] == 'generate' or url:match("://") then url = '?view=3D#janus.url=' .. EscapeFragment( url ) url = util.baseURLify(url) @@ -54,15 +54,29 @@ end} local visible = item.view2D == nil or (item.view2D ~= nil and item.view2D ~= false) if visible then local icon = 'list-tree' + local url = item.url local thumbnail = '' if #item.thumbnail > 0 then thumbnail = 'style="background-image: url(' .. EscapeFragment( util.stripPath(item.thumbnail) ) .. ');"' end - if item.view3D or item.portal3D == false then icon = 'play' end + if (item.view3D or item.portal3D == false) + or (item.janusxr and item.janusxr.room) + or (item.xrfragment and item.xrfragment.href) + then + url = url .. '?view=3D' + icon = 'play' + end print([[
- +
 ]] .. item.title .. [[ + ]] .. ( + item.janusxr and item.janusxr.room and [[ + + + + ]] or '' + ) .. [[
diff --git a/src/page/janusxr.html b/src/page/janusxr.html index e866fa7..f78ea73 100644 --- a/src/page/janusxr.html +++ b/src/page/janusxr.html @@ -72,7 +72,7 @@ end} {if not defined(item) and defined(items) and #items > 0 then - local layout = itemdir.layout or '' + local layout = (itemdir.janusxr and itemdir.janusxr.layout) or '' if #layout > 0 and app.plugin.janusxr.layout[ layout ] then print( app.plugin.janusxr.layout[ layout ].render(items) ) else @@ -81,7 +81,7 @@ end} end} {if not defined(item) and defined(itemsremote) and #itemsremote > 0 then for i,v in pairs(itemsremote) do - local width = v.portal_width or tonumber( app.opts.plugin_global_portal_width ) + local width = (v.janusxr and v.janusxr.portal_width) or tonumber( app.opts.plugin_global_portal_width ) local center = -((#itemsremote*width)/1.3) + (i*width) local url = v.url local thumb = ' shader_id="defaultportal" round="true"' diff --git a/src/plugin/janusxr/layout/grid.lua b/src/plugin/janusxr/layout/grid.lua index dccc6dc..0aef867 100644 --- a/src/plugin/janusxr/layout/grid.lua +++ b/src/plugin/janusxr/layout/grid.lua @@ -14,7 +14,6 @@ local grid = { local turns = 0 local index = 0 for i, v in pairs(items) do - jml = '\n' local url = v.redirect and v.redirect or v.url local overlay = v.title:match('overlay') and true or false -- Position current item diff --git a/src/plugin/janusxr/layout/portals.lua b/src/plugin/janusxr/layout/portals.lua index bdfb4ea..d689e6a 100644 --- a/src/plugin/janusxr/layout/portals.lua +++ b/src/plugin/janusxr/layout/portals.lua @@ -3,11 +3,11 @@ local portals = { local jml = '' for i,v in pairs(items) do local url = v.url - local width = tonumber(app.opts.plugin_global_portal_width ) + local width = util.pluck('parent.janusxr.portal_width', v, false) or app.opts.plugin_global_portal_width + width = tonumber(width) local thumb = ' shader_id="defaultportal"' if #v.thumbnail > 0 then thumb = ' thumb_id="img' .. i .. '" ' - if v.portal_width then width = tonumber(v.portal_width) end end local center = -((#items*width)/1.3) + (i*width) if v.dir then url = url .. "/" end diff --git a/src/plugin/openbrush.lua b/src/plugin/openbrush.lua index 4da1533..51692a9 100644 --- a/src/plugin/openbrush.lua +++ b/src/plugin/openbrush.lua @@ -11,32 +11,42 @@ local function scanTiltFile(exp) end end -local function scanForOpenBrush(exp) - local tags = app.plugin.openbrush.tags - if not tags then - tags = util.split( app.opts.plugin_openbrush_sync_hashtag, ' ') - table.insert( tags,"openbrush") - app.plugin.openbrush.tags = tags - end +local function scanForOpenBrush(exp,opts) + local tags = app.plugin.openbrush.getTags() foreach( tags, function(k,tag) tag = tag:gsub("#","") - if exp.path:match('/' .. tag:gsub("-","%%-") .. '/') then -- might not be precise enough - if not exp.parent.janusxr then - exp.parent.janusxr = {} + if exp.url:match( app.plugin.openbrush.pattern.collection(tag) ) then -- collection + if not exp.janusxr then + exp.janusxr = {} end - exp.parent.janusxr.room = app.opts[ "plugin_openbrush_wrap_room_" .. app.opts.plugin_openbrush_layout ] or 'empty' - exp.parent.portal_width = tonumber( app.opts.plugin_openbrush_portal_width ) - exp.parent.grid_size = tonumber( app.opts.plugin_openbrush_grid_size ) - exp.parent.layout = app.opts.plugin_openbrush_layout + exp.janusxr.layout = app.opts.plugin_openbrush_layout + exp.janusxr.room = app.opts[ "plugin_openbrush_wrap_room_" .. app.opts.plugin_openbrush_layout ] or 'empty' + exp.janusxr.portal_width = tonumber( app.opts.plugin_openbrush_portal_width ) + exp.janusxr.grid_size = tonumber( app.opts.plugin_openbrush_grid_size ) end end) scanTiltFile(exp) end - -app.on('scan_experience', scanForOpenBrush ) -app.on('scan_experience_file', scanForOpenBrush ) -app.on("scan_experience_janusxr", function(opts) scanForOpenBrush(opts.exp) end) +app.on('scan_experience', function(exp) scanForOpenBrush(exp,{dir=true}) end) +app.on('scan_experience_janusxr', function(opts) + local exp = opts.exp + if exp then + local tags = app.plugin.openbrush.getTags() + foreach( tags, function(k,tag) + tag = tag:gsub("#","") + if exp.url:match( app.plugin.openbrush.pattern.asset(tag) ) then -- asset + -- disable janusxr room wrapping (if any) + exp.janusxr = nil + -- also for the parent, and redirect to indirect child asset + if exp.parent.layout == nil and exp.parent.janusxr then + exp.parent.janusxr = nil + exp.parent.redirect = exp.url + end + end + end) + end +end) app.on('set', function(k,v) end) @@ -62,7 +72,7 @@ local plugin = { key='app.opts.plugin_openbrush_layout', title='Layout assets', info='NOTE: use #overlay in asset-title to skip layout (sky/floor/e.g.)', - default="grid", + default="portals", values={portals="As portals", grid="As grid"} }, { @@ -205,6 +215,21 @@ local plugin = { } }, + pattern = { + collection = function(tag) return '/' .. tag:gsub("-","%%-") .. '$' end, + asset = function(tag) return '/' .. tag:gsub("-","%%-") .. '/' end, + }, + + getTags = function() + local tags = app.plugin.openbrush.tags + if not tags then + tags = util.split( app.opts.plugin_openbrush_sync_hashtag, ' ') + table.insert( tags,"openbrush") + app.plugin.openbrush.tags = tags + end + return tags + end, + -- expected by src/.lua/apiSync.lua apiCall = function(tag) return 'https://api.' .. app.opts.plugin_openbrush_sync_URL .. '/v1/assets?xrforge=' .. EscapeFragment(app.host) diff --git a/src/test/main.lua b/src/test/main.lua index 538631b..2a8b523 100644 --- a/src/test/main.lua +++ b/src/test/main.lua @@ -5,13 +5,13 @@ local describe, it, expect = lust.describe, lust.it, lust.expect lust.queueServerRequest = util.queueServerRequest ---require('test/plugin_global')(lust) ---require('test/plugin_git')(lust) ---require('test/plugin_diskscan')(lust) ---require('test/plugin_xrfragment')(lust) +require('test/plugin_global')(lust) +require('test/plugin_git')(lust) +require('test/plugin_diskscan')(lust) +require('test/plugin_xrfragment')(lust) require('test/plugin_janusxr')(lust) ---require('test/plugin_openbrush')(lust) ---require('test/util')(lust) +require('test/plugin_openbrush')(lust) +require('test/util')(lust) if lust.errors == 0 then print("✅ all tests passed") diff --git a/src/test/plugin_git.lua b/src/test/plugin_git.lua index bace5ea..7c46fbd 100644 --- a/src/test/plugin_git.lua +++ b/src/test/plugin_git.lua @@ -13,6 +13,7 @@ return function(lust) app.init() local destdir = app.opts.plugin_diskscan_dir .. '/' .. 'xrfragment' expect( util.fileExist( destdir ) ).to.be.truthy() + os.execute('rm -rf ' .. destdir) end) end) diff --git a/src/test/plugin_janusxr.lua b/src/test/plugin_janusxr.lua index aa47490..e92f6f9 100644 --- a/src/test/plugin_janusxr.lua +++ b/src/test/plugin_janusxr.lua @@ -30,7 +30,25 @@ return function(lust) describe('ℹ️ wrap AFRAME file', function() -- Can be nested it('detect & serve to iframe', function() - -- *TODO* + app.init() + app.use( require('page/dir').middleware ) + app.use( app.response() ) + app.on('response', function(opts) + expect( not opts.res._body:match('use_local_asset=""') ).to.be.truthy() + expect( not opts.res._body:match('') ).to.be.truthy() + end) + + local url = '/myverse/janusxr_tutorial/AFRAME' + + foreach(app.cache.items, function(k,exp) + if exp.url:match(url) then + if exp.url:match( url .. "$") then + --print_r(exp) + lust.queueServerRequest('GET', url, nil, nil, nil, nil, nil, 8080 ) + app.run() + end + end + end) end) end) diff --git a/src/test/plugin_openbrush.lua b/src/test/plugin_openbrush.lua index 8ed6cce..774b2e1 100644 --- a/src/test/plugin_openbrush.lua +++ b/src/test/plugin_openbrush.lua @@ -17,6 +17,29 @@ return function(lust) expect( t.assets and #t.assets > 0 ).to.be.truthy() end) + describe('ℹ️ grid-layout', function() -- Can be nested + it('unwrap janusxr-room for assets', function() + app.init() + app.use( require('page/dir').middleware ) + app.use( app.response() ) + app.on('response', function(opts) + expect( not opts.res._body:match('/myverse/tronverse/tronverse-icosagallery/_0dycp4HDxf4-tronverse_floor-overlay-tronverse-icosagallery/tronverse_floor.glb') ).to.be.truthy() + end) + + local url = '/myverse/tronverse/tronverse-icosagallery' + + foreach(app.cache.items, function(k,exp) + if exp.url:match(url) then + if exp.url:match( url .. "$") then + --print_r(exp) + lust.queueServerRequest('GET', url, nil, nil, nil, nil, nil, 8080 ) + app.run() + end + end + end) + end) + end) + --describe('download icosa.gallery assets', function() -- Can be nested -- local json = util.readfile('/zip/test/json/icosagallery.json') -- local opts = {body=json}