entityjs 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +4 -0
- data/README.md +49 -0
- data/Rakefile +1 -0
- data/bin/entityjs +14 -0
- data/build/build_debug.bat +1 -0
- data/build/build_min.bat +1 -0
- data/build/config.php +64 -0
- data/build/debug.php +48 -0
- data/build/files.php +74 -0
- data/build/jsmin.php +376 -0
- data/build/min.php +50 -0
- data/changelog.txt +53 -0
- data/entityjs.gemspec +25 -0
- data/examples/keys/arrow.png +0 -0
- data/examples/keys/keys.html +59 -0
- data/examples/keys/keys.js +148 -0
- data/examples/mouse/mouse.html +58 -0
- data/examples/mouse/mouse.js +60 -0
- data/examples/scenes/home.png +0 -0
- data/examples/scenes/scenes.html +55 -0
- data/examples/scenes/scenes.js +134 -0
- 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 +56 -0
- data/examples/sounds/sounds.js +44 -0
- data/examples/style/background.png +0 -0
- data/examples/style/sheet.css +762 -0
- data/examples/tiles/tiles.html +56 -0
- data/examples/tiles/tiles.js +85 -0
- data/examples/tiles/tiles.png +0 -0
- data/lib/blank/config.js +4 -0
- data/lib/blank/config.yml +21 -0
- data/lib/blank/home.js +11 -0
- data/lib/blank/init.js +7 -0
- data/lib/blank/load.js +21 -0
- data/lib/blank/play.html +29 -0
- data/lib/entity.debug.js +52 -0
- data/lib/entity.min.js +184 -0
- data/lib/entityjs/command.rb +37 -0
- data/lib/entityjs/comp.rb +11 -0
- data/lib/entityjs/game.rb +93 -0
- data/lib/entityjs/min.rb +11 -0
- data/lib/entityjs/refresh.rb +14 -0
- data/lib/entityjs/version.rb +3 -0
- data/lib/entityjs.rb +6 -0
- data/license.txt +1 -0
- data/spec/lib/entityjs/game_spec.rb +11 -0
- data/spec/spec_helper.rb +3 -0
- data/src/entityjs/core/component.js +306 -0
- data/src/entityjs/core/entity.js +516 -0
- data/src/entityjs/core/load.js +224 -0
- data/src/entityjs/core/query.js +410 -0
- data/src/entityjs/core/re.js +70 -0
- data/src/entityjs/core/system.js +125 -0
- data/src/entityjs/cycle/draw.js +185 -0
- data/src/entityjs/cycle/ticker.js +27 -0
- data/src/entityjs/cycle/tween.js +61 -0
- data/src/entityjs/cycle/update.js +86 -0
- data/src/entityjs/cycle/wait.js +22 -0
- data/src/entityjs/cycle/worker.js +9 -0
- data/src/entityjs/display/anchor.js +53 -0
- data/src/entityjs/display/bitfont.js +93 -0
- data/src/entityjs/display/bitmap.js +37 -0
- data/src/entityjs/display/circle.js +30 -0
- data/src/entityjs/display/font.js +41 -0
- data/src/entityjs/display/group.js +63 -0
- data/src/entityjs/display/rect.js +19 -0
- data/src/entityjs/display/screen.js +46 -0
- data/src/entityjs/display/sprite.js +37 -0
- data/src/entityjs/input/keyboard.js +150 -0
- data/src/entityjs/input/mouse.js +123 -0
- data/src/entityjs/input/pressed.js +81 -0
- data/src/entityjs/input/touch.js +28 -0
- data/src/entityjs/math/bind.js +76 -0
- data/src/entityjs/math/bisect.js +69 -0
- data/src/entityjs/math/body.js +39 -0
- data/src/entityjs/math/drag.js +39 -0
- data/src/entityjs/math/hitmap.js +165 -0
- data/src/entityjs/math/hittest.js +26 -0
- data/src/entityjs/math/physics.js +142 -0
- data/src/entityjs/math/point.js +57 -0
- data/src/entityjs/math/tile.js +91 -0
- data/src/entityjs/media/channel.js +93 -0
- data/src/entityjs/media/playlist.js +5 -0
- data/src/entityjs/media/sound.js +110 -0
- data/src/entityjs/net/socket.js +52 -0
- data/src/entityjs/pattern/arraymap.js +89 -0
- data/src/entityjs/pattern/flicker.js +214 -0
- data/src/entityjs/pattern/timestep.js +34 -0
- data/src/entityjs/save/database.js +7 -0
- data/src/entityjs/save/storage.js +57 -0
- data/src/entityjs/util/log.js +25 -0
- data/src/entityjs/util/polyfill.js +25 -0
- data/src/entityjs/util/random.js +38 -0
- data/src/entityjs/util/scene.js +101 -0
- data/src/entityjs/util/sheet.js +51 -0
- data/src/entityjs/util/support.js +132 -0
- metadata +156 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Entity JS
|
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
|
+
## What makes this different from other javascript game engines?
|
7
|
+
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.
|
8
|
+
|
9
|
+
This becomes a big mess.
|
10
|
+
|
11
|
+
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.
|
12
|
+
|
13
|
+
## Directory Structure
|
14
|
+
|
15
|
+
* **build** Contains two build commands to compile entityjs code.
|
16
|
+
* **build_min.bat** Will build a minified version for release.
|
17
|
+
* **build_debug.bat** Will build a debug file for testing offline.
|
18
|
+
* **lib** Contains two compiled sources *entity.min.js* and *entity.debug.js*
|
19
|
+
* **src** Contains source code of *entityjs*
|
20
|
+
* **tutorials** Contains simple tutorials and examples.
|
21
|
+
|
22
|
+
## Quick Start Guide
|
23
|
+
This will take you through some quick steps to display an image on a canvas element.
|
24
|
+
|
25
|
+
* Include *entity.min.js* in your html document (All compiled sources can be found in */lib*).
|
26
|
+
|
27
|
+
* Initialize the system by calling *re.system.init*.
|
28
|
+
|
29
|
+
`re.system.init('#canvasId');`
|
30
|
+
|
31
|
+
* Start the *main loop* of the application. This will refresh the screen and update logic.
|
32
|
+
|
33
|
+
`re.system.start();`
|
34
|
+
|
35
|
+
* We now have to load our image *welcome.png*.
|
36
|
+
|
37
|
+
<code>re.load('welcome.png').complete(function(){ });</code>
|
38
|
+
|
39
|
+
* Now inside the complete function body we can display the image. *re.entity* creates a new entity with the given components.
|
40
|
+
|
41
|
+
`re.entity('bitmap welcome.png');`
|
42
|
+
|
43
|
+
That should now display an image on your canvas. Yes! For more information check out [the website](entityjs.com).
|
44
|
+
|
45
|
+
## Future
|
46
|
+
* Ruby YUI compiler
|
47
|
+
* Level Editor
|
48
|
+
* JS Loader
|
49
|
+
* More tutorials!
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/entityjs
ADDED
@@ -0,0 +1,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
|
+
require 'entityjs/command'
|
9
|
+
|
10
|
+
args = ARGV.dup
|
11
|
+
ARGV.clear
|
12
|
+
command = args.shift.strip rescue 'help'
|
13
|
+
|
14
|
+
Entityjs::Command.run(command, args)
|
@@ -0,0 +1 @@
|
|
1
|
+
php debug.php
|
data/build/build_min.bat
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
php min.php
|
data/build/config.php
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
<?php
|
2
|
+
/*
|
3
|
+
This file contains configurable variables for both debug.php and min.php.
|
4
|
+
*/
|
5
|
+
|
6
|
+
//turn off error for blank regex
|
7
|
+
error_reporting(E_ALL ^ E_WARNING);
|
8
|
+
|
9
|
+
//current entityjs version
|
10
|
+
//this will be added to all built files.
|
11
|
+
$version = '0.3';
|
12
|
+
|
13
|
+
//full length path to entityjs folder
|
14
|
+
$absolute_path = '..';
|
15
|
+
|
16
|
+
//path to entityjs source files
|
17
|
+
$source_path = $absolute_path.'/src';
|
18
|
+
|
19
|
+
//path to output directory
|
20
|
+
$des_path = $absolute_path.'/lib';
|
21
|
+
|
22
|
+
//location of license
|
23
|
+
$license = $absolute_path.'/license.txt';
|
24
|
+
|
25
|
+
//name of entityjs directory
|
26
|
+
$entity = 'entityjs';
|
27
|
+
|
28
|
+
//name of re definition file
|
29
|
+
$re_file = 're.js';
|
30
|
+
|
31
|
+
//ignore regular expression
|
32
|
+
/*
|
33
|
+
ignore regular expression
|
34
|
+
|
35
|
+
example
|
36
|
+
|
37
|
+
$ignore_reg = '/(socket|storage|group)/'
|
38
|
+
|
39
|
+
*/
|
40
|
+
$ignore_reg = '/(socket)/';
|
41
|
+
|
42
|
+
//path to entityjs directory
|
43
|
+
$retro_folder = $source_path.'/'.$entity.'/';
|
44
|
+
|
45
|
+
//name of outputed minified file
|
46
|
+
$min_name = 'entity.min.js';
|
47
|
+
|
48
|
+
//name of outputed debug file
|
49
|
+
$debug_name = 'entity.debug.js';
|
50
|
+
|
51
|
+
|
52
|
+
/*
|
53
|
+
Compile replace variables.
|
54
|
+
|
55
|
+
Adding these variables to your release source files will be replaced
|
56
|
+
with the respected value.
|
57
|
+
*/
|
58
|
+
|
59
|
+
//replaces $VERSION with current entity js version
|
60
|
+
$version_pattern = '$VERSION';
|
61
|
+
|
62
|
+
//more to come..
|
63
|
+
|
64
|
+
?>
|
data/build/debug.php
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
<?php
|
2
|
+
/*
|
3
|
+
The debug.php file is used to create an entity.debug.php file for your application.
|
4
|
+
Include this file into your web page and it will load all files in the source
|
5
|
+
directory automatically for you.
|
6
|
+
|
7
|
+
@usage
|
8
|
+
Open the command prompt
|
9
|
+
Navigate to the debug.php directory
|
10
|
+
type "php debug.php"
|
11
|
+
This will create for you a entity.debug.js in the lib directory
|
12
|
+
|
13
|
+
You can now use this file in debug testing / debugging.
|
14
|
+
|
15
|
+
@warning
|
16
|
+
Each time a file is deleted or created in the source directory
|
17
|
+
you must run this php script again.
|
18
|
+
*/
|
19
|
+
|
20
|
+
require 'config.php';
|
21
|
+
|
22
|
+
require 'files.php';
|
23
|
+
|
24
|
+
$header = file_get_contents($license)."\nif(!path) path = '';\n";
|
25
|
+
|
26
|
+
//add version
|
27
|
+
$source = str_replace($version_pattern, $version, $header);
|
28
|
+
|
29
|
+
//print out all files
|
30
|
+
foreach($files as $k){
|
31
|
+
//remove ../
|
32
|
+
$cut = substr($k, 3);
|
33
|
+
|
34
|
+
$source .= "document.write(\"<script src='\"+path+\"".$cut."' language='javascript'><\/script>\");\n";
|
35
|
+
}
|
36
|
+
|
37
|
+
//add version
|
38
|
+
$source .= "\nwindow.onload = function(){ re.version = '".$version."'; }";
|
39
|
+
|
40
|
+
$final = $des_path .'/'.$debug_name;
|
41
|
+
|
42
|
+
|
43
|
+
//create file
|
44
|
+
file_put_contents($final, $source);
|
45
|
+
|
46
|
+
printf('Success! File created at %s', $final);
|
47
|
+
|
48
|
+
?>
|
data/build/files.php
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
<?php
|
2
|
+
/*
|
3
|
+
Used in php files min.php and local.php to find all files in the source directory.
|
4
|
+
|
5
|
+
Creates a $file variable.
|
6
|
+
*/
|
7
|
+
|
8
|
+
//finds all files in source path
|
9
|
+
function findFiles($dir) {
|
10
|
+
global $re_file, $ignore_reg;
|
11
|
+
|
12
|
+
if($dh = opendir($dir)) {
|
13
|
+
|
14
|
+
$files = array();
|
15
|
+
$inner_files = array();
|
16
|
+
|
17
|
+
while($file = readdir($dh)) {
|
18
|
+
|
19
|
+
if($file != "." && $file != ".." && $file[0] != '.') {
|
20
|
+
|
21
|
+
if(is_dir($dir . "/" . $file)) {
|
22
|
+
$inner_files = findFiles($dir . "/" . $file);
|
23
|
+
if(is_array($inner_files)) $files = array_merge($files, $inner_files);
|
24
|
+
|
25
|
+
} else if(strrpos($file, '.js')){
|
26
|
+
$f = $dir .'/' . $file;
|
27
|
+
|
28
|
+
if(!preg_match($ignore_reg, $f)){
|
29
|
+
|
30
|
+
//push to the beginning to prevent null re errors
|
31
|
+
if($file == $re_file){
|
32
|
+
array_unshift($files, $f);
|
33
|
+
} else {
|
34
|
+
array_push($files, $f);
|
35
|
+
}
|
36
|
+
|
37
|
+
printf("Found file: %s\n", $f);
|
38
|
+
} else {
|
39
|
+
|
40
|
+
printf("[Ignored] file: %s\n", $f);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
}
|
45
|
+
|
46
|
+
}
|
47
|
+
|
48
|
+
closedir($dh);
|
49
|
+
|
50
|
+
return $files;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
$files = findFiles($source_path);
|
55
|
+
|
56
|
+
//sort files in correct order
|
57
|
+
for($i=count($files)-1; $i>=0; $i--){
|
58
|
+
|
59
|
+
$t = $files[$i];
|
60
|
+
|
61
|
+
if(strpos($t, $retro_folder)){
|
62
|
+
//move to beginning
|
63
|
+
|
64
|
+
//remove
|
65
|
+
array_splice($files, $i);
|
66
|
+
|
67
|
+
//move to front
|
68
|
+
array_unshift($t);
|
69
|
+
}
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
?>
|
data/build/jsmin.php
ADDED
@@ -0,0 +1,376 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* jsmin.php - PHP implementation of Douglas Crockford's JSMin.
|
4
|
+
*
|
5
|
+
* This is pretty much a direct port of jsmin.c to PHP with just a few
|
6
|
+
* PHP-specific performance tweaks. Also, whereas jsmin.c reads from stdin and
|
7
|
+
* outputs to stdout, this library accepts a string as input and returns another
|
8
|
+
* string as output.
|
9
|
+
*
|
10
|
+
* PHP 5 or higher is required.
|
11
|
+
*
|
12
|
+
* Permission is hereby granted to use this version of the library under the
|
13
|
+
* same terms as jsmin.c, which has the following license:
|
14
|
+
*
|
15
|
+
* --
|
16
|
+
* Copyright (c) 2002 Douglas Crockford (www.crockford.com)
|
17
|
+
*
|
18
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
19
|
+
* this software and associated documentation files (the "Software"), to deal in
|
20
|
+
* the Software without restriction, including without limitation the rights to
|
21
|
+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
22
|
+
* of the Software, and to permit persons to whom the Software is furnished to do
|
23
|
+
* so, subject to the following conditions:
|
24
|
+
*
|
25
|
+
* The above copyright notice and this permission notice shall be included in all
|
26
|
+
* copies or substantial portions of the Software.
|
27
|
+
*
|
28
|
+
* The Software shall be used for Good, not Evil.
|
29
|
+
*
|
30
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
31
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
32
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
33
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
34
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
35
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
36
|
+
* SOFTWARE.
|
37
|
+
* --
|
38
|
+
*
|
39
|
+
* @package JSMin
|
40
|
+
* @author Ryan Grove <ryan@wonko.com>
|
41
|
+
* @copyright 2002 Douglas Crockford <douglas@crockford.com> (jsmin.c)
|
42
|
+
* @copyright 2008 Ryan Grove <ryan@wonko.com> (PHP port)
|
43
|
+
* @license http://opensource.org/licenses/mit-license.php MIT License
|
44
|
+
* @version 1.1.1 (2008-03-02)
|
45
|
+
* @link https://github.com/rgrove/jsmin-php/
|
46
|
+
*/
|
47
|
+
|
48
|
+
class JSMin {
|
49
|
+
const ORD_LF = 10;
|
50
|
+
const ORD_SPACE = 32;
|
51
|
+
const ACTION_KEEP_A = 1;
|
52
|
+
const ACTION_DELETE_A = 2;
|
53
|
+
const ACTION_DELETE_A_B = 3;
|
54
|
+
|
55
|
+
protected $a = '';
|
56
|
+
protected $b = '';
|
57
|
+
protected $input = '';
|
58
|
+
protected $inputIndex = 0;
|
59
|
+
protected $inputLength = 0;
|
60
|
+
protected $lookAhead = null;
|
61
|
+
protected $output = '';
|
62
|
+
|
63
|
+
// -- Public Static Methods --------------------------------------------------
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Minify Javascript
|
67
|
+
*
|
68
|
+
* @uses __construct()
|
69
|
+
* @uses min()
|
70
|
+
* @param string $js Javascript to be minified
|
71
|
+
* @return string
|
72
|
+
*/
|
73
|
+
public static function minify($js) {
|
74
|
+
$jsmin = new JSMin($js);
|
75
|
+
return $jsmin->min();
|
76
|
+
}
|
77
|
+
|
78
|
+
// -- Public Instance Methods ------------------------------------------------
|
79
|
+
|
80
|
+
/**
|
81
|
+
* Constructor
|
82
|
+
*
|
83
|
+
* @param string $input Javascript to be minified
|
84
|
+
*/
|
85
|
+
public function __construct($input) {
|
86
|
+
$this->input = str_replace("\r\n", "\n", $input);
|
87
|
+
$this->inputLength = strlen($this->input);
|
88
|
+
}
|
89
|
+
|
90
|
+
// -- Protected Instance Methods ---------------------------------------------
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Action -- do something! What to do is determined by the $command argument.
|
94
|
+
*
|
95
|
+
* action treats a string as a single character. Wow!
|
96
|
+
* action recognizes a regular expression if it is preceded by ( or , or =.
|
97
|
+
*
|
98
|
+
* @uses next()
|
99
|
+
* @uses get()
|
100
|
+
* @throws JSMinException If parser errors are found:
|
101
|
+
* - Unterminated string literal
|
102
|
+
* - Unterminated regular expression set in regex literal
|
103
|
+
* - Unterminated regular expression literal
|
104
|
+
* @param int $command One of class constants:
|
105
|
+
* ACTION_KEEP_A Output A. Copy B to A. Get the next B.
|
106
|
+
* ACTION_DELETE_A Copy B to A. Get the next B. (Delete A).
|
107
|
+
* ACTION_DELETE_A_B Get the next B. (Delete B).
|
108
|
+
*/
|
109
|
+
protected function action($command) {
|
110
|
+
switch($command) {
|
111
|
+
case self::ACTION_KEEP_A:
|
112
|
+
$this->output .= $this->a;
|
113
|
+
|
114
|
+
case self::ACTION_DELETE_A:
|
115
|
+
$this->a = $this->b;
|
116
|
+
|
117
|
+
if ($this->a === "'" || $this->a === '"') {
|
118
|
+
for (;;) {
|
119
|
+
$this->output .= $this->a;
|
120
|
+
$this->a = $this->get();
|
121
|
+
|
122
|
+
if ($this->a === $this->b) {
|
123
|
+
break;
|
124
|
+
}
|
125
|
+
|
126
|
+
if (ord($this->a) <= self::ORD_LF) {
|
127
|
+
throw new JSMinException('Unterminated string literal.');
|
128
|
+
}
|
129
|
+
|
130
|
+
if ($this->a === '\\') {
|
131
|
+
$this->output .= $this->a;
|
132
|
+
$this->a = $this->get();
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
case self::ACTION_DELETE_A_B:
|
138
|
+
$this->b = $this->next();
|
139
|
+
|
140
|
+
if ($this->b === '/' && (
|
141
|
+
$this->a === '(' || $this->a === ',' || $this->a === '=' ||
|
142
|
+
$this->a === ':' || $this->a === '[' || $this->a === '!' ||
|
143
|
+
$this->a === '&' || $this->a === '|' || $this->a === '?' ||
|
144
|
+
$this->a === '{' || $this->a === '}' || $this->a === ';' ||
|
145
|
+
$this->a === "\n" )) {
|
146
|
+
|
147
|
+
$this->output .= $this->a . $this->b;
|
148
|
+
|
149
|
+
for (;;) {
|
150
|
+
$this->a = $this->get();
|
151
|
+
|
152
|
+
if ($this->a === '[') {
|
153
|
+
/*
|
154
|
+
inside a regex [...] set, which MAY contain a '/' itself. Example: mootools Form.Validator near line 460:
|
155
|
+
return Form.Validator.getValidator('IsEmpty').test(element) || (/^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]\.?){0,63}[a-z0-9!#$%&'*+/=?^_`{|}~-]@(?:(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\])$/i).test(element.get('value'));
|
156
|
+
*/
|
157
|
+
for (;;) {
|
158
|
+
$this->output .= $this->a;
|
159
|
+
$this->a = $this->get();
|
160
|
+
|
161
|
+
if ($this->a === ']') {
|
162
|
+
break;
|
163
|
+
} elseif ($this->a === '\\') {
|
164
|
+
$this->output .= $this->a;
|
165
|
+
$this->a = $this->get();
|
166
|
+
} elseif (ord($this->a) <= self::ORD_LF) {
|
167
|
+
throw new JSMinException('Unterminated regular expression set in regex literal.');
|
168
|
+
}
|
169
|
+
}
|
170
|
+
} elseif ($this->a === '/') {
|
171
|
+
break;
|
172
|
+
} elseif ($this->a === '\\') {
|
173
|
+
$this->output .= $this->a;
|
174
|
+
$this->a = $this->get();
|
175
|
+
} elseif (ord($this->a) <= self::ORD_LF) {
|
176
|
+
throw new JSMinException('Unterminated regular expression literal.');
|
177
|
+
}
|
178
|
+
|
179
|
+
$this->output .= $this->a;
|
180
|
+
}
|
181
|
+
|
182
|
+
$this->b = $this->next();
|
183
|
+
}
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
/**
|
188
|
+
* Get next char. Convert ctrl char to space.
|
189
|
+
*
|
190
|
+
* @return string|null
|
191
|
+
*/
|
192
|
+
protected function get() {
|
193
|
+
$c = $this->lookAhead;
|
194
|
+
$this->lookAhead = null;
|
195
|
+
|
196
|
+
if ($c === null) {
|
197
|
+
if ($this->inputIndex < $this->inputLength) {
|
198
|
+
$c = substr($this->input, $this->inputIndex, 1);
|
199
|
+
$this->inputIndex += 1;
|
200
|
+
} else {
|
201
|
+
$c = null;
|
202
|
+
}
|
203
|
+
}
|
204
|
+
|
205
|
+
if ($c === "\r") {
|
206
|
+
return "\n";
|
207
|
+
}
|
208
|
+
|
209
|
+
if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) {
|
210
|
+
return $c;
|
211
|
+
}
|
212
|
+
|
213
|
+
return ' ';
|
214
|
+
}
|
215
|
+
|
216
|
+
/**
|
217
|
+
* Is $c a letter, digit, underscore, dollar sign, or non-ASCII character.
|
218
|
+
*
|
219
|
+
* @return bool
|
220
|
+
*/
|
221
|
+
protected function isAlphaNum($c) {
|
222
|
+
return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1;
|
223
|
+
}
|
224
|
+
|
225
|
+
/**
|
226
|
+
* Perform minification, return result
|
227
|
+
*
|
228
|
+
* @uses action()
|
229
|
+
* @uses isAlphaNum()
|
230
|
+
* @return string
|
231
|
+
*/
|
232
|
+
protected function min() {
|
233
|
+
$this->a = "\n";
|
234
|
+
$this->action(self::ACTION_DELETE_A_B);
|
235
|
+
|
236
|
+
while ($this->a !== null) {
|
237
|
+
switch ($this->a) {
|
238
|
+
case ' ':
|
239
|
+
if ($this->isAlphaNum($this->b)) {
|
240
|
+
$this->action(self::ACTION_KEEP_A);
|
241
|
+
} else {
|
242
|
+
$this->action(self::ACTION_DELETE_A);
|
243
|
+
}
|
244
|
+
break;
|
245
|
+
|
246
|
+
case "\n":
|
247
|
+
switch ($this->b) {
|
248
|
+
case '{':
|
249
|
+
case '[':
|
250
|
+
case '(':
|
251
|
+
case '+':
|
252
|
+
case '-':
|
253
|
+
$this->action(self::ACTION_KEEP_A);
|
254
|
+
break;
|
255
|
+
|
256
|
+
case ' ':
|
257
|
+
$this->action(self::ACTION_DELETE_A_B);
|
258
|
+
break;
|
259
|
+
|
260
|
+
default:
|
261
|
+
if ($this->isAlphaNum($this->b)) {
|
262
|
+
$this->action(self::ACTION_KEEP_A);
|
263
|
+
}
|
264
|
+
else {
|
265
|
+
$this->action(self::ACTION_DELETE_A);
|
266
|
+
}
|
267
|
+
}
|
268
|
+
break;
|
269
|
+
|
270
|
+
default:
|
271
|
+
switch ($this->b) {
|
272
|
+
case ' ':
|
273
|
+
if ($this->isAlphaNum($this->a)) {
|
274
|
+
$this->action(self::ACTION_KEEP_A);
|
275
|
+
break;
|
276
|
+
}
|
277
|
+
|
278
|
+
$this->action(self::ACTION_DELETE_A_B);
|
279
|
+
break;
|
280
|
+
|
281
|
+
case "\n":
|
282
|
+
switch ($this->a) {
|
283
|
+
case '}':
|
284
|
+
case ']':
|
285
|
+
case ')':
|
286
|
+
case '+':
|
287
|
+
case '-':
|
288
|
+
case '"':
|
289
|
+
case "'":
|
290
|
+
$this->action(self::ACTION_KEEP_A);
|
291
|
+
break;
|
292
|
+
|
293
|
+
default:
|
294
|
+
if ($this->isAlphaNum($this->a)) {
|
295
|
+
$this->action(self::ACTION_KEEP_A);
|
296
|
+
}
|
297
|
+
else {
|
298
|
+
$this->action(self::ACTION_DELETE_A_B);
|
299
|
+
}
|
300
|
+
}
|
301
|
+
break;
|
302
|
+
|
303
|
+
default:
|
304
|
+
$this->action(self::ACTION_KEEP_A);
|
305
|
+
break;
|
306
|
+
}
|
307
|
+
}
|
308
|
+
}
|
309
|
+
|
310
|
+
return $this->output;
|
311
|
+
}
|
312
|
+
|
313
|
+
/**
|
314
|
+
* Get the next character, skipping over comments. peek() is used to see
|
315
|
+
* if a '/' is followed by a '/' or '*'.
|
316
|
+
*
|
317
|
+
* @uses get()
|
318
|
+
* @uses peek()
|
319
|
+
* @throws JSMinException On unterminated comment.
|
320
|
+
* @return string
|
321
|
+
*/
|
322
|
+
protected function next() {
|
323
|
+
$c = $this->get();
|
324
|
+
|
325
|
+
if ($c === '/') {
|
326
|
+
switch($this->peek()) {
|
327
|
+
case '/':
|
328
|
+
for (;;) {
|
329
|
+
$c = $this->get();
|
330
|
+
|
331
|
+
if (ord($c) <= self::ORD_LF) {
|
332
|
+
return $c;
|
333
|
+
}
|
334
|
+
}
|
335
|
+
|
336
|
+
case '*':
|
337
|
+
$this->get();
|
338
|
+
|
339
|
+
for (;;) {
|
340
|
+
switch($this->get()) {
|
341
|
+
case '*':
|
342
|
+
if ($this->peek() === '/') {
|
343
|
+
$this->get();
|
344
|
+
return ' ';
|
345
|
+
}
|
346
|
+
break;
|
347
|
+
|
348
|
+
case null:
|
349
|
+
throw new JSMinException('Unterminated comment.');
|
350
|
+
}
|
351
|
+
}
|
352
|
+
|
353
|
+
default:
|
354
|
+
return $c;
|
355
|
+
}
|
356
|
+
}
|
357
|
+
|
358
|
+
return $c;
|
359
|
+
}
|
360
|
+
|
361
|
+
/**
|
362
|
+
* Get next char. If is ctrl character, translate to a space or newline.
|
363
|
+
*
|
364
|
+
* @uses get()
|
365
|
+
* @return string|null
|
366
|
+
*/
|
367
|
+
protected function peek() {
|
368
|
+
$this->lookAhead = $this->get();
|
369
|
+
return $this->lookAhead;
|
370
|
+
}
|
371
|
+
}
|
372
|
+
|
373
|
+
// -- Exceptions ---------------------------------------------------------------
|
374
|
+
class JSMinException extends Exception {}
|
375
|
+
|
376
|
+
?>
|
data/build/min.php
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
<?php
|
2
|
+
/*
|
3
|
+
Retrojs minifier
|
4
|
+
Version 0.1
|
5
|
+
|
6
|
+
This will minify all javascript files in the source path.
|
7
|
+
|
8
|
+
The default source path is entityjs/src/
|
9
|
+
|
10
|
+
When releasing a new version of your game. You could put it inside the source folder (entityjs/src)
|
11
|
+
and it will be compiled into one javascript file for you.
|
12
|
+
|
13
|
+
@warning This will minify ALL files in source path directories and sub-directories even
|
14
|
+
if its not a javascript file!
|
15
|
+
|
16
|
+
@usage
|
17
|
+
Go into the command prompt
|
18
|
+
Nagivate to min.php
|
19
|
+
type "php min.php"
|
20
|
+
or put all files into your server and navigate to the min.php file.
|
21
|
+
*/
|
22
|
+
|
23
|
+
require 'config.php';
|
24
|
+
|
25
|
+
require 'jsmin.php';
|
26
|
+
|
27
|
+
require 'files.php';
|
28
|
+
|
29
|
+
//add all files
|
30
|
+
foreach($files as $k){
|
31
|
+
$source .= file_get_contents($k);
|
32
|
+
}
|
33
|
+
|
34
|
+
//compile
|
35
|
+
$js=JSMin::minify($source);
|
36
|
+
|
37
|
+
//add license
|
38
|
+
$js = file_get_contents($license) . $js;
|
39
|
+
|
40
|
+
//add version
|
41
|
+
$js = str_replace($version_pattern, $version, $js);
|
42
|
+
|
43
|
+
//paste into file
|
44
|
+
$full_des = $des_path.'/'.$min_name;
|
45
|
+
|
46
|
+
file_put_contents($full_des, $js);
|
47
|
+
|
48
|
+
printf('Success! Minified file at %s',$full_des);
|
49
|
+
|
50
|
+
?>
|