Skip to content
This repository was archived by the owner on Jan 24, 2020. It is now read-only.

Commit 5be6282

Browse files
author
Avaer Kazmer
committed
Abstract scene attach save functions
1 parent 6681350 commit 5be6282

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

index.html

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,29 +2440,42 @@
24402440
mesh.y = newY;
24412441
};
24422442
mesh.scene = null;
2443-
mesh.setSceneBinding = newSceneMesh => {
2443+
const _makeSetSceneBinding = (_save = () => Promise.resolve()) => newSceneMesh => {
24442444
if (newSceneMesh) {
2445-
newSceneMesh.apps.push(mesh);
2446-
newSceneMesh.token.apps.push({
2445+
const tokenApps = newSceneMesh.token.apps.concat([{
24472446
appType: mesh.type,
24482447
url: mesh.url,
24492448
position: mesh.moveMesh.position.toArray(),
24502449
orientation: mesh.moveMesh.quaternion.toArray(),
2451-
});
2452-
_saveData();
2453-
2454-
mesh.moveMesh.material.color.setHex(0x9ccc65);
2450+
}]);
2451+
const apps = newSceneMesh.apps.concat([mesh]);
2452+
_save(newSceneMesh.token.id, tokenApps)
2453+
.then(() => {
2454+
newSceneMesh.apps = apps;
2455+
newSceneMesh.token.apps = tokenApps;
2456+
2457+
mesh.moveMesh.material.color.setHex(0x9ccc65);
2458+
});
24552459
} else {
24562460
if (mesh.scene) {
24572461
const index = mesh.scene.apps.indexOf(mesh);
2458-
mesh.scene.apps.splice(index, 1);
2459-
mesh.scene.token.apps.splice(index, 1);
2460-
_saveData();
2462+
const tokenApps = mesh.scene.token.apps.slice();
2463+
tokenApps.splice(index, 1);
2464+
const apps = mesh.scene.apps.slice();
2465+
apps.splice(index, 1);
2466+
_save(newSceneMesh.token.id, tokenApps)
2467+
.then(() => {
2468+
mesh.scene.token.apps = tokenApps;
2469+
mesh.scene.apps = apps;
2470+
2471+
mesh.moveMesh.material.color.setHex(0x333333);
2472+
});
24612473
}
2462-
mesh.moveMesh.material.color.setHex(0x333333);
24632474
}
24642475
mesh.scene = newSceneMesh;
24652476
};
2477+
mesh.setSceneBinding = _makeSetSceneBinding(_setSceneApps);
2478+
mesh.setSceneBindingRaw = _makeSetSceneBinding();
24662479
mesh.update = page => {
24672480
const _select = () => {
24682481
mesh.material.uniforms.uColor.value = new THREE.Color(0x9ccc65);

0 commit comments

Comments
 (0)