entityjs 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/bin/entityjs +1 -1
- data/entityjs.gemspec +3 -2
- data/lib/entityjs.rb +13 -1
- data/lib/entityjs/command.rb +22 -16
- data/lib/entityjs/commands/build.rb +96 -48
- data/lib/entityjs/commands/eunit.rb +1 -1
- data/lib/entityjs/commands/html.rb +31 -0
- data/lib/entityjs/commands/min.rb +37 -0
- data/lib/entityjs/commands/new.rb +3 -0
- data/lib/entityjs/commands/server.rb +9 -3
- data/lib/entityjs/config.rb +163 -59
- data/lib/entityjs/dirc.rb +28 -0
- data/lib/entityjs/page.rb +73 -34
- data/lib/entityjs/version.rb +1 -1
- data/public/favicon.ico +0 -0
- data/public/play.html +33 -28
- data/public/qunit/qunit.entity.js +56 -6
- data/public/qunit/qunit.input.js +5 -5
- data/public/test.html +49 -0
- data/spec/javascripts/src/core/comp_spec.js +17 -6
- data/spec/javascripts/src/core/entity_spec.js +4 -5
- data/spec/javascripts/src/core/query_spec.js +25 -0
- data/spec/javascripts/src/core/re_spec.js +3 -3
- data/spec/javascripts/src/cycle/update_spec.js +8 -8
- data/spec/javascripts/src/display/align_spec.js +2 -2
- data/spec/javascripts/src/display/el_spec.js +17 -0
- data/spec/javascripts/src/input/keyboard_spec.js +4 -4
- data/spec/javascripts/src/input/mouse_spec.js +8 -7
- data/spec/javascripts/src/math/random_spec.js +8 -0
- data/spec/javascripts/src/util/clone_spec.js +20 -0
- data/spec/lib/entityjs/commands/build_spec.rb +3 -8
- data/spec/lib/entityjs/commands/html_spec.rb +27 -0
- data/spec/lib/entityjs/commands/min_spec.rb +30 -0
- data/spec/lib/entityjs/config_spec.rb +6 -0
- data/spec/lib/entityjs/page_spec.rb +4 -4
- data/src/core/comp.js +87 -31
- data/src/core/entity.js +38 -43
- data/src/core/load.js +2 -8
- data/src/core/query.js +17 -5
- data/src/core/re.js +1 -1
- data/src/core/system.js +8 -11
- data/src/cycle/drawlist.js +11 -11
- data/src/cycle/update.js +5 -5
- data/src/display/align.js +10 -3
- data/src/display/animate.js +26 -12
- data/src/display/el.js +99 -0
- data/src/input/keyboard.js +5 -5
- data/src/input/mouse.js +16 -11
- data/src/math/bisect.js +1 -1
- data/src/math/force.js +4 -4
- data/src/math/hitmap.js +2 -1
- data/src/math/iso.js +1 -1
- data/src/math/random.js +17 -2
- data/src/math/tile.js +1 -1
- data/src/media/sound.js +1 -1
- data/src/pattern/pathfind.js +2 -4
- data/src/save/storage.js +1 -1
- data/src/util/clone.js +12 -0
- data/src/util/scene.js +21 -16
- data/templates/circle/game.json +16 -0
- data/templates/circle/scripts/displays/circle.js +40 -0
- data/templates/circle/scripts/scenes/home.js +8 -17
- data/templates/circle/tests/scenes/home_test.js +3 -11
- data/templates/dom/game.json +6 -0
- data/templates/dom/scripts/els/btn.js +5 -0
- data/templates/dom/scripts/els/contain.js +5 -0
- data/templates/dom/scripts/els/header.js +5 -0
- data/templates/{animation → dom}/scripts/init.js +0 -0
- data/templates/dom/scripts/scenes/home.js +22 -0
- data/templates/{animation → dom}/scripts/scenes/load.js +0 -0
- data/templates/dom/tests/scenes/home_test.js +9 -0
- data/templates/{animation → dom}/tests/scenes/load_test.js +0 -0
- data/templates/isometric/game.json +16 -0
- data/templates/platform/game.json +18 -0
- data/templates/platform/scripts/displays/hero.js +1 -1
- data/templates/platform/scripts/items/coin.js +1 -1
- data/templates/platform/scripts/items/spring.js +1 -1
- data/templates/platform/tests/displays/hero_test.js +4 -4
- data/templates/platform/tests/factories.js +1 -1
- data/templates/platform/tests/items/coin_test.js +1 -1
- data/templates/pong/game.json +16 -0
- data/templates/tiltmaze/game.json +16 -0
- data/templates/tiltmaze/scripts/structs/level.js +1 -1
- data/templates/tiltmaze/scripts/tiles/walltile.js +1 -1
- metadata +45 -32
- data/.rspec +0 -2
- data/public/tests.html +0 -31
- data/src/cycle/worker.js +0 -9
- data/templates/animation/assets/images/hero.png +0 -0
- data/templates/animation/scripts/scenes/home.js +0 -41
- data/templates/animation/tests/init_test.js +0 -4
- data/templates/animation/tests/scenes/home_test.js +0 -15
- data/templates/arrow_keys/assets/images/arrow.png +0 -0
- data/templates/arrow_keys/config.yml +0 -22
- data/templates/arrow_keys/readme.txt +0 -9
- data/templates/arrow_keys/scripts/displays/arrow.js +0 -69
- data/templates/arrow_keys/scripts/init.js +0 -10
- data/templates/arrow_keys/scripts/inputs/controls.js +0 -35
- data/templates/arrow_keys/scripts/scenes/home.js +0 -20
- data/templates/arrow_keys/scripts/scenes/load.js +0 -57
- data/templates/arrow_keys/tests/displays/arrow_test.js +0 -29
- data/templates/arrow_keys/tests/init_test.js +0 -4
- data/templates/arrow_keys/tests/inputs/controls_test.js +0 -32
- data/templates/arrow_keys/tests/scenes/home_test.js +0 -0
- data/templates/arrow_keys/tests/scenes/load_test.js +0 -18
- data/templates/circle/config.yml +0 -22
- data/templates/isometric/config.yml +0 -22
- data/templates/platform/config.yml +0 -23
- data/templates/pong/config.yml +0 -22
- data/templates/tiltmaze/config.yml +0 -25
data/src/display/el.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/*
|
|
2
|
+
The element comp creates and displays DOM elements. This can be used to display buttons,
|
|
3
|
+
images, icons etc. on top of the canvas element.
|
|
4
|
+
|
|
5
|
+
re.e('el:a').$el //jquery element refence
|
|
6
|
+
|
|
7
|
+
Jquery must be available to work!
|
|
8
|
+
|
|
9
|
+
*/
|
|
10
|
+
re.c('el')
|
|
11
|
+
.requires('align')
|
|
12
|
+
.defines({
|
|
13
|
+
|
|
14
|
+
posX:function(x){
|
|
15
|
+
if(re.is(x)){
|
|
16
|
+
return this.$el.css('left', x);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return this.$el.position().left;
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
posY:function(y){
|
|
23
|
+
if(re.is(y)){
|
|
24
|
+
return this.$el.css('top', y);
|
|
25
|
+
}
|
|
26
|
+
return this.$el.position().top;
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
sizeX:function(){
|
|
30
|
+
return this.$el.outerWidth();
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
sizeY:function(){
|
|
34
|
+
return this.$el.outerHeight();
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
click:function(f){
|
|
38
|
+
var that = this;
|
|
39
|
+
this.$el.click(function(e){
|
|
40
|
+
f.call(that,e);
|
|
41
|
+
return false;
|
|
42
|
+
});
|
|
43
|
+
return this;
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
$:function(a,b){
|
|
47
|
+
return this.$el.find(a,b);
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
setEl:function(el){
|
|
51
|
+
this.remove();
|
|
52
|
+
|
|
53
|
+
this.el = el;
|
|
54
|
+
this.$el = $(el).addClass('el');
|
|
55
|
+
|
|
56
|
+
this.posX(0);
|
|
57
|
+
this.posY(0);
|
|
58
|
+
return this;
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
text:function(t){
|
|
62
|
+
if(re.is(t)){
|
|
63
|
+
this.$el.text(t);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
return this.$el.text();
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
//places element to parent of canvas
|
|
70
|
+
place:function(){
|
|
71
|
+
$(re.sys.canvas).parent().append(this.el);
|
|
72
|
+
return this;
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
remove:function(){
|
|
76
|
+
if(this.$el){
|
|
77
|
+
this.$el.remove();
|
|
78
|
+
this.$el = this.el = null;
|
|
79
|
+
}
|
|
80
|
+
return this;
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
hide:function(){
|
|
84
|
+
this.$el.hide();
|
|
85
|
+
return this;
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
show:function(){
|
|
89
|
+
this.$el.show();
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
})
|
|
94
|
+
.init(function(e){
|
|
95
|
+
if(e) this.setEl(re.$new(e));
|
|
96
|
+
})
|
|
97
|
+
.dispose(function(){
|
|
98
|
+
this.remove();
|
|
99
|
+
});
|
data/src/input/keyboard.js
CHANGED
|
@@ -111,7 +111,7 @@ re.c('keyboard')
|
|
|
111
111
|
.trigger('ctrl+k')
|
|
112
112
|
*/
|
|
113
113
|
event: function(e){
|
|
114
|
-
var that = re.
|
|
114
|
+
var that = re.keyboard;
|
|
115
115
|
|
|
116
116
|
var tagName = (e.target || e.srcElement || {}).tagName;
|
|
117
117
|
|
|
@@ -151,11 +151,11 @@ re.c('keyboard')
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
})
|
|
154
|
-
.init(function(
|
|
154
|
+
.init(function(){
|
|
155
155
|
//add to statics key array
|
|
156
|
-
|
|
156
|
+
re.keyboard.l.push(this);
|
|
157
157
|
})
|
|
158
|
-
.dispose(function(
|
|
158
|
+
.dispose(function(){
|
|
159
159
|
//remove from statics key array
|
|
160
|
-
|
|
160
|
+
re.keyboard.l.splice(re.keyboard.l.indexOf(this), 1);
|
|
161
161
|
});
|
data/src/input/mouse.js
CHANGED
|
@@ -47,7 +47,7 @@ re.c('mouse')
|
|
|
47
47
|
re.pressed.d[c] = (e.type == 'mousedown');
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
re.
|
|
50
|
+
re.mouse.event(e, c);
|
|
51
51
|
|
|
52
52
|
},
|
|
53
53
|
|
|
@@ -68,7 +68,7 @@ re.c('mouse')
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
|
|
71
|
-
var listeners = re.
|
|
71
|
+
var listeners = re.mouse.l;
|
|
72
72
|
|
|
73
73
|
/*
|
|
74
74
|
if(re.preventDefault && re.preventDefault.d[key]){
|
|
@@ -76,17 +76,20 @@ re.c('mouse')
|
|
|
76
76
|
}
|
|
77
77
|
*/
|
|
78
78
|
|
|
79
|
-
var c, t, obj;
|
|
79
|
+
var c, t, obj, tx, ty;
|
|
80
80
|
for(var i=0; i<listeners.length; i++){
|
|
81
81
|
t = listeners[i];
|
|
82
82
|
if(t.screenable){
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
tx = re.screen.toScreenX(x);
|
|
84
|
+
ty = re.screen.toScreenY(y);
|
|
85
|
+
} else {
|
|
86
|
+
tx = x;
|
|
87
|
+
ty = y;
|
|
85
88
|
}
|
|
86
89
|
|
|
87
90
|
//offset mouse coordinates
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
tx += t.offX;
|
|
92
|
+
ty += t.offY;
|
|
90
93
|
|
|
91
94
|
t.trigger(e.type, tx, ty, e);
|
|
92
95
|
|
|
@@ -102,6 +105,8 @@ re.c('mouse')
|
|
|
102
105
|
re.listener('mousedown', this.press, c);
|
|
103
106
|
re.listener('mouseup', this.press, c);
|
|
104
107
|
re.listener('mousemove', this.event, c);
|
|
108
|
+
re.listener('mouseover', this.event, c);
|
|
109
|
+
re.listener('mouseout', this.event, c);
|
|
105
110
|
re.listener('click', this.event, c);
|
|
106
111
|
re.listener('dblclick', this.event, c);
|
|
107
112
|
re.listener('contextmenu', this.event, c);
|
|
@@ -112,12 +117,12 @@ re.c('mouse')
|
|
|
112
117
|
offX:0,
|
|
113
118
|
offY:0
|
|
114
119
|
})
|
|
115
|
-
.init(function(
|
|
120
|
+
.init(function(){
|
|
116
121
|
//add to listener array
|
|
117
|
-
|
|
122
|
+
re.mouse.l.push(this);
|
|
118
123
|
})
|
|
119
|
-
.dispose(function(
|
|
124
|
+
.dispose(function(){
|
|
120
125
|
//remove from listener array
|
|
121
126
|
|
|
122
|
-
|
|
127
|
+
re.mouse.l.splice(re.mouse.l.indexOf(this), 1);
|
|
123
128
|
});
|
data/src/math/bisect.js
CHANGED
data/src/math/force.js
CHANGED
|
@@ -20,7 +20,7 @@ e.hitmap == re.hitmap //true
|
|
|
20
20
|
|
|
21
21
|
Warning - this component is not delta time safe. It assumes a fixed timestep.
|
|
22
22
|
*/
|
|
23
|
-
re.
|
|
23
|
+
re.c('force')
|
|
24
24
|
.requires('update')
|
|
25
25
|
.statics({
|
|
26
26
|
graX:0,
|
|
@@ -125,13 +125,13 @@ re.force = re.c('force')
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
})
|
|
128
|
-
.init(function(
|
|
128
|
+
.init(function(){
|
|
129
129
|
|
|
130
130
|
//setup defaults
|
|
131
131
|
this.def({
|
|
132
132
|
hitmap:re.hitmap,
|
|
133
|
-
graX:
|
|
134
|
-
graY:
|
|
133
|
+
graX:re.force.graX,
|
|
134
|
+
graY:re.force.graY
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
this.on('update', this.force_update);
|
data/src/math/hitmap.js
CHANGED
data/src/math/iso.js
CHANGED
data/src/math/random.js
CHANGED
|
@@ -3,19 +3,34 @@ re.random() // 0 - 1 floats
|
|
|
3
3
|
re.random(10) // 0 - 9 integer
|
|
4
4
|
re.random(10, 30) // 10 - 30 integer
|
|
5
5
|
re.random([1, 10, 40]) // 1 or 10 or 40
|
|
6
|
+
re.random({ok:10, b:10, c:1}) //ok or b or c
|
|
6
7
|
|
|
7
8
|
*/
|
|
8
9
|
re.random = function(max, min){
|
|
9
10
|
var r = Math.random();
|
|
10
11
|
if(re.is(max, 'array')){
|
|
11
12
|
return max[r * max.length | 0];
|
|
13
|
+
} else if(re.is(max, 'object')){
|
|
14
|
+
|
|
15
|
+
var result;
|
|
16
|
+
for (var prop in max){
|
|
17
|
+
if (Math.random() < 1/++r || !re.is(result)){
|
|
18
|
+
result = prop;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return result;
|
|
12
23
|
}
|
|
13
24
|
switch(arguments.length){
|
|
14
25
|
case 0:
|
|
15
26
|
return r;
|
|
16
27
|
case 1:
|
|
17
|
-
return r * max
|
|
28
|
+
return r * max;
|
|
18
29
|
case 2:
|
|
19
|
-
return r * (max - min + 1) + min
|
|
30
|
+
return r * (max - min + 1) + min;
|
|
20
31
|
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
re.randomInt = function(){
|
|
35
|
+
return re.random.apply(this, arguments)|0;
|
|
21
36
|
};
|
data/src/math/tile.js
CHANGED
data/src/media/sound.js
CHANGED
data/src/pattern/pathfind.js
CHANGED
|
@@ -53,14 +53,12 @@ while(ints.length){
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
*/
|
|
56
|
-
re.
|
|
57
|
-
.
|
|
58
|
-
search:function(){
|
|
56
|
+
re.c('pathfind')
|
|
57
|
+
.method(function(){
|
|
59
58
|
var p = re.e('pathfind');
|
|
60
59
|
var path = p.pathfind.apply(p, arguments);
|
|
61
60
|
p.dispose();
|
|
62
61
|
return path;
|
|
63
|
-
}
|
|
64
62
|
})
|
|
65
63
|
.defines({
|
|
66
64
|
|
data/src/save/storage.js
CHANGED
data/src/util/clone.js
ADDED
data/src/util/scene.js
CHANGED
|
@@ -27,40 +27,45 @@ re.e('scene:game')
|
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
|
|
31
|
+
re.c('scene')
|
|
32
|
+
.statics({
|
|
33
|
+
|
|
34
|
+
_scenes:{}
|
|
35
|
+
|
|
36
|
+
})
|
|
37
|
+
.method(function(title){
|
|
38
|
+
var d = re.scene;
|
|
32
39
|
|
|
33
40
|
if(!re.is(title)){
|
|
34
|
-
return
|
|
41
|
+
return d._scenes[re.scene.current];
|
|
35
42
|
}
|
|
36
43
|
|
|
37
|
-
if(!
|
|
44
|
+
if(!d._scenes[title]){
|
|
38
45
|
//add scene
|
|
39
46
|
re.e('scene:'+title);
|
|
40
47
|
}
|
|
41
48
|
|
|
42
|
-
return
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
re.c('scene')
|
|
46
|
-
.statics({
|
|
47
|
-
|
|
48
|
-
_scenes:{}
|
|
49
|
-
|
|
49
|
+
return d._scenes[title];
|
|
50
50
|
})
|
|
51
|
-
.init(function(
|
|
51
|
+
.init(function(title){
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
re.scene._scenes[title] = this;
|
|
54
54
|
this.sceneName = title;
|
|
55
55
|
|
|
56
56
|
})
|
|
57
|
-
.dispose(function(
|
|
57
|
+
.dispose(function(){
|
|
58
58
|
|
|
59
|
-
delete
|
|
59
|
+
delete re.scene._scenes[this.sceneName];
|
|
60
60
|
|
|
61
61
|
})
|
|
62
62
|
.defines({
|
|
63
63
|
|
|
64
|
+
clear:function(){
|
|
65
|
+
re('el').query('draw').dispose();
|
|
66
|
+
return this;
|
|
67
|
+
},
|
|
68
|
+
|
|
64
69
|
enter:function(title){
|
|
65
70
|
if(!re.is(title, 'function')){
|
|
66
71
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
//configure game settings
|
|
3
|
+
"width": 500,
|
|
4
|
+
"height": 400,
|
|
5
|
+
"canvas-id": "game-canvas",
|
|
6
|
+
|
|
7
|
+
//ignore entity scripts
|
|
8
|
+
"entity-ignore": "wait",
|
|
9
|
+
|
|
10
|
+
"tests-ignore": null,
|
|
11
|
+
"scripts-ignore": null,
|
|
12
|
+
"tests-scripts-ignore":"init.js",
|
|
13
|
+
|
|
14
|
+
//order scripts
|
|
15
|
+
"order": null
|
|
16
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
A simple circle component. Keep in mind this is extending the default circle in the
|
|
3
|
+
game engine.
|
|
4
|
+
|
|
5
|
+
A circle can be created on of two ways:
|
|
6
|
+
|
|
7
|
+
re.e('circle');
|
|
8
|
+
|
|
9
|
+
or through a factory:
|
|
10
|
+
|
|
11
|
+
re.circle(10, "#00CCFF");
|
|
12
|
+
|
|
13
|
+
*/
|
|
14
|
+
re.c('circle')
|
|
15
|
+
.factory(function(radius, color){
|
|
16
|
+
//this is called when using re.circle()
|
|
17
|
+
this.radius = radius;
|
|
18
|
+
this.color = color;
|
|
19
|
+
})
|
|
20
|
+
.requires('align update')
|
|
21
|
+
.defines({
|
|
22
|
+
//define properties
|
|
23
|
+
speed:15,
|
|
24
|
+
color:'#ff0000'
|
|
25
|
+
})
|
|
26
|
+
.events({
|
|
27
|
+
|
|
28
|
+
//adds a listener for updates
|
|
29
|
+
update:function(){
|
|
30
|
+
|
|
31
|
+
//move on keypressed
|
|
32
|
+
if(re.pressed('a', 'left')) this.posX -= this.speed;
|
|
33
|
+
if(re.pressed('d', 'right')) this.posX += this.speed;
|
|
34
|
+
|
|
35
|
+
if(re.pressed('w', 'up')) this.posY -= this.speed;
|
|
36
|
+
if(re.pressed('s', 'down')) this.posY += this.speed;
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
});
|