entityjs 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. data/.gitignore +7 -6
  2. data/.rspec +2 -0
  3. data/README.md +170 -49
  4. data/Rakefile +9 -0
  5. data/bin/entityjs +24 -14
  6. data/entityjs.gemspec +15 -9
  7. data/lib/entityjs/assets.rb +167 -0
  8. data/lib/entityjs/command.rb +52 -27
  9. data/lib/entityjs/commands/build.rb +128 -0
  10. data/lib/entityjs/commands/comp.rb +74 -0
  11. data/lib/entityjs/commands/font.rb +73 -0
  12. data/lib/entityjs/commands/new.rb +59 -0
  13. data/lib/entityjs/commands/server.rb +54 -0
  14. data/lib/entityjs/commands/templates.rb +28 -0
  15. data/lib/entityjs/commands/test.rb +69 -0
  16. data/lib/entityjs/config.rb +130 -0
  17. data/lib/entityjs/dirc.rb +184 -0
  18. data/lib/entityjs/parsers/parse_tmx.rb +41 -0
  19. data/lib/entityjs/parsers/parse_xml.rb +39 -0
  20. data/lib/entityjs/version.rb +1 -1
  21. data/lib/entityjs.rb +53 -0
  22. data/license.txt +1 -1
  23. data/public/play.html +122 -0
  24. data/public/qunit/qunit.css +226 -0
  25. data/public/qunit/qunit.entity.js +190 -0
  26. data/public/qunit/qunit.input.js +200 -0
  27. data/public/qunit/qunit.js +1598 -0
  28. data/public/qunit/qunit.mock.js +97 -0
  29. data/public/tests.html +45 -0
  30. data/spec/javascripts/helpers/accept.png +0 -0
  31. data/spec/javascripts/helpers/alligator.mp3 +0 -0
  32. data/spec/javascripts/helpers/alligator.ogg +0 -0
  33. data/spec/javascripts/helpers/canvas.js +15 -0
  34. data/spec/javascripts/helpers/entityunit.js +50 -0
  35. data/spec/javascripts/helpers/factories.js +11 -0
  36. data/spec/javascripts/helpers/jquery-1.7.1.min.js +4 -0
  37. data/spec/javascripts/src/core/comp_spec.js +145 -0
  38. data/spec/javascripts/src/core/entity_spec.js +324 -0
  39. data/spec/javascripts/src/core/load_spec.js +71 -0
  40. data/spec/javascripts/src/core/query_spec.js +157 -0
  41. data/spec/javascripts/src/core/re_spec.js +61 -0
  42. data/spec/javascripts/src/core/system_spec.js +41 -0
  43. data/spec/javascripts/src/cycle/draw_spec.js +106 -0
  44. data/spec/javascripts/src/cycle/tick_spec.js +20 -0
  45. data/spec/javascripts/src/cycle/update_spec.js +86 -0
  46. data/spec/javascripts/src/display/align_spec.js +43 -0
  47. data/spec/javascripts/src/display/circle_spec.js +26 -0
  48. data/spec/javascripts/src/display/group_spec.js +7 -0
  49. data/spec/javascripts/src/display/image_spec.js +32 -0
  50. data/spec/javascripts/src/display/imgtext_spec.js +32 -0
  51. data/spec/javascripts/src/display/rect_spec.js +13 -0
  52. data/spec/javascripts/src/display/screen_spec.js +47 -0
  53. data/spec/javascripts/src/display/sprite_spec.js +28 -0
  54. data/spec/javascripts/src/display/text_spec.js +30 -0
  55. data/spec/javascripts/src/input/keyboard_spec.js +67 -0
  56. data/spec/javascripts/src/input/mouse_spec.js +133 -0
  57. data/spec/javascripts/src/input/pressed_spec.js +31 -0
  58. data/spec/javascripts/src/math/bisect_spec.js +59 -0
  59. data/spec/javascripts/src/math/body_spec.js +30 -0
  60. data/spec/javascripts/src/math/drag_spec.js +38 -0
  61. data/spec/javascripts/src/math/force_spec.js +134 -0
  62. data/spec/javascripts/src/math/hit_spec.js +28 -0
  63. data/spec/javascripts/src/math/hitmap_spec.js +52 -0
  64. data/spec/javascripts/src/math/limit_spec.js +35 -0
  65. data/spec/javascripts/src/math/point_spec.js +57 -0
  66. data/spec/javascripts/src/math/tile_spec.js +78 -0
  67. data/spec/javascripts/src/media/sound_spec.js +40 -0
  68. data/spec/javascripts/src/pattern/automap_spec.js +93 -0
  69. data/spec/javascripts/src/pattern/flicker_spec.js +66 -0
  70. data/spec/javascripts/src/pattern/timestep_spec.js +23 -0
  71. data/spec/javascripts/src/save/storage_spec.js +37 -0
  72. data/spec/javascripts/src/util/log_spec.js +9 -0
  73. data/spec/javascripts/src/util/polyfill_spec.js +13 -0
  74. data/spec/javascripts/src/util/random_spec.js +33 -0
  75. data/spec/javascripts/src/util/scene_spec.js +52 -0
  76. data/spec/javascripts/src/util/sheet_spec.js +25 -0
  77. data/spec/javascripts/src/util/support_spec.js +17 -0
  78. data/spec/javascripts/support/jasmine.yml +76 -0
  79. data/spec/javascripts/support/jasmine_config.rb +32 -0
  80. data/spec/javascripts/support/jasmine_runner.rb +32 -0
  81. data/spec/lib/entityjs/assets_spec.rb +216 -0
  82. data/spec/lib/entityjs/command_spec.rb +53 -0
  83. data/spec/lib/entityjs/commands/build_spec.rb +69 -0
  84. data/spec/lib/entityjs/commands/comp_spec.rb +45 -0
  85. data/spec/lib/entityjs/commands/font_spec.rb +7 -0
  86. data/spec/lib/entityjs/commands/new_spec.rb +20 -0
  87. data/spec/lib/entityjs/commands/templates_spec.rb +9 -0
  88. data/spec/lib/entityjs/commands/test_spec.rb +31 -0
  89. data/spec/lib/entityjs/config_spec.rb +19 -0
  90. data/spec/lib/entityjs/dirc_spec.rb +83 -0
  91. data/spec/lib/entityjs/version_spec.rb +9 -0
  92. data/spec/spec_helper.rb +21 -3
  93. data/spec/support/factories.rb +19 -0
  94. data/spec/support/mygame.rb +11 -0
  95. data/src/core/comp.js +318 -0
  96. data/src/core/entity.js +549 -0
  97. data/src/core/load.js +242 -0
  98. data/src/core/query.js +354 -0
  99. data/src/core/re.js +74 -0
  100. data/src/core/system.js +121 -0
  101. data/src/cycle/draw.js +178 -0
  102. data/src/cycle/tick.js +25 -0
  103. data/src/{entityjs/cycle → cycle}/tween.js +60 -60
  104. data/src/{entityjs/cycle → cycle}/update.js +86 -85
  105. data/src/{entityjs/cycle → cycle}/wait.js +22 -21
  106. data/src/{entityjs/cycle → cycle}/worker.js +8 -8
  107. data/src/display/align.js +45 -0
  108. data/src/display/circle.js +33 -0
  109. data/src/{entityjs/display → display}/group.js +62 -62
  110. data/src/display/image.js +35 -0
  111. data/src/display/imgtext.js +102 -0
  112. data/src/{entityjs/display → display}/rect.js +18 -18
  113. data/src/display/screen.js +57 -0
  114. data/src/display/sprite.js +54 -0
  115. data/src/display/text.js +44 -0
  116. data/src/{entityjs/input → input}/keyboard.js +152 -150
  117. data/src/input/mouse.js +111 -0
  118. data/src/input/pressed.js +41 -0
  119. data/src/{entityjs/input → input}/touch.js +24 -28
  120. data/src/math/bisect.js +84 -0
  121. data/src/math/body.js +70 -0
  122. data/src/{entityjs/math → math}/drag.js +44 -38
  123. data/src/math/force.js +143 -0
  124. data/src/math/hit.js +32 -0
  125. data/src/math/hitmap.js +167 -0
  126. data/src/math/limit.js +37 -0
  127. data/src/math/point.js +40 -0
  128. data/src/math/tile.js +109 -0
  129. data/src/media/channel.js +93 -0
  130. data/src/{entityjs/media → media}/playlist.js +4 -4
  131. data/src/media/sound.js +114 -0
  132. data/src/{entityjs/net → net}/socket.js +51 -51
  133. data/src/pattern/automap.js +133 -0
  134. data/src/{entityjs/pattern → pattern}/flicker.js +206 -213
  135. data/src/pattern/timestep.js +31 -0
  136. data/src/{entityjs/save → save}/database.js +6 -6
  137. data/src/{entityjs/save → save}/storage.js +47 -56
  138. data/src/{entityjs/util → util}/log.js +17 -25
  139. data/src/{entityjs/util → util}/polyfill.js +24 -24
  140. data/src/util/random.js +20 -0
  141. data/src/util/scene.js +102 -0
  142. data/src/util/sheet.js +35 -0
  143. data/src/{entityjs/util → util}/support.js +109 -132
  144. data/{examples/keys → templates/arrow_keys/assets/images}/arrow.png +0 -0
  145. data/templates/arrow_keys/config.yml +22 -0
  146. data/templates/arrow_keys/readme.txt +9 -0
  147. data/templates/arrow_keys/scripts/display/arrow.js +69 -0
  148. data/templates/arrow_keys/scripts/init.js +10 -0
  149. data/templates/arrow_keys/scripts/input/controls.js +35 -0
  150. data/templates/arrow_keys/scripts/scenes/home.js +20 -0
  151. data/templates/arrow_keys/scripts/scenes/load.js +57 -0
  152. data/templates/arrow_keys/tests/display/arrow_test.js +29 -0
  153. data/templates/arrow_keys/tests/init_test.js +4 -0
  154. data/templates/arrow_keys/tests/input/controls_test.js +32 -0
  155. data/templates/arrow_keys/tests/scenes/home_test.js +0 -0
  156. data/templates/arrow_keys/tests/scenes/load_test.js +16 -0
  157. data/templates/blank/config.yml +22 -0
  158. data/templates/blank/readme.txt +79 -0
  159. data/templates/platform/assets/images/bit.png +0 -0
  160. data/templates/platform/assets/images/hero.png +0 -0
  161. data/templates/platform/assets/images/items.png +0 -0
  162. data/templates/platform/assets/images/tiles.png +0 -0
  163. data/templates/platform/assets/levels/level1.tmx +44 -0
  164. data/templates/platform/assets/sounds/coin.mp3 +0 -0
  165. data/templates/platform/assets/sounds/coin.ogg +0 -0
  166. data/templates/platform/config.yml +22 -0
  167. data/templates/platform/readme.txt +87 -0
  168. data/templates/platform/scripts/display/bit.js +12 -0
  169. data/templates/platform/scripts/display/hero.js +77 -0
  170. data/templates/platform/scripts/display/tile.js +2 -0
  171. data/templates/platform/scripts/display/tsprite.js +17 -0
  172. data/templates/platform/scripts/init.js +7 -0
  173. data/templates/platform/scripts/items/coin.js +27 -0
  174. data/templates/platform/scripts/items/item.js +41 -0
  175. data/templates/platform/scripts/items/spring.js +25 -0
  176. data/templates/platform/scripts/scenes/home.js +10 -0
  177. data/templates/platform/scripts/scenes/load.js +27 -0
  178. data/templates/platform/scripts/scenes/play.js +31 -0
  179. data/templates/platform/scripts/util/counter.js +34 -0
  180. data/templates/platform/scripts/util/level.js +84 -0
  181. data/templates/platform/tests/display/bit_test.js +7 -0
  182. data/templates/platform/tests/display/hero_test.js +73 -0
  183. data/templates/platform/tests/display/tile_test.js +7 -0
  184. data/templates/platform/tests/display/tsprite_test.js +8 -0
  185. data/templates/platform/tests/factories.js +30 -0
  186. data/templates/platform/tests/items/coin_test.js +28 -0
  187. data/templates/platform/tests/items/item_test.js +36 -0
  188. data/templates/platform/tests/items/spring_test.js +21 -0
  189. data/templates/platform/tests/scenes/home_test.js +9 -0
  190. data/templates/platform/tests/scenes/load_test.js +11 -0
  191. data/templates/platform/tests/scenes/play_test.js +15 -0
  192. data/templates/platform/tests/util/counter_test.js +9 -0
  193. data/templates/platform/tests/util/level_test.js +29 -0
  194. metadata +249 -97
  195. data/build/build_debug.bat +0 -1
  196. data/build/build_min.bat +0 -1
  197. data/build/config.php +0 -64
  198. data/build/debug.php +0 -48
  199. data/build/files.php +0 -74
  200. data/build/jsmin.php +0 -376
  201. data/build/min.php +0 -50
  202. data/changelog.txt +0 -53
  203. data/examples/keys/keys.html +0 -59
  204. data/examples/keys/keys.js +0 -148
  205. data/examples/mouse/mouse.html +0 -58
  206. data/examples/mouse/mouse.js +0 -60
  207. data/examples/scenes/home.png +0 -0
  208. data/examples/scenes/scenes.html +0 -55
  209. data/examples/scenes/scenes.js +0 -134
  210. data/examples/scenes/win.png +0 -0
  211. data/examples/sounds/sound1.mp3 +0 -0
  212. data/examples/sounds/sound1.ogg +0 -0
  213. data/examples/sounds/sounds.html +0 -56
  214. data/examples/sounds/sounds.js +0 -44
  215. data/examples/style/background.png +0 -0
  216. data/examples/style/sheet.css +0 -762
  217. data/examples/tiles/tiles.html +0 -56
  218. data/examples/tiles/tiles.js +0 -85
  219. data/examples/tiles/tiles.png +0 -0
  220. data/lib/blank/config.js +0 -4
  221. data/lib/blank/config.yml +0 -21
  222. data/lib/blank/home.js +0 -11
  223. data/lib/blank/init.js +0 -7
  224. data/lib/blank/load.js +0 -21
  225. data/lib/blank/play.html +0 -29
  226. data/lib/entity.debug.js +0 -52
  227. data/lib/entity.min.js +0 -184
  228. data/lib/entityjs/comp.rb +0 -11
  229. data/lib/entityjs/game.rb +0 -93
  230. data/lib/entityjs/min.rb +0 -11
  231. data/lib/entityjs/refresh.rb +0 -14
  232. data/spec/lib/entityjs/game_spec.rb +0 -11
  233. data/src/entityjs/core/component.js +0 -306
  234. data/src/entityjs/core/entity.js +0 -516
  235. data/src/entityjs/core/load.js +0 -224
  236. data/src/entityjs/core/query.js +0 -410
  237. data/src/entityjs/core/re.js +0 -70
  238. data/src/entityjs/core/system.js +0 -125
  239. data/src/entityjs/cycle/draw.js +0 -185
  240. data/src/entityjs/cycle/ticker.js +0 -27
  241. data/src/entityjs/display/anchor.js +0 -53
  242. data/src/entityjs/display/bitfont.js +0 -93
  243. data/src/entityjs/display/bitmap.js +0 -37
  244. data/src/entityjs/display/circle.js +0 -30
  245. data/src/entityjs/display/font.js +0 -41
  246. data/src/entityjs/display/screen.js +0 -46
  247. data/src/entityjs/display/sprite.js +0 -37
  248. data/src/entityjs/input/mouse.js +0 -123
  249. data/src/entityjs/input/pressed.js +0 -81
  250. data/src/entityjs/math/bind.js +0 -76
  251. data/src/entityjs/math/bisect.js +0 -69
  252. data/src/entityjs/math/body.js +0 -39
  253. data/src/entityjs/math/hitmap.js +0 -165
  254. data/src/entityjs/math/hittest.js +0 -26
  255. data/src/entityjs/math/physics.js +0 -142
  256. data/src/entityjs/math/point.js +0 -57
  257. data/src/entityjs/math/tile.js +0 -91
  258. data/src/entityjs/media/channel.js +0 -93
  259. data/src/entityjs/media/sound.js +0 -110
  260. data/src/entityjs/pattern/arraymap.js +0 -89
  261. data/src/entityjs/pattern/timestep.js +0 -34
  262. data/src/entityjs/util/random.js +0 -38
  263. data/src/entityjs/util/scene.js +0 -101
  264. data/src/entityjs/util/sheet.js +0 -51
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'build' do
4
+
5
+ before(:all) do
6
+ setup_mygame
7
+ end
8
+
9
+ after(:all) do
10
+ teardown_mygame
11
+ end
12
+
13
+ it 'should run' do
14
+ #Entityjs::Command.run('build', []).should == 0
15
+ end
16
+
17
+ it 'should run release1' do
18
+
19
+ Entityjs::Assets.stub(:search_datas).and_return(['level.tmx'])
20
+
21
+ Entityjs::Assets.stub(:file_to_json).and_return(Entityjs::Assets.data_to_json(%q(<?xml version="1.0" encoding="UTF-8"?>
22
+ <map version="1.0" orientation="orthogonal" width="40" height="20" tilewidth="25" tileheight="25">
23
+ <tileset firstgid="1" name="tiles" tilewidth="25" tileheight="25">
24
+ <image source="../images/tiles.png" width="200" height="25"/>
25
+ </tileset>
26
+ <layer name="Tile Layer 1" width="40" height="20">
27
+ <data encoding="csv">
28
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
29
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
30
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
31
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
32
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
33
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
34
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
35
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
36
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
37
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
38
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
40
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
41
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
42
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
43
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
44
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
45
+ 2,2,2,2,2,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
46
+ 1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
47
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
48
+ </data>
49
+ </layer>
50
+ <objectgroup name="Hero" width="40" height="20">
51
+ <object name="hero" x="43" y="356"/>
52
+ </objectgroup>
53
+ </map>), 'tmx'))
54
+
55
+ name = "release#{rand(999)}"
56
+ Entityjs::Command.run('b', [name]).should == 0
57
+
58
+ dir = Entityjs::Config.builds_folder+"/"+name
59
+
60
+ Dir.exists?(dir).should == true
61
+
62
+ Dir.chdir(dir) do
63
+ contents = IO.read('game.min.js')
64
+
65
+ contents.should match /Tile Layer 1/i
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Comp' do
4
+
5
+ before(:all) do
6
+ setup_mygame
7
+
8
+ end
9
+
10
+ after(:all) do
11
+ teardown_mygame
12
+ end
13
+
14
+ before do
15
+ @n = "asdf#{rand(9999999)}"
16
+ end
17
+
18
+ it 'should create init.js' do
19
+
20
+ Entityjs::Comp.generate("#{@n}.js").should == 0
21
+
22
+ File.exists?("scripts/#{@n}.js").should == true
23
+ end
24
+
25
+ it 'should create init' do
26
+
27
+ Entityjs::Comp.generate(@n).should == 0
28
+
29
+ File.exists?("scripts/#{@n}.js").should == true
30
+ end
31
+
32
+ it 'should create init.js in display' do
33
+
34
+ Entityjs::Comp.generate("display/#{@n}").should == 0
35
+
36
+ File.exists?("scripts/display/#{@n}.js").should == true
37
+ end
38
+
39
+ it 'should create init.js and items' do
40
+
41
+ Entityjs::Comp.generate("items/#{@n}.js").should == 0
42
+ File.exists?("scripts/items/#{@n}.js").should == true
43
+ end
44
+
45
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Font' do
4
+
5
+ it 'should generate font'
6
+
7
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'new' do
4
+
5
+ it 'should generate mygame' do
6
+
7
+ Entityjs::New.generate(['mygame']).should == 0
8
+ Dir.pwd.should match /\/EntityJS$/i
9
+
10
+ end
11
+
12
+ it 'should generate mygame with template' do
13
+ Entityjs::New.generate(['mygame', 'blank']).should == 0
14
+ Dir.pwd.should match /\/EntityJS$/i
15
+
16
+ File.exists?('mygame/config.yml').should == true
17
+ File.exists?('mygame/readme.txt').should == true
18
+ end
19
+
20
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Templates' do
4
+
5
+ it 'should display templates' do
6
+ Entityjs::Command.run('templates', []).should == 0
7
+ end
8
+
9
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'test' do
4
+
5
+ before(:all) do
6
+ setup_mygame
7
+ @n = rand(999999999999)
8
+ end
9
+
10
+ after(:all) do
11
+ teardown_mygame
12
+ end
13
+
14
+ it 'should create rock' do
15
+ Dir.pwd.should_not match /mygame\/mygame/
16
+ Entityjs::Command.run('test', ["rock#{@n}"]).should == 0
17
+ File.exists?("tests/rock#{@n}_test.js").should == true
18
+ end
19
+
20
+ it 'should create rock in items' do
21
+ Entityjs::Command.run('test', ["items/rock#{@n}"]).should == 0
22
+ File.exists?("tests/items/rock#{@n}_test.js").should == true
23
+ end
24
+
25
+ it 'should create test with tests' do
26
+ Entityjs::Command.run('test', ["tess#{@n}", "first", "second", "third"]).should == 0
27
+
28
+ File.exists?("tests/tess#{@n}_test.js").should == true
29
+ end
30
+
31
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'config' do
4
+
5
+ before(:all) do
6
+ setup_mygame
7
+ end
8
+
9
+ after(:all) do
10
+ teardown_mygame
11
+ end
12
+
13
+ it 'should load config' do
14
+
15
+ @config = Entityjs::Config.instance
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'dirc' do
4
+
5
+ before(:all) do
6
+ setup_mygame
7
+ end
8
+
9
+ after(:all) do
10
+ teardown_mygame
11
+ end
12
+
13
+ it 'should be game dir' do
14
+ Entityjs::Dirc.game?.should == true
15
+ end
16
+
17
+ it 'should not be game dir' do
18
+ Dir.chdir(Dir.pwd+'/..')
19
+ Entityjs::Dirc.game?.should == false
20
+ end
21
+
22
+ it 'should return script urls' do
23
+ Entityjs::Dirc.stub(:find_scripts).and_return(['asdfsdf/scripts/asdf.js', 'sfhs/scripts/sdf.js'])
24
+
25
+ Entityjs::Dirc.find_scripts_url.should be_instance_of Array
26
+ end
27
+
28
+ it 'should ignore and order game scripts' do
29
+ Entityjs::Dirc.stub(:find_scripts).and_return(['asdfsdf/scripts/second.js', 'sfhs/scripts/first.js',
30
+ 'sdf/scripts/kill.js','sdf/scripts/kill2.js'])
31
+
32
+ out = Entityjs::Dirc.find_scripts_url(['kill'], ['first'])
33
+
34
+ out.first.should match /first/
35
+ out.each do |i|
36
+ i.should_not match /kill|kill2/
37
+ end
38
+
39
+ end
40
+
41
+ it 'should return entity src urls' do
42
+ Entityjs::Dirc.stub(:find_entity_src).and_return(['asdfsdf/src/asdf.js', 'sfhs/src/sdf.js'])
43
+
44
+ u = Entityjs::Dirc.find_entity_src_url
45
+
46
+ u.size.should == 2
47
+
48
+ end
49
+
50
+ it 'should be alpha ordered' do
51
+ s = Entityjs::Dirc.find_entity_src
52
+
53
+ s[1].should_not match /socket\.js/
54
+
55
+ end
56
+
57
+ it 'should ignore entity scripts' do
58
+ Entityjs::Dirc.stub(:find_entity_src).and_return(['asdfsdf/src/first.js', 'sfhs/src/ignore.js', 'sdfds/src/ignore2.js'])
59
+
60
+ out = Entityjs::Dirc.find_entity_src_url(['ignore', 'ignore2'])
61
+
62
+ out.each do |i|
63
+ i.should_not match /ignore|ignore2/
64
+ end
65
+ end
66
+
67
+ it 'should return tests' do
68
+ Dir.stub(:'[]').and_return(['C:/asdfsdf/tests/asdf.js', 'C:/sfhs/tests/sdf.js'])
69
+
70
+ Entityjs::Dirc.find_tests_url.first.should_not match /C:/
71
+
72
+ end
73
+
74
+ it 'should ignore tests' do
75
+ Dir.stub(:'[]').and_return(['C:/asdfsdf/tests/asdf.js', 'C:/sfhs/tests/sdf.js'])
76
+
77
+ Entityjs::Dirc.find_tests_url(['asdf']).each do |i|
78
+ i.should_not match(/asdf/)
79
+ end
80
+
81
+ end
82
+
83
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'version' do
4
+
5
+ it 'should display valid version' do
6
+ Entityjs::VERSION.should match /^(\d+\.)?(\d+\.)?(\*|\d+).*$/
7
+ end
8
+
9
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,21 @@
1
- root = File.dirname(__FILE__)+'/../'
2
-
3
- Dir[root+"lib/entityjs/*.rb"].each {|file| require file }
1
+ RSpec.configure do |config|
2
+ # Use color in STDOUT
3
+ config.color_enabled = true
4
+
5
+ # Use color not only in STDOUT but also in pagers and files
6
+ config.tty = true
7
+
8
+ # Use the specified formatter
9
+ #config.formatter = :documentation # :progress, :html, :textmate
10
+ end
11
+
12
+
13
+ root = File.dirname(__FILE__)+'/..'
14
+
15
+
16
+ Dir[root+'/spec/support/*'].each {|f| require f}
17
+
18
+ require "#{root}/lib/entityjs"
19
+
20
+ Dir[root+"/lib/entityjs/*.rb"].each {|file| require file }
21
+
@@ -0,0 +1,19 @@
1
+ def factory(type)
2
+
3
+ case type
4
+ when :assets
5
+
6
+ files = []
7
+
8
+ files.push 'assets/levels/bob.json'
9
+ #files.push 'assets/levels/bob.xml'
10
+ files.push 'assets/images/yep.png'
11
+ files.push 'assets/images/bdd.png'
12
+ files.push 'assets/sounds/bdd.mp3'
13
+ return files
14
+
15
+
16
+ end
17
+
18
+ return nil
19
+ end
@@ -0,0 +1,11 @@
1
+
2
+ def setup_mygame
3
+ root = File.dirname(__FILE__)+'/../..'
4
+ Dir.chdir(root+'/mygame')
5
+
6
+ Entityjs::Dirc.game?
7
+ end
8
+
9
+ def teardown_mygame
10
+ Dir.chdir('..')
11
+ end
data/src/core/comp.js ADDED
@@ -0,0 +1,318 @@
1
+ /*
2
+ Quick way to convert sentences to arrays.
3
+ */
4
+ var __z = function(n, r){
5
+ this._checkFinal();
6
+
7
+ if(!this[n]){
8
+ this[n] = [];
9
+ }
10
+
11
+ if(re.is(r, 'string')){
12
+ this[n] = this[n].concat(r.split(' '));
13
+ } else {
14
+ this[n] = this[n].concat(r);
15
+ }
16
+
17
+ return this;
18
+ };
19
+
20
+ /*
21
+ If component exists, the component will NOT be overwritten.
22
+
23
+ @return component reference
24
+ */
25
+ re.comp = re.c = function(title){
26
+
27
+ if(!re._c[title]){
28
+ re._c[title] = new re.c.init(title);
29
+ }
30
+
31
+ return re._c[title];
32
+ };
33
+
34
+ re.c.init = function(name){
35
+
36
+ this.name = name;
37
+ this._re_signals = {};
38
+ this._re_inherits = {};
39
+ this._re_defines = {};
40
+ this._re_final = false;
41
+ };
42
+
43
+ /*
44
+ p._re_requiress = null;
45
+
46
+ p._re_init = null;
47
+
48
+ p._re_dispose = null;
49
+
50
+ p._re_asserts = null;
51
+
52
+ p._re_interface = null;
53
+ */
54
+
55
+ re.c.init.prototype = {
56
+
57
+ _checkFinal:function(){
58
+
59
+ if(this._re_final){
60
+ throw this.name+' is final.';
61
+ }
62
+ },
63
+
64
+ global:function(){
65
+ throw 'Deprecated use statics'
66
+ },
67
+
68
+ statics:function(obj, value){
69
+ this._checkFinal();
70
+
71
+ if(arguments.length == 1){
72
+
73
+ for(var type in obj){
74
+ this[type] = obj[type];
75
+ }
76
+
77
+ } else {
78
+ this[obj] = value;
79
+ }
80
+
81
+ return this;
82
+ },
83
+
84
+ require:function(){
85
+ throw 'Deprecated use requires'
86
+ },
87
+
88
+ requires:function(r){
89
+ return __z.call(this, '_re_requires', r);
90
+ },
91
+
92
+ /*
93
+ Upon component init it will throw an error
94
+ if one of the listed components exist.
95
+
96
+ This prevents incompatible components from colliding.
97
+ */
98
+ asserts:function(r){
99
+ return __z.call(this, '_re_asserts', r);
100
+ },
101
+
102
+ /*
103
+ The implement method checks and enforces implmentation
104
+ of the given keys. This can create interface components
105
+ for organization and query searches.
106
+
107
+ Forcing an interface on components will allow instant
108
+ runtime errors and save time.
109
+
110
+ //reccommended to put an i infront to represent an interface
111
+ re.c('ienemy')
112
+ //create an enemy interface
113
+ .interface('moveTo spawn attack runAway');
114
+
115
+ */
116
+ interfaces:function(r){
117
+ return __z.call(this, '_re_implements', r);
118
+ },
119
+
120
+ /*
121
+ Creates new names for a component.
122
+
123
+ //create a new alias of draw
124
+ re.c('draw')
125
+ .alias('bob');
126
+
127
+ //remove alias
128
+ re.c('draw')
129
+ .alias('-bob');
130
+
131
+ //aliases can even delete components itself
132
+ re.c('draw').alias('-draw');
133
+
134
+ //add two aliases
135
+ re.c('draw').alias('dr bob');
136
+
137
+ */
138
+ alias:function(s){
139
+ this._checkFinal();
140
+
141
+ var p = s.split(' ');
142
+
143
+ if(p.length > 1){
144
+
145
+ for(var i in p){
146
+ this.alias(p[i]);
147
+ }
148
+
149
+ return this;
150
+ }
151
+
152
+ if(s.charAt(0) == '-'){
153
+ //only remove if its a reference
154
+ if(re._c[s.substr(1)] == this){
155
+ delete re._c[s.substr(1)];
156
+ }
157
+ } else {
158
+
159
+ re._c[s] = this;
160
+ }
161
+
162
+ return this;
163
+ },
164
+
165
+ /*
166
+ Adds bind functionality to components.
167
+ All components will automatically call two signals, init and dispose.
168
+
169
+ Init on entity creation and dispose on entitiy disposition.
170
+
171
+ This is useful for 'watch tower' components that keep a list of
172
+ all entities that have its component. Check the cycle directory.
173
+
174
+ */
175
+ on:function(){
176
+ return re.e.init.prototype.on.apply(this, arguments);
177
+ },
178
+
179
+ off:function(){
180
+ return re.e.init.prototype.off.apply(this, arguments);
181
+ },
182
+
183
+ trigger:function(){
184
+ return re.e.init.prototype.trigger.apply(this, arguments);
185
+ },
186
+
187
+ inherit:function(){
188
+ throw 'Deprecated use defaults'
189
+ },
190
+
191
+ /*
192
+ Default adds onto but doesn't overwrite values.
193
+ */
194
+ defaults:function(d, value){
195
+ this._checkFinal();
196
+
197
+ if(arguments.length == 1){
198
+
199
+ for(var k in d){
200
+ this._re_inherits[k] = d[k];
201
+ }
202
+
203
+ } else {
204
+
205
+ this._re_inherits[d] = value;
206
+
207
+ }
208
+
209
+ return this;
210
+ },
211
+
212
+ /*
213
+ The namespace method is used to put private component variables
214
+ in its own space. This prevents unwanted overrites.
215
+
216
+ re.c('draw')
217
+ .namespace({
218
+ pos:0,
219
+ type:'none'
220
+
221
+ });
222
+
223
+ //or
224
+ re.c('draw')
225
+ .namespace("pos", 0);
226
+
227
+ //Will cast to
228
+ this.draw_pos = 10;
229
+ this.draw_type = 'none';
230
+
231
+ */
232
+ namespaces:function(obj, value){
233
+ this._checkFinal();
234
+ var name = this.name+'_';
235
+
236
+ if(arguments.length == 1){
237
+
238
+ for(var k in obj){
239
+ this._re_defines[name+k] = obj[k];
240
+ }
241
+
242
+ } else {
243
+ this._re_defines[name+obj] = value;
244
+ }
245
+
246
+ return this;
247
+ },
248
+
249
+ extend:function(){
250
+ this.defines.apply(this, arguments);
251
+ re.log('warning extend is deprecated, use defines');
252
+ },
253
+
254
+ /*
255
+ defines overrides everything.
256
+ */
257
+ defines:function(d, value){
258
+ this._checkFinal();
259
+
260
+ if(arguments.length == 1){
261
+
262
+ for(var k in d){
263
+ this._re_defines[k] = d[k];
264
+ }
265
+
266
+ } else {
267
+ this._re_defines[d] = value;
268
+ }
269
+
270
+ return this;
271
+ },
272
+
273
+ init:function(method){
274
+ this._checkFinal();
275
+
276
+ this._re_init = method;
277
+
278
+ return this;
279
+ },
280
+
281
+ dispose:function(method){
282
+ this._checkFinal();
283
+
284
+ this._re_dispose = method;
285
+
286
+ return this;
287
+ },
288
+
289
+ /*
290
+ The lock method prevents modification to the component.
291
+
292
+ This is handy to stop unexpected changes to a component.
293
+ */
294
+ lock:function(){
295
+ this._checkFinal();
296
+
297
+ this._re_final = true;
298
+
299
+ return this;
300
+ },
301
+
302
+ /*
303
+ The run method allows a function to be ran in the context
304
+ of the component.
305
+
306
+ Useful to keep everything in one big component.
307
+ */
308
+ run:function(method){
309
+ this._checkFinal();
310
+
311
+ //re.ready(function(){
312
+ method.call(this);
313
+ //});
314
+
315
+ return this;
316
+ }
317
+
318
+ };