Merge pull request #6 from jesstelford/pause-support

Pause support
This commit is contained in:
Jess Telford 2016-11-05 13:45:17 +11:00 committed by GitHub
commit 7157f2c215
5 changed files with 249 additions and 184 deletions

65
CHANGELOG.md Normal file
View file

@ -0,0 +1,65 @@
# Change Log
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased][]
### Added
- This changelog
### Fixed
- Remove drag listeners when entity paused
## [1.3.1][] - 2016-10-15
### Examples
- Updated to latest keyboard controls in examples
## [1.3.0][] - 2016-10-05
### Added
- Touch support
## [1.2.0][] - 2016-10-04
### Added
- Support for locking to camera during rotation
## [1.1.1][] - 2016-09-30
### Fixed
- Correct the main export
### Examples
- Physics based examples
## [1.1.0][] - 2016-09-28
### Added
- Events - `dragstart`, `dragmove` & `dragend`
- Drag end velocity calculation
## [1.0.1][] - 2016-09-23
### Initial release
- Click & Drag component for A-Frame.
[Unreleased]: https://github.com/jesstelford/aframe-click-drag-component/compare/v1.3.1...HEAD
[1.3.1]: https://github.com/jesstelford/aframe-click-drag-component/compare/v1.3.0...v1.3.1
[1.3.0]: https://github.com/jesstelford/aframe-click-drag-component/compare/v1.2.0...v1.3.0
[1.2.0]: https://github.com/jesstelford/aframe-click-drag-component/compare/v1.1.1...v1.2.0
[1.1.1]: https://github.com/jesstelford/aframe-click-drag-component/compare/v1.1.0...v1.1.1
[1.1.0]: https://github.com/jesstelford/aframe-click-drag-component/compare/v1.0.1...v1.1.0
[1.0.1]: https://github.com/jesstelford/aframe-click-drag-component/tree/v1.0.1

View file

@ -47,7 +47,7 @@
<script>
var draggable = document.querySelector('[click-drag]');
draggable.addEventListener('dragstart', function(dragInfo) {
draggable.pause();
draggable.components['dynamic-body'].pause();
});
draggable.addEventListener('dragend', function(dragInfo) {
@ -74,7 +74,7 @@
// This gives the feeling of "tossing" the ball
rotatedVelocity.applyAxisAngle(rotation, Math.PI / 8);
draggable.play();
draggable.components['dynamic-body'].play();
draggable.body.velocity.set(rotatedVelocity.x, rotatedVelocity.y, rotatedVelocity.z);
});
</script>

View file

@ -25,14 +25,14 @@
<script>
var draggable = document.querySelector('[click-drag]');
draggable.addEventListener('dragstart', function(dragInfo) {
draggable.pause();
draggable.components['dynamic-body'].pause();
});
draggable.addEventListener('dragend', function(dragInfo) {
var x = dragInfo.detail.velocity.x;
var y = dragInfo.detail.velocity.y;
var z = dragInfo.detail.velocity.z;
draggable.play();
draggable.components['dynamic-body'].play();
draggable.body.velocity.set(x, y, z);
console.log('drag end', dragInfo.detail.velocity);
});

View file

@ -12,7 +12,8 @@
"start": "budo examples/main.js:../build.js --serve build.js --dir examples --port 8000 --live --open -- --debug --verbose -t babelify -t [envify --NODE_ENV development ]",
"prepublish": "in-publish && npm run dist && npm run build-lib || not-in-publish",
"preghpages": "npm run build-example && rm -rf gh-pages && mkdir gh-pages && cp -r examples/* gh-pages",
"ghpages": "npm run preghpages && ghpages -p gh-pages"
"ghpages": "npm run preghpages && ghpages -p gh-pages",
"version": "version-changelog CHANGELOG.md && changelog-verify CHANGELOG.md && git add CHANGELOG.md"
},
"repository": {
"type": "git",
@ -47,6 +48,7 @@
"browserify": "^13.1.0",
"browserify-css": "^0.9.1",
"budo": "^9.2.0",
"changelog-verify": "^1.0.4",
"envify": "^3.4.1",
"eslint": "^3.2.2",
"eslint-config-airbnb": "^10.0.0",
@ -60,7 +62,8 @@
"rollup-plugin-node-resolve": "^2.0.0",
"rollupify": "^0.3.4",
"uglify-js": "^2.7.3",
"uglifyify": "^3.0.3"
"uglifyify": "^3.0.3",
"version-changelog": "^2.0.1"
},
"dependencies": {
"deep-equal": "^1.0.1",

View file

@ -386,18 +386,18 @@ function dragItem(THREE, element, offset, camera, depth, mouseInfo, lockToLocalR
}
// Closure to close over the removal of the event listeners
const {initialize, tearDown} = (function closeOverInitAndTearDown() {
const {didMount, didUnmount} = (function getDidMountAndUnmount() {
let removeClickListeners;
let removeDragListeners;
const cache = [];
return {
initialize(THREE, componentName, lockToLocalRotation) {
function initialize(THREE, componentName, lockToLocalRotation) {
// TODO: Based on a scene from the element passed in?
const scene = document.querySelector('a-scene');
// delay loading of this as we're not 100% if the scene has loaded yet or not
let camera;
let removeDragListeners;
let draggedElement;
let dragInfo;
const positionLog = [];
@ -448,8 +448,6 @@ const {initialize, tearDown} = (function closeOverInitAndTearDown() {
clientY,
};
element.emit(DRAG_START_EVENT, dragInfo);
element.addEventListener(DRAG_MOVE_EVENT, onDragged);
removeDragListeners = _ => {
@ -459,6 +457,8 @@ const {initialize, tearDown} = (function closeOverInitAndTearDown() {
// in case this removal function gets called more than once
removeDragItemListeners = null;
};
element.emit(DRAG_START_EVENT, dragInfo);
}
}
@ -553,18 +553,12 @@ const {initialize, tearDown} = (function closeOverInitAndTearDown() {
scene.addEventListener('loaded', run);
}
},
}
tearDown() {
function tearDown() {
removeClickListeners && removeClickListeners(); // eslint-disable-line no-unused-expressions
removeClickListeners = undefined;
},
};
}());
const {didMount, didUnmount} = (function getDidMountAndUnmount() {
const cache = [];
}
return {
didMount(element, THREE, componentName, lockToLocalRotation) {
@ -582,6 +576,9 @@ const {didMount, didUnmount} = (function getDidMountAndUnmount() {
const cacheIndex = cache.indexOf(element);
removeDragListeners && removeDragListeners(); // eslint-disable-line no-unused-expressions
removeDragListeners = undefined;
if (cacheIndex === -1) {
return;
}
@ -638,7 +635,7 @@ export default function aframeDraggableComponent(aframe, componentName = COMPONE
* Generally undoes all modifications to the entity.
*/
remove() {
didUnmount();
didUnmount(this);
},
/**
@ -646,7 +643,7 @@ export default function aframeDraggableComponent(aframe, componentName = COMPONE
* Use to stop or remove any dynamic or background behavior such as events.
*/
pause() {
didUnmount();
didUnmount(this);
},
/**