entityjs 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -6
- data/.rspec +2 -0
- data/README.md +170 -49
- data/Rakefile +9 -0
- data/bin/entityjs +24 -14
- data/entityjs.gemspec +15 -9
- data/lib/entityjs/assets.rb +167 -0
- data/lib/entityjs/command.rb +52 -27
- data/lib/entityjs/commands/build.rb +128 -0
- data/lib/entityjs/commands/comp.rb +74 -0
- data/lib/entityjs/commands/font.rb +73 -0
- data/lib/entityjs/commands/new.rb +59 -0
- data/lib/entityjs/commands/server.rb +54 -0
- data/lib/entityjs/commands/templates.rb +28 -0
- data/lib/entityjs/commands/test.rb +69 -0
- data/lib/entityjs/config.rb +130 -0
- data/lib/entityjs/dirc.rb +184 -0
- data/lib/entityjs/parsers/parse_tmx.rb +41 -0
- data/lib/entityjs/parsers/parse_xml.rb +39 -0
- data/lib/entityjs/version.rb +1 -1
- data/lib/entityjs.rb +53 -0
- data/license.txt +1 -1
- data/public/play.html +122 -0
- data/public/qunit/qunit.css +226 -0
- data/public/qunit/qunit.entity.js +190 -0
- data/public/qunit/qunit.input.js +200 -0
- data/public/qunit/qunit.js +1598 -0
- data/public/qunit/qunit.mock.js +97 -0
- data/public/tests.html +45 -0
- data/spec/javascripts/helpers/accept.png +0 -0
- data/spec/javascripts/helpers/alligator.mp3 +0 -0
- data/spec/javascripts/helpers/alligator.ogg +0 -0
- data/spec/javascripts/helpers/canvas.js +15 -0
- data/spec/javascripts/helpers/entityunit.js +50 -0
- data/spec/javascripts/helpers/factories.js +11 -0
- data/spec/javascripts/helpers/jquery-1.7.1.min.js +4 -0
- data/spec/javascripts/src/core/comp_spec.js +145 -0
- data/spec/javascripts/src/core/entity_spec.js +324 -0
- data/spec/javascripts/src/core/load_spec.js +71 -0
- data/spec/javascripts/src/core/query_spec.js +157 -0
- data/spec/javascripts/src/core/re_spec.js +61 -0
- data/spec/javascripts/src/core/system_spec.js +41 -0
- data/spec/javascripts/src/cycle/draw_spec.js +106 -0
- data/spec/javascripts/src/cycle/tick_spec.js +20 -0
- data/spec/javascripts/src/cycle/update_spec.js +86 -0
- data/spec/javascripts/src/display/align_spec.js +43 -0
- data/spec/javascripts/src/display/circle_spec.js +26 -0
- data/spec/javascripts/src/display/group_spec.js +7 -0
- data/spec/javascripts/src/display/image_spec.js +32 -0
- data/spec/javascripts/src/display/imgtext_spec.js +32 -0
- data/spec/javascripts/src/display/rect_spec.js +13 -0
- data/spec/javascripts/src/display/screen_spec.js +47 -0
- data/spec/javascripts/src/display/sprite_spec.js +28 -0
- data/spec/javascripts/src/display/text_spec.js +30 -0
- data/spec/javascripts/src/input/keyboard_spec.js +67 -0
- data/spec/javascripts/src/input/mouse_spec.js +133 -0
- data/spec/javascripts/src/input/pressed_spec.js +31 -0
- data/spec/javascripts/src/math/bisect_spec.js +59 -0
- data/spec/javascripts/src/math/body_spec.js +30 -0
- data/spec/javascripts/src/math/drag_spec.js +38 -0
- data/spec/javascripts/src/math/force_spec.js +134 -0
- data/spec/javascripts/src/math/hit_spec.js +28 -0
- data/spec/javascripts/src/math/hitmap_spec.js +52 -0
- data/spec/javascripts/src/math/limit_spec.js +35 -0
- data/spec/javascripts/src/math/point_spec.js +57 -0
- data/spec/javascripts/src/math/tile_spec.js +78 -0
- data/spec/javascripts/src/media/sound_spec.js +40 -0
- data/spec/javascripts/src/pattern/automap_spec.js +93 -0
- data/spec/javascripts/src/pattern/flicker_spec.js +66 -0
- data/spec/javascripts/src/pattern/timestep_spec.js +23 -0
- data/spec/javascripts/src/save/storage_spec.js +37 -0
- data/spec/javascripts/src/util/log_spec.js +9 -0
- data/spec/javascripts/src/util/polyfill_spec.js +13 -0
- data/spec/javascripts/src/util/random_spec.js +33 -0
- data/spec/javascripts/src/util/scene_spec.js +52 -0
- data/spec/javascripts/src/util/sheet_spec.js +25 -0
- data/spec/javascripts/src/util/support_spec.js +17 -0
- data/spec/javascripts/support/jasmine.yml +76 -0
- data/spec/javascripts/support/jasmine_config.rb +32 -0
- data/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/spec/lib/entityjs/assets_spec.rb +216 -0
- data/spec/lib/entityjs/command_spec.rb +53 -0
- data/spec/lib/entityjs/commands/build_spec.rb +69 -0
- data/spec/lib/entityjs/commands/comp_spec.rb +45 -0
- data/spec/lib/entityjs/commands/font_spec.rb +7 -0
- data/spec/lib/entityjs/commands/new_spec.rb +20 -0
- data/spec/lib/entityjs/commands/templates_spec.rb +9 -0
- data/spec/lib/entityjs/commands/test_spec.rb +31 -0
- data/spec/lib/entityjs/config_spec.rb +19 -0
- data/spec/lib/entityjs/dirc_spec.rb +83 -0
- data/spec/lib/entityjs/version_spec.rb +9 -0
- data/spec/spec_helper.rb +21 -3
- data/spec/support/factories.rb +19 -0
- data/spec/support/mygame.rb +11 -0
- data/src/core/comp.js +318 -0
- data/src/core/entity.js +549 -0
- data/src/core/load.js +242 -0
- data/src/core/query.js +354 -0
- data/src/core/re.js +74 -0
- data/src/core/system.js +121 -0
- data/src/cycle/draw.js +178 -0
- data/src/cycle/tick.js +25 -0
- data/src/{entityjs/cycle → cycle}/tween.js +60 -60
- data/src/{entityjs/cycle → cycle}/update.js +86 -85
- data/src/{entityjs/cycle → cycle}/wait.js +22 -21
- data/src/{entityjs/cycle → cycle}/worker.js +8 -8
- data/src/display/align.js +45 -0
- data/src/display/circle.js +33 -0
- data/src/{entityjs/display → display}/group.js +62 -62
- data/src/display/image.js +35 -0
- data/src/display/imgtext.js +102 -0
- data/src/{entityjs/display → display}/rect.js +18 -18
- data/src/display/screen.js +57 -0
- data/src/display/sprite.js +54 -0
- data/src/display/text.js +44 -0
- data/src/{entityjs/input → input}/keyboard.js +152 -150
- data/src/input/mouse.js +111 -0
- data/src/input/pressed.js +41 -0
- data/src/{entityjs/input → input}/touch.js +24 -28
- data/src/math/bisect.js +84 -0
- data/src/math/body.js +70 -0
- data/src/{entityjs/math → math}/drag.js +44 -38
- data/src/math/force.js +143 -0
- data/src/math/hit.js +32 -0
- data/src/math/hitmap.js +167 -0
- data/src/math/limit.js +37 -0
- data/src/math/point.js +40 -0
- data/src/math/tile.js +109 -0
- data/src/media/channel.js +93 -0
- data/src/{entityjs/media → media}/playlist.js +4 -4
- data/src/media/sound.js +114 -0
- data/src/{entityjs/net → net}/socket.js +51 -51
- data/src/pattern/automap.js +133 -0
- data/src/{entityjs/pattern → pattern}/flicker.js +206 -213
- data/src/pattern/timestep.js +31 -0
- data/src/{entityjs/save → save}/database.js +6 -6
- data/src/{entityjs/save → save}/storage.js +47 -56
- data/src/{entityjs/util → util}/log.js +17 -25
- data/src/{entityjs/util → util}/polyfill.js +24 -24
- data/src/util/random.js +20 -0
- data/src/util/scene.js +102 -0
- data/src/util/sheet.js +35 -0
- data/src/{entityjs/util → util}/support.js +109 -132
- data/{examples/keys → templates/arrow_keys/assets/images}/arrow.png +0 -0
- data/templates/arrow_keys/config.yml +22 -0
- data/templates/arrow_keys/readme.txt +9 -0
- data/templates/arrow_keys/scripts/display/arrow.js +69 -0
- data/templates/arrow_keys/scripts/init.js +10 -0
- data/templates/arrow_keys/scripts/input/controls.js +35 -0
- data/templates/arrow_keys/scripts/scenes/home.js +20 -0
- data/templates/arrow_keys/scripts/scenes/load.js +57 -0
- data/templates/arrow_keys/tests/display/arrow_test.js +29 -0
- data/templates/arrow_keys/tests/init_test.js +4 -0
- data/templates/arrow_keys/tests/input/controls_test.js +32 -0
- data/templates/arrow_keys/tests/scenes/home_test.js +0 -0
- data/templates/arrow_keys/tests/scenes/load_test.js +16 -0
- data/templates/blank/config.yml +22 -0
- data/templates/blank/readme.txt +79 -0
- data/templates/platform/assets/images/bit.png +0 -0
- data/templates/platform/assets/images/hero.png +0 -0
- data/templates/platform/assets/images/items.png +0 -0
- data/templates/platform/assets/images/tiles.png +0 -0
- data/templates/platform/assets/levels/level1.tmx +44 -0
- data/templates/platform/assets/sounds/coin.mp3 +0 -0
- data/templates/platform/assets/sounds/coin.ogg +0 -0
- data/templates/platform/config.yml +22 -0
- data/templates/platform/readme.txt +87 -0
- data/templates/platform/scripts/display/bit.js +12 -0
- data/templates/platform/scripts/display/hero.js +77 -0
- data/templates/platform/scripts/display/tile.js +2 -0
- data/templates/platform/scripts/display/tsprite.js +17 -0
- data/templates/platform/scripts/init.js +7 -0
- data/templates/platform/scripts/items/coin.js +27 -0
- data/templates/platform/scripts/items/item.js +41 -0
- data/templates/platform/scripts/items/spring.js +25 -0
- data/templates/platform/scripts/scenes/home.js +10 -0
- data/templates/platform/scripts/scenes/load.js +27 -0
- data/templates/platform/scripts/scenes/play.js +31 -0
- data/templates/platform/scripts/util/counter.js +34 -0
- data/templates/platform/scripts/util/level.js +84 -0
- data/templates/platform/tests/display/bit_test.js +7 -0
- data/templates/platform/tests/display/hero_test.js +73 -0
- data/templates/platform/tests/display/tile_test.js +7 -0
- data/templates/platform/tests/display/tsprite_test.js +8 -0
- data/templates/platform/tests/factories.js +30 -0
- data/templates/platform/tests/items/coin_test.js +28 -0
- data/templates/platform/tests/items/item_test.js +36 -0
- data/templates/platform/tests/items/spring_test.js +21 -0
- data/templates/platform/tests/scenes/home_test.js +9 -0
- data/templates/platform/tests/scenes/load_test.js +11 -0
- data/templates/platform/tests/scenes/play_test.js +15 -0
- data/templates/platform/tests/util/counter_test.js +9 -0
- data/templates/platform/tests/util/level_test.js +29 -0
- metadata +249 -97
- data/build/build_debug.bat +0 -1
- data/build/build_min.bat +0 -1
- data/build/config.php +0 -64
- data/build/debug.php +0 -48
- data/build/files.php +0 -74
- data/build/jsmin.php +0 -376
- data/build/min.php +0 -50
- data/changelog.txt +0 -53
- data/examples/keys/keys.html +0 -59
- data/examples/keys/keys.js +0 -148
- data/examples/mouse/mouse.html +0 -58
- data/examples/mouse/mouse.js +0 -60
- data/examples/scenes/home.png +0 -0
- data/examples/scenes/scenes.html +0 -55
- data/examples/scenes/scenes.js +0 -134
- data/examples/scenes/win.png +0 -0
- data/examples/sounds/sound1.mp3 +0 -0
- data/examples/sounds/sound1.ogg +0 -0
- data/examples/sounds/sounds.html +0 -56
- data/examples/sounds/sounds.js +0 -44
- data/examples/style/background.png +0 -0
- data/examples/style/sheet.css +0 -762
- data/examples/tiles/tiles.html +0 -56
- data/examples/tiles/tiles.js +0 -85
- data/examples/tiles/tiles.png +0 -0
- data/lib/blank/config.js +0 -4
- data/lib/blank/config.yml +0 -21
- data/lib/blank/home.js +0 -11
- data/lib/blank/init.js +0 -7
- data/lib/blank/load.js +0 -21
- data/lib/blank/play.html +0 -29
- data/lib/entity.debug.js +0 -52
- data/lib/entity.min.js +0 -184
- data/lib/entityjs/comp.rb +0 -11
- data/lib/entityjs/game.rb +0 -93
- data/lib/entityjs/min.rb +0 -11
- data/lib/entityjs/refresh.rb +0 -14
- data/spec/lib/entityjs/game_spec.rb +0 -11
- data/src/entityjs/core/component.js +0 -306
- data/src/entityjs/core/entity.js +0 -516
- data/src/entityjs/core/load.js +0 -224
- data/src/entityjs/core/query.js +0 -410
- data/src/entityjs/core/re.js +0 -70
- data/src/entityjs/core/system.js +0 -125
- data/src/entityjs/cycle/draw.js +0 -185
- data/src/entityjs/cycle/ticker.js +0 -27
- data/src/entityjs/display/anchor.js +0 -53
- data/src/entityjs/display/bitfont.js +0 -93
- data/src/entityjs/display/bitmap.js +0 -37
- data/src/entityjs/display/circle.js +0 -30
- data/src/entityjs/display/font.js +0 -41
- data/src/entityjs/display/screen.js +0 -46
- data/src/entityjs/display/sprite.js +0 -37
- data/src/entityjs/input/mouse.js +0 -123
- data/src/entityjs/input/pressed.js +0 -81
- data/src/entityjs/math/bind.js +0 -76
- data/src/entityjs/math/bisect.js +0 -69
- data/src/entityjs/math/body.js +0 -39
- data/src/entityjs/math/hitmap.js +0 -165
- data/src/entityjs/math/hittest.js +0 -26
- data/src/entityjs/math/physics.js +0 -142
- data/src/entityjs/math/point.js +0 -57
- data/src/entityjs/math/tile.js +0 -91
- data/src/entityjs/media/channel.js +0 -93
- data/src/entityjs/media/sound.js +0 -110
- data/src/entityjs/pattern/arraymap.js +0 -89
- data/src/entityjs/pattern/timestep.js +0 -34
- data/src/entityjs/util/random.js +0 -38
- data/src/entityjs/util/scene.js +0 -101
- data/src/entityjs/util/sheet.js +0 -51
data/.gitignore
CHANGED
data/.rspec
ADDED
data/README.md
CHANGED
@@ -1,49 +1,170 @@
|
|
1
|
-
#
|
2
|
-
An HTML5 javascript game engine utlizing the entity-component design. Write highly flexible code in a powerful javascript framework.
|
3
|
-
|
4
|
-
[EntityJS Website](http://entityjs.com) | [Demos](http://entityjs.com/demos) | [Tutorials](http://entityjs.com/tutorials) | [API](http://entityjs.com/api)
|
5
|
-
|
6
|
-
##
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
1
|
+
# EntityJS
|
2
|
+
An HTML5 javascript game engine utlizing the entity-component design. Write highly flexible code in a powerful javascript framework.
|
3
|
+
|
4
|
+
[EntityJS Website](http://entityjs.com) | [Demos](http://entityjs.com/demos) | [Tutorials](http://entityjs.com/tutorials) | [API](http://entityjs.com/api)
|
5
|
+
|
6
|
+
## Version 0.3
|
7
|
+
|
8
|
+
Version 0.3 is a major release with many revisions and a brand new ruby gem to work with. You can now type `entityjs new game-name` and a new game will be created. Of course there are more commands, check below.
|
9
|
+
|
10
|
+
There is a new directory structure, testing framework, better minifier, better config file and more. This is currently in alpha and most of it doesn't work!
|
11
|
+
|
12
|
+
**Warning:** there are many name changes which will break older versions!
|
13
|
+
|
14
|
+
## API
|
15
|
+
Currently the [API](http://entityjs.com/api) is out of date. It will be updated once version 0.3 is released.
|
16
|
+
|
17
|
+
## What makes this different from other javascript game engines?
|
18
|
+
Entity strives to be the most flexible game engine available. We understand no one likes rewritting the same functions and lines of code over and over. So we have developed a solution to this problem and that is the component-entity design. The traditional approach to game engine design is creating a hierarchy of classes. This is infact the **most** tightly coupled design. This creates close coupled classes whos functionality is strictly typed to one class, its not easily portable to other projects, good luck copying that one needed function and as game development progresses classes get bigger and more complex. You will eventually end up with *god-classes* who control most of the game logic.
|
19
|
+
|
20
|
+
This becomes a big mess.
|
21
|
+
|
22
|
+
In the world of *entity-component* designs. All logic is implemented in a *component*, as big or small as you want. You can then create an *entity* and add/remove components to it. The entity is a live represantation of all its components. With this low coupling of components and entities you can mix and match components together to create powerful functionality yet still portable and robust.
|
23
|
+
|
24
|
+
## Requirements
|
25
|
+
|
26
|
+
You must have at least [Ruby 1.8.1+](http://rubyinstaller.org/).
|
27
|
+
|
28
|
+
## Installion
|
29
|
+
|
30
|
+
EntityJS is now an easy to install gem. In the terminal type in:
|
31
|
+
|
32
|
+
`gem install entityjs`
|
33
|
+
|
34
|
+
This will install the latest version of the gem and now you can easily create some games!
|
35
|
+
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
**Warning** at the moment the gemfile is at version 0.2.2 and is **broken**. Wait until version 0.3 to try these commands.
|
40
|
+
|
41
|
+
When using these commands make sure you are always in the root directory of your game.
|
42
|
+
|
43
|
+
### Creating a New Game
|
44
|
+
|
45
|
+
Creating a game is simple, move to any directory and type in:
|
46
|
+
|
47
|
+
`entityjs new mygame`
|
48
|
+
|
49
|
+
This will create a new game using the default template.
|
50
|
+
|
51
|
+
Create a game with a platform template:
|
52
|
+
|
53
|
+
`entityjs new mygame platform`
|
54
|
+
|
55
|
+
See all available templates:
|
56
|
+
|
57
|
+
`entityjs templates`
|
58
|
+
|
59
|
+
### Creating a Component
|
60
|
+
|
61
|
+
`entityjs comp rock`
|
62
|
+
|
63
|
+
This will create a new component called *rock* at scripts/rock.js and will create a test file inside test/rock.js
|
64
|
+
|
65
|
+
`entityjs comp display/hero`
|
66
|
+
|
67
|
+
This will create a new component in the directory scripts/display.
|
68
|
+
|
69
|
+
### Creating a Test
|
70
|
+
|
71
|
+
`entityjs test name test1 test1`
|
72
|
+
|
73
|
+
Create a test in tests/name_test.js with two test methods.
|
74
|
+
|
75
|
+
### Build Game
|
76
|
+
|
77
|
+
`entityjs build`
|
78
|
+
|
79
|
+
This will minify all entityjs src code and game src code into one file inside /builds
|
80
|
+
|
81
|
+
### Running the Game / Tests
|
82
|
+
|
83
|
+
Make sure the server is running:
|
84
|
+
`entityjs server`
|
85
|
+
|
86
|
+
To play visit:
|
87
|
+
`localhost:2345`
|
88
|
+
|
89
|
+
To run tests visit:
|
90
|
+
`localhost:2345/tests`
|
91
|
+
|
92
|
+
Assets are located here:
|
93
|
+
`localhost:2345/assets/*name`
|
94
|
+
|
95
|
+
## Directory Structure
|
96
|
+
|
97
|
+
* Assets - Contains all external assets
|
98
|
+
* Images - Add any images here and retrieve them with `re.assets.images`
|
99
|
+
* Sounds - Add any sounds and retrieve them with `re.assets.sounds`
|
100
|
+
* [Custom] - Create any folders or files and they will be available in code.
|
101
|
+
* json, tmx, xml, sounds and images are accepted files.
|
102
|
+
|
103
|
+
* Builds - Contains all finished builds
|
104
|
+
|
105
|
+
* Scripts - Contains all javascript sources.
|
106
|
+
* Plugins - Contains external scripts from other authors.
|
107
|
+
|
108
|
+
* Tests - Contains test files to run in [QUnit](http://docs.jquery.com/QUnit)
|
109
|
+
|
110
|
+
* config.yml - Optional, simple configuration.
|
111
|
+
* readme.txt - Optional, simple description of the game.
|
112
|
+
|
113
|
+
## Changes In V0.3
|
114
|
+
|
115
|
+
* `Inherit()` is now `defaults()`
|
116
|
+
* `Extend()` is now `defines()`
|
117
|
+
* `Inherit()` on entities is now `def()`
|
118
|
+
* `Extend()` on entities is now `attr()`
|
119
|
+
|
120
|
+
There are many more name changes, make sure to read the component source code for more information. Also every component has a usage example.
|
121
|
+
|
122
|
+
### Short getters and setters
|
123
|
+
|
124
|
+
var tile = re.e('tile');
|
125
|
+
tile.tileX(1); //sets
|
126
|
+
tile.tileX(); //gets
|
127
|
+
|
128
|
+
#### Setters can even be used in `attr()`
|
129
|
+
|
130
|
+
tile.attr('tileX', 2); //sets
|
131
|
+
|
132
|
+
#### Setter with multiple parameters
|
133
|
+
|
134
|
+
tile.tile(1, 2); //sets tilex and tiley
|
135
|
+
//or
|
136
|
+
tile.attr('tile', [1,2]); //samething
|
137
|
+
|
138
|
+
### Signals Changed to on/off
|
139
|
+
|
140
|
+
* `addSignal()` is now `on()`
|
141
|
+
* `removeSignal()` is now `off()`
|
142
|
+
* `signal()` is now `trigger()`
|
143
|
+
|
144
|
+
## QUnit Testing
|
145
|
+
|
146
|
+
All games will now use [QUnit](http://docs.jquery.com/QUnit) as the primary test framework. Its light weight and awesome.
|
147
|
+
|
148
|
+
Special methods like `keypress` and `click` are available to simulate user input. Check `localhost:2345/qunit/qunit.input.js` for more information.
|
149
|
+
|
150
|
+
## Tile Map Editor
|
151
|
+
|
152
|
+
The awesome [tiled](http://www.mapeditor.org/) map editor is now compatible and can be used in your projects.
|
153
|
+
|
154
|
+
Simply create a new directory in /assets named levels or anything you like to save your maps in. They can accessed in code like so:
|
155
|
+
|
156
|
+
re('level1.tmx')[0]; //assuming the file name is level1.tmx
|
157
|
+
re('level'); //find all levels that are in the /assets/levels directory
|
158
|
+
|
159
|
+
If you are still confused create a new platform game and view how the levels are used.
|
160
|
+
|
161
|
+
## Quick Start Guide
|
162
|
+
First you should install [ruby](http://rubyinstaller.org/) and the [entityjs gem](http://rubygems.org/gems/entityjs).
|
163
|
+
|
164
|
+
Now you can create a new game:
|
165
|
+
`entityjs new mygame`
|
166
|
+
|
167
|
+
Move into the mygame/ directory and lets play the game:
|
168
|
+
`entityjs server`
|
169
|
+
|
170
|
+
Open your browser and navigate to `localhost:2345`
|
data/Rakefile
CHANGED
data/bin/entityjs
CHANGED
@@ -1,14 +1,24 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
5
|
-
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
6
|
-
|
7
|
-
require 'entityjs'
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
|
4
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
5
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
6
|
+
|
7
|
+
require 'entityjs'
|
8
|
+
|
9
|
+
args = ARGV.dup
|
10
|
+
ARGV.clear
|
11
|
+
command = args.shift.strip rescue 'help'
|
12
|
+
|
13
|
+
code = Entityjs::Command.run(command, args)
|
14
|
+
|
15
|
+
case code
|
16
|
+
when 1
|
17
|
+
puts "Command not found"
|
18
|
+
when 2
|
19
|
+
puts "EntityJS game not found"
|
20
|
+
puts "Move inside the root directory"
|
21
|
+
when 3
|
22
|
+
puts "File/Directory exists"
|
23
|
+
|
24
|
+
end
|
data/entityjs.gemspec
CHANGED
@@ -6,20 +6,26 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "entityjs"
|
7
7
|
s.version = Entityjs::VERSION
|
8
8
|
s.authors = ["Ben D'Angelo"]
|
9
|
-
s.email = ["ben
|
9
|
+
s.email = ["ben@entityjs.com"]
|
10
10
|
s.homepage = "http://entityjs.com"
|
11
|
-
s.summary = %q{
|
12
|
-
s.description = %q{
|
13
|
-
|
11
|
+
s.summary = %q{Create HTML5 javascript games in EntityJS.}
|
12
|
+
s.description = %q{The EntityJS gem supplies easy to use commands for creating javascript games.}
|
13
|
+
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
14
16
|
s.rubyforge_project = "entityjs"
|
15
|
-
|
17
|
+
|
16
18
|
s.files = `git ls-files`.split("\n")
|
17
19
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
21
|
s.require_paths = ["lib"]
|
20
|
-
|
22
|
+
|
21
23
|
# specify any dependencies here; for example:
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
s.add_development_dependency "rspec"
|
25
|
+
s.add_development_dependency "jasmine"
|
26
|
+
|
27
|
+
s.add_dependency "sinatra"
|
28
|
+
s.add_dependency 'uglifier'
|
29
|
+
s.add_dependency 'json'
|
30
|
+
s.add_dependency 'cobravsmongoose'
|
25
31
|
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
|
2
|
+
module Entityjs
|
3
|
+
|
4
|
+
class Assets
|
5
|
+
|
6
|
+
def self.valid_datas
|
7
|
+
['xml', 'json', 'tmx']
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.set_vars(contents, tests=false)
|
11
|
+
#read file for changes
|
12
|
+
Config.instance.reload
|
13
|
+
|
14
|
+
contents = contents.gsub("$WIDTH", Config.instance.width.to_s)
|
15
|
+
contents = contents.gsub("$HEIGHT", Config.instance.height.to_s)
|
16
|
+
contents = contents.gsub("$CANVAS_ID", Config.instance.canvas_id)
|
17
|
+
|
18
|
+
contents.gsub("$JS", Assets.to_html(tests))
|
19
|
+
end
|
20
|
+
|
21
|
+
#combine all sources into valid html scripts
|
22
|
+
def self.to_html(tests=false)
|
23
|
+
js = %Q(
|
24
|
+
<script type='text/javascript'>
|
25
|
+
window.addEventListener\('load', function(){
|
26
|
+
#{Assets.to_js}
|
27
|
+
re.version = '#{VERSION}';
|
28
|
+
|
29
|
+
}\);
|
30
|
+
</script>
|
31
|
+
)
|
32
|
+
ent = Dirc.find_entity_src_url(Config.instance.entity_ignore)
|
33
|
+
srcs = Dirc.find_scripts_url(Config.instance.scripts_ignore, Config.instance.scripts_order)
|
34
|
+
|
35
|
+
if tests
|
36
|
+
tests_src = Dirc.find_tests_url(Config.instance.tests_ignore)
|
37
|
+
else
|
38
|
+
tests_src = []
|
39
|
+
end
|
40
|
+
|
41
|
+
merg = ent | srcs | tests_src
|
42
|
+
|
43
|
+
merg.each do |s|
|
44
|
+
js += "\t<script src='#{s}' type='text/javascript'></script>\n"
|
45
|
+
end
|
46
|
+
js
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.to_js
|
50
|
+
out = %Q(
|
51
|
+
re.load.path = 'assets/';
|
52
|
+
re.assets = {
|
53
|
+
images:#{self.images_to_js},
|
54
|
+
sounds:#{self.sounds_to_js}
|
55
|
+
};
|
56
|
+
re.canvas = '##{Config.instance.canvas_id}';
|
57
|
+
#{self.datas_to_js}
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.images_to_js
|
62
|
+
s = self.search('images').collect{|i| "'#{i}'"}.join(', ')
|
63
|
+
|
64
|
+
"[#{s}]"
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.sounds_to_js
|
68
|
+
s = self.search('sounds').collect{|i| "'#{i}'"}.join(', ')
|
69
|
+
|
70
|
+
"[#{s}]"
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.datas_to_js
|
74
|
+
s = self.search
|
75
|
+
|
76
|
+
out = ''
|
77
|
+
|
78
|
+
s.each do |i|
|
79
|
+
|
80
|
+
basename = File.basename(i)
|
81
|
+
dirname = File.dirname(i)
|
82
|
+
|
83
|
+
#make singular
|
84
|
+
if dirname[-1] == 's'
|
85
|
+
dirname = dirname[0..-2]
|
86
|
+
end
|
87
|
+
|
88
|
+
contents = self.file_to_json(Dirc.game_root+'/'+Config.assets_folder+'/'+i)
|
89
|
+
|
90
|
+
out += %Q(
|
91
|
+
re.e('#{basename} #{dirname}')
|
92
|
+
.attr(#{contents});
|
93
|
+
)
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
out
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.data_to_json(data, ext)
|
102
|
+
case ext
|
103
|
+
when /json/
|
104
|
+
return data
|
105
|
+
|
106
|
+
when /tmx/
|
107
|
+
|
108
|
+
return ParseTMX.parse(data)
|
109
|
+
|
110
|
+
when /xml/
|
111
|
+
return ParseXML.parse(data)
|
112
|
+
|
113
|
+
when /csv/
|
114
|
+
raise 'CSV files are not supported at the moment'
|
115
|
+
|
116
|
+
when /yml/
|
117
|
+
raise 'YML files are not supported at the moment'
|
118
|
+
|
119
|
+
else
|
120
|
+
raise "Extension #{ext} not recognized"
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
return nil
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.file_to_json(file)
|
128
|
+
contents = IO.read(file)
|
129
|
+
#remove dot from extension
|
130
|
+
ext = File.extname(file).downcase
|
131
|
+
return self.data_to_json(contents, ext)
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.search(type='*')
|
135
|
+
images_folder = Config.images_folder
|
136
|
+
sounds_folder = Config.sounds_folder
|
137
|
+
assets_folder = Config.assets_folder
|
138
|
+
|
139
|
+
case type
|
140
|
+
when 'images'
|
141
|
+
return self.find_files(images_folder+'/*').select{|i| i.match(/^*\.(gif|png|jpg|jpeg)$/i)}
|
142
|
+
|
143
|
+
when 'sounds'
|
144
|
+
return self.find_files(sounds_folder+'/*').select{|i| i.match(/^*\.(mp3|ogg|aac|wav)$/i)}
|
145
|
+
|
146
|
+
else
|
147
|
+
return self.search_datas
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
def self.search_datas
|
154
|
+
datas = self.valid_datas.join('|')
|
155
|
+
return self.find_files("#{Config.assets_folder}/*/*").select{|i| !i.match(/\/(images|sounds)\//i) && i.match(/^*\.(#{datas})$/i)}
|
156
|
+
end
|
157
|
+
|
158
|
+
def self.find_files(search)
|
159
|
+
Dir[Dirc.game_root+'/'+search].collect do |i|
|
160
|
+
#remove long string
|
161
|
+
i = i.split("assets/").pop
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
data/lib/entityjs/command.rb
CHANGED
@@ -1,36 +1,61 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
Dir.glob("#{Entityjs::root}/lib/entityjs/*.rb").each {|f| require f }
|
2
|
+
Dir.glob("#{Entityjs::root}/lib/entityjs/*/*.rb").each {|f| require f }
|
3
|
+
|
4
|
+
# 0 - ok
|
5
|
+
# 1 - command not found
|
6
|
+
# 2 - not in game directory
|
7
|
+
# 3 - file exists
|
6
8
|
|
7
9
|
module Entityjs
|
8
10
|
class Command
|
9
11
|
|
10
12
|
def self.run(command, args=nil)
|
11
|
-
|
12
|
-
case command
|
13
|
-
when
|
14
|
-
Entityjs::
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
13
|
+
|
14
|
+
case command
|
15
|
+
when /^(new|n)$/
|
16
|
+
return Entityjs::New.generate(args)
|
17
|
+
when 'templates'
|
18
|
+
return Entityjs::Templates.generate(args)
|
19
|
+
|
20
|
+
when /^(build|b)$/
|
21
|
+
return Entityjs::Build.generate(args)
|
22
|
+
|
23
|
+
when /^(test|t)$/
|
24
|
+
return Entityjs::Test.generate(args)
|
25
|
+
|
26
|
+
when /^(comp|c)$/
|
27
|
+
return Entityjs::Comp.generate(args)
|
28
|
+
|
29
|
+
when /^(server|s)$/
|
30
|
+
return Entityjs::Server.run(args)
|
31
|
+
|
32
|
+
when /^(font|f)$/
|
33
|
+
return Entityjs::Font.generate(args)
|
34
|
+
|
35
|
+
when /^(version|v)$/
|
36
|
+
puts 'EntityJS V'+Entityjs::VERSION
|
37
|
+
return 0
|
38
|
+
|
39
|
+
when /^(help|h)$/
|
40
|
+
puts ""
|
41
|
+
puts '---- Commands ----'
|
42
|
+
puts 'entityjs new [name]'
|
43
|
+
puts 'entityjs new [name] [template]'
|
44
|
+
puts 'entityjs templates'
|
45
|
+
puts 'entityjs comp [name]'
|
46
|
+
puts 'entityjs test [name]'
|
47
|
+
puts 'entityjs test [name] [tests]+'
|
48
|
+
puts 'entityjs font [name] (soon...)'
|
49
|
+
puts 'entityjs build'
|
50
|
+
puts 'entityjs build [name]'
|
51
|
+
puts 'entityjs server'
|
52
|
+
puts 'entityjs help'
|
53
|
+
puts 'entityjs version'
|
54
|
+
return 0
|
55
|
+
|
33
56
|
end
|
57
|
+
|
58
|
+
return 1
|
34
59
|
end
|
35
60
|
|
36
61
|
end
|