Skip to content

Commit

Permalink
chore(release): Release 2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Jan 15, 2018
1 parent c213378 commit 390cc89
Show file tree
Hide file tree
Showing 11 changed files with 7,962 additions and 18 deletions.
2,437 changes: 2,437 additions & 0 deletions dist/axes.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/axes.js.map

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions dist/axes.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/axes.min.js.map

Large diffs are not rendered by default.

5,445 changes: 5,445 additions & 0 deletions dist/axes.pkgd.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/axes.pkgd.js.map

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions dist/axes.pkgd.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/axes.pkgd.min.js.map

Large diffs are not rendered by default.

58 changes: 44 additions & 14 deletions outjs/inputType/MoveKeyInput.js
Expand Up @@ -20,17 +20,22 @@ exports.KEYMAP = {
DOWN_ARROW: 40,
S: 83
};
var DIRECTION_REVERSE = -1;
var DIRECTION_FORWARD = 1;
var DELAY = 80;
var MoveKeyInput = (function () {
function MoveKeyInput(el, options) {
this.axes = [];
this.element = null;
this._isEnabled = false;
this._isHolded = false;
this._timer = null;
this.element = utils_1.$(el);
this.options = __assign({
scale: [1, 1]
}, options);
this.onKeydown = this.onKeydown.bind(this);
this.onKeyup = this.onKeyup.bind(this);
}
MoveKeyInput.prototype.mapAxes = function (axes) {
this.axes = axes;
Expand All @@ -51,46 +56,71 @@ var MoveKeyInput = (function () {
this.disconnect();
this.element = null;
};
MoveKeyInput.prototype.onKeydown = function (event) {
MoveKeyInput.prototype.onKeydown = function (e) {
if (!this._isEnabled) {
return;
}
event.preventDefault();
var isMoveKey = true;
var direction = DIRECTION_FORWARD;
var offsets;
var e = event;
switch (e.keyCode) {
case exports.KEYMAP.LEFT_ARROW:
case exports.KEYMAP.A:
offsets = [-this.options.scale[0], 0];
break;
direction = DIRECTION_REVERSE;
case exports.KEYMAP.RIGHT_ARROW:
case exports.KEYMAP.D:
offsets = [this.options.scale[0], 0];
break;
case exports.KEYMAP.UP_ARROW:
case exports.KEYMAP.W:
offsets = [0, this.options.scale[1]];
if (!this.axes[0]) {
isMoveKey = false;
break;
}
offsets = [+this.options.scale[0] * direction, 0];
break;
case exports.KEYMAP.DOWN_ARROW:
case exports.KEYMAP.S:
offsets = [0, -this.options.scale[1]];
direction = DIRECTION_REVERSE;
case exports.KEYMAP.UP_ARROW:
case exports.KEYMAP.W:
if (!this.axes[1]) {
isMoveKey = false;
break;
}
offsets = [0, +this.options.scale[1] * direction];
break;
default:
isMoveKey = false;
}
if (isMoveKey) {
this.observer.change(this, event, InputType_1.toAxis(this.axes, offsets));
e.preventDefault();
if (!isMoveKey) {
return;
}
if (!this._isHolded) {
this.observer.hold(this, event);
this._isHolded = true;
}
clearTimeout(this._timer);
this.observer.change(this, event, InputType_1.toAxis(this.axes, offsets));
};
MoveKeyInput.prototype.onKeyup = function (e) {
var _this = this;
if (!this._isHolded) {
return;
}
clearTimeout(this._timer);
this._timer = setTimeout(function () {
_this.observer.release(_this, e, InputType_1.toAxis(_this.axes, [0, 0]));
_this._isHolded = false;
}, DELAY);
};
MoveKeyInput.prototype.attachEvent = function (observer) {
this.observer = observer;
this.element.addEventListener("keydown", this.onKeydown, false);
this.element.addEventListener("keypress", this.onKeydown, false);
this.element.addEventListener("keyup", this.onKeyup, false);
this._isEnabled = true;
};
MoveKeyInput.prototype.dettachEvent = function () {
this.element.removeEventListener("keydown", this.onKeydown, false);
this.element.removeEventListener("keypress", this.onKeydown, false);
this.element.removeEventListener("keyup", this.onKeyup, false);
this._isEnabled = false;
this.observer = null;
};
Expand Down
8 changes: 5 additions & 3 deletions outjs/inputType/WheelInput.js
Expand Up @@ -19,7 +19,8 @@ var WheelInput = (function () {
this._timer = null;
this.element = utils_1.$(el);
this.options = __assign({
scale: 1
scale: 1,
useNormalized: true
}, options);
this.onWheel = this.onWheel.bind(this);
}
Expand Down Expand Up @@ -52,13 +53,14 @@ var WheelInput = (function () {
this.observer.hold(this, event);
this._isHolded = true;
}
var offset = (event.deltaY > 0 ? -1 : 1) * this.options.scale;
var offset = (event.deltaY > 0 ? -1 : 1) * this.options.scale * (this.options.useNormalized ? 1 : Math.abs(event.deltaY));
this.observer.change(this, event, InputType_1.toAxis(this.axes, [offset]));
clearTimeout(this._timer);
var inst = this;
this._timer = setTimeout(function () {
if (_this._isHolded) {
_this.observer.release(_this, event, InputType_1.toAxis(_this.axes, [0]));
_this._isHolded = false;
_this.observer.release(_this, event, InputType_1.toAxis(_this.axes, [0]));
}
}, 50);
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@egjs/axes",
"version": "2.4.0-rc",
"version": "2.4.0",
"description": "A module used to change the information of user action entered by various input devices such as touch screen or mouse into the logical virtual coordinates. You can easily create a UI that responds to user actions.",
"main": "dist/axes.js",
"module": "outjs/index.js",
Expand Down

0 comments on commit 390cc89

Please sign in to comment.