entityjs 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +18 -14
- data/entityjs.gemspec +1 -0
- data/lib/entityjs/assets.rb +13 -163
- data/lib/entityjs/command.rb +5 -2
- data/lib/entityjs/commands/build.rb +63 -23
- data/lib/entityjs/commands/eunit.rb +44 -0
- data/lib/entityjs/commands/release.rb +1 -1
- data/lib/entityjs/commands/server.rb +19 -4
- data/lib/entityjs/compile.rb +152 -0
- data/lib/entityjs/config.rb +8 -0
- data/lib/entityjs/dirc.rb +70 -17
- data/lib/entityjs/page.rb +106 -0
- data/lib/entityjs/parsers/parse_coffee.rb +12 -0
- data/lib/entityjs/version.rb +1 -1
- data/lib/entityjs.rb +18 -4
- data/public/qunit/qunit.css +9 -3
- data/public/qunit/qunit.entity.js +113 -31
- data/public/qunit/qunit.js +296 -235
- data/public/qunit/qunit.mock.js +54 -2
- data/public/tests.html +0 -15
- data/spec/javascripts/src/cycle/tween_spec.js +59 -0
- data/spec/javascripts/src/display/screen_spec.js +0 -15
- data/spec/javascripts/src/display/text_spec.js +4 -0
- data/spec/javascripts/src/input/mouse_spec.js +18 -18
- data/spec/javascripts/src/input/preventdefault_spec.js +14 -0
- data/spec/javascripts/src/math/drag_spec.js +2 -2
- data/spec/javascripts/src/math/hit_spec.js +24 -0
- data/spec/javascripts/src/math/point_spec.js +3 -3
- data/spec/javascripts/src/math/tile_spec.js +1 -1
- data/spec/javascripts/src/media/sound_spec.js +1 -1
- data/spec/javascripts/src/pattern/automap_spec.js +3 -3
- data/spec/javascripts/src/pattern/flicker_spec.js +2 -1
- data/spec/javascripts/src/util/random_spec.js +17 -0
- data/spec/javascripts/src/util/scene_spec.js +15 -0
- data/spec/lib/entityjs/assets_spec.rb +2 -201
- data/spec/lib/entityjs/commands/build_spec.rb +18 -5
- data/spec/lib/entityjs/commands/eunit_spec.rb +18 -0
- data/spec/lib/entityjs/commands/release_spec.rb +2 -0
- data/spec/lib/entityjs/compile_spec.rb +204 -0
- data/spec/lib/entityjs/dirc_spec.rb +8 -4
- data/spec/lib/entityjs/page_spec.rb +59 -0
- data/spec/support/factories.rb +0 -2
- data/src/core/entity.js +4 -18
- data/src/core/query.js +1 -1
- data/src/core/re.js +6 -6
- data/src/core/system.js +17 -12
- data/src/cycle/tween.js +93 -31
- data/src/display/align.js +11 -6
- data/src/display/circle.js +5 -4
- data/src/display/imgtext.js +33 -22
- data/src/display/screen.js +0 -8
- data/src/display/text.js +37 -4
- data/src/input/keyboard.js +15 -5
- data/src/input/mouse.js +15 -25
- data/src/input/preventdefault.js +11 -0
- data/src/math/body.js +35 -16
- data/src/math/drag.js +2 -2
- data/src/math/force.js +2 -2
- data/src/math/hit.js +15 -6
- data/src/math/hitmap.js +6 -6
- data/src/math/point.js +1 -1
- data/src/math/tile.js +22 -17
- data/src/media/sound.js +1 -1
- data/src/pattern/automap.js +16 -27
- data/src/pattern/flicker.js +9 -5
- data/src/util/random.js +4 -0
- data/src/util/scene.js +2 -6
- data/templates/arrow_keys/scripts/{display → displays}/arrow.js +0 -0
- data/templates/arrow_keys/scripts/{input → inputs}/controls.js +0 -0
- data/templates/arrow_keys/tests/{display → displays}/arrow_test.js +1 -1
- data/templates/arrow_keys/tests/{input → inputs}/controls_test.js +0 -0
- data/templates/arrow_keys/tests/scenes/load_test.js +2 -0
- data/templates/{blank → circle}/config.yml +0 -0
- data/templates/{blank → circle}/readme.txt +0 -0
- data/templates/circle/scripts/init.js +7 -0
- data/templates/circle/scripts/scenes/home.js +62 -0
- data/templates/circle/scripts/scenes/load.js +11 -0
- data/templates/circle/tests/scenes/home_test.js +29 -0
- data/templates/circle/tests/scenes/load_test.js +15 -0
- data/templates/platform/config.yml +2 -1
- data/templates/platform/readme.txt +15 -16
- data/templates/platform/scripts/{display → displays}/bit.js +0 -0
- data/templates/platform/scripts/{display → displays}/hero.js +0 -0
- data/templates/platform/scripts/{display → displays}/tile.js +0 -0
- data/templates/platform/scripts/{display → displays}/tsprite.js +0 -0
- data/templates/platform/{assets → scripts}/levels/level1.tmx +0 -0
- data/templates/platform/scripts/{util → utils}/counter.js +0 -0
- data/templates/platform/scripts/{util → utils}/level.js +0 -0
- data/templates/platform/tests/{display → displays}/bit_test.js +1 -1
- data/templates/platform/tests/displays/hero_test.js +73 -0
- data/templates/platform/tests/{display → displays}/tile_test.js +1 -1
- data/templates/platform/tests/displays/tsprite_test.js +8 -0
- data/templates/platform/tests/items/coin_test.js +10 -10
- data/templates/platform/tests/items/item_test.js +9 -9
- data/templates/platform/tests/items/spring_test.js +3 -3
- data/templates/platform/tests/scenes/load_test.js +2 -1
- data/templates/platform/tests/{util → utils}/counter_test.js +2 -2
- data/templates/platform/tests/{util → utils}/level_test.js +3 -0
- data/templates/pong/config.yml +22 -0
- data/templates/pong/readme.txt +3 -0
- data/templates/pong/scripts/controls/ai.js +30 -0
- data/templates/pong/scripts/controls/arena.js +33 -0
- data/templates/pong/scripts/controls/hitmap.js +54 -0
- data/templates/pong/scripts/controls/player.js +24 -0
- data/templates/pong/scripts/controls/twoarena.js +14 -0
- data/templates/pong/scripts/displays/ball.js +29 -0
- data/templates/pong/scripts/displays/counter.js +22 -0
- data/templates/pong/scripts/displays/paddle.js +22 -0
- data/templates/pong/scripts/init.js +9 -0
- data/templates/pong/scripts/scenes/game.js +61 -0
- data/templates/pong/scripts/scenes/home.js +55 -0
- data/templates/pong/scripts/scenes/over.js +29 -0
- data/templates/pong/tests/controls/ai_test.js +34 -0
- data/templates/pong/tests/controls/arena_test.js +20 -0
- data/templates/pong/tests/controls/hitmap_test.js +89 -0
- data/templates/pong/tests/controls/player_test.js +25 -0
- data/templates/pong/tests/controls/twoarena_test.js +7 -0
- data/templates/pong/tests/displays/ball_test.js +10 -0
- data/templates/pong/tests/displays/counter_test.js +13 -0
- data/templates/pong/tests/displays/paddle_test.js +17 -0
- data/templates/pong/tests/scenes/game_test.js +16 -0
- data/templates/pong/tests/scenes/home_test.js +30 -0
- data/templates/pong/tests/scenes/over_test.js +16 -0
- data/templates/tiltmaze/config.yml +25 -0
- data/templates/tiltmaze/readme.txt +79 -0
- data/templates/tiltmaze/scripts/displays/ball.js +78 -0
- data/templates/tiltmaze/scripts/displays/target.js +13 -0
- data/templates/tiltmaze/scripts/displays/tile.js +2 -0
- data/templates/tiltmaze/scripts/init.js +7 -0
- data/templates/tiltmaze/scripts/levels/level1.json +14 -0
- data/templates/tiltmaze/scripts/levels/level2.json +14 -0
- data/templates/tiltmaze/scripts/levels/level3.json +14 -0
- data/templates/tiltmaze/scripts/levels/level4.json +15 -0
- data/templates/tiltmaze/scripts/levels/level5.json +18 -0
- data/templates/tiltmaze/scripts/scenes/game.js +56 -0
- data/templates/tiltmaze/scripts/scenes/home.js +24 -0
- data/templates/tiltmaze/scripts/structs/level.js +82 -0
- data/templates/tiltmaze/scripts/tiles/walltile.js +147 -0
- data/templates/tiltmaze/tests/displays/ball_test.js +67 -0
- data/templates/tiltmaze/tests/displays/target_test.js +8 -0
- data/templates/tiltmaze/tests/factories.js +38 -0
- data/templates/tiltmaze/tests/scenes/game_test.js +59 -0
- data/templates/tiltmaze/tests/scenes/home_test.js +7 -0
- data/templates/tiltmaze/tests/structs/level_test.js +44 -0
- data/templates/tiltmaze/tests/tiles/walltile_test.js +36 -0
- metadata +106 -33
- data/templates/platform/tests/display/hero_test.js +0 -73
- data/templates/platform/tests/display/tsprite_test.js +0 -8
data/src/core/re.js
CHANGED
@@ -7,7 +7,7 @@ Licensed under MIT http://entityjs.com/license
|
|
7
7
|
|
8
8
|
*/
|
9
9
|
re = function(selector){
|
10
|
-
|
10
|
+
return new re.query(selector);
|
11
11
|
};
|
12
12
|
|
13
13
|
//automatically filled when compiled
|
@@ -19,17 +19,17 @@ re._e = [];
|
|
19
19
|
re._c = {};
|
20
20
|
|
21
21
|
re.ready = function(r){
|
22
|
-
|
22
|
+
re.listener('load', r);
|
23
23
|
};
|
24
24
|
|
25
25
|
/*
|
26
26
|
The $ method is used for selecting ids and tags.
|
27
27
|
*/
|
28
28
|
re.$ = function(s){
|
29
|
-
return re.$.
|
29
|
+
return re.$._[s] = re.$._[s] || ((s.charAt(0) == '#') ? document.getElementById(s.substr(1)) : document.getElementsByTagName(s)[0]);
|
30
30
|
};
|
31
31
|
//caches dom queries
|
32
|
-
re.$.
|
32
|
+
re.$._ = {};
|
33
33
|
|
34
34
|
re.$new = function(n){
|
35
35
|
return document.createElement(n);
|
@@ -38,8 +38,8 @@ re.$new = function(n){
|
|
38
38
|
/*
|
39
39
|
Special polyfills and object additions
|
40
40
|
*/
|
41
|
-
re.listener = function(t, c){
|
42
|
-
window.addEventListener(t, c, true);
|
41
|
+
re.listener = function(t, c, context){
|
42
|
+
(context || window).addEventListener(t, c, true);
|
43
43
|
};
|
44
44
|
|
45
45
|
/*
|
data/src/core/system.js
CHANGED
@@ -51,7 +51,7 @@ re.c('system')
|
|
51
51
|
|
52
52
|
}
|
53
53
|
|
54
|
-
return
|
54
|
+
return this;
|
55
55
|
},
|
56
56
|
|
57
57
|
loop:function(m){
|
@@ -68,22 +68,16 @@ re.c('system')
|
|
68
68
|
|
69
69
|
//scale is currently not implemented!
|
70
70
|
init:function(canvasId, scale, contextType){
|
71
|
-
//init listeners
|
72
|
-
if(re._c.keyboard){
|
73
|
-
re._c.keyboard.i();
|
74
|
-
}
|
75
|
-
if(re._c.mouse){
|
76
|
-
re._c.mouse.i();
|
77
|
-
}
|
78
|
-
if(re._c.touch){
|
79
|
-
re._c.touch.i();
|
80
|
-
}
|
81
71
|
|
82
72
|
//add comps here because system is defined earlier than other comps
|
83
73
|
this.comp('polyfill tick timestep');
|
84
74
|
|
85
75
|
//setup canvas
|
86
|
-
|
76
|
+
if(re.is(canvasId, 'htmlcanvaselement')){
|
77
|
+
this.canvas = canvasId;
|
78
|
+
} else {
|
79
|
+
this.canvas = re.$(canvasId);
|
80
|
+
}
|
87
81
|
|
88
82
|
this.scale = scale || 1;
|
89
83
|
|
@@ -94,6 +88,17 @@ re.c('system')
|
|
94
88
|
this.sizeX = s.sizeX = this.canvas.width;
|
95
89
|
this.sizeY = s.sizeY = this.canvas.height;
|
96
90
|
|
91
|
+
//init listeners
|
92
|
+
if(re._c.keyboard){
|
93
|
+
re._c.keyboard.i();
|
94
|
+
}
|
95
|
+
if(re._c.mouse){
|
96
|
+
re._c.mouse.i();
|
97
|
+
}
|
98
|
+
if(re._c.touch){
|
99
|
+
re._c.touch.i();
|
100
|
+
}
|
101
|
+
|
97
102
|
return this;
|
98
103
|
},
|
99
104
|
|
data/src/cycle/tween.js
CHANGED
@@ -4,58 +4,120 @@ The tween component tweens properties of entities to the given value over a peri
|
|
4
4
|
This is useful for animations.
|
5
5
|
|
6
6
|
re.e('tween')
|
7
|
-
.tween(
|
7
|
+
.tween(800, {x:10})
|
8
|
+
.wait(500)
|
9
|
+
|
10
|
+
EVENTS:
|
11
|
+
tween:start
|
12
|
+
tween:finish
|
13
|
+
tween:update
|
8
14
|
|
9
15
|
*/
|
10
16
|
re.c('tween')
|
11
17
|
.requires('update')
|
12
|
-
.statics({
|
13
|
-
|
14
|
-
tween:function(obj, time, props){
|
15
|
-
return obj.comp('tween')
|
16
|
-
.tween(time, props);
|
17
|
-
}
|
18
|
-
|
19
|
-
})
|
20
18
|
.namespaces({
|
21
19
|
|
22
20
|
update:function(t){
|
21
|
+
if(!this.tweening) return;
|
23
22
|
|
24
|
-
|
25
|
-
|
23
|
+
this.tween_time += t;
|
24
|
+
|
25
|
+
var elapsed = this.tween_time / this.tween_t;
|
26
|
+
|
27
|
+
if(elapsed > 1) elapsed = 1;
|
28
|
+
|
29
|
+
//easing function
|
30
|
+
value = this.tweenEase(elapsed);
|
31
|
+
|
32
|
+
//advance
|
33
|
+
for(var i in this.tween_d){
|
34
|
+
|
35
|
+
//set deltas
|
36
|
+
var ease = this.tween_s[i] + this.tween_d[i] * value;
|
37
|
+
if(re.is(this[i], 'function')){
|
38
|
+
this[i](ease);
|
39
|
+
} else {
|
40
|
+
this[i] = ease;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
this.trigger('tween:update', value);
|
45
|
+
|
46
|
+
if(elapsed == 1){
|
47
|
+
|
48
|
+
this.tweening = false;
|
49
|
+
|
50
|
+
this.trigger('tween:finish');
|
51
|
+
|
52
|
+
//remove from queue
|
53
|
+
var next = this.tween_queue.shift();
|
54
|
+
|
55
|
+
if(next){
|
56
|
+
this.tween.apply(this, next);
|
57
|
+
}
|
58
|
+
|
59
|
+
}
|
60
|
+
|
26
61
|
}
|
27
62
|
|
28
63
|
})
|
29
64
|
.defaults({
|
30
65
|
|
31
|
-
tweening:false
|
66
|
+
tweening:false,
|
67
|
+
|
68
|
+
tweenEase:function(v){
|
69
|
+
return v;
|
70
|
+
}
|
32
71
|
|
33
72
|
})
|
34
73
|
.defines({
|
35
74
|
|
36
75
|
tween:function(time, props){
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
76
|
+
if(this.tweening){
|
77
|
+
this.tween_queue.push(arguments);
|
78
|
+
return;
|
79
|
+
}
|
80
|
+
|
81
|
+
//accepts ms or seconds
|
82
|
+
if(time >= 30){
|
83
|
+
time /= 1000;
|
84
|
+
}
|
85
|
+
|
86
|
+
var maxTime = (time || 1) / (re.sys.stepSize * 60);
|
87
|
+
this.tween_time = 0;
|
88
|
+
//steps are substracted until it reaches zero
|
89
|
+
|
90
|
+
var deltas = {};
|
91
|
+
var starts = {};
|
92
|
+
for(var i in props){
|
93
|
+
var value = this[i];
|
94
|
+
if(re.is(value, 'function')) value = value();
|
95
|
+
|
96
|
+
deltas[i] = props[i] - value;
|
97
|
+
starts[i] = value;
|
98
|
+
}
|
99
|
+
|
100
|
+
//tween initial values
|
101
|
+
this.tween_s = starts;
|
102
|
+
//tween deltas
|
103
|
+
this.tween_d = deltas;
|
104
|
+
//tween maximum time
|
105
|
+
this.tween_t = maxTime;
|
106
|
+
|
107
|
+
|
108
|
+
this.tweening = true;
|
109
|
+
|
110
|
+
return this.trigger('tween:start', starts);
|
53
111
|
}
|
54
|
-
|
112
|
+
|
55
113
|
})
|
56
114
|
.init(function(){
|
57
115
|
|
58
|
-
|
116
|
+
this.on('update', this.tween_update);
|
117
|
+
this.tween_queue = [];
|
59
118
|
|
60
119
|
});
|
61
|
-
|
120
|
+
|
121
|
+
re.tween = function(obj, time, props){
|
122
|
+
return obj.comp('tween').tween(time, props);
|
123
|
+
};
|
data/src/display/align.js
CHANGED
@@ -8,40 +8,45 @@ re.c('align')
|
|
8
8
|
.requires('draw')
|
9
9
|
.defines({
|
10
10
|
|
11
|
+
align:function(x, y){
|
12
|
+
this.alignHor(x);
|
13
|
+
return this.alignVer(y);
|
14
|
+
},
|
15
|
+
|
11
16
|
alignHor:function(o){
|
12
17
|
o = o || 0;
|
13
|
-
this.posX = re.sys.sizeX * 0.5 - (this.sizeX
|
18
|
+
this.posX = re.sys.sizeX * 0.5 - (this.sizeX - this.regX)*0.5 + o | 0;
|
14
19
|
|
15
20
|
return this;
|
16
21
|
},
|
17
22
|
|
18
23
|
alignVer:function(o){
|
19
24
|
o = o || 0;
|
20
|
-
this.posY = re.sys.sizeY * 0.5 - (this.sizeY
|
25
|
+
this.posY = re.sys.sizeY * 0.5 - (this.sizeY - this.regY)*0.5 + o | 0;
|
21
26
|
return this;
|
22
27
|
},
|
23
28
|
|
24
29
|
alignRight:function(x){
|
25
30
|
x = x || 0;
|
26
|
-
this.posX = re.sys.sizeX - (this.sizeX
|
31
|
+
this.posX = re.sys.sizeX - (this.sizeX - this.regX) + x | 0;
|
27
32
|
return this;
|
28
33
|
},
|
29
34
|
|
30
35
|
alignLeft:function(x){
|
31
36
|
x = x || 0;
|
32
|
-
this.posX = x + this.sizeX - (this.sizeX
|
37
|
+
this.posX = x + this.sizeX - (this.sizeX - this.regX) | 0;
|
33
38
|
return this;
|
34
39
|
},
|
35
40
|
|
36
41
|
alignTop:function(y){
|
37
42
|
y = y || 0;
|
38
|
-
this.posY = y + this.sizeY - (this.sizeY
|
43
|
+
this.posY = y + this.sizeY - (this.sizeY - this.regY) | 0;
|
39
44
|
return this;
|
40
45
|
},
|
41
46
|
|
42
47
|
alignBottom:function(y){
|
43
48
|
y = y || 0;
|
44
|
-
this.posY = re.sys.sizeY - (this.sizeY
|
49
|
+
this.posY = re.sys.sizeY - (this.sizeY - this.regY) + y | 0;
|
45
50
|
return this;
|
46
51
|
}
|
47
52
|
|
data/src/display/circle.js
CHANGED
@@ -13,8 +13,9 @@ re.c('circle')
|
|
13
13
|
c.fillStyle = this.color;
|
14
14
|
|
15
15
|
c.beginPath();
|
16
|
-
|
17
|
-
|
16
|
+
var r = this.radius();
|
17
|
+
|
18
|
+
c.arc(-this.regX + r , -this.regY + r , r, 0, Math.PI*2, true);
|
18
19
|
|
19
20
|
c.closePath();
|
20
21
|
|
@@ -24,10 +25,10 @@ re.c('circle')
|
|
24
25
|
|
25
26
|
radius:function(r){
|
26
27
|
if(re.is(r)){
|
27
|
-
this.sizeX = this.sizeY = r;
|
28
|
+
this.sizeX = this.sizeY = r * 2;
|
28
29
|
return this;
|
29
30
|
}
|
30
|
-
return this.sizeX;
|
31
|
+
return this.sizeX * 0.5;
|
31
32
|
}
|
32
33
|
|
33
34
|
});
|
data/src/display/imgtext.js
CHANGED
@@ -20,6 +20,8 @@ re('font')
|
|
20
20
|
|
21
21
|
*could be turned in to a special sprite component but wouldn't
|
22
22
|
be very useful.
|
23
|
+
|
24
|
+
|
23
25
|
*/
|
24
26
|
|
25
27
|
re.c('imgtext')
|
@@ -27,8 +29,8 @@ re.c('imgtext')
|
|
27
29
|
.interfaces('imgtext')
|
28
30
|
.defaults({
|
29
31
|
//remove empty characters in ascii
|
30
|
-
charOffset:32
|
31
|
-
|
32
|
+
charOffset:32,
|
33
|
+
lineHeight:15
|
32
34
|
})
|
33
35
|
.defines({
|
34
36
|
|
@@ -37,13 +39,22 @@ re.c('imgtext')
|
|
37
39
|
},
|
38
40
|
|
39
41
|
draw:function(c){
|
42
|
+
|
43
|
+
for(var i=0; i<this.text_lines.length; i++){
|
44
|
+
this.drawText(c, this.text_lines[i], i * this.lineHeight);
|
45
|
+
}
|
46
|
+
|
47
|
+
return this;
|
48
|
+
},
|
40
49
|
|
50
|
+
drawText:function(c, text, yPos){
|
51
|
+
|
41
52
|
var slot = 0, charWidth, code, charPos;
|
42
53
|
|
43
|
-
for(var i=0, l =
|
54
|
+
for(var i=0, l = text.length; i<l; ++i){
|
44
55
|
|
45
56
|
//get char code
|
46
|
-
code =
|
57
|
+
code = text.charCodeAt(i) - this.charOffset;
|
47
58
|
|
48
59
|
//find width of character
|
49
60
|
charWidth = this.imgtext[code];
|
@@ -57,35 +68,35 @@ re.c('imgtext')
|
|
57
68
|
this.charCache[code] = charPos;
|
58
69
|
}
|
59
70
|
|
60
|
-
c.drawImage(this._image, this.charCache[code], 0, charWidth, this._image.height, -this.regX + slot, -this.regY, charWidth, this._image.height);
|
71
|
+
c.drawImage(this._image, this.charCache[code], 0, charWidth, this._image.height, -this.regX + slot, -this.regY + yPos, charWidth, this._image.height);
|
61
72
|
|
62
73
|
//append to next character slot
|
63
74
|
slot += charWidth;
|
64
75
|
|
65
76
|
}
|
66
|
-
|
67
|
-
|
68
|
-
this.sizeY = this._image.height;
|
69
|
-
return this;
|
70
|
-
},
|
71
|
-
|
77
|
+
},
|
78
|
+
|
72
79
|
text:function(t){
|
73
80
|
if(re.is(t)){
|
74
81
|
this._text = t;
|
75
82
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
t += this.imgtext[p];
|
80
|
-
}
|
83
|
+
this.text_lines = this._text.split('\n');
|
84
|
+
|
85
|
+
this.sizeX = 0;
|
81
86
|
|
82
|
-
|
87
|
+
//find the longest line and set that as the width
|
88
|
+
for(var i in this.text_lines){
|
89
|
+
var w = 0;
|
90
|
+
//TODO size is slightly off
|
91
|
+
for(var p=0; p<this.text_lines[i].length; p++){
|
92
|
+
w += this.imgtext[p];
|
93
|
+
}
|
94
|
+
if(w > this.sizeX){
|
95
|
+
this.sizeX = w;
|
96
|
+
}
|
97
|
+
}
|
83
98
|
|
84
|
-
|
85
|
-
this.sizeY = this._image.height;
|
86
|
-
} else {
|
87
|
-
this.sizeY = 0;
|
88
|
-
}
|
99
|
+
this.sizeY = this.text_lines.length * this.lineHeight;
|
89
100
|
|
90
101
|
return this;
|
91
102
|
}
|
data/src/display/screen.js
CHANGED
@@ -29,14 +29,6 @@ re.c('screen')
|
|
29
29
|
|
30
30
|
toScreenY:function(y){
|
31
31
|
return y + this.posY + this.offY;
|
32
|
-
},
|
33
|
-
|
34
|
-
toScreen:function(x, y){
|
35
|
-
if(arguments.length==1){
|
36
|
-
y = x.posY || x.y;
|
37
|
-
x = x.posX || x.x;
|
38
|
-
}
|
39
|
-
return {x: this.toScreenX(x), y: this.toScreenY(y)};
|
40
32
|
}
|
41
33
|
|
42
34
|
})
|
data/src/display/text.js
CHANGED
@@ -16,18 +16,43 @@ re.c('text')
|
|
16
16
|
.defaults({
|
17
17
|
font:"14px sans-serif",
|
18
18
|
textColor:'#000000',
|
19
|
-
textAlign:'',
|
20
|
-
|
19
|
+
textAlign:'left',
|
20
|
+
textBaseline:'top',
|
21
|
+
lineHeight:15
|
21
22
|
})
|
22
23
|
.defines({
|
23
24
|
|
24
25
|
visible:function(){
|
25
|
-
return this._text && this.parent('draw', 'visible')
|
26
|
+
return this._text && this.parent('draw', 'visible');
|
26
27
|
},
|
27
28
|
|
28
29
|
text:function(t){
|
29
30
|
if(re.is(t)){
|
31
|
+
t += '';
|
32
|
+
this.text_lines = t.split('\n');
|
30
33
|
this._text = t;
|
34
|
+
//set text width
|
35
|
+
if(re.sys.context){
|
36
|
+
var c = re.sys.context;
|
37
|
+
c.save();
|
38
|
+
c.font = this.font;
|
39
|
+
|
40
|
+
this.sizeX = 0;
|
41
|
+
|
42
|
+
var w = 0;
|
43
|
+
for(var i in this.text_lines){
|
44
|
+
w = c.measureText(this.text_lines[i]).width;
|
45
|
+
if(w > this.sizeX){
|
46
|
+
this.sizeX = w;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
c.restore();
|
51
|
+
}
|
52
|
+
|
53
|
+
//set height
|
54
|
+
this.sizeY = this.text_lines.length * this.lineHeight;
|
55
|
+
|
31
56
|
return this;
|
32
57
|
}
|
33
58
|
return this._text;
|
@@ -37,7 +62,15 @@ re.c('text')
|
|
37
62
|
|
38
63
|
c.font = this.font;
|
39
64
|
c.fillStyle = this.textColor;
|
40
|
-
|
65
|
+
c.textAlign = this.textAlgin;
|
66
|
+
c.textBaseline = this.textBaseline;
|
67
|
+
|
68
|
+
//multi-line
|
69
|
+
var lines = this.text_lines;
|
70
|
+
for(var i=0, l=lines.length; i<l; i++){
|
71
|
+
c.fillText(lines[i], -this.regX, -this.regY + (i * this.lineHeight));
|
72
|
+
}
|
73
|
+
|
41
74
|
return this;
|
42
75
|
}
|
43
76
|
|
data/src/input/keyboard.js
CHANGED
@@ -113,8 +113,10 @@ re.c('keyboard')
|
|
113
113
|
event: function(e){
|
114
114
|
var that = re._c.keyboard;
|
115
115
|
|
116
|
+
var tagName = (e.target || e.srcElement || {}).tagName;
|
117
|
+
|
116
118
|
//disable keyboard keys if focus lost
|
117
|
-
if(
|
119
|
+
if(tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA'){
|
118
120
|
return;
|
119
121
|
}
|
120
122
|
|
@@ -122,10 +124,14 @@ re.c('keyboard')
|
|
122
124
|
|
123
125
|
var key = that.keyCodes[c];
|
124
126
|
|
125
|
-
if(re.pressed.d){
|
127
|
+
if(re.pressed && re.pressed.d){
|
126
128
|
re.pressed.d[key] = (e.type == 'keydown');
|
127
129
|
}
|
128
|
-
|
130
|
+
|
131
|
+
if(re.preventDefault && re.preventDefault.d[key]){
|
132
|
+
e.preventDefault();
|
133
|
+
}
|
134
|
+
|
129
135
|
for(var k=0; k<that.l.length; k++){
|
130
136
|
that.l[k]
|
131
137
|
.trigger(e.type, key, e)
|
@@ -136,8 +142,12 @@ re.c('keyboard')
|
|
136
142
|
|
137
143
|
//initialize function
|
138
144
|
i:function(){
|
139
|
-
re.listener('keydown', this.event
|
140
|
-
re.listener('keyup', this.event
|
145
|
+
re.listener('keydown', this.event);
|
146
|
+
re.listener('keyup', this.event);
|
147
|
+
//reset all keys
|
148
|
+
re.listener('focus', function(){
|
149
|
+
re.pressed.d = {};
|
150
|
+
});
|
141
151
|
}
|
142
152
|
|
143
153
|
})
|
data/src/input/mouse.js
CHANGED
@@ -51,32 +51,21 @@ re.c('mouse')
|
|
51
51
|
event:function(e, extra){
|
52
52
|
|
53
53
|
//calculate mouse coordinate
|
54
|
-
var x;
|
55
|
-
var y;
|
54
|
+
var x = e.offsetX;
|
55
|
+
var y = e.offsetY;
|
56
56
|
|
57
|
-
|
58
|
-
x = e.pageX;
|
59
|
-
y = e.pageY;
|
60
|
-
} else {
|
61
|
-
x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
|
62
|
-
y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
|
63
|
-
}
|
64
|
-
|
65
|
-
x -= re.sys.canvas.offsetLeft;
|
66
|
-
y -= re.sys.canvas.offsetTop;
|
57
|
+
var that = re.c('mouse');
|
67
58
|
|
68
|
-
|
69
|
-
if(
|
70
|
-
|
59
|
+
/*
|
60
|
+
if(re.preventDefault && re.preventDefault.d[key]){
|
61
|
+
e.preventDefault();
|
71
62
|
}
|
63
|
+
*/
|
72
64
|
|
73
|
-
var that = re.c('mouse');
|
74
|
-
|
75
|
-
//FUTURE automatically transform screen coordinates?
|
76
65
|
var c, t, obj;
|
77
66
|
for(var i=0; i<that.l.length; i++){
|
78
67
|
t = that.l[i];
|
79
|
-
obj = {
|
68
|
+
obj = {posX:x, posY:y};
|
80
69
|
obj.screenX = re.screen.toScreenX(x);
|
81
70
|
obj.screenY = re.screen.toScreenY(y);
|
82
71
|
|
@@ -90,12 +79,13 @@ re.c('mouse')
|
|
90
79
|
},
|
91
80
|
|
92
81
|
i:function(){
|
93
|
-
re.
|
94
|
-
re.listener('
|
95
|
-
re.listener('
|
96
|
-
re.listener('
|
97
|
-
re.listener('
|
98
|
-
re.listener('
|
82
|
+
var c = re.sys.canvas;
|
83
|
+
re.listener('mousedown', this.press, c);
|
84
|
+
re.listener('mouseup', this.press, c);
|
85
|
+
re.listener('mousemove', this.event, c);
|
86
|
+
re.listener('click', this.event, c);
|
87
|
+
re.listener('dblclick', this.event, c);
|
88
|
+
re.listener('contextmenu', this.event, c);
|
99
89
|
}
|
100
90
|
|
101
91
|
})
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/*
|
2
|
+
The PreventDefault method prevents defaults for input events.
|
3
|
+
*/
|
4
|
+
re.preventDefault = function(pres){
|
5
|
+
if(re.is(pres, 'string')) pres = pres.split(' ');
|
6
|
+
|
7
|
+
for(var i in pres){
|
8
|
+
re.preventDefault.d[pres[i]] = 1;
|
9
|
+
}
|
10
|
+
};
|
11
|
+
re.preventDefault.d = {};
|
data/src/math/body.js
CHANGED
@@ -20,37 +20,56 @@ padX:2 //pushes the body in 2 pixels on both right and left
|
|
20
20
|
re.c('body')
|
21
21
|
.defines({
|
22
22
|
|
23
|
-
hit:function(x, y, w, h){
|
23
|
+
hit:function(x, y, w, h, rx, ry){
|
24
24
|
if(re.is(x,'object')){
|
25
|
-
y = x.posY;
|
26
|
-
w = x.sizeX;
|
27
|
-
h = x.sizeY;
|
28
|
-
|
25
|
+
y = x.posY || x.y;
|
26
|
+
w = x.sizeX || x.w;
|
27
|
+
h = x.sizeY || x.h;
|
28
|
+
rx = x.regX || 0;
|
29
|
+
ry = x.regY || 0;
|
30
|
+
x = x.posX || x.x;
|
29
31
|
}
|
32
|
+
|
33
|
+
rx = rx || 0;
|
34
|
+
ry = ry || 0;
|
35
|
+
|
36
|
+
var regX = this.regX ||0;
|
37
|
+
var regY = this.regY ||0;
|
38
|
+
|
30
39
|
return !
|
31
40
|
(
|
32
|
-
x > this.posX + this.bodyX - this.padX ||
|
33
|
-
x + w < this.posX + this.padX ||
|
34
|
-
y > this.posY + this.bodyY - this.padY||
|
35
|
-
y + h < this.posY + this.padY
|
41
|
+
x - rx > this.posX + this.bodyX - this.padX - regX ||
|
42
|
+
x + w -rx < this.posX + this.padX - regX ||
|
43
|
+
y -ry > this.posY + this.bodyY - this.padY - regY ||
|
44
|
+
y + h - ry < this.posY + this.padY - regY
|
36
45
|
);
|
37
46
|
},
|
38
47
|
|
39
|
-
hitBody:function(x, y, bx, by, px, py){
|
48
|
+
hitBody:function(x, y, bx, by, px, py, rx, ry){
|
40
49
|
if(re.is(x,'object')){
|
41
|
-
y = x.posY;
|
50
|
+
y = x.posY || x.y;
|
42
51
|
bx = x.bodyX;
|
43
52
|
by = x.bodyY;
|
44
53
|
px = x.padX;
|
45
54
|
py = x.padY;
|
46
|
-
|
55
|
+
rx = x.regX || 0;
|
56
|
+
ry = x.regY || 0;
|
57
|
+
x = x.posX || x.x;
|
47
58
|
}
|
59
|
+
|
60
|
+
rx = rx || 0;
|
61
|
+
ry = ry || 0;
|
62
|
+
|
63
|
+
var regX = this.regX ||0;
|
64
|
+
var regY = this.regY ||0;
|
65
|
+
|
66
|
+
|
48
67
|
return !
|
49
68
|
(
|
50
|
-
x + px > this.posX + this.bodyX + this.padX ||
|
51
|
-
x + bx - px < this.posX + this.padX ||
|
52
|
-
y + py > this.posY + this.bodyY - this.padY ||
|
53
|
-
y + by - py < this.posY + this.padY
|
69
|
+
x + px - rx> this.posX + this.bodyX + this.padX -regX ||
|
70
|
+
x + bx - px -rx < this.posX + this.padX -regX ||
|
71
|
+
y + py -ry > this.posY + this.bodyY - this.padY - regY ||
|
72
|
+
y + by - py -ry < this.posY + this.padY - regY
|
54
73
|
);
|
55
74
|
}
|
56
75
|
|