Skip to content

Commit

Permalink
Add functional test for behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
brianpeiris committed Nov 15, 2016
1 parent c75a544 commit d6e2d38
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
69 changes: 69 additions & 0 deletions examples/tests/behaviors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Behavior Tests</title>
<meta charset="utf-8">
<script src="https://cdn.rawgit.com/mrdoob/three.js/r74/build/three.min.js"></script>
<script src="https://cdn.rawgit.com/mrdoob/three.js/r74/examples/js/controls/OrbitControls.js"></script>
<script src="../../dist/altspace.js"></script>
</head>
<body>
<select id="behaviorSelector">
<option>none</option>
<option data-config='{"x": 0.1, "y": 0.2}'>Bob</option>
<option>Spin</option>
<option data-config='{"x": true, "z": true}'>Drag</option>
<option>ButtonStateStyle</option>
<option>HoverColor</option>
<option>HoverScale</option>
</select>
<script>
var sim = new altspace.utilities.Simulation();
sim.scene.scale.multiplyScalar(200);

var container = new THREE.Group();
container.scale.multiplyScalar(0.5);
container.rotation.x = Math.PI * 0.25;
container.position.y = -1;

var boxSize = 1;

var boxTex = new THREE.TextureLoader().load('../images/UV_Grid_Sm.jpg');
var boxMesh = new THREE.Mesh(
new THREE.BoxGeometry(boxSize, boxSize, boxSize),
new THREE.MeshBasicMaterial({color: 'green', map: boxTex}));
boxMesh.position.set(0.5, -0.3, 0.5);
container.add(boxMesh);

sim.scene.add(container);

var behaviorSelector = document.getElementById('behaviorSelector')

var behaviorConfigs = Array.from(behaviorSelector.options).reduce(function (configs, opt) {
if (opt.dataset.config) {
configs[opt.value] = JSON.parse(opt.dataset.config);
}
return configs;
}, {});

behaviorSelector.addEventListener('change', function () {
var behaviorName = this.value;
if (behaviorName === 'none') { return; }
boxMesh.removeAllBehaviors();
var behavior = altspace.utilities.behaviors[behaviorName];
var config = behaviorConfigs[behaviorName];
boxMesh.addBehavior(new behavior(config));
});

if (location.search) {
var behaviorName = location.search.substr(1);
var behavior = altspace.utilities.behaviors[behaviorName];
var config = behaviorConfigs[behaviorName];
boxMesh.addBehavior(new behavior(config));
behaviorSelector.selectedIndex = Array.from(behaviorSelector.options).
map(function (opt) { return opt.value; }).indexOf(behaviorName);
}
</script>
</body>
</html>

1 change: 1 addition & 0 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<script src="./src/main.js"></script>
<script src="./src/sync.js"></script>
<script src="./src/layout.js"></script>
<script src="./src/behaviors.js"></script>
<script>
mocha.run();
</script>
Expand Down

0 comments on commit d6e2d38

Please sign in to comment.