-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prototype handle tours snapshots merge
- Loading branch information
Showing
10 changed files
with
205 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { mapTarget } from "./snapshot.js"; | ||
import { SOURCE_INDEX } from "./types.js"; | ||
|
||
|
||
describe("mapTarget()", function(){ | ||
|
||
it("Keeps identity for indices not expected to change", function(){ | ||
[ | ||
"scenes/0/setup/reader/enabled", | ||
"scenes/0/setup/viewer/annotationsVisible", | ||
"scenes/0/setup/reader/position", | ||
].forEach((t)=>{ | ||
expect(mapTarget(t)).to.equal(t); | ||
}); | ||
}); | ||
|
||
it("dereferences nodes", function(){ | ||
expect(mapTarget("node/0/position", [ | ||
{id: "foo", name: "node1"}, | ||
])).to.equal("node/foo/position"); | ||
}); | ||
|
||
it("dereferences models", function(){ | ||
expect(mapTarget("model/0/position", [ | ||
{id: "foo", name: "node1", model: {[SOURCE_INDEX]: 0} as any}, | ||
])).to.equal("model/foo/position"); | ||
}); | ||
|
||
it("derefences lights", function(){ | ||
expect(mapTarget("light/0/position", [ | ||
{id: "foo", name: "node1", light: {[SOURCE_INDEX]: 0} as any}, | ||
])).to.equal("light/foo/position"); | ||
}); | ||
|
||
|
||
it("throws an error if node is missing", function(){ | ||
expect(()=>mapTarget("light/1/position", [ | ||
{id: "foo", name: "node1", light: {[SOURCE_INDEX]: 0} as any}, | ||
])).to.throw('does not point to a valid node'); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { INode } from "../../schema/document.js"; | ||
import { DerefNode, SOURCE_INDEX } from "./types.js"; | ||
|
||
|
||
export function mapTarget(target :string, nodes :DerefNode[] =[]){ | ||
const [root, indexString, ...propPath] = target.split("/"); | ||
const index = parseInt(indexString); | ||
if(Number.isNaN(index)) return target; | ||
|
||
if(root=='scenes'){ | ||
return target; //Scene index is not expected to change | ||
} | ||
|
||
let node :DerefNode | undefined; | ||
|
||
if(root == "node"){ | ||
node = nodes[index]; | ||
}else if(root == "model"){ | ||
node = nodes.find(n=>n.model?.[SOURCE_INDEX] === index); | ||
} if(root == "light"){ | ||
node = nodes.find(n=>n.light?.[SOURCE_INDEX] === index); | ||
} | ||
|
||
if(!node) throw new Error(`Invalid pathMap: ${target} does not point to a valid node`); | ||
return `${root}/${node.id}/${propPath.join("/")}`; | ||
} | ||
|
||
|
||
export function unmapTarget(target :string, nodes :INode[]){ | ||
const [root, id, ...propPath] = target.split("/"); | ||
|
||
if(root=='scenes'){ | ||
return target; //Scene index is not expected to change | ||
} | ||
|
||
let index :number|undefined; | ||
const nodeIndex = nodes.findIndex(n=>n.id === id); | ||
if(nodeIndex === -1) throw new Error(`can't find node with id : ${id} (in ${target})`); | ||
|
||
if(root == "node"){ | ||
index = nodeIndex; | ||
}else if(root == "model"){ | ||
index = nodes[nodeIndex].model; | ||
} if(root == "light"){ | ||
index = nodes[nodeIndex].model; | ||
} | ||
|
||
if(typeof index !== "number") throw new Error(`Invalid pathMap: ${target} does not point to a valid node`); | ||
return `${root}/${index}/${propPath.join("/")}`; | ||
} |
Oops, something went wrong.