added roundrobin
This commit is contained in:
parent
80a93d3538
commit
d948cb2d8b
|
@ -240,7 +240,9 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
Frag_h["description"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["session"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.NAVIGATOR | xrfragment_XRF.EMBEDDED | xrfragment_XRF.PROMPT;
|
||||
if(value.length == 0 && !Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
var v = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
v.validate(key);
|
||||
resultMap[key] = v;
|
||||
return true;
|
||||
}
|
||||
if(key.split(".").length > 1 && value.split(".").length > 1) {
|
||||
|
@ -250,11 +252,11 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:77:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
console.log("src/xrfragment/Parser.hx:79:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:80:","✔ " + key + ": " + v.string);
|
||||
console.log("src/xrfragment/Parser.hx:82:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
}
|
||||
|
@ -615,6 +617,20 @@ xrf.query = function(){
|
|||
alert("queries are not implemented (yet) for this particular framework")
|
||||
}
|
||||
|
||||
xrf.roundrobin = (frag, store) => {
|
||||
if( !frag.args || frag.args.length == 0 ) return 0
|
||||
if( !store.rr ) store.rr = {}
|
||||
let label = frag.fragment
|
||||
if( store.rr[label] ) return store.rr[label].next()
|
||||
store.rr[label] = frag.args
|
||||
store.rr[label].next = () => {
|
||||
store.rr[label].index = (store.rr[label].index + 1) % store.rr[label].length
|
||||
return store.rr[label].index
|
||||
}
|
||||
return store.rr[label].index = 0
|
||||
}
|
||||
|
||||
|
||||
// map library functions to xrf
|
||||
for ( let i in xrfragment ) xrf[i] = xrfragment[i]
|
||||
/*
|
||||
|
@ -860,7 +876,7 @@ xrf.parseModel = function(model,url){
|
|||
|
||||
xrf.getLastModel = () => xrf.model.last
|
||||
|
||||
xrf.eval = function( url, model, flags ){ // evaluate local toplevel url
|
||||
xrf.eval = function( url, model, flags ){ // evaluate fragments in url
|
||||
let notice = false
|
||||
model = model || xrf.model
|
||||
let { THREE, camera } = xrf
|
||||
|
@ -885,7 +901,7 @@ xrf.eval.mesh = (mesh,model) => { // evaluate embedded fragments (metadata)
|
|||
}
|
||||
}
|
||||
|
||||
xrf.eval.fragment = (k, opts ) => {
|
||||
xrf.eval.fragment = (k, opts ) => { // evaluate one fragment
|
||||
// call native function (xrf/env.js e.g.), or pass it to user decorator
|
||||
let func = xrf.frag[k] || function(){}
|
||||
if( xrf[k] ) xrf[k]( func, opts.frag[k], opts)
|
||||
|
@ -1041,6 +1057,8 @@ xrf.frag.href = function(v, opts){
|
|||
opts.embedded = v // indicate embedded XR fragment
|
||||
let { mesh, model, camera, scene, renderer, THREE} = opts
|
||||
|
||||
if( mesh.userData.XRF.href.exec ) return // mesh already initialized
|
||||
|
||||
const world = {
|
||||
pos: new THREE.Vector3(),
|
||||
scale: new THREE.Vector3(),
|
||||
|
@ -1158,7 +1176,6 @@ xrf.frag.pos = function(v, opts){
|
|||
}
|
||||
const doPredefinedView = (opts) => {
|
||||
let {frag,scene} = opts
|
||||
console.dir(opts)
|
||||
|
||||
const selectionOfInterest = (id,scene,mesh) => {
|
||||
// Selection of Interest if predefined_view matches object name
|
||||
|
@ -1170,7 +1187,6 @@ const doPredefinedView = (opts) => {
|
|||
xrf.emit('selection',opts)
|
||||
.then( () => {
|
||||
const margin = 1.2
|
||||
console.dir(mesh.scale.x)
|
||||
mesh.scale.multiplyScalar( margin )
|
||||
mesh.selection = new xrf.THREE.BoxHelper(mesh,0xff00ff)
|
||||
mesh.scale.divideScalar( margin )
|
||||
|
@ -1182,12 +1198,12 @@ const doPredefinedView = (opts) => {
|
|||
}
|
||||
}
|
||||
|
||||
const predefinedView = (id,scene,mesh) => {
|
||||
const predefinedView = (frag,scene,mesh) => {
|
||||
let id = frag.string
|
||||
if( mesh.userData[id] ){
|
||||
let frag = xrf.URI.parse( mesh.userData[id], xrf.XRF.NAVIGATOR | xrf.XRF.PV_OVERRIDE | xrf.XRF.EMBEDDED )
|
||||
for ( let k in frag ){
|
||||
let opts = {frag, model, camera: xrf.camera, scene: xrf.scene, renderer: xrf.renderer, THREE: xrf.THREE }
|
||||
console.log(k)
|
||||
xrf.emit('predefinedView',opts)
|
||||
.then( () => xrf.eval.fragment(k,opts) )
|
||||
}
|
||||
|
@ -1198,12 +1214,13 @@ const doPredefinedView = (opts) => {
|
|||
for ( let i in frag ) {
|
||||
let v = frag[i]
|
||||
if( v.is( xrf.XRF.PV_EXECUTE ) ){
|
||||
if( v.args ) v = v.args[ xrf.roundrobin(v,xrf.model) ]
|
||||
// wait for nested instances to arrive at the scene
|
||||
setTimeout( () => {
|
||||
if( !scene ) return
|
||||
scene.traverse( (mesh) => {
|
||||
selectionOfInterest( v.fragment, scene, mesh )
|
||||
predefinedView( v.fragment, scene, mesh )
|
||||
selectionOfInterest( v.string, scene, mesh )
|
||||
predefinedView( v , scene, mesh )
|
||||
})
|
||||
},100)
|
||||
}
|
||||
|
@ -1256,10 +1273,16 @@ xrf.frag.q = function(v, opts){
|
|||
|
||||
const showHide = () => {
|
||||
let q = frag.q.query
|
||||
console.log(frag.q.string)
|
||||
console.dir(frag)
|
||||
scene.traverse( (mesh) => {
|
||||
for ( let i in q ) {
|
||||
if( i == mesh.name && q[i].id != undefined ) mesh.visible = q[i].id
|
||||
if( i == mesh.userData.class && q[i].class != undefined ) mesh.visible = q[i].class
|
||||
let isMeshId = q[i].id != undefined
|
||||
let isMeshClass = q[i].class != undefined
|
||||
let isMeshProperty = q[i].rules != undefined && q[i].rules.length && !isMeshId && !isMeshClass
|
||||
if( isMeshId && i == mesh.name ) mesh.visible = q[i].id
|
||||
if( isMeshClass && i == mesh.userData.class ) mesh.visible = q[i].class
|
||||
if( isMeshProperty && mesh.userData[i] ) mesh.visible = (new xrf.Query(frag.q.string)).testProperty(i,mesh.userData[i])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -1311,7 +1334,7 @@ xrf.frag.src = function(v, opts){
|
|||
src.scale.copy( mesh.scale )
|
||||
mesh.add(src)
|
||||
console.dir(opts)
|
||||
if( !opts.recursive ) mesh.material.visible = false // lets hide the preview object because deleting disables animations
|
||||
if( !opts.recursive ) mesh.material.visible = false // lets hide the preview object because deleting disables animations+nested objs
|
||||
},10)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -240,7 +240,9 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
Frag_h["description"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["session"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.NAVIGATOR | xrfragment_XRF.EMBEDDED | xrfragment_XRF.PROMPT;
|
||||
if(value.length == 0 && !Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
var v = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
v.validate(key);
|
||||
resultMap[key] = v;
|
||||
return true;
|
||||
}
|
||||
if(key.split(".").length > 1 && value.split(".").length > 1) {
|
||||
|
@ -250,11 +252,11 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:77:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
console.log("src/xrfragment/Parser.hx:79:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:80:","✔ " + key + ": " + v.string);
|
||||
console.log("src/xrfragment/Parser.hx:82:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
}
|
||||
|
|
|
@ -1547,8 +1547,9 @@ __xrfragment_Parser.parse = function(key,value,resultMap)
|
|||
Frag_h.session = value1;
|
||||
end;
|
||||
if ((__lua_lib_luautf8_Utf8.len(value) == 0) and (Frag_h[key] == nil)) then
|
||||
local value = __xrfragment_XRF.new(key, _hx_bit.bor(__xrfragment_XRF.PV_EXECUTE,__xrfragment_XRF.NAVIGATOR));
|
||||
resultMap[key] = value;
|
||||
local v = __xrfragment_XRF.new(key, _hx_bit.bor(__xrfragment_XRF.PV_EXECUTE,__xrfragment_XRF.NAVIGATOR));
|
||||
v:validate(key);
|
||||
resultMap[key] = v;
|
||||
do return true end;
|
||||
end;
|
||||
local tmp;
|
||||
|
@ -1613,11 +1614,11 @@ __xrfragment_Parser.parse = function(key,value,resultMap)
|
|||
end;
|
||||
local v = __xrfragment_XRF.new(key, ret);
|
||||
if (not v:validate(value)) then
|
||||
__haxe_Log.trace(Std.string(Std.string(Std.string(Std.string("⚠ fragment '") .. Std.string(key)) .. Std.string("' has incompatible value (")) .. Std.string(value)) .. Std.string(")"), _hx_o({__fields__={fileName=true,lineNumber=true,className=true,methodName=true},fileName="src/xrfragment/Parser.hx",lineNumber=77,className="xrfragment.Parser",methodName="parse"}));
|
||||
__haxe_Log.trace(Std.string(Std.string(Std.string(Std.string("⚠ fragment '") .. Std.string(key)) .. Std.string("' has incompatible value (")) .. Std.string(value)) .. Std.string(")"), _hx_o({__fields__={fileName=true,lineNumber=true,className=true,methodName=true},fileName="src/xrfragment/Parser.hx",lineNumber=79,className="xrfragment.Parser",methodName="parse"}));
|
||||
do return false end;
|
||||
end;
|
||||
if (__xrfragment_Parser.debug) then
|
||||
__haxe_Log.trace(Std.string(Std.string(Std.string("✔ ") .. Std.string(key)) .. Std.string(": ")) .. Std.string(v.string), _hx_o({__fields__={fileName=true,lineNumber=true,className=true,methodName=true},fileName="src/xrfragment/Parser.hx",lineNumber=80,className="xrfragment.Parser",methodName="parse"}));
|
||||
__haxe_Log.trace(Std.string(Std.string(Std.string("✔ ") .. Std.string(key)) .. Std.string(": ")) .. Std.string(v.string), _hx_o({__fields__={fileName=true,lineNumber=true,className=true,methodName=true},fileName="src/xrfragment/Parser.hx",lineNumber=82,className="xrfragment.Parser",methodName="parse"}));
|
||||
end;
|
||||
resultMap[key] = v;
|
||||
end;
|
||||
|
|
|
@ -240,7 +240,9 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
Frag_h["description"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["session"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.NAVIGATOR | xrfragment_XRF.EMBEDDED | xrfragment_XRF.PROMPT;
|
||||
if(value.length == 0 && !Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
var v = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
v.validate(key);
|
||||
resultMap[key] = v;
|
||||
return true;
|
||||
}
|
||||
if(key.split(".").length > 1 && value.split(".").length > 1) {
|
||||
|
@ -250,11 +252,11 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:77:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
console.log("src/xrfragment/Parser.hx:79:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:80:","✔ " + key + ": " + v.string);
|
||||
console.log("src/xrfragment/Parser.hx:82:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
}
|
||||
|
|
|
@ -1317,8 +1317,9 @@ class xrfragment_Parser:
|
|||
Frag.h["description"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING)
|
||||
Frag.h["session"] = (((((xrfragment_XRF.ASSET | xrfragment_XRF.T_URL) | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.NAVIGATOR) | xrfragment_XRF.EMBEDDED) | xrfragment_XRF.PROMPT)
|
||||
if ((len(value) == 0) and (not (key in Frag.h))):
|
||||
value1 = xrfragment_XRF(key,(xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR))
|
||||
setattr(resultMap,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),value1)
|
||||
v = xrfragment_XRF(key,(xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR))
|
||||
v.validate(key)
|
||||
setattr(resultMap,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),v)
|
||||
return True
|
||||
if ((len(key.split(".")) > 1) and ((len(value.split(".")) > 1))):
|
||||
value1 = xrfragment_XRF(key,(((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_STRING) | xrfragment_XRF.PROP_BIND))
|
||||
|
|
|
@ -240,7 +240,9 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
Frag_h["description"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["session"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.NAVIGATOR | xrfragment_XRF.EMBEDDED | xrfragment_XRF.PROMPT;
|
||||
if(value.length == 0 && !Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
var v = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
v.validate(key);
|
||||
resultMap[key] = v;
|
||||
return true;
|
||||
}
|
||||
if(key.split(".").length > 1 && value.split(".").length > 1) {
|
||||
|
@ -250,11 +252,11 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:77:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
console.log("src/xrfragment/Parser.hx:79:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:80:","✔ " + key + ": " + v.string);
|
||||
console.log("src/xrfragment/Parser.hx:82:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
}
|
||||
|
@ -615,6 +617,20 @@ xrf.query = function(){
|
|||
alert("queries are not implemented (yet) for this particular framework")
|
||||
}
|
||||
|
||||
xrf.roundrobin = (frag, store) => {
|
||||
if( !frag.args || frag.args.length == 0 ) return 0
|
||||
if( !store.rr ) store.rr = {}
|
||||
let label = frag.fragment
|
||||
if( store.rr[label] ) return store.rr[label].next()
|
||||
store.rr[label] = frag.args
|
||||
store.rr[label].next = () => {
|
||||
store.rr[label].index = (store.rr[label].index + 1) % store.rr[label].length
|
||||
return store.rr[label].index
|
||||
}
|
||||
return store.rr[label].index = 0
|
||||
}
|
||||
|
||||
|
||||
// map library functions to xrf
|
||||
for ( let i in xrfragment ) xrf[i] = xrfragment[i]
|
||||
/*
|
||||
|
@ -860,7 +876,7 @@ xrf.parseModel = function(model,url){
|
|||
|
||||
xrf.getLastModel = () => xrf.model.last
|
||||
|
||||
xrf.eval = function( url, model, flags ){ // evaluate local toplevel url
|
||||
xrf.eval = function( url, model, flags ){ // evaluate fragments in url
|
||||
let notice = false
|
||||
model = model || xrf.model
|
||||
let { THREE, camera } = xrf
|
||||
|
@ -885,7 +901,7 @@ xrf.eval.mesh = (mesh,model) => { // evaluate embedded fragments (metadata)
|
|||
}
|
||||
}
|
||||
|
||||
xrf.eval.fragment = (k, opts ) => {
|
||||
xrf.eval.fragment = (k, opts ) => { // evaluate one fragment
|
||||
// call native function (xrf/env.js e.g.), or pass it to user decorator
|
||||
let func = xrf.frag[k] || function(){}
|
||||
if( xrf[k] ) xrf[k]( func, opts.frag[k], opts)
|
||||
|
@ -1041,6 +1057,8 @@ xrf.frag.href = function(v, opts){
|
|||
opts.embedded = v // indicate embedded XR fragment
|
||||
let { mesh, model, camera, scene, renderer, THREE} = opts
|
||||
|
||||
if( mesh.userData.XRF.href.exec ) return // mesh already initialized
|
||||
|
||||
const world = {
|
||||
pos: new THREE.Vector3(),
|
||||
scale: new THREE.Vector3(),
|
||||
|
@ -1158,7 +1176,6 @@ xrf.frag.pos = function(v, opts){
|
|||
}
|
||||
const doPredefinedView = (opts) => {
|
||||
let {frag,scene} = opts
|
||||
console.dir(opts)
|
||||
|
||||
const selectionOfInterest = (id,scene,mesh) => {
|
||||
// Selection of Interest if predefined_view matches object name
|
||||
|
@ -1170,7 +1187,6 @@ const doPredefinedView = (opts) => {
|
|||
xrf.emit('selection',opts)
|
||||
.then( () => {
|
||||
const margin = 1.2
|
||||
console.dir(mesh.scale.x)
|
||||
mesh.scale.multiplyScalar( margin )
|
||||
mesh.selection = new xrf.THREE.BoxHelper(mesh,0xff00ff)
|
||||
mesh.scale.divideScalar( margin )
|
||||
|
@ -1182,12 +1198,12 @@ const doPredefinedView = (opts) => {
|
|||
}
|
||||
}
|
||||
|
||||
const predefinedView = (id,scene,mesh) => {
|
||||
const predefinedView = (frag,scene,mesh) => {
|
||||
let id = frag.string
|
||||
if( mesh.userData[id] ){
|
||||
let frag = xrf.URI.parse( mesh.userData[id], xrf.XRF.NAVIGATOR | xrf.XRF.PV_OVERRIDE | xrf.XRF.EMBEDDED )
|
||||
for ( let k in frag ){
|
||||
let opts = {frag, model, camera: xrf.camera, scene: xrf.scene, renderer: xrf.renderer, THREE: xrf.THREE }
|
||||
console.log(k)
|
||||
xrf.emit('predefinedView',opts)
|
||||
.then( () => xrf.eval.fragment(k,opts) )
|
||||
}
|
||||
|
@ -1198,12 +1214,13 @@ const doPredefinedView = (opts) => {
|
|||
for ( let i in frag ) {
|
||||
let v = frag[i]
|
||||
if( v.is( xrf.XRF.PV_EXECUTE ) ){
|
||||
if( v.args ) v = v.args[ xrf.roundrobin(v,xrf.model) ]
|
||||
// wait for nested instances to arrive at the scene
|
||||
setTimeout( () => {
|
||||
if( !scene ) return
|
||||
scene.traverse( (mesh) => {
|
||||
selectionOfInterest( v.fragment, scene, mesh )
|
||||
predefinedView( v.fragment, scene, mesh )
|
||||
selectionOfInterest( v.string, scene, mesh )
|
||||
predefinedView( v , scene, mesh )
|
||||
})
|
||||
},100)
|
||||
}
|
||||
|
@ -1256,10 +1273,16 @@ xrf.frag.q = function(v, opts){
|
|||
|
||||
const showHide = () => {
|
||||
let q = frag.q.query
|
||||
console.log(frag.q.string)
|
||||
console.dir(frag)
|
||||
scene.traverse( (mesh) => {
|
||||
for ( let i in q ) {
|
||||
if( i == mesh.name && q[i].id != undefined ) mesh.visible = q[i].id
|
||||
if( i == mesh.userData.class && q[i].class != undefined ) mesh.visible = q[i].class
|
||||
let isMeshId = q[i].id != undefined
|
||||
let isMeshClass = q[i].class != undefined
|
||||
let isMeshProperty = q[i].rules != undefined && q[i].rules.length && !isMeshId && !isMeshClass
|
||||
if( isMeshId && i == mesh.name ) mesh.visible = q[i].id
|
||||
if( isMeshClass && i == mesh.userData.class ) mesh.visible = q[i].class
|
||||
if( isMeshProperty && mesh.userData[i] ) mesh.visible = (new xrf.Query(frag.q.string)).testProperty(i,mesh.userData[i])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -1311,7 +1334,7 @@ xrf.frag.src = function(v, opts){
|
|||
src.scale.copy( mesh.scale )
|
||||
mesh.add(src)
|
||||
console.dir(opts)
|
||||
if( !opts.recursive ) mesh.material.visible = false // lets hide the preview object because deleting disables animations
|
||||
if( !opts.recursive ) mesh.material.visible = false // lets hide the preview object because deleting disables animations+nested objs
|
||||
},10)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -240,7 +240,9 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
Frag_h["description"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["session"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.NAVIGATOR | xrfragment_XRF.EMBEDDED | xrfragment_XRF.PROMPT;
|
||||
if(value.length == 0 && !Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
var v = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
v.validate(key);
|
||||
resultMap[key] = v;
|
||||
return true;
|
||||
}
|
||||
if(key.split(".").length > 1 && value.split(".").length > 1) {
|
||||
|
@ -250,11 +252,11 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:77:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
console.log("src/xrfragment/Parser.hx:79:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:80:","✔ " + key + ": " + v.string);
|
||||
console.log("src/xrfragment/Parser.hx:82:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
}
|
||||
|
@ -615,6 +617,20 @@ xrf.query = function(){
|
|||
alert("queries are not implemented (yet) for this particular framework")
|
||||
}
|
||||
|
||||
xrf.roundrobin = (frag, store) => {
|
||||
if( !frag.args || frag.args.length == 0 ) return 0
|
||||
if( !store.rr ) store.rr = {}
|
||||
let label = frag.fragment
|
||||
if( store.rr[label] ) return store.rr[label].next()
|
||||
store.rr[label] = frag.args
|
||||
store.rr[label].next = () => {
|
||||
store.rr[label].index = (store.rr[label].index + 1) % store.rr[label].length
|
||||
return store.rr[label].index
|
||||
}
|
||||
return store.rr[label].index = 0
|
||||
}
|
||||
|
||||
|
||||
// map library functions to xrf
|
||||
for ( let i in xrfragment ) xrf[i] = xrfragment[i]
|
||||
/*
|
||||
|
@ -860,7 +876,7 @@ xrf.parseModel = function(model,url){
|
|||
|
||||
xrf.getLastModel = () => xrf.model.last
|
||||
|
||||
xrf.eval = function( url, model, flags ){ // evaluate local toplevel url
|
||||
xrf.eval = function( url, model, flags ){ // evaluate fragments in url
|
||||
let notice = false
|
||||
model = model || xrf.model
|
||||
let { THREE, camera } = xrf
|
||||
|
@ -885,7 +901,7 @@ xrf.eval.mesh = (mesh,model) => { // evaluate embedded fragments (metadata)
|
|||
}
|
||||
}
|
||||
|
||||
xrf.eval.fragment = (k, opts ) => {
|
||||
xrf.eval.fragment = (k, opts ) => { // evaluate one fragment
|
||||
// call native function (xrf/env.js e.g.), or pass it to user decorator
|
||||
let func = xrf.frag[k] || function(){}
|
||||
if( xrf[k] ) xrf[k]( func, opts.frag[k], opts)
|
||||
|
@ -1041,6 +1057,8 @@ xrf.frag.href = function(v, opts){
|
|||
opts.embedded = v // indicate embedded XR fragment
|
||||
let { mesh, model, camera, scene, renderer, THREE} = opts
|
||||
|
||||
if( mesh.userData.XRF.href.exec ) return // mesh already initialized
|
||||
|
||||
const world = {
|
||||
pos: new THREE.Vector3(),
|
||||
scale: new THREE.Vector3(),
|
||||
|
@ -1158,7 +1176,6 @@ xrf.frag.pos = function(v, opts){
|
|||
}
|
||||
const doPredefinedView = (opts) => {
|
||||
let {frag,scene} = opts
|
||||
console.dir(opts)
|
||||
|
||||
const selectionOfInterest = (id,scene,mesh) => {
|
||||
// Selection of Interest if predefined_view matches object name
|
||||
|
@ -1170,7 +1187,6 @@ const doPredefinedView = (opts) => {
|
|||
xrf.emit('selection',opts)
|
||||
.then( () => {
|
||||
const margin = 1.2
|
||||
console.dir(mesh.scale.x)
|
||||
mesh.scale.multiplyScalar( margin )
|
||||
mesh.selection = new xrf.THREE.BoxHelper(mesh,0xff00ff)
|
||||
mesh.scale.divideScalar( margin )
|
||||
|
@ -1182,12 +1198,12 @@ const doPredefinedView = (opts) => {
|
|||
}
|
||||
}
|
||||
|
||||
const predefinedView = (id,scene,mesh) => {
|
||||
const predefinedView = (frag,scene,mesh) => {
|
||||
let id = frag.string
|
||||
if( mesh.userData[id] ){
|
||||
let frag = xrf.URI.parse( mesh.userData[id], xrf.XRF.NAVIGATOR | xrf.XRF.PV_OVERRIDE | xrf.XRF.EMBEDDED )
|
||||
for ( let k in frag ){
|
||||
let opts = {frag, model, camera: xrf.camera, scene: xrf.scene, renderer: xrf.renderer, THREE: xrf.THREE }
|
||||
console.log(k)
|
||||
xrf.emit('predefinedView',opts)
|
||||
.then( () => xrf.eval.fragment(k,opts) )
|
||||
}
|
||||
|
@ -1198,12 +1214,13 @@ const doPredefinedView = (opts) => {
|
|||
for ( let i in frag ) {
|
||||
let v = frag[i]
|
||||
if( v.is( xrf.XRF.PV_EXECUTE ) ){
|
||||
if( v.args ) v = v.args[ xrf.roundrobin(v,xrf.model) ]
|
||||
// wait for nested instances to arrive at the scene
|
||||
setTimeout( () => {
|
||||
if( !scene ) return
|
||||
scene.traverse( (mesh) => {
|
||||
selectionOfInterest( v.fragment, scene, mesh )
|
||||
predefinedView( v.fragment, scene, mesh )
|
||||
selectionOfInterest( v.string, scene, mesh )
|
||||
predefinedView( v , scene, mesh )
|
||||
})
|
||||
},100)
|
||||
}
|
||||
|
@ -1256,10 +1273,16 @@ xrf.frag.q = function(v, opts){
|
|||
|
||||
const showHide = () => {
|
||||
let q = frag.q.query
|
||||
console.log(frag.q.string)
|
||||
console.dir(frag)
|
||||
scene.traverse( (mesh) => {
|
||||
for ( let i in q ) {
|
||||
if( i == mesh.name && q[i].id != undefined ) mesh.visible = q[i].id
|
||||
if( i == mesh.userData.class && q[i].class != undefined ) mesh.visible = q[i].class
|
||||
let isMeshId = q[i].id != undefined
|
||||
let isMeshClass = q[i].class != undefined
|
||||
let isMeshProperty = q[i].rules != undefined && q[i].rules.length && !isMeshId && !isMeshClass
|
||||
if( isMeshId && i == mesh.name ) mesh.visible = q[i].id
|
||||
if( isMeshClass && i == mesh.userData.class ) mesh.visible = q[i].class
|
||||
if( isMeshProperty && mesh.userData[i] ) mesh.visible = (new xrf.Query(frag.q.string)).testProperty(i,mesh.userData[i])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -1311,7 +1334,7 @@ xrf.frag.src = function(v, opts){
|
|||
src.scale.copy( mesh.scale )
|
||||
mesh.add(src)
|
||||
console.dir(opts)
|
||||
if( !opts.recursive ) mesh.material.visible = false // lets hide the preview object because deleting disables animations
|
||||
if( !opts.recursive ) mesh.material.visible = false // lets hide the preview object because deleting disables animations+nested objs
|
||||
},10)
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -16,5 +16,19 @@ xrf.query = function(){
|
|||
alert("queries are not implemented (yet) for this particular framework")
|
||||
}
|
||||
|
||||
xrf.roundrobin = (frag, store) => {
|
||||
if( !frag.args || frag.args.length == 0 ) return 0
|
||||
if( !store.rr ) store.rr = {}
|
||||
let label = frag.fragment
|
||||
if( store.rr[label] ) return store.rr[label].next()
|
||||
store.rr[label] = frag.args
|
||||
store.rr[label].next = () => {
|
||||
store.rr[label].index = (store.rr[label].index + 1) % store.rr[label].length
|
||||
return store.rr[label].index
|
||||
}
|
||||
return store.rr[label].index = 0
|
||||
}
|
||||
|
||||
|
||||
// map library functions to xrf
|
||||
for ( let i in xrfragment ) xrf[i] = xrfragment[i]
|
||||
|
|
|
@ -32,6 +32,8 @@ xrf.frag.href = function(v, opts){
|
|||
opts.embedded = v // indicate embedded XR fragment
|
||||
let { mesh, model, camera, scene, renderer, THREE} = opts
|
||||
|
||||
if( mesh.userData.XRF.href.exec ) return // mesh already initialized
|
||||
|
||||
const world = {
|
||||
pos: new THREE.Vector3(),
|
||||
scale: new THREE.Vector3(),
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
const doPredefinedView = (opts) => {
|
||||
let {frag,scene} = opts
|
||||
console.dir(opts)
|
||||
|
||||
const selectionOfInterest = (id,scene,mesh) => {
|
||||
// Selection of Interest if predefined_view matches object name
|
||||
|
@ -12,7 +11,6 @@ const doPredefinedView = (opts) => {
|
|||
xrf.emit('selection',opts)
|
||||
.then( () => {
|
||||
const margin = 1.2
|
||||
console.dir(mesh.scale.x)
|
||||
mesh.scale.multiplyScalar( margin )
|
||||
mesh.selection = new xrf.THREE.BoxHelper(mesh,0xff00ff)
|
||||
mesh.scale.divideScalar( margin )
|
||||
|
@ -24,12 +22,12 @@ const doPredefinedView = (opts) => {
|
|||
}
|
||||
}
|
||||
|
||||
const predefinedView = (id,scene,mesh) => {
|
||||
const predefinedView = (frag,scene,mesh) => {
|
||||
let id = frag.string
|
||||
if( mesh.userData[id] ){
|
||||
let frag = xrf.URI.parse( mesh.userData[id], xrf.XRF.NAVIGATOR | xrf.XRF.PV_OVERRIDE | xrf.XRF.EMBEDDED )
|
||||
for ( let k in frag ){
|
||||
let opts = {frag, model, camera: xrf.camera, scene: xrf.scene, renderer: xrf.renderer, THREE: xrf.THREE }
|
||||
console.log(k)
|
||||
xrf.emit('predefinedView',opts)
|
||||
.then( () => xrf.eval.fragment(k,opts) )
|
||||
}
|
||||
|
@ -40,12 +38,13 @@ const doPredefinedView = (opts) => {
|
|||
for ( let i in frag ) {
|
||||
let v = frag[i]
|
||||
if( v.is( xrf.XRF.PV_EXECUTE ) ){
|
||||
if( v.args ) v = v.args[ xrf.roundrobin(v,xrf.model) ]
|
||||
// wait for nested instances to arrive at the scene
|
||||
setTimeout( () => {
|
||||
if( !scene ) return
|
||||
scene.traverse( (mesh) => {
|
||||
selectionOfInterest( v.fragment, scene, mesh )
|
||||
predefinedView( v.fragment, scene, mesh )
|
||||
selectionOfInterest( v.string, scene, mesh )
|
||||
predefinedView( v , scene, mesh )
|
||||
})
|
||||
},100)
|
||||
}
|
||||
|
|
|
@ -35,10 +35,16 @@ xrf.frag.q = function(v, opts){
|
|||
|
||||
const showHide = () => {
|
||||
let q = frag.q.query
|
||||
console.log(frag.q.string)
|
||||
console.dir(frag)
|
||||
scene.traverse( (mesh) => {
|
||||
for ( let i in q ) {
|
||||
if( i == mesh.name && q[i].id != undefined ) mesh.visible = q[i].id
|
||||
if( i == mesh.userData.class && q[i].class != undefined ) mesh.visible = q[i].class
|
||||
let isMeshId = q[i].id != undefined
|
||||
let isMeshClass = q[i].class != undefined
|
||||
let isMeshProperty = q[i].rules != undefined && q[i].rules.length && !isMeshId && !isMeshClass
|
||||
if( isMeshId && i == mesh.name ) mesh.visible = q[i].id
|
||||
if( isMeshClass && i == mesh.userData.class ) mesh.visible = q[i].class
|
||||
if( isMeshProperty && mesh.userData[i] ) mesh.visible = (new xrf.Query(frag.q.string)).testProperty(i,mesh.userData[i])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ xrf.frag.src = function(v, opts){
|
|||
src.scale.copy( mesh.scale )
|
||||
mesh.add(src)
|
||||
console.dir(opts)
|
||||
if( !opts.recursive ) mesh.material.visible = false // lets hide the preview object because deleting disables animations
|
||||
if( !opts.recursive ) mesh.material.visible = false // lets hide the preview object because deleting disables animations+nested objs
|
||||
},10)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
{"fn":"query","data":"price:>=15", "expect":{ "fn":"testProperty","input":["price","10"],"out":false}},
|
||||
{"fn":"query","data":"price:>=5", "expect":{ "fn":"testProperty","input":["price","4"],"out":false}},
|
||||
{"fn":"query","data":"price:>=5", "expect":{ "fn":"testProperty","input":["price","0"],"out":false}},
|
||||
{"fn":"query","data":"price:>=2", "expect":{ "fn":"testProperty","input":["price","2"],"out":true}},
|
||||
{"fn":"query","data":"price:>=5 price:0", "expect":{ "fn":"testProperty","input":["price","1"],"out":false},"label":"price=1"},
|
||||
{"fn":"query","data":"price:>=5 price:0", "expect":{ "fn":"testProperty","input":["price","0"],"out":true},"label":"price=0"},
|
||||
{"fn":"query","data":"price:>=5 price:0", "expect":{ "fn":"testProperty","input":["price","6"],"out":true},"label":"price=6"},
|
||||
|
|
|
@ -62,7 +62,9 @@ class Parser {
|
|||
|
||||
// dynamic fragments cases: predefined views & assign/binds
|
||||
if( value.length == 0 && !Frag.exists(key) ){
|
||||
resultMap.set(key, new XRF(key, XRF.PV_EXECUTE | XRF.NAVIGATOR ) );
|
||||
var v:XRF = new XRF(key, XRF.PV_EXECUTE | XRF.NAVIGATOR );
|
||||
v.validate(key); // will fail but will parse multiple args for us (separated by |)
|
||||
resultMap.set(key, v );
|
||||
return true;
|
||||
}
|
||||
if( key.split(".").length > 1 && value.split(".").length > 1 ){
|
||||
|
|
|
@ -138,7 +138,7 @@ Test.__name__ = true;
|
|||
Test.main = function() {
|
||||
Test.test([{ fn : "url", expect : { fn : "equal.xyz", input : "pos", out : false}, label : "equal.xyz: should trigger incompatible type)", data : "http://foo.com?foo=1#pos=1.2,2.2"},{ fn : "url", expect : { fn : "equal.xyz", input : "pos", out : "1.2,2.2,3"}, label : "equal.xyz", data : "http://foo.com?foo=1#pos=1.2,2.2,3"},{ fn : "url", expect : { fn : "equal.xy", input : "t", out : "1,100"}, label : "a equal.xy", data : "http://foo.com?foo=1#t=1,100"},{ fn : "url", expect : { fn : "testParsed", input : "prio", out : false}, label : "should trigger incompatible type", data : "http://foo.com?foo=1#prio=foo"},{ fn : "url", expect : { fn : "equal.multi", input : "pos", out : "c|d|1,2,3"}, label : "b equal.multi", data : "http://foo.com?foo=1#pos=c|d|1,2,3"},{ fn : "url", expect : { fn : "testBrowserOverride", input : "t", out : true}, label : "browser URI can override t (defined in asset)", data : "http://foo.com?foo=1#t=2,500"},{ fn : "url", expect : { fn : "testBrowserOverride", input : "q", out : false}, label : "browser URI cannot override q (defined in asset)", data : "http://foo.com?foo=1#q=-bar"},{ fn : "url", expect : { fn : "testBrowserOverride", input : "scale", out : false}, label : "scale does not have NAVIGATOR set", data : "http://foo.com?foo=1#scale=2,2,2"},{ fn : "url", expect : { fn : "testEmbedOverride", input : "scale", out : true}, label : "embedded (src) URI can override scale", data : "http://foo.com?foo=1#scale=2,2,2"},{ fn : "url", expect : { fn : "testPredefinedView", input : "mypredefinedview", out : true}, label : "test predefined view executed", data : "http://foo.com?foo=1#mypredefinedview"},{ fn : "url", expect : { fn : "testPredefinedView", input : "another", out : true}, label : "test predefined view executed (multiple)", data : "http://foo.com?foo=1#mypredefinedview&another"},{ fn : "url", expect : { fn : "testPredefinedView", input : "mypredefinedview", out : true}, label : "test predefined view executed (multiple)", data : "http://foo.com?foo=1#mypredefinedview&another"},{ fn : "url", expect : { fn : "testPropertyAssign", input : "cube.position.x", out : true}, label : "test data assign", data : "#cube.position.x=music.position.x"},{ fn : "url", expect : { fn : "testPropertyAssign", input : "cube.position.x", out : true}, label : "test one-way data bind", data : "#cube.position.x=@music.position.x"}]);
|
||||
Test.test([{ fn : "query", expect : { fn : "testProperty", input : ["class","bar"], out : true}, data : "class:bar"},{ fn : "query", expect : { fn : "testProperty", input : ["class","bar"], out : true}, label : ".bar shorthand", data : ".bar"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : false}, data : ".bar -.foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, data : ".bar -.foo .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","bar"], out : true}, data : ".bar -.bar .bar"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo bar:5 .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo bar:>5 .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo bar:>5 .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["id","foo"], out : false}, label : "!id:foo", data : ".foo -.foo .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["id","foo"], out : true}, label : "id:foo?", data : "foo -foo foo"}]);
|
||||
Test.test([{ fn : "query", expect : { fn : "testProperty", input : ["price","10"], out : true}, data : "price:>=5"},{ fn : "query", expect : { fn : "testProperty", input : ["price","10"], out : false}, data : "price:>=15"},{ fn : "query", expect : { fn : "testProperty", input : ["price","4"], out : false}, data : "price:>=5"},{ fn : "query", expect : { fn : "testProperty", input : ["price","0"], out : false}, data : "price:>=5"},{ fn : "query", expect : { fn : "testProperty", input : ["price","1"], out : false}, label : "price=1", data : "price:>=5 price:0"},{ fn : "query", expect : { fn : "testProperty", input : ["price","0"], out : true}, label : "price=0", data : "price:>=5 price:0"},{ fn : "query", expect : { fn : "testProperty", input : ["price","6"], out : true}, label : "price=6", data : "price:>=5 price:0"},{ fn : "query", expect : { fn : "testProperty", input : ["tag","foo"], out : true}, data : "tag:foo"},{ fn : "query", expect : { fn : "testProperty", input : ["tag","foo"], out : false}, data : "-tag:foo"},{ fn : "query", expect : { fn : "testPropertyExclude", input : ["tag","foo"], out : true}, label : "testExclude", data : "-tag:foo"},{ fn : "query", expect : { fn : "test", input : [{ price : 5}], out : true}, data : ".foo price:5 -tag:foo"},{ fn : "query", expect : { fn : "test", input : [{ tag : "foo", price : 5}], out : false}, data : ".foo price:5 -tag:foo"}]);
|
||||
Test.test([{ fn : "query", expect : { fn : "testProperty", input : ["price","10"], out : true}, data : "price:>=5"},{ fn : "query", expect : { fn : "testProperty", input : ["price","10"], out : false}, data : "price:>=15"},{ fn : "query", expect : { fn : "testProperty", input : ["price","4"], out : false}, data : "price:>=5"},{ fn : "query", expect : { fn : "testProperty", input : ["price","0"], out : false}, data : "price:>=5"},{ fn : "query", expect : { fn : "testProperty", input : ["price","2"], out : true}, data : "price:>=2"},{ fn : "query", expect : { fn : "testProperty", input : ["price","1"], out : false}, label : "price=1", data : "price:>=5 price:0"},{ fn : "query", expect : { fn : "testProperty", input : ["price","0"], out : true}, label : "price=0", data : "price:>=5 price:0"},{ fn : "query", expect : { fn : "testProperty", input : ["price","6"], out : true}, label : "price=6", data : "price:>=5 price:0"},{ fn : "query", expect : { fn : "testProperty", input : ["tag","foo"], out : true}, data : "tag:foo"},{ fn : "query", expect : { fn : "testProperty", input : ["tag","foo"], out : false}, data : "-tag:foo"},{ fn : "query", expect : { fn : "testPropertyExclude", input : ["tag","foo"], out : true}, label : "testExclude", data : "-tag:foo"},{ fn : "query", expect : { fn : "test", input : [{ price : 5}], out : true}, data : ".foo price:5 -tag:foo"},{ fn : "query", expect : { fn : "test", input : [{ tag : "foo", price : 5}], out : false}, data : ".foo price:5 -tag:foo"}]);
|
||||
if(Test.errors > 1) {
|
||||
console.log("src/Test.hx:22:","\n-----\n[ ❌] " + Test.errors + " errors :/");
|
||||
}
|
||||
|
@ -350,7 +350,9 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
Frag_h["description"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["session"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.NAVIGATOR | xrfragment_XRF.EMBEDDED | xrfragment_XRF.PROMPT;
|
||||
if(value.length == 0 && !Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
var v = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
v.validate(key);
|
||||
resultMap[key] = v;
|
||||
return true;
|
||||
}
|
||||
if(key.split(".").length > 1 && value.split(".").length > 1) {
|
||||
|
@ -360,11 +362,11 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:77:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
console.log("src/xrfragment/Parser.hx:79:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:80:","✔ " + key + ": " + v.string);
|
||||
console.log("src/xrfragment/Parser.hx:82:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
}
|
||||
|
|
|
@ -392,7 +392,7 @@ class Test:
|
|||
def main():
|
||||
Test.test([_hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.xyz", 'input': "pos", 'out': False}), 'label': "equal.xyz: should trigger incompatible type)", 'data': "http://foo.com?foo=1#pos=1.2,2.2"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.xyz", 'input': "pos", 'out': "1.2,2.2,3"}), 'label': "equal.xyz", 'data': "http://foo.com?foo=1#pos=1.2,2.2,3"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.xy", 'input': "t", 'out': "1,100"}), 'label': "a equal.xy", 'data': "http://foo.com?foo=1#t=1,100"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testParsed", 'input': "prio", 'out': False}), 'label': "should trigger incompatible type", 'data': "http://foo.com?foo=1#prio=foo"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.multi", 'input': "pos", 'out': "c|d|1,2,3"}), 'label': "b equal.multi", 'data': "http://foo.com?foo=1#pos=c|d|1,2,3"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testBrowserOverride", 'input': "t", 'out': True}), 'label': "browser URI can override t (defined in asset)", 'data': "http://foo.com?foo=1#t=2,500"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testBrowserOverride", 'input': "q", 'out': False}), 'label': "browser URI cannot override q (defined in asset)", 'data': "http://foo.com?foo=1#q=-bar"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testBrowserOverride", 'input': "scale", 'out': False}), 'label': "scale does not have NAVIGATOR set", 'data': "http://foo.com?foo=1#scale=2,2,2"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testEmbedOverride", 'input': "scale", 'out': True}), 'label': "embedded (src) URI can override scale", 'data': "http://foo.com?foo=1#scale=2,2,2"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testPredefinedView", 'input': "mypredefinedview", 'out': True}), 'label': "test predefined view executed", 'data': "http://foo.com?foo=1#mypredefinedview"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testPredefinedView", 'input': "another", 'out': True}), 'label': "test predefined view executed (multiple)", 'data': "http://foo.com?foo=1#mypredefinedview&another"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testPredefinedView", 'input': "mypredefinedview", 'out': True}), 'label': "test predefined view executed (multiple)", 'data': "http://foo.com?foo=1#mypredefinedview&another"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testPropertyAssign", 'input': "cube.position.x", 'out': True}), 'label': "test data assign", 'data': "#cube.position.x=music.position.x"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testPropertyAssign", 'input': "cube.position.x", 'out': True}), 'label': "test one-way data bind", 'data': "#cube.position.x=@music.position.x"})])
|
||||
Test.test([_hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "bar"], 'out': True}), 'data': "class:bar"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "bar"], 'out': True}), 'label': ".bar shorthand", 'data': ".bar"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': False}), 'data': ".bar -.foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'data': ".bar -.foo .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "bar"], 'out': True}), 'data': ".bar -.bar .bar"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo bar:5 .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo bar:>5 .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo bar:>5 .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["id", "foo"], 'out': False}), 'label': "!id:foo", 'data': ".foo -.foo .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["id", "foo"], 'out': True}), 'label': "id:foo?", 'data': "foo -foo foo"})])
|
||||
Test.test([_hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "10"], 'out': True}), 'data': "price:>=5"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "10"], 'out': False}), 'data': "price:>=15"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "4"], 'out': False}), 'data': "price:>=5"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "0"], 'out': False}), 'data': "price:>=5"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "1"], 'out': False}), 'label': "price=1", 'data': "price:>=5 price:0"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "0"], 'out': True}), 'label': "price=0", 'data': "price:>=5 price:0"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "6"], 'out': True}), 'label': "price=6", 'data': "price:>=5 price:0"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["tag", "foo"], 'out': True}), 'data': "tag:foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["tag", "foo"], 'out': False}), 'data': "-tag:foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testPropertyExclude", 'input': ["tag", "foo"], 'out': True}), 'label': "testExclude", 'data': "-tag:foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': [_hx_AnonObject({'price': 5})], 'out': True}), 'data': ".foo price:5 -tag:foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': [_hx_AnonObject({'tag': "foo", 'price': 5})], 'out': False}), 'data': ".foo price:5 -tag:foo"})])
|
||||
Test.test([_hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "10"], 'out': True}), 'data': "price:>=5"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "10"], 'out': False}), 'data': "price:>=15"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "4"], 'out': False}), 'data': "price:>=5"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "0"], 'out': False}), 'data': "price:>=5"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "2"], 'out': True}), 'data': "price:>=2"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "1"], 'out': False}), 'label': "price=1", 'data': "price:>=5 price:0"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "0"], 'out': True}), 'label': "price=0", 'data': "price:>=5 price:0"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "6"], 'out': True}), 'label': "price=6", 'data': "price:>=5 price:0"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["tag", "foo"], 'out': True}), 'data': "tag:foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["tag", "foo"], 'out': False}), 'data': "-tag:foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testPropertyExclude", 'input': ["tag", "foo"], 'out': True}), 'label': "testExclude", 'data': "-tag:foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': [_hx_AnonObject({'price': 5})], 'out': True}), 'data': ".foo price:5 -tag:foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': [_hx_AnonObject({'tag': "foo", 'price': 5})], 'out': False}), 'data': ".foo price:5 -tag:foo"})])
|
||||
if (Test.errors > 1):
|
||||
print(str((("\n-----\n[ ❌] " + Std.string(Test.errors)) + " errors :/")))
|
||||
|
||||
|
@ -1431,8 +1431,9 @@ class xrfragment_Parser:
|
|||
Frag.h["description"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING)
|
||||
Frag.h["session"] = (((((xrfragment_XRF.ASSET | xrfragment_XRF.T_URL) | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.NAVIGATOR) | xrfragment_XRF.EMBEDDED) | xrfragment_XRF.PROMPT)
|
||||
if ((len(value) == 0) and (not (key in Frag.h))):
|
||||
value1 = xrfragment_XRF(key,(xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR))
|
||||
setattr(resultMap,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),value1)
|
||||
v = xrfragment_XRF(key,(xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR))
|
||||
v.validate(key)
|
||||
setattr(resultMap,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),v)
|
||||
return True
|
||||
if ((len(key.split(".")) > 1) and ((len(value.split(".")) > 1))):
|
||||
value1 = xrfragment_XRF(key,(((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_STRING) | xrfragment_XRF.PROP_BIND))
|
||||
|
@ -1598,8 +1599,8 @@ class xrfragment_Query:
|
|||
fails = 0
|
||||
qualify = 0
|
||||
def _hx_local_2(expr):
|
||||
nonlocal conds
|
||||
nonlocal fails
|
||||
nonlocal conds
|
||||
conds = (conds + 1)
|
||||
fails = (fails + (0 if expr else 1))
|
||||
return expr
|
||||
|
|
Loading…
Reference in New Issue