entityjs 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,5 +20,7 @@ case code
20
20
  puts "Move inside the root directory"
21
21
  when 3
22
22
  puts "File/Directory already exists"
23
+ when 4
24
+ puts "Argument error"
23
25
 
24
26
  end
@@ -11,7 +11,7 @@ module Entityjs
11
11
  ['mp3', 'ogg', 'aac', 'wav']
12
12
  end
13
13
 
14
- def self.search(type='*')
14
+ def self.search(type=nil)
15
15
 
16
16
  case type
17
17
  when 'images'
@@ -25,8 +25,7 @@ module Entityjs
25
25
  return self.find_files(sounds_folder+"/**/*.{#{valid_sounds}}")
26
26
 
27
27
  else
28
- #TODO: fix up
29
- return self.search_datas
28
+ return self.find_files(Config.assets_folder+'/**/*')
30
29
 
31
30
  end
32
31
 
@@ -34,14 +33,18 @@ module Entityjs
34
33
 
35
34
  def self.search_datas
36
35
  #TODO: find all other folders and generate a key in re.assets
36
+ #DEPRECATED
37
37
  return self.find_files("#{Config.assets_folder}/*/*").select{|i| i.match(/(images|sounds)\//i) == nil }
38
38
  end
39
39
 
40
40
  def self.find_files(search)
41
- Dir[Dirc.game_root+'/'+search].collect do |i|
42
- #remove long string
43
- i = i.split("assets/").pop
44
- end
41
+ Dir.glob(Dirc.game_root+'/'+search).collect do |i|
42
+ if File.file?(i)
43
+ #remove long string
44
+ i = i.split(Config.assets_folder+"/").pop
45
+ end
46
+ end.compact
47
+ #remove nils from array too
45
48
  end
46
49
 
47
50
  end
@@ -21,7 +21,7 @@ module Entityjs
21
21
  scripts_folder = Config.scripts_folder
22
22
  styles_folder = Config.instance.build_styles_path
23
23
 
24
- final_name = Config.instance.build_name+'.js'
24
+ final_name = Config.instance.build_scripts_name
25
25
  html_name = 'play.html'
26
26
 
27
27
  puts "Building to #{build_folder}"
@@ -63,7 +63,7 @@ module Entityjs
63
63
  #save css
64
64
  Dirc.create_dir(styles_folder)
65
65
 
66
- File.open(styles_folder+"/"+Config.instance.build_styles_name+'.css', 'w') do |f|
66
+ File.open(styles_folder+"/"+Config.instance.build_styles_name, 'w') do |f|
67
67
  f.write(css)
68
68
  end
69
69
 
@@ -181,7 +181,15 @@ module Entityjs
181
181
  entity_src = self.compile_entity(Config.instance.build_entity_ignore+Config.instance.entity_ignore)
182
182
  scripts = self.compile_scripts(Config.instance.build_scripts_ignore+Config.instance.scripts_ignore, Config.instance.scripts_order)
183
183
 
184
- self.build_wrap(entity_src+scripts)
184
+ code = self.build_wrap(entity_src+scripts)
185
+
186
+ #build erase
187
+ Config.instance.build_erase.each do |i|
188
+ #replace all finds with comments in front
189
+ code = code.gsub(i, "//#{i}")
190
+ end
191
+
192
+ return code
185
193
  end
186
194
 
187
195
  def self.build_wrap(code)
@@ -209,18 +217,21 @@ module Entityjs
209
217
  return code
210
218
  end
211
219
 
212
- def self.js_config(path = nil, images = nil, sounds = nil, canvas = nil)
220
+ def self.js_config(path = nil, assets = nil, canvas = nil)
213
221
  path ||= Config.assets_folder+'/'
214
- images ||= self.images_to_js
215
- sounds ||= self.sounds_to_js
222
+
223
+ if assets.nil?
224
+ assets = self.assets_to_js
225
+ end
226
+ if assets.is_a? Hash
227
+ assets = assets.to_json
228
+ end
229
+
216
230
  canvas ||= Config.instance.canvas_id
217
231
 
218
232
  return %Q(
219
233
  re.load.path = \"#{path}\";
220
- re.assets = {
221
- images:#{images},
222
- sounds:#{sounds}
223
- };
234
+ re.assets = #{assets};
224
235
  re.canvas = \"##{canvas}\";
225
236
  )
226
237
  end
@@ -242,6 +253,43 @@ module Entityjs
242
253
 
243
254
  "[#{s}]"
244
255
  end
256
+
257
+ #returns all folders from assets array in a js object
258
+ #
259
+ #Input like this:
260
+ # ["images/blah.png", "images/tree.png", "models/tree.xml"]
261
+ #
262
+ # Is returned like this:
263
+ # {
264
+ # images:["blah.png", "tree.png"],
265
+ # model:["tree.xml"]
266
+ # }
267
+ #
268
+ def self.assets_to_js(assets = nil, ignore=nil)
269
+ assets ||= Assets.search()
270
+ ignore ||= Config.instance.assets_ignore
271
+
272
+ tree = {}
273
+
274
+ assets.each do |i|
275
+
276
+ if ignore.any? && !i.match(/#{ignore.join('|')}/).nil?
277
+ #ignore assets
278
+ next
279
+ end
280
+
281
+ #folder
282
+ folder = i.split('/').first
283
+
284
+ if tree[folder].nil?
285
+ tree[folder] = []
286
+ end
287
+
288
+ tree[folder].push(i)
289
+ end
290
+
291
+ return tree.to_json
292
+ end
245
293
 
246
294
  end
247
295
 
@@ -6,8 +6,12 @@ module Entityjs
6
6
  if !Dirc.game?
7
7
  return 2
8
8
  end
9
+
10
+ if name.nil?
11
+ return 4
12
+ end
9
13
 
10
- if name.class == Array
14
+ if name.is_a? Array
11
15
  name = name.first
12
16
  end
13
17
 
@@ -17,6 +21,7 @@ module Entityjs
17
21
  end
18
22
 
19
23
  filename = name
24
+
20
25
  if name.index('.').nil?
21
26
  filename += '.js'
22
27
  end
@@ -60,7 +65,7 @@ module Entityjs
60
65
  f.close
61
66
  end
62
67
 
63
- puts "Created comp: #{dir}/#{filename}"
68
+ puts "Created comp: #{filename}"
64
69
 
65
70
  Dir.chdir(Dirc.game_root)
66
71
 
@@ -10,6 +10,11 @@ module Entityjs
10
10
 
11
11
  Config.instance.reload
12
12
 
13
+ #make build dir if not found
14
+ if !File.directory?(Config.instance.build_path)
15
+ Dir.mkdir(Config.instance.build_path)
16
+ end
17
+
13
18
  final_name = Config.instance.build_name+'.js'
14
19
  path = Config.instance.build_path+'/'+final_name
15
20
 
@@ -31,6 +31,10 @@ module Entityjs
31
31
  Page.render_test_page()
32
32
 
33
33
  end
34
+
35
+ get '/tests' do
36
+ Page.render_test_page()
37
+ end
34
38
 
35
39
  get '/favicon.ico' do
36
40
  content_type 'image/ico'
@@ -8,8 +8,12 @@ module Entityjs
8
8
  end
9
9
 
10
10
  tests = []
11
+
12
+ if name.nil?
13
+ return 4
14
+ end
11
15
 
12
- if name.class == Array
16
+ if name.is_a? Array
13
17
  tests = name[1..-1]
14
18
 
15
19
  name = name.first
@@ -44,7 +48,7 @@ module Entityjs
44
48
  return 3
45
49
  end
46
50
 
47
- test_name = filename.split('_test.').shift
51
+ test_name = filename.split('_test.').first
48
52
 
49
53
  File.open(filename, 'w') do |f|
50
54
 
@@ -57,7 +61,7 @@ module Entityjs
57
61
  f.close
58
62
  end
59
63
 
60
- puts "Created test: tests/#{filename}"
64
+ puts "Created test: #{filename}"
61
65
 
62
66
  Dir.chdir(Dirc.game_root)
63
67
 
@@ -96,6 +96,10 @@ module Entityjs
96
96
  def scripts_order
97
97
  return split_attr('scripts-order')
98
98
  end
99
+
100
+ def assets_ignore
101
+ return split_attr('assets-ignore')
102
+ end
99
103
 
100
104
  def tests_ignore
101
105
  return split_attr('tests-ignore')
@@ -104,6 +108,18 @@ module Entityjs
104
108
  def entity_ignore
105
109
  return split_attr('entity-ignore')
106
110
  end
111
+
112
+ #erases found lines on compiling
113
+ #NOT implemented
114
+ def build_erase
115
+ return split_attr('build-erase')
116
+ end
117
+
118
+ #overwrites config vars during compiling
119
+ #NOT implemented
120
+ def build_vars
121
+
122
+ end
107
123
 
108
124
  def build_entity_ignore
109
125
  return split_attr('build-entity-ignore')
@@ -113,8 +129,12 @@ module Entityjs
113
129
  return get_attr('build-name', self.title_slug+'.min')
114
130
  end
115
131
 
132
+ def build_scripts_name
133
+ return get_attr('build-scripts-name', self.build_name+'.js')
134
+ end
135
+
116
136
  def build_styles_name
117
- return get_attr('build_styles_name', self.build_name)
137
+ return get_attr('build-styles-name', self.build_name+'.css')
118
138
  end
119
139
 
120
140
  def build_styles_ignore
@@ -202,6 +222,8 @@ module Entityjs
202
222
  contents = contents.gsub("RE_#{val}", v.to_s)
203
223
  end
204
224
 
225
+ #build erase
226
+
205
227
  #set width, height and canvas id
206
228
  #contents = contents.sub("RE_WIDTH", Config.instance.width.to_s)
207
229
  #contents = contents.sub("RE_HEIGHT", Config.instance.height.to_s)
@@ -5,6 +5,7 @@ module Entityjs
5
5
 
6
6
  class Dirc
7
7
 
8
+ #is the current directory an EntityJS game?
8
9
  def self.game?
9
10
 
10
11
  #check if scripts dir exists
@@ -19,17 +20,17 @@ module Entityjs
19
20
  return false
20
21
  end
21
22
 
22
- #checks if a local file exists
23
+ #checks if file exists in the EntityJS game
23
24
  def self.exists?(file)
24
25
  return File.file? Dirc.game_root+'/'+file
25
26
  end
26
27
 
28
+ #path to EntityJS game
27
29
  def self.to_game_root
28
30
  Dir.chdir(@game_root)
29
31
  end
30
32
 
31
33
  def self.game_root
32
-
33
34
  @game_root
34
35
  end
35
36
 
@@ -130,7 +130,13 @@ module Entityjs
130
130
 
131
131
  first_folder = folders
132
132
  if last != first_folder
133
- js += "\n\n\t<!-- #{first_folder} -->\n"
133
+ if first_folder.is_a? Array
134
+ line = first_folder.join('/')
135
+ else
136
+ line = first_folder
137
+ end
138
+
139
+ js += "\n\n\t<!-- #{line} -->\n"
134
140
  last = first_folder
135
141
  end
136
142
 
@@ -1,3 +1,3 @@
1
1
  module Entityjs
2
- VERSION = "0.4.3" unless const_defined? :VERSION
2
+ VERSION = "0.4.4" unless const_defined? :VERSION
3
3
  end
@@ -238,6 +238,7 @@ function lazy(comps, obj){
238
238
  teardown:function(){
239
239
  if(obj && obj.teardown) obj.teardown(e);
240
240
  e.dispose();
241
+ delete window[name];
241
242
  }
242
243
  }
243
244
  }
@@ -318,4 +319,4 @@ function match(test, reg, i){
318
319
 
319
320
  ok(test.match(reg) != null, "Expected to match "+reg)
320
321
 
321
- }
322
+ }
@@ -50,7 +50,9 @@ stub(re, 'pressed', 10);
50
50
 
51
51
  return expectation.callCount += 1;
52
52
  };
53
- return mocking.expectations.push(expectation);
53
+ mocking.expectations.push(expectation);
54
+
55
+ return object[method];
54
56
  };
55
57
  stub = function(object, method, fn) {
56
58
  var stb;
@@ -70,6 +72,11 @@ stub(re, 'pressed', 10);
70
72
  original: object[method]
71
73
  };
72
74
  object[method] = fn;
75
+
76
+ if(!mocking || !mocking.stubs){
77
+ throw "Can only stub inside tests!";
78
+ }
79
+
73
80
  return mocking.stubs.push(stb);
74
81
  };
75
82
  mock = function(test) {
@@ -20,6 +20,42 @@ describe('comp', function(){
20
20
  eq(re[k.name].yep, 'yep')
21
21
  })
22
22
 
23
+ it('should create comp in new style', function(){
24
+
25
+ re.c('jump12', {
26
+ requires:"sdf",
27
+
28
+ init:function(){
29
+
30
+ },
31
+
32
+ defines:{
33
+ ok:10
34
+ },
35
+
36
+ defaults:{
37
+ k:10
38
+ },
39
+
40
+ factory:function(){
41
+
42
+ }
43
+
44
+ });
45
+
46
+ eq(re.c('jump12')._re_requires, ['sdf']);
47
+ eq(re.c('jump12')._re_defines, {ok:10});
48
+ eq(re.c('jump12')._re_defaults, {k:10});
49
+
50
+ });
51
+
52
+ it('should use default factory', function(){
53
+ var a = 10;
54
+
55
+ eq(re[k.name]("blah", a).blah, a);
56
+
57
+ });
58
+
23
59
  it('should create a factory', function(){
24
60
  var val = 10;
25
61
 
@@ -30,6 +30,19 @@ describe('entity', function(){
30
30
  eq(e.get('bla'), 10);
31
31
  });
32
32
 
33
+ it('should trigger once', function(){
34
+ var count = 0;
35
+ e.once('blah', function(){
36
+ count++;
37
+ });
38
+
39
+ e.trigger('blah');
40
+ e.trigger('blah');
41
+ e.trigger('blah');
42
+
43
+ eq(count, 1);
44
+ });
45
+
33
46
  it('comp', function(){
34
47
  e.comp('qwdqwd wer')
35
48
 
@@ -4,7 +4,7 @@ describe('load', function(){
4
4
  //add images
5
5
  re.load.path = '__spec__/'
6
6
  var img = '/__spec__/helpers/accept.png'
7
- var sfx = 'helpers/alligator.mp3'
7
+ var sfx = 'http://localhost:8888/__spec__/helpers/alligator.mp3'
8
8
  var sfx2 = 'helpers/alligator.ogg'
9
9
 
10
10
  var called = false
@@ -180,6 +180,7 @@ describe('query', function(){
180
180
 
181
181
  var e = re.e();
182
182
 
183
+ q.push(10);
183
184
  q.push(e);
184
185
 
185
186
  //add in
@@ -21,14 +21,6 @@ describe('sound', function(){
21
21
  })
22
22
  });
23
23
 
24
- it('resume', function(){
25
- is(e.resume())
26
- })
27
-
28
- it('pause', function(){
29
- is(e.pause())
30
- })
31
-
32
24
  it('currenttime', function(){
33
25
  //is(e.currentTime())
34
26
  })
@@ -10,7 +10,7 @@ describe 'Assets' do
10
10
  @sounds_file = Entityjs::Config.sounds_folder+'/fold/secret1.mp3'
11
11
  files.push @sounds_file
12
12
 
13
- Dir.stub(:'[]').and_return(files)
13
+ Dir.stub(:glob).and_return(files)
14
14
  IO.stub(:read).and_return('{"test":0, "array":[1,2,3]}')
15
15
  end
16
16
 
@@ -32,6 +32,10 @@ describe 'Assets' do
32
32
 
33
33
  end
34
34
 
35
- it 'should return all datas'
35
+ it 'should return all assets' do
36
+ r = Entityjs::Assets.search()
37
+
38
+ r.should include(@sounds_file.gsub('assets/',''))
39
+ end
36
40
 
37
41
  end
@@ -46,12 +46,18 @@ describe 'build' do
46
46
  canvas = 'game-canvas'
47
47
  scripts = "re.ready(function(){});"
48
48
 
49
- scripts += Entityjs::Build.js_config('', images, sounds, canvas)
49
+ scripts += Entityjs::Build.js_config('', {:images=>images, :sounds=>sounds}, canvas)
50
50
 
51
51
  #min
52
52
  min = Entityjs::Build.minify(scripts)
53
53
 
54
54
  min.should match /Entityjs/i
55
55
  end
56
+
57
+ it 'should build assets to js' do
58
+ data = ["images/blah.png", "models/tree.xml"]
59
+
60
+ Entityjs::Build.assets_to_js(data).should include("blah.png")
61
+ end
56
62
 
57
63
  end
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe 'Templates' do
4
4
 
5
5
  it 'should display templates' do
6
+ Dir.chdir("..")
6
7
  Entityjs::Command.run('templates', []).should == 0
7
8
  end
8
9
 
@@ -1,14 +1,22 @@
1
1
 
2
2
  def setup_mygame
3
+
3
4
  root = File.dirname(__FILE__)+'/../..'
4
5
 
5
6
  if !File.directory? root+'/mygame'
6
7
  Dir.mkdir(root+'/mygame')
7
8
  end
8
-
9
+
10
+ if !File.directory? root+'/mygame/scripts'
11
+ Dir.mkdir(root+'/mygame/scripts')
12
+ end
13
+
9
14
  Dir.chdir(root+'/mygame')
10
15
 
11
- Entityjs::Dirc.game?
16
+ if !Entityjs::Dirc.game?
17
+ raise "Error game folder not found"
18
+ end
19
+
12
20
  end
13
21
 
14
22
  def teardown_mygame
@@ -3,11 +3,18 @@
3
3
 
4
4
  @return component reference
5
5
  */
6
- re.comp = re.c = function(title){
6
+ re.comp = re.c = function(title, data){
7
7
 
8
8
  if(!re._c[title]){
9
9
  re._c[title] = new re.c.init(title);
10
10
  }
11
+
12
+ //set data
13
+ if(data){
14
+ for(var i in data){
15
+ re._c[title][i](data[i]);
16
+ }
17
+ }
11
18
 
12
19
  return re._c[title];
13
20
  };
@@ -74,7 +81,7 @@ re.c.init.prototype = {
74
81
  //turns global method into a singleton
75
82
  singleton:function(){
76
83
  this._re_method = function(){
77
- return this._ || (this._ = re.e(this.name));
84
+ return this._singleton || (this._singleton = re.e(this.name));
78
85
  }
79
86
  return this;
80
87
  },
@@ -122,7 +129,6 @@ re.c.init.prototype = {
122
129
 
123
130
  //new control entity
124
131
  re.control(val1, val2);
125
- re.c('control').factory
126
132
 
127
133
  */
128
134
  factory:function(f){
@@ -133,11 +139,23 @@ re.c.init.prototype = {
133
139
  return this;
134
140
  },
135
141
 
142
+ /*
143
+ Controls the factory method flow.
144
+
145
+ Will create a new entity and try to use the defined factory or else
146
+ uses the default:
147
+
148
+ //default factory
149
+ re.circle({radius:10, color:"#ff0000"});
150
+
151
+ */
136
152
  _re_method:function(){
137
153
  var e = re.e(this.name), f = this._re_factory;
138
154
 
139
155
  if(f)
140
156
  f.apply(e, arguments);
157
+ else
158
+ e.attr.apply(e,arguments); //this is the default factory method
141
159
 
142
160
  return e;
143
161
  },
@@ -329,12 +329,12 @@
329
329
 
330
330
  });
331
331
  */
332
- p.on = function(type, method, context){
332
+ p.on = function(type, method, context, once){
333
333
 
334
334
  if(re.is(type, 'object')){
335
335
 
336
336
  for(var k in type){
337
- this.on(k, type[k], method);
337
+ this.on(k, type[k], method, context);
338
338
  }
339
339
 
340
340
  } else {
@@ -344,12 +344,16 @@
344
344
  }
345
345
  if(!re.is(method)) throw 'Method is null'
346
346
  //save context
347
- this._re_listens[type].push({c:context || this, f:method});
347
+ this._re_listens[type].push({c:context || this, f:method, o:once});
348
348
 
349
349
  }
350
350
 
351
351
  return this;
352
352
  };
353
+
354
+ p.once = function(type, method, context){
355
+ return this.on(type, method, context, 1);
356
+ };
353
357
 
354
358
  /*
355
359
  Added in V0.2.1
@@ -423,8 +427,8 @@
423
427
  if(!b) break;
424
428
  if(!b[i]) continue;
425
429
 
426
- //return false remove
427
- if(b[i].f.apply(b[i].c, Array.prototype.slice.call(arguments, 1)) === false){
430
+ //return false remove or if is once listen
431
+ if(b[i].f.apply(b[i].c, Array.prototype.slice.call(arguments, 1)) === false || (b[i] && b[i].o)){
428
432
  b.splice(i, 1);
429
433
  }
430
434
 
@@ -78,7 +78,7 @@
78
78
  a = this.assets[i];
79
79
 
80
80
  //copy full source path
81
- var s = (a.charAt(0)=='/')?a:re.load.path+a;
81
+ var s = (a.match(/^(\/|http:)/))?a:re.load.path+a;
82
82
 
83
83
  //remove directories
84
84
  a = re.load.file(a);
@@ -125,6 +125,9 @@
125
125
  p.current = 0;
126
126
  p.total = 0;
127
127
 
128
+ //src - full path to image
129
+ //a - image name
130
+ //n - image name without ext
128
131
  p._loadImg = function(src, a, n){
129
132
  var that = this;
130
133
  var img = new Image();
@@ -146,6 +149,7 @@
146
149
 
147
150
  that._loaded();
148
151
  };
152
+ img.crossOrigin = '';
149
153
 
150
154
  img.onerror = function(){
151
155
 
@@ -202,8 +206,7 @@
202
206
  });
203
207
 
204
208
  } else {
205
- s = new Audio(src);
206
- s.src = src;
209
+ s = new Audio();
207
210
  s.preload = "auto";
208
211
  s.load();
209
212
 
@@ -223,6 +226,8 @@
223
226
  }
224
227
  },false);
225
228
 
229
+ s.src = src;
230
+
226
231
  this._def_sfx(s, a, n);
227
232
 
228
233
  }
@@ -232,7 +237,7 @@
232
237
  p._def_sfx = function(s, a, n){
233
238
 
234
239
  re.c(a)
235
- //create statics codec for easy use
240
+ //create static codec for easy use
236
241
  .alias(n+re.load.soundExt)
237
242
  .defines({
238
243
  _sound:s
@@ -443,7 +443,7 @@
443
443
 
444
444
  */
445
445
  p.erase = function(ref){
446
- for(var i=this.length; i--;){
446
+ for(var i=0; i<this.length; i++){
447
447
  if(this[i] == ref) this.splice(i, 1);
448
448
  }
449
449
  return this;
@@ -13,7 +13,7 @@ re.c('circle')
13
13
  c.fillStyle = this.color;
14
14
 
15
15
  c.beginPath();
16
- var r = this.radius;
16
+ var r = this.get('radius');
17
17
 
18
18
  c.arc(-this.regX + r , -this.regY + r , r, 0, Math.PI*2, true);
19
19
 
@@ -31,4 +31,4 @@ re.c('circle')
31
31
  return this.sizeX * 0.5;
32
32
  }
33
33
 
34
- });
34
+ });
@@ -133,7 +133,7 @@ re.c('draw')
133
133
  */
134
134
  visible:function(){
135
135
 
136
- return this.drawable && re.screen.hit(this.posX - this.regX, this.posY - this.regY, this.sizeX, this.sizeY);
136
+ return this.drawable && re.screen.hit(this.posX, this.posY, this.sizeX, this.sizeY);
137
137
 
138
138
  }
139
139
 
@@ -64,7 +64,7 @@ re.c('text')
64
64
 
65
65
  c.font = this.font;
66
66
  c.fillStyle = this.textColor;
67
- c.textAlign = this.textAlgin;
67
+ c.textAlign = this.textAlign;
68
68
  c.textBaseline = this.textBaseline;
69
69
 
70
70
  //multi-line
@@ -15,6 +15,7 @@ re.c('keyboard')
15
15
  .statics({
16
16
  //list of listing entities
17
17
  l:[],
18
+ focusStop:true,
18
19
 
19
20
  keyCodes: {
20
21
  /* start the a-z keys */
@@ -116,7 +117,7 @@ re.c('keyboard')
116
117
  var tagName = (e.target || e.srcElement || {}).tagName;
117
118
 
118
119
  //disable keyboard keys if focus lost
119
- if(tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA'){
120
+ if(that.focusStop && tagName && tagName.match(/INPUT|SELECT|TEXTAREA/)){
120
121
  return;
121
122
  }
122
123
 
@@ -28,13 +28,13 @@ re.c('bisect')
28
28
  return this.toTileY(bi, width, sizeX) * sizeY;
29
29
  },
30
30
 
31
- toTileX:function(bi, width, size){
31
+ toTileX:function(bi, width, sizeX){
32
32
 
33
- return bi % (width / size) | 0;
33
+ return bi % (width / sizeX) | 0;
34
34
  },
35
35
 
36
- toTileY:function(bi, width, size){
37
- return (bi * size) / (width - 0.1) | 0;
36
+ toTileY:function(bi, width, sizeX){
37
+ return (bi * sizeX) / (width - 0.1) | 0;
38
38
  },
39
39
 
40
40
  /*
@@ -0,0 +1,8 @@
1
+ /*
2
+ Similar to limit comp.
3
+ */
4
+ re.clamp = function(value, min, max){
5
+ if(value < min) return min;
6
+ else if(max!=null && value > max) return max;
7
+ return value;
8
+ };
@@ -14,27 +14,20 @@ re.c('hit')
14
14
  k.hit(entity);
15
15
 
16
16
  */
17
- hit:function(x, y, w, h, rx, ry){
17
+ hit:function(x, y, w, h){
18
18
  if(re.is(x, 'object')){
19
19
  y = x.posY || x.y;
20
20
  w = x.sizeX || x.w;
21
21
  h = x.sizeY || x.h;
22
- rx = x.regX || 0;
23
- ry = x.regY || 0;
24
22
  x = x.posX || x.x;
25
23
  }
26
24
 
27
- rx = rx || 0;
28
- ry = ry || 0;
29
- var regX = this.regX || 0;
30
- var regY = this.regY || 0;
31
-
32
25
  return !
33
26
  (
34
- x - rx > this.posX + this.sizeX - regX ||
35
- x + w - rx < this.posX - regX ||
36
- y - ry > this.posY + this.sizeY - regY ||
37
- y + h - ry < this.posY - regY
27
+ x > this.posX + this.sizeX ||
28
+ x + w < this.posX ||
29
+ y > this.posY + this.sizeY ||
30
+ y + h < this.posY
38
31
  );
39
32
  }
40
33
 
@@ -30,6 +30,9 @@ re.c('iso')
30
30
  return {posX:this.toPosX(x, y), posY:this.toPosY(x, y)};
31
31
  },
32
32
 
33
+ /*
34
+ Converts a position into the closest iso tile
35
+ */
33
36
  toIsoX:function(x, y){
34
37
  var ym = (2*y - x) * 0.5;
35
38
  var xm = x + ym;
@@ -125,5 +125,4 @@ re.c('tile')
125
125
  .init(function(){
126
126
  this.sizeX = re.tile.sizeX;
127
127
  this.sizeY = re.tile.sizeY;
128
-
129
- })
128
+ });
@@ -45,17 +45,18 @@ This will be fixed with the channel component.
45
45
  re.c('sound')
46
46
  .statics({
47
47
 
48
- enabled:true
48
+ enabled:true,
49
+ volume:1
49
50
 
50
51
  })
51
52
  .defaults({
52
53
  playing:false
53
54
  })
54
55
  .namespaces({
55
- e:false,
56
+ e:0,
56
57
 
57
58
  ended:function(){
58
-
59
+ this.playing = 0;
59
60
  this.trigger('sound:finish');
60
61
 
61
62
  }
@@ -63,50 +64,60 @@ re.c('sound')
63
64
  })
64
65
  .defines({
65
66
 
66
- play:function(){
67
+ /*
68
+ Plays the sound from the beginning.
69
+
70
+ onFinish is called when the sound has finished playing through all loops.
71
+ */
72
+ play:function(loops, volume, onFinish){
67
73
  if(!this._sound || !re.sound.enabled) return this;
68
74
  if(this.playing) this.stop();
69
75
 
70
76
  var c = this._sound;
71
77
  var that = this;
78
+ volume = volume || re.sound.volume;
72
79
 
73
- if(window['soundManager']){
74
-
75
- c.play({onfinish:function(){
76
- that.sound_ended();
77
- }
80
+ if(window.soundManager){
81
+ //play sound with soundManager
82
+ c.play({
83
+ onfinish:function(){
84
+ that.sound_ended();
85
+ if(onFinish) onFinish(that);
86
+ },
87
+ position:0,
88
+ volume:volume,
89
+ loops:loops||1
78
90
  });
79
91
 
80
92
  } else {
93
+ //play with browser
81
94
  c.currentTime = 0;
95
+ c.volume = volume;
96
+ loops = loops||1;
82
97
 
83
- if(!this.sound_e){
84
- this.sound_e = true;
85
- var f = function(){
86
- that.sound_ended();
98
+ var f = function(){
99
+ if(--loops>0){
100
+ c.play();
101
+ } else {
87
102
  c.removeEventListener('ended', f);
88
- that.sound_e = false;
89
- };
90
-
91
- c.addEventListener('ended', f, false);
92
-
93
- }
103
+ that.sound_ended();
104
+ if(onFinish) onFinish(that);
105
+ }
106
+ };
107
+
108
+ c.addEventListener('ended', f);
109
+
94
110
  c.play();
95
111
  }
112
+ this.playing = 1;
96
113
 
97
114
  return this;
98
115
  },
99
116
 
100
- resume:function(){
101
- this._sound.play();
102
- this.playing = true;
103
-
104
- return this;
105
- },
106
-
107
- pause:function(){
117
+ //stops playing the sound
118
+ stop:function(){
108
119
  this._sound.pause();
109
- this.playing = false;
120
+ this.playing = 0;
110
121
 
111
122
  return this;
112
123
  }
@@ -0,0 +1,10 @@
1
+ /*
2
+ Throws an exception when false. This is useful for development.
3
+
4
+ All asserts will be removed when compiled.
5
+ */
6
+ re.assert = function(test, message){
7
+ message = message || '';
8
+ if(!test) throw "Assert Fail: "+message;
9
+ re.log("Assert Pass: "+message);
10
+ };
@@ -0,0 +1,9 @@
1
+ re.extend = function(){
2
+ var out = {};
3
+ for(var i in arguments){
4
+ for(var b in arguments[i]){
5
+ out[b] = arguments[i][b];
6
+ }
7
+ }
8
+ return out;
9
+ };
@@ -77,9 +77,10 @@ re.support = function(s){
77
77
  if(c.audio = !!ele.canPlayType){
78
78
 
79
79
  c.ogg = ele.canPlayType('audio/ogg; codecs="vorbis"');
80
- c.mp3 = ele.canPlayType('audio/mpeg;');
81
80
  c.wav = ele.canPlayType('audio/wav; codecs="1"');
82
- c.aac = ele.canPlayType('audio/x-m4a;') || ele.canPlayType('audio/aac;');
81
+ c.webma = ele.canPlayType('audio/webm; codecs="vorbis"');
82
+ c.mp3 = ele.canPlayType('audio/mpeg; codecs="mp3"');
83
+ c.m4a = ele.canPlayType('audio/mp4; codecs=mp4a.40.2');
83
84
 
84
85
  //switch unsupported codecs to false
85
86
  for(var i in c){
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entityjs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-22 00:00:00.000000000 Z
12
+ date: 2012-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &23146660 !ruby/object:Gem::Requirement
16
+ requirement: &21132740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *23146660
24
+ version_requirements: *21132740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jasmine
27
- requirement: &23146240 !ruby/object:Gem::Requirement
27
+ requirement: &21113980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *23146240
35
+ version_requirements: *21113980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sinatra
38
- requirement: &23145740 !ruby/object:Gem::Requirement
38
+ requirement: &21112560 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.3.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *23145740
46
+ version_requirements: *21112560
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: coffee-script
49
- requirement: &23145320 !ruby/object:Gem::Requirement
49
+ requirement: &21110820 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *23145320
57
+ version_requirements: *21110820
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: uglifier
60
- requirement: &23144860 !ruby/object:Gem::Requirement
60
+ requirement: &21108600 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *23144860
68
+ version_requirements: *21108600
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: json
71
- requirement: &23144440 !ruby/object:Gem::Requirement
71
+ requirement: &21106980 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *23144440
79
+ version_requirements: *21106980
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: cobravsmongoose
82
- requirement: &23144020 !ruby/object:Gem::Requirement
82
+ requirement: &21105280 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *23144020
90
+ version_requirements: *21105280
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: cssmin
93
- requirement: &23143600 !ruby/object:Gem::Requirement
93
+ requirement: &21102740 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *23143600
101
+ version_requirements: *21102740
102
102
  description: HTML5 Javascript game engine, quickly create robust, flexible and reusable
103
103
  games.
104
104
  email:
@@ -262,6 +262,7 @@ files:
262
262
  - src/input/touch.js
263
263
  - src/math/bisect.js
264
264
  - src/math/body.js
265
+ - src/math/clamp.js
265
266
  - src/math/distance.js
266
267
  - src/math/drag.js
267
268
  - src/math/force.js
@@ -282,7 +283,9 @@ files:
282
283
  - src/pattern/timestep.js
283
284
  - src/save/database.js
284
285
  - src/save/storage.js
286
+ - src/util/assert.js
285
287
  - src/util/clone.js
288
+ - src/util/extend.js
286
289
  - src/util/log.js
287
290
  - src/util/polyfill.js
288
291
  - src/util/scene.js