Skip to content

Commit 4136ccf

Browse files
committed
Lots more updates moving everything to consistent class structure.
1 parent b534803 commit 4136ccf

20 files changed

Lines changed: 714 additions & 610 deletions
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
var Class = require('../../../utils/Class');
12
var Event = require('../../../events/Event');
23

3-
var AddAnimationEvent = function (key, animation)
4-
{
5-
Event.call(this, 'ADD_ANIMATION_EVENT');
4+
var AddAnimationEvent = new Class({
65

7-
this.key = key;
8-
this.animation = animation;
9-
};
6+
Extends: Event,
107

11-
AddAnimationEvent.prototype = Object.create(Event.prototype);
12-
AddAnimationEvent.prototype.constructor = AddAnimationEvent;
8+
initialize:
9+
10+
function AddAnimationEvent (key, animation)
11+
{
12+
Event.call(this, 'ADD_ANIMATION_EVENT');
13+
14+
this.key = key;
15+
this.animation = animation;
16+
}
17+
18+
});
1319

1420
module.exports = AddAnimationEvent;
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
var Class = require('../../../utils/Class');
12
var Event = require('../../../events/Event');
23

3-
var PauseAllAnimationEvent = function ()
4-
{
5-
Event.call(this, 'PAUSE_ALL_ANIMATION_EVENT');
6-
};
4+
var PauseAllAnimationEvent = new Class({
75

8-
PauseAllAnimationEvent.prototype = Object.create(Event.prototype);
9-
PauseAllAnimationEvent.prototype.constructor = PauseAllAnimationEvent;
6+
Extends: Event,
7+
8+
initialize:
9+
10+
function PauseAllAnimationEvent ()
11+
{
12+
Event.call(this, 'PAUSE_ALL_ANIMATION_EVENT');
13+
}
14+
15+
});
1016

1117
module.exports = PauseAllAnimationEvent;
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
var Class = require('../../../utils/Class');
12
var Event = require('../../../events/Event');
23

3-
var RemoveAnimationEvent = function (key, animation)
4-
{
5-
Event.call(this, 'REMOVE_ANIMATION_EVENT');
4+
var RemoveAnimationEvent = new Class({
65

7-
this.key = key;
8-
this.animation = animation;
9-
};
6+
Extends: Event,
107

11-
RemoveAnimationEvent.prototype = Object.create(Event.prototype);
12-
RemoveAnimationEvent.prototype.constructor = RemoveAnimationEvent;
8+
initialize:
9+
10+
function RemoveAnimationEvent (key, animation)
11+
{
12+
Event.call(this, 'REMOVE_ANIMATION_EVENT');
13+
14+
this.key = key;
15+
this.animation = animation;
16+
}
17+
18+
});
1319

1420
module.exports = RemoveAnimationEvent;
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
var Class = require('../../../utils/Class');
12
var Event = require('../../../events/Event');
23

3-
var ResumeAllAnimationEvent = function ()
4-
{
5-
Event.call(this, 'RESUME_ALL_ANIMATION_EVENT');
6-
};
4+
var ResumeAllAnimationEvent = new Class({
75

8-
ResumeAllAnimationEvent.prototype = Object.create(Event.prototype);
9-
ResumeAllAnimationEvent.prototype.constructor = ResumeAllAnimationEvent;
6+
Extends: Event,
7+
8+
initialize:
9+
10+
function ResumeAllAnimationEvent ()
11+
{
12+
Event.call(this, 'RESUME_ALL_ANIMATION_EVENT');
13+
}
14+
15+
});
1016

1117
module.exports = ResumeAllAnimationEvent;

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: 'c709d480-5fe1-11e7-96a8-9381099cfcf1'
2+
build: 'dfe80200-6000-11e7-a426-abaf4c1292d1'
33
};
44
module.exports = CHECKSUM;
Lines changed: 84 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,127 @@
1-
var GetValue = require('../../../utils/object/GetValue');
2-
var ResetKeyCombo = require('./ResetKeyCombo');
3-
var ProcessKeyCombo = require('./ProcessKeyCombo');
1+
var Class = require('../../../utils/Class');
2+
var GetFastValue = require('../../../utils/object/GetFastValue');
43
var KeyComboMatchEvent = require('./KeyComboMatchEvent');
4+
var ProcessKeyCombo = require('./ProcessKeyCombo');
5+
var ResetKeyCombo = require('./ResetKeyCombo');
56

67
// Keys can be either:
78
//
89
// A string (ATARI)
910
// An array of either integers (key codes) or strings, or a mixture of both
1011
// An array of objects (such as Key objects) with a public 'keyCode' property
1112

12-
var KeyCombo = function (keyboardManager, keys, config)
13-
{
14-
if (config === undefined) { config = {}; }
13+
var KeyCombo = new Class({
1514

16-
// Can't have a zero or single length combo (string or array based)
17-
if (keys.length < 2)
15+
initialize:
16+
17+
function KeyCombo (keyboardManager, keys, config)
1818
{
19-
return false;
20-
}
19+
if (config === undefined) { config = {}; }
2120

22-
this.manager = keyboardManager;
21+
// Can't have a zero or single length combo (string or array based)
22+
if (keys.length < 2)
23+
{
24+
return false;
25+
}
2326

24-
this.enabled = true;
27+
this.manager = keyboardManager;
2528

26-
this.keyCodes = [];
29+
this.enabled = true;
2730

28-
// if 'keys' is a string we need to get the keycode of each character in it
31+
this.keyCodes = [];
2932

30-
for (var i = 0; i < keys.length; i++)
31-
{
32-
var char = keys[i];
33+
// if 'keys' is a string we need to get the keycode of each character in it
3334

34-
if (typeof char === 'string')
35-
{
36-
this.keyCodes.push(char.toUpperCase().charCodeAt(0));
37-
}
38-
else if (typeof char === 'number')
39-
{
40-
this.keyCodes.push(char);
41-
}
42-
else if (char.hasOwnProperty('keyCode'))
35+
for (var i = 0; i < keys.length; i++)
4336
{
44-
this.keyCodes.push(char.keyCode);
37+
var char = keys[i];
38+
39+
if (typeof char === 'string')
40+
{
41+
this.keyCodes.push(char.toUpperCase().charCodeAt(0));
42+
}
43+
else if (typeof char === 'number')
44+
{
45+
this.keyCodes.push(char);
46+
}
47+
else if (char.hasOwnProperty('keyCode'))
48+
{
49+
this.keyCodes.push(char.keyCode);
50+
}
4551
}
46-
}
4752

48-
// The current keyCode the combo is waiting for
49-
this.current = this.keyCodes[0];
53+
// The current keyCode the combo is waiting for
54+
this.current = this.keyCodes[0];
5055

51-
// The current index of the key being waited for in the 'keys' string
52-
this.index = 0;
56+
// The current index of the key being waited for in the 'keys' string
57+
this.index = 0;
5358

54-
// The length of this combo (in keycodes)
55-
this.size = this.keyCodes.length;
59+
// The length of this combo (in keycodes)
60+
this.size = this.keyCodes.length;
5661

57-
// The time the previous key in the combo was matched
58-
this.timeLastMatched = 0;
62+
// The time the previous key in the combo was matched
63+
this.timeLastMatched = 0;
5964

60-
// Has this Key Combo been matched yet?
61-
this.matched = false;
65+
// Has this Key Combo been matched yet?
66+
this.matched = false;
6267

63-
// The time the entire combo was matched
64-
this.timeMatched = 0;
68+
// The time the entire combo was matched
69+
this.timeMatched = 0;
6570

66-
// Custom options ...
71+
// Custom options ...
6772

68-
// If they press the wrong key do we reset the combo?
69-
this.resetOnWrongKey = GetValue(config, 'resetOnWrongKey', true);
73+
// If they press the wrong key do we reset the combo?
74+
this.resetOnWrongKey = GetFastValue(config, 'resetOnWrongKey', true);
7075

71-
// The max delay in ms between each key press. Above this the combo is reset. 0 means disabled.
72-
this.maxKeyDelay = GetValue(config, 'maxKeyDelay', 0);
76+
// The max delay in ms between each key press. Above this the combo is reset. 0 means disabled.
77+
this.maxKeyDelay = GetFastValue(config, 'maxKeyDelay', 0);
7378

74-
// If previously matched and they press Key 1 again, will it reset?
75-
this.resetOnMatch = GetValue(config, 'resetOnMatch', false);
79+
// If previously matched and they press Key 1 again, will it reset?
80+
this.resetOnMatch = GetFastValue(config, 'resetOnMatch', false);
7681

77-
// If the combo matches, will it delete itself?
78-
this.deleteOnMatch = GetValue(config, 'deleteOnMatch', false);
82+
// If the combo matches, will it delete itself?
83+
this.deleteOnMatch = GetFastValue(config, 'deleteOnMatch', false);
7984

80-
var _this = this;
85+
var _this = this;
8186

82-
var onKeyDownHandler = function (event)
83-
{
84-
if (_this.matched || !_this.enabled)
87+
var onKeyDownHandler = function (event)
8588
{
86-
return;
87-
}
88-
89-
var matched = ProcessKeyCombo(event.data, _this);
90-
91-
if (matched)
92-
{
93-
_this.manager.events.dispatch(new KeyComboMatchEvent(_this, event));
94-
95-
if (_this.resetOnMatch)
89+
if (_this.matched || !_this.enabled)
9690
{
97-
ResetKeyCombo(_this);
91+
return;
9892
}
99-
else if (_this.deleteOnMatch)
93+
94+
var matched = ProcessKeyCombo(event.data, _this);
95+
96+
if (matched)
10097
{
101-
_this.destroy();
98+
_this.manager.events.dispatch(new KeyComboMatchEvent(_this, event));
99+
100+
if (_this.resetOnMatch)
101+
{
102+
ResetKeyCombo(_this);
103+
}
104+
else if (_this.deleteOnMatch)
105+
{
106+
_this.destroy();
107+
}
102108
}
103-
}
104-
};
109+
};
105110

106-
this.onKeyDown = onKeyDownHandler;
111+
this.onKeyDown = onKeyDownHandler;
107112

108-
this.manager.events.on('KEY_DOWN_EVENT', onKeyDownHandler);
109-
};
113+
this.manager.events.on('KEY_DOWN_EVENT', onKeyDownHandler);
114+
},
110115

111-
KeyCombo.prototype.constructor = KeyCombo;
116+
progress: {
112117

113-
KeyCombo.prototype = {
118+
// How far complete is this combo? A value between 0 and 1.
119+
get: function ()
120+
{
121+
return this.index / this.size;
122+
}
123+
124+
},
114125

115126
destroy: function ()
116127
{
@@ -121,22 +132,6 @@ KeyCombo.prototype = {
121132
this.manager = undefined;
122133
}
123134

124-
};
125-
126-
Object.defineProperties(KeyCombo.prototype, {
127-
128-
progress: {
129-
130-
enumerable: true,
131-
132-
// How far complete is this combo? A value between 0 and 1.
133-
get: function ()
134-
{
135-
return this.index / this.size;
136-
}
137-
138-
}
139-
140135
});
141136

142137
module.exports = KeyCombo;
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1+
var Class = require('../../../utils/Class');
12
var Event = require('../../../events/Event');
23

3-
var KeyComboMatchEvent = function (keyCombo, keyboardEvent)
4-
{
5-
Event.call(this, 'KEY_COMBO_MATCH_EVENT');
4+
var KeyComboMatchEvent = new Class({
65

7-
this.target = keyCombo;
6+
Extends: Event,
87

9-
this.data = keyboardEvent;
10-
};
8+
initialize:
119

12-
KeyComboMatchEvent.prototype = Object.create(Event.prototype);
13-
KeyComboMatchEvent.prototype.constructor = KeyComboMatchEvent;
10+
function KeyComboMatchEvent (keyCombo, keyboardEvent)
11+
{
12+
Event.call(this, 'KEY_COMBO_MATCH_EVENT');
13+
14+
this.target = keyCombo;
15+
16+
this.data = keyboardEvent;
17+
}
18+
19+
});
1420

1521
module.exports = KeyComboMatchEvent;
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
var Class = require('../../../utils/Class');
12
var Event = require('../../../events/Event');
23

3-
var KeyDownEvent = function (keyboardEvent)
4-
{
5-
Event.call(this, 'KEY_DOWN_EVENT');
4+
var KeyDownEvent = new Class({
65

7-
this.data = keyboardEvent;
8-
};
6+
Extends: Event,
97

10-
KeyDownEvent.prototype = Object.create(Event.prototype);
11-
KeyDownEvent.prototype.constructor = KeyDownEvent;
8+
initialize:
9+
10+
function KeyDownEvent (keyboardEvent)
11+
{
12+
Event.call(this, 'KEY_DOWN_EVENT');
13+
14+
this.data = keyboardEvent;
15+
}
16+
17+
});
1218

1319
module.exports = KeyDownEvent;

0 commit comments

Comments
 (0)