Reorg of packages.
authordsc <david.schoonover@gmail.com>
Wed, 10 Nov 2010 06:22:01 +0000 (22:22 -0800)
committerdsc <david.schoonover@gmail.com>
Wed, 10 Nov 2010 06:22:01 +0000 (22:22 -0800)
32 files changed:
index.php
src/Y/type.js
src/Y/y-core.js
src/portal/loop/cooldown.js [moved from src/portal/util/cooldown.js with 100% similarity]
src/portal/loop/eventloop.js [moved from src/portal/util/eventloop.js with 100% similarity]
src/portal/loop/fps.js [moved from src/portal/util/fps.js with 100% similarity]
src/portal/math/vec.js
src/portal/path.js [deleted file]
src/portal/portal.js [deleted file]
src/portal/shape.js [deleted file]
src/portal/shape/circle.js [new file with mode: 0644]
src/portal/shape/line.js [new file with mode: 0644]
src/portal/shape/polygon.js [new file with mode: 0644]
src/portal/shape/rect.js [new file with mode: 0644]
src/portal/shape/shape.js [new file with mode: 0644]
src/portal/transform.js [deleted file]
src/portal/util/tree/pointquadtree.js [moved from src/portal/util/pointquadtree.js with 100% similarity]
src/portal/util/tree/quadtree.js [moved from src/portal/util/quadtree.js with 100% similarity]
src/portal/util/tree/rbtree.js [moved from src/portal/util/rbtree.js with 100% similarity]
src/tanks/calc.js [moved from src/tanks/util/calc.js with 100% similarity]
src/tanks/game/map.game.js [moved from src/tanks/game/map.js with 100% similarity]
src/tanks/lttl.js [deleted file]
src/tanks/main.js [new file with mode: 0644]
src/tanks/map/level.js [moved from src/tanks/game/level.js with 100% similarity]
src/tanks/map/loc.js [moved from src/portal/util/loc.js with 95% similarity]
src/tanks/map/pathmap.js [moved from src/tanks/util/pathmap.js with 100% similarity]
src/tanks/ui.js [deleted file]
src/tanks/ui.main.js [new file with mode: 0644]
src/tanks/ui/grid.js [moved from src/tanks/util/grid.js with 100% similarity]
src/tanks/ui/player.js [moved from src/tanks/game/player.js with 100% similarity]
tanks.php [new file with mode: 0644]
test/math/index.php

index 330dc95..8b6593d 100644 (file)
--- a/index.php
+++ b/index.php
 
 <div id="scripts">
     <!--[if IE]><script type="text/javascript" src="lib/excanvas.min.js"></script><![endif]-->
-<?php
-$scripts = array(
-    "lib/jquery-1.4.3.js",
-    "lib/jquery.sparkline.min.js",
-    "lib/jquery.hotkeys.js",
-    
-    // "http://static.ukijs.org/pkg/0.3.8/uki.js",
-    // "http://static.ukijs.org/pkg/0.3.8/uki-more.js",
-    
-    "src/lessly/future.js",
-    
-    "src/Y/y.js.php",
-    "src/Y/modules/y.event.js",
-    
-    "src/evt/evt.class.js",
-    
-    "src/portal/layer.js",
-    "src/portal/shape.js",
-    
-    "src/portal/math/math.js",
-    "src/portal/math/vec.js",
-    "src/portal/math/line.js",
-    
-    "src/portal/util/loc.js",
-    "src/portal/util/quadtree.js",
-    "src/portal/util/rbtree.js",
-    
-    "src/portal/util/eventloop.js",
-    "src/portal/util/fps.js",
-    "src/portal/util/cooldown.js",
-    
-    "src/tanks/globals.js",
-    "src/tanks/util/calc.js",
-    "src/tanks/util/grid.js",
-    "src/tanks/util/pathmap.js",
-    
-    "src/tanks/game/level.js",
-    "src/tanks/game/game.js",
-    "src/tanks/game/map.js",
-    
-    "src/tanks/thing/thing.js",
-    "src/tanks/thing/bullet.js",
-    "src/tanks/thing/tank.js",
-    "src/tanks/game/player.js",
-    
-    "src/tanks/lttl.js",
-    "src/tanks/ui.js"
-    
-);
-
-function js($src) {
-    echo "    <script src=\"$src\" type=\"text/javascript\"></script>\n";
-}
-
-foreach ($scripts as $s) js($s);
-?>
+<?php require "tanks.php"; Tanks::writeTags( Tanks::ALL_SCRIPTS ); ?>
 </div>
 
 </body>
index c23970c..11d7360 100644 (file)
@@ -15,16 +15,9 @@ function type_of(obj){
 }
 
 function isFunction(obj) { return type_of(obj) === "function"; }
-
 function isString(obj)   { return type_of(obj) === "string"; }
-
 function isNumber(obj)   { return type_of(obj) === "number"; }
-
-
-// A crude way of determining if an object is a window
-function isWindow( obj ) {
-       return obj && typeof obj === "object" && "setInterval" in obj;
-}
+function isWindow( obj ) { return obj && typeof obj === "object" && "setInterval" in obj; }
 
 function isPlainObject( obj ){
     // Must be an Object.
@@ -42,7 +35,6 @@ function isPlainObject( obj ){
     
     // Own properties are enumerated firstly, so to speed up,
     // if last one is own, then all properties are own.
-    
     var key;
     for ( key in obj ) {}
     
index dced427..ec51cba 100644 (file)
@@ -4,9 +4,10 @@ Y.set    = dset;
 Y.attr   = dattr;
 Y.extend = extend;
 
-Y.isFunction = isFunction;
-Y.isString = isString;
-Y.isNumber = isNumber;
+Y.isString      = isString;
+Y.isNumber      = isNumber;
+Y.isFunction    = isFunction;
+Y.isArray       = isArray;
 Y.isPlainObject = isPlainObject;
 
 
index 7ac8e02..76421f6 100644 (file)
@@ -4,14 +4,12 @@
 math.Vec = new Y.Class('Vec', [], {
     
     init : function init(x, y){
-        if ( Array.isArray(x) ) {
-            y = x[1];
-            x = x[0];
-        }
-        
         this.length = 2;
-        this.x = this[0] = x;
-        this.y = this[1] = y;
+        
+        if ( x instanceof Array ) {
+            y = x[1]; x = x[0];
+        }
+        this.setXY(x,y);
     },
     
     equals : function equals(b){
@@ -22,32 +20,30 @@ math.Vec = new Y.Class('Vec', [], {
         return new math.Vec(this.x, this.y);
     },
     
-    scale : function scale(s){
-        this.x *= s;
-        this.y *= s;
+    setXY : function setXY(x,y){
+        this.x = this[0] = x;
+        this.y = this[1] = y;
         return this;
     },
     
-    invert : function invert(){
-        this.x = -this.x;
-        this.y = -this.y;
-        return this;
+    add : function add(b){
+        return this.setXY(this.x+b.x, this.y+b.y);
     },
     
-    normalize : function normalize(){
-        return this.scale(1 / this.magnitude());
+    subtract : function subtract(b){
+        return this.setXY(this.x-b.x, this.y-b.y);
     },
     
-    add : function add(b){
-        this.x += b.x;
-        this.y += b.y;
-        return this;
+    scale : function scale(s){
+        return this.setXY(this.x*s, this.y*s);
     },
     
-    subtract : function subtract(b){
-        this.x -= b.x;
-        this.y -= b.y;
-        return this;
+    invert : function invert(){
+        return this.setXY(-this.x, -this.y);
+    },
+    
+    normalize : function normalize(){
+        return this.scale(1 / this.magnitude());
     },
     
     magnitude : function magnitude(){
diff --git a/src/portal/path.js b/src/portal/path.js
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/src/portal/portal.js b/src/portal/portal.js
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/src/portal/shape.js b/src/portal/shape.js
deleted file mode 100644 (file)
index 50d3895..0000000
+++ /dev/null
@@ -1,252 +0,0 @@
-Shape = new Y.Class('Shape', Layer, {
-    _cssClasses : 'portal layer shape',
-    fillStyle   : 'rgba(231,48,117, 1)',
-    strokeStyle : 'transparent',
-    lineWidth   : 0,
-    
-    _calcDimension : function _calcDimension(which, values){
-        values.unshift(0);
-        var self = this
-        ,   neg = -1 * Math.min.apply(Math, values)
-        // ,   pos = Math.min(0, Math.max.apply(Max, values) - max)
-        ;
-        
-        self.negBleed.attr(which, neg);
-        // self.posBleed.attr(which, pos);
-        
-        return values.map(function(v, i){
-                return (self[which+i] = v);
-            });
-    }
-    
-});
-
-
-Line = new Y.Class('Line', Shape, {
-    _cssClasses : 'portal layer shape line',
-    
-    useCanvasScaling : true,
-    fillStyle   : 'transparent',
-    strokeStyle : "#000000",
-    lineWidth   : 1,
-    
-    drawDefinitionPoints : false,
-    invertY : false,
-    
-    
-    init : function initLine(x,y){
-        Layer.init.call(this);
-        
-        this.sublayer = jQuery('<div style="overflow:hidden" />')
-            .append(this.canvas)
-            .appendTo(this.layer);
-        
-        this.x2 = x; this.y2 = y;
-        this.position(0,0);
-    },
-    
-    position : function position(left, top){
-        if (top === undefined && left === undefined)
-            return this.line.p1;
-        
-        var pos = Y.isPlainObject(top) ? top : {'top':top, 'left':left};
-        
-        this.x1 = pos.left; this.x2 += this.x1;
-        this.y1 = pos.top;  this.y2 += this.y1;
-        
-        this.line = new math.Line(this.x1,this.y1, this.x2,this.y2, (this.line||{}).tdist);
-        
-        return this;
-    },
-    
-    origin : function origin(x,y){
-        var o = this.transform.origin;
-        if (arguments.length === 0)
-            return o.absolute(this.layerWidth, this.layerHeight);
-        
-        o.x = x;
-        o.y = y;
-        this.ctx.translate(x,y);
-        this.dirty = true;
-        return this._applyTransforms();
-    },
-    
-    appendTo : function appendTo(parent){
-        var r = Layer.prototype.appendTo.call(this, parent);
-        this._fixSize();
-        return r;
-    },
-    
-    _fixSize : function _fixSize(){
-        var p  = this.parent
-        ,   pw = p.canvasWidth,    ph = p.canvasHeight
-        ,   w  = this.canvasWidth, h  = this.canvasHeight
-        ;
-        
-        if (w !== pw) {
-            this.width(pw);
-            this.sublayer.width(pw);
-        }
-        if (h !== ph) {
-            this.height(ph);
-            this.sublayer.height(ph);
-        }
-        return this;
-    },
-    
-    drawShape : function drawShape(ctx){
-        this._fixSize();
-        var x1,y1, x2,y2, t = this.transform.translate
-        ,   line = this.line, p1 = line.p1, p2 = line.p2
-        ,   minW = -t.x, minH = -t.y
-        ,   maxW = this.canvasWidth+minW, maxH = this.canvasHeight+minH
-        ;
-        
-        x1 = minW; y1 = line.calcY(x1);
-        if (isNaN(y1) || !isFinite(y1)) {
-            y1 = minH; x1 = line.calcX(y1);
-        }
-        
-        x2 = maxW; y2 = line.calcY(x2);
-        if (isNaN(y2) || !isFinite(y2)) {
-            y2 = maxH; x2 = line.calcX(y2);
-        }
-        
-        if (this.invertY){
-            y1 = -y1;
-            y2 = -y2;
-        }
-        
-        try {
-            ctx.moveTo(x1,y1);
-            ctx.lineTo(x2,y2);
-            ctx.stroke();
-            ctx.closePath();
-        } catch(e) {
-            console.error(this+'.drawShape()');
-            console.log('  points:', x1,y1, ' ', x2,y2);
-            console.log('  bounds:', minW,minH, ' ', maxW,maxH);
-            console.log('  ::', this, line);
-        }
-        
-        // Show definition points
-        if ( this.drawDefinitionPoints ) {
-            this.point(p1.x,p1.y, 'rgba(69,150,255,0.4)');
-            this.point(p2.x,p2.y, 'rgba(69,150,255,0.4)');
-        }
-    },
-    
-    
-    toString : function toString(){
-        return this.className+'['+this.x1+','+this.y1+', '+this.x2+','+this.y2+']';
-    }
-    
-    
-});
-Line.fromPoints = function fromPoints(x1,y1, x2,y2){
-    return new Line(x2-x1, y2-y1).position(x1,y1);
-};
-
-
-
-Rect = new Y.Class('Rect', Shape, {
-    _cssClasses : 'portal layer shape rect',
-    
-    init : function initRect(w, h){
-        Layer.init.call(this);
-        
-        this.width(w)
-            .height(h);
-            // .origin(w/2, h/2);
-    },
-    
-    drawShape : function drawShape(ctx){
-        ctx.rect(0,0, this.canvasWidth,this.canvasHeight);
-        ctx.fill();
-    }
-    
-});
-
-Circle = new Y.Class('Circle', Shape, {
-    _cssClasses : 'portal layer shape circle',
-    
-    init : function initCircle(radius){
-        Layer.init.call(this);
-        
-        var d = radius * 2;
-        this.radius = this.negBleed.x = this.negBleed.y = radius;
-        this.width(d).height(d);
-            // .origin(radius,radius);
-    },
-    
-    drawShape : function drawShape(ctx){
-        var r  = this.radius;
-        ctx.arc(0,0, r, 0, Math.PI*2, false);
-        ctx.fill();
-        ctx.stroke();
-    }
-    
-});
-
-Polygon = new Y.Class('Polygon', Shape, {
-    _cssClasses : 'portal layer shape polygon',
-    
-    /**
-     * Expects two arrays of coordinate-halfs, which could be zipped
-     * together to make the numbered coordinates.
-     * x0 and y0 will always be 0.
-     */
-    init : function initPolygon(xs, ys){
-        Layer.init.call(this);
-        
-        var xs = this._calcDimension('x', xs)
-        ,   ys = this._calcDimension('y', ys)
-        ,   w  = Math.max.apply(Math, xs)
-        ,   h  = Math.max.apply(Math, ys)
-        ;
-        
-        this.points = Y(xs).zip(ys).map(Loc.instantiate, Loc);
-        this.width(w)
-            .height(h);
-            // .origin(w/2, h/2);
-    },
-    
-    drawShape : function drawShape(ctx){
-        this.points.forEach(function(loc, i){
-            ctx.lineTo(loc.x, loc.y);
-        });
-        ctx.fill();
-    }
-});
-
-
-Triangle = new Y.Class('Triangle', Polygon, {
-    _cssClasses : 'portal layer shape polygon triangle',
-    
-    init : function initTriangle(x1,y1, x2,y2){
-        Polygon.init.call(this, [x1,x2], [y1,y2]);
-    },
-    
-    circumcenter : function circumcenter(){
-        var offX = this.offsetX, offY = this.offsetY
-        ,   x1 = this.x1 - offX, y1 = -1 * (this.y1 - offY) // remember, DOM is Y-inverted
-        ,   x2 = this.x2 - offX, y2 = -1 * (this.y2 - offY) // which affects the signs
-        
-        ,   D = 2 * (x1*y2 - y1*x2)
-        ,   B = Math.pow(x1,2) + Math.pow(y1,2)
-        ,   C = Math.pow(x2,2) + Math.pow(y2,2)
-        ;
-        return { 'x' : offX + (y2*B - y1*C)/D
-               , 'y' : offY + (x1*C - x2*B)/D * -1 // fix inverted Y-axis
-               };
-    },
-});
-
-Quad = new Y.Class('Quad', Polygon, {
-    _cssClasses : 'portal layer shape polygon quad',
-    
-    init : function initQuad(x1,y1, x2,y2, x3,y3){
-        Polygon.init.call(this, [x1,x2,x3], [y1,y2,y3]);
-    }
-    
-});
diff --git a/src/portal/shape/circle.js b/src/portal/shape/circle.js
new file mode 100644 (file)
index 0000000..10e824f
--- /dev/null
@@ -0,0 +1,21 @@
+
+Circle = new Y.Class('Circle', Shape, {
+    _cssClasses : 'portal layer shape circle',
+    
+    init : function initCircle(radius){
+        Layer.init.call(this);
+        
+        var d = radius * 2;
+        this.radius = this.negBleed.x = this.negBleed.y = radius;
+        this.width(d).height(d);
+            // .origin(radius,radius);
+    },
+    
+    drawShape : function drawShape(ctx){
+        var r  = this.radius;
+        ctx.arc(0,0, r, 0, Math.PI*2, false);
+        ctx.fill();
+        ctx.stroke();
+    }
+    
+});
diff --git a/src/portal/shape/line.js b/src/portal/shape/line.js
new file mode 100644 (file)
index 0000000..fe9ddcd
--- /dev/null
@@ -0,0 +1,130 @@
+
+Line = new Y.Class('Line', Shape, {
+    _cssClasses : 'portal layer shape line',
+    
+    useCanvasScaling : true,
+    fillStyle   : 'transparent',
+    strokeStyle : "#000000",
+    lineWidth   : 1,
+    
+    drawDefinitionPoints : false,
+    invertY : false,
+    
+    
+    init : function initLine(x,y){
+        Layer.init.call(this);
+        
+        this.sublayer = jQuery('<div style="overflow:hidden" />')
+            .append(this.canvas)
+            .appendTo(this.layer);
+        
+        this.x2 = x; this.y2 = y;
+        this.position(0,0);
+    },
+    
+    position : function position(left, top){
+        if (top === undefined && left === undefined)
+            return this.line.p1;
+        
+        var pos = Y.isPlainObject(top) ? top : {'top':top, 'left':left};
+        
+        this.x1 = pos.left; this.x2 += this.x1;
+        this.y1 = pos.top;  this.y2 += this.y1;
+        
+        this.line = new math.Line(this.x1,this.y1, this.x2,this.y2, (this.line||{}).tdist);
+        
+        return this;
+    },
+    
+    origin : function origin(x,y){
+        var o = this.transform.origin;
+        if (arguments.length === 0)
+            return o.absolute(this.layerWidth, this.layerHeight);
+        
+        o.x = x;
+        o.y = y;
+        this.ctx.translate(x,y);
+        this.dirty = true;
+        return this._applyTransforms();
+    },
+    
+    appendTo : function appendTo(parent){
+        var r = Layer.prototype.appendTo.call(this, parent);
+        this._fixSize();
+        return r;
+    },
+    
+    _fixSize : function _fixSize(){
+        var p  = this.parent
+        ,   pw = p.canvasWidth,    ph = p.canvasHeight
+        ,   w  = this.canvasWidth, h  = this.canvasHeight
+        ;
+        
+        if (w !== pw) {
+            this.width(pw);
+            this.sublayer.width(pw);
+        }
+        if (h !== ph) {
+            this.height(ph);
+            this.sublayer.height(ph);
+        }
+        return this;
+    },
+    
+    drawShape : function drawShape(ctx){
+        this._fixSize();
+        var x1,y1, x2,y2
+        ,   line = this.line, p1 = line.p1, p2 = line.p2
+        ,   t = this.transform.translate
+        ,   minW = -t.x, minH = -t.y
+        ,   maxW = this.canvasWidth+minW, maxH = this.canvasHeight+minH
+        ;
+        
+        // We need endpoints at the edges of the viewport to draw the full line.
+        x1 = minW; y1 = line.calcY(x1);
+        if (isNaN(y1) || !isFinite(y1)) {
+            y1 = minH; x1 = line.calcX(y1);
+        }
+        
+        x2 = maxW; y2 = line.calcY(x2);
+        if (isNaN(y2) || !isFinite(y2)) {
+            y2 = maxH; x2 = line.calcX(y2);
+        }
+        
+        if (this.invertY){
+            y1 = -y1;
+            y2 = -y2;
+        }
+        
+        try {
+            ctx.moveTo(x1,y1);
+            ctx.lineTo(x2,y2);
+            ctx.stroke();
+            ctx.closePath();
+        } catch(e) {
+            if (window.console) {
+                console.error(this+'.drawShape()');
+                console.log('  points:', x1,y1, ' ', x2,y2);
+                console.log('  bounds:', minW,minH, ' ', maxW,maxH);
+                console.log('  ::', this, line);
+            }
+        }
+        
+        // Show definition points
+        if ( this.drawDefinitionPoints ) {
+            this.point(p1.x,p1.y, 'rgba(69,150,255,0.4)');
+            this.point(p2.x,p2.y, 'rgba(69,150,255,0.4)');
+        }
+    },
+    
+    
+    toString : function toString(){
+        return this.className+'['+this.x1+','+this.y1+', '+this.x2+','+this.y2+']';
+    }
+    
+    
+});
+Line.fromPoints = function fromPoints(x1,y1, x2,y2){
+    return new Line(x2-x1, y2-y1).position(x1,y1);
+};
+
diff --git a/src/portal/shape/polygon.js b/src/portal/shape/polygon.js
new file mode 100644 (file)
index 0000000..a2cf377
--- /dev/null
@@ -0,0 +1,63 @@
+
+Polygon = new Y.Class('Polygon', Shape, {
+    _cssClasses : 'portal layer shape polygon',
+    
+    /**
+     * Expects two arrays of coordinate-halfs, which could be zipped
+     * together to make the numbered coordinates.
+     * x0 and y0 will always be 0.
+     */
+    init : function initPolygon(xs, ys){
+        Layer.init.call(this);
+        
+        var xs = this._calcDimension('x', xs)
+        ,   ys = this._calcDimension('y', ys)
+        ,   w  = Math.max.apply(Math, xs)
+        ,   h  = Math.max.apply(Math, ys)
+        ;
+        
+        this.points = Y(xs).zip(ys).map(Loc.instantiate, Loc);
+        this.width(w)
+            .height(h);
+            // .origin(w/2, h/2);
+    },
+    
+    drawShape : function drawShape(ctx){
+        this.points.forEach(function(loc, i){
+            ctx.lineTo(loc.x, loc.y);
+        });
+        ctx.fill();
+    }
+});
+
+
+Triangle = new Y.Class('Triangle', Polygon, {
+    _cssClasses : 'portal layer shape polygon triangle',
+    
+    init : function initTriangle(x1,y1, x2,y2){
+        Polygon.init.call(this, [x1,x2], [y1,y2]);
+    },
+    
+    circumcenter : function circumcenter(){
+        var offX = this.offsetX, offY = this.offsetY
+        ,   x1 = this.x1 - offX, y1 = -1 * (this.y1 - offY) // remember, DOM is Y-inverted
+        ,   x2 = this.x2 - offX, y2 = -1 * (this.y2 - offY) // which affects the signs
+        
+        ,   D = 2 * (x1*y2 - y1*x2)
+        ,   B = Math.pow(x1,2) + Math.pow(y1,2)
+        ,   C = Math.pow(x2,2) + Math.pow(y2,2)
+        ;
+        return { 'x' : offX + (y2*B - y1*C)/D
+               , 'y' : offY + (x1*C - x2*B)/D * -1 // fix inverted Y-axis
+               };
+    },
+});
+
+Quad = new Y.Class('Quad', Polygon, {
+    _cssClasses : 'portal layer shape polygon quad',
+    
+    init : function initQuad(x1,y1, x2,y2, x3,y3){
+        Polygon.init.call(this, [x1,x2,x3], [y1,y2,y3]);
+    }
+    
+});
diff --git a/src/portal/shape/rect.js b/src/portal/shape/rect.js
new file mode 100644 (file)
index 0000000..ef21d2d
--- /dev/null
@@ -0,0 +1,18 @@
+
+Rect = new Y.Class('Rect', Shape, {
+    _cssClasses : 'portal layer shape rect',
+    
+    init : function initRect(w, h){
+        Layer.init.call(this);
+        
+        this.width(w)
+            .height(h);
+            // .origin(w/2, h/2);
+    },
+    
+    drawShape : function drawShape(ctx){
+        ctx.rect(0,0, this.canvasWidth,this.canvasHeight);
+        ctx.fill();
+    }
+    
+});
diff --git a/src/portal/shape/shape.js b/src/portal/shape/shape.js
new file mode 100644 (file)
index 0000000..609a74a
--- /dev/null
@@ -0,0 +1,23 @@
+Shape = new Y.Class('Shape', Layer, {
+    _cssClasses : 'portal layer shape',
+    fillStyle   : 'rgba(231,48,117, 1)',
+    strokeStyle : 'transparent',
+    lineWidth   : 0,
+    
+    _calcDimension : function _calcDimension(which, values){
+        values.unshift(0);
+        var self = this
+        ,   neg = -1 * Math.min.apply(Math, values)
+        // ,   pos = Math.min(0, Math.max.apply(Max, values) - max)
+        ;
+        
+        self.negBleed.attr(which, neg);
+        // self.posBleed.attr(which, pos);
+        
+        return values.map(function(v, i){
+                return (self[which+i] = v);
+            });
+    }
+    
+});
+
diff --git a/src/portal/transform.js b/src/portal/transform.js
deleted file mode 100644 (file)
index 6e829f6..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-Transform = new Y.Class('Transform', {
-    
-    scale : function scale(x,y, layer, ctx){
-        
-    },
-    
-    translate : function translate(x,y, layer, ctx){
-        
-    },
-    
-    crop : function crop(){
-        
-    }
-    
-});
-
-Transform.Rotation = new Y.Class('Rotation', Transform, {
-    
-    init : function initRotation(theta, x,y){
-        this.theta = theta;
-        this.x = x;
-        this.y = y;
-    },
-    
-    apply : function applyRotation(layer, ctx){
-        ctx = ctx || layer.ctx;
-        ctx.translate(this.x, this.y);
-        ctx.rotate(this.theta);
-        ctx.translate(-this.x, -this.y);
-    }
-    
-});
-
-Transform.Scale = new Y.Class('Scale', Transform, {
-    
-    init : function initScale(x,y){
-        this.x = x;
-        this.y = y;
-    },
-    
-    apply : function apply(layer, ctx){
-        ctx = ctx || layer.ctx;
-        ctx.scale(this.x, this.y);
-    }
-    
-});
-
-Transform.Translate = new Y.Class('Translate', Transform, {
-    
-    init : function init(x,y){
-        this.x = x;
-        this.y = y;
-    },
-    
-    apply : function apply(layer, ctx){
-        ctx = ctx || layer.ctx;
-        ctx.translate(this.x, this.y);
-    }
-    
-});
-
similarity index 100%
rename from src/tanks/util/calc.js
rename to src/tanks/calc.js
diff --git a/src/tanks/lttl.js b/src/tanks/lttl.js
deleted file mode 100644 (file)
index 2ce4ee3..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-jQuery(function($){
-
-v = $('#viewport');
-LBT = new Game();
-
-var sq = REF_SIZE
-,   wall = new Wall(6*sq,1*sq, 1*sq,4*sq);
-LBT.level.append(wall);
-
-
-T = new Tank(0);
-LBT.addUnit(T, 1,2);
-T.shape.hide();
-
-B = new Bullet(T, 5*REF_SIZE,5*REF_SIZE);
-LBT.addUnit(B);
-B.render( LBT.level );
-
-B = new Bullet(T, 25,25);
-LBT.addUnit(B);
-B.render( LBT.level );
-
-B = new Bullet(T, 1*REF_SIZE,3*REF_SIZE);
-LBT.addUnit(B);
-B.render( LBT.level );
-
-P = new Player(LBT, T);
-
-
-ctx = LBT.level.ctx;
-tr = B.trajectory;
-
-
-
-});
\ No newline at end of file
diff --git a/src/tanks/main.js b/src/tanks/main.js
new file mode 100644 (file)
index 0000000..1d220c7
--- /dev/null
@@ -0,0 +1,39 @@
+jQuery(main);
+
+function main(){
+    
+    v = $('#viewport');
+    LBT = new Game();
+    
+    
+    var sq = REF_SIZE
+    ,   wall = new Wall(6*sq,1*sq, 1*sq,4*sq);
+    LBT.level.append(wall);
+    
+    
+    T = new Tank(0);
+    LBT.addUnit(T, 1,2);
+    T.shape.hide();
+    
+    B = new Bullet(T, 5*REF_SIZE,5*REF_SIZE);
+    LBT.addUnit(B);
+    B.render( LBT.level );
+    
+    B = new Bullet(T, 25,25);
+    LBT.addUnit(B);
+    B.render( LBT.level );
+    
+    B = new Bullet(T, 1*REF_SIZE,3*REF_SIZE);
+    LBT.addUnit(B);
+    B.render( LBT.level );
+    
+    P = new Player(LBT, T);
+    
+    
+    ctx = LBT.level.ctx;
+    tr = B.trajectory;
+    
+    
+    
+}
+
similarity index 95%
rename from src/portal/util/loc.js
rename to src/tanks/map/loc.js
index 659a6d8..f90f3cf 100644 (file)
@@ -1,16 +1,9 @@
 // [x,y]
 Loc = new Y.Class('Loc', math.Vec, {
     
-    init : function init(x, y){
-        if ( Array.isArray(x) ) {
-            y = x[1];
-            x = x[0];
-        }
-        
-        this.length = 2;
-        this.x = this[0] = x;
-        this.y = this[1] = y;
-    },
+    // init : function init(x,y){
+    //     math.Vec.init.call(this, x,y);
+    // },
     
     set : function set(k, v, def){
         v = (v !== undefined ? v : def);
@@ -48,6 +41,9 @@ Loc = new Y.Class('Loc', math.Vec, {
         return Loc.Square.fromLoc(this.x, this.y);
     },
     
+    /**
+     * Converts relative locations like ('50%','50%') to a numeric location.
+     */
     absolute : function absolute(w,h){
         var x = this.x, y = this.y
         return new Loc( Y.isString(x) ? parseFloat(x.slice(0,-1))/100 * w : x
diff --git a/src/tanks/ui.js b/src/tanks/ui.js
deleted file mode 100644 (file)
index 88c3ddb..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-
-// Update performance info periodically
-function updateInfo(){
-    var loop = LBT.loop
-    ,   fps = loop.fps()
-    ,   n_units = LBT.units.size()
-    ,   n_projs = LBT.bullets.size()
-    ;
-    
-    $('#info [name=fps]').val( fps.toFixed(2) + " / " + loop.framerate );
-    $('#info [name=frame]').val( loop.frametime().toFixed(3)+" ms" );
-    $('#info #state').text( loop.running ? 'Running!' : ('Paused (tick '+TICKS+')') );
-    
-    $('#info [name=objects]').val( n_units+n_projs );
-    $('#info [name=units]').val( n_units );
-    $('#info [name=bullets]').val( n_projs );
-    
-    spark.drawTimes();
-    
-    return false;
-}
-
-function toggleGame(evt){
-    if (LBT.loop.running)
-        LBT.stop();
-    else
-        LBT.start();
-    
-    updateInfo();
-    return false;
-}
-
-function fixStartText(){
-    var txt  = (LBT.loop.running ? 'pause' : 'start');
-    $('.start_btn').text(txt).attr('title', txt);
-    return false;
-}
-function fixOverlayText(){
-    var txt = (LBT.showOverlay ? 'hide' : 'show') + ' bounds';
-    $('.overlay_btn').text(txt).attr('title', txt);
-    return false;
-}
-
-
-
-jQuery(function($){
-    spark = new FpsSparkline(LBT.loop, '.fps-sparkline', 0,0);
-    
-    // Tick once to draw grid, initial units
-    // LBT.start();
-    // LBT.stop();
-    // LBT.loop.elapsedAtStop = 1;
-    
-    LBT.root.draw();
-    
-    
-    setInterval(updateInfo, 1000);
-    updateInfo();
-    
-    // Update Text on Click
-    LBT.addEventListener('start', fixStartText);
-    LBT.addEventListener('stop',  fixStartText);
-    
-    // Start button (click or return key)
-    $('.start_btn').bind('click', toggleGame);
-    $(document).bind('keydown', 'return', toggleGame);
-    
-    $(document).bind('keydown', 'ctrl+o', function(evt){ LBT.showOverlay = !(LBT.showOverlay); });
-    
-    // Show Overlays
-    $('.overlay_btn').bind('click', function(evt){
-        LBT.showOverlay = !(LBT.showOverlay);
-        fixOverlayText();
-        return false;
-    });
-    
-    // Fix Starting text
-    fixStartText();
-    fixOverlayText();
-    
-    // Fix grid-size on resize
-    // $(window).bind('resize', function(evt){
-    //     LBT.resize(evt);
-    //     
-    //     if (!LBT.loop.running) {
-    //         LBT.start();
-    //         LBT.stop();
-    //     }
-    // });
-    
-});
\ No newline at end of file
diff --git a/src/tanks/ui.main.js b/src/tanks/ui.main.js
new file mode 100644 (file)
index 0000000..ad074a0
--- /dev/null
@@ -0,0 +1,61 @@
+// Set up UI listeners
+function setupUI(){
+    spark = LBT.loop.spark = new FpsSparkline(LBT.loop, '.fps-sparkline', 0,0);
+    
+    // Draw grid, initial units
+    LBT.root.draw();
+    
+    setInterval(updateInfo, 1000);
+    updateInfo();
+    
+    // Start button (click or return key)
+    $(document).bind('keydown', 'return', toggleGame);
+    $(document).bind('keydown', 'ctrl+o', toggleOverlay);
+    
+    // Fix grid-size on resize
+    // $(window).bind('resize', resizeGame);
+}
+
+// Update performance info periodically
+function updateInfo(){
+    var loop = LBT.loop
+    ,   fps = loop.fps()
+    ,   n_units = LBT.units.size()
+    ,   n_projs = LBT.bullets.size()
+    ;
+    
+    $('#info [name=fps]').val( fps.toFixed(2) + " / " + loop.framerate );
+    $('#info [name=frame]').val( loop.frametime().toFixed(3)+" ms" );
+    $('#info #state').text( loop.running ? 'Running!' : ('Paused (tick '+TICKS+')') );
+    
+    $('#info [name=objects]').val( n_units+n_projs );
+    $('#info [name=units]').val( n_units );
+    $('#info [name=bullets]').val( n_projs );
+    
+    spark.drawTimes();
+    
+    return false;
+}
+
+function toggleGame(evt){
+    if (LBT.loop.running)
+        LBT.stop();
+    else
+        LBT.start();
+    
+    updateInfo();
+}
+
+function toggleOverlay(evt){
+    LBT.showOverlay = !(LBT.showOverlay);
+}
+
+function resizeGame(evt){
+    LBT.resize(evt);
+    
+    if (!LBT.loop.running) {
+        LBT.start();
+        LBT.stop();
+    }
+}
+
similarity index 100%
rename from src/tanks/util/grid.js
rename to src/tanks/ui/grid.js
diff --git a/tanks.php b/tanks.php
new file mode 100644 (file)
index 0000000..1be4094
--- /dev/null
+++ b/tanks.php
@@ -0,0 +1,86 @@
+<?php
+
+class Tanks {
+    const MAIN_SCRIPTS = 1;
+    const SRC_SCRIPTS  = 2;
+    const LIB_SCRIPTS  = 4;
+    
+    const ONLY_LIB    = 4; // LIB_SCRIPTS; // wtf i can't use expressions of constants?
+    const SRC_AND_LIB = 6; // LIB_SCRIPTS  | SRC_SCRIPTS;
+    const ALL_SCRIPTS = 7; // MAIN_SCRIPTS | LIB_SCRIPTS | SRC_SCRIPTS;
+    
+    
+    static $mainScripts = array(
+        "src/tanks/main.js",
+        "src/tanks/ui.main.js"
+    );
+    
+    static $srcScripts = array(
+        "src/tanks/globals.js",
+        "src/tanks/calc.js",
+        
+        "src/tanks/map/loc.js",
+        "src/tanks/map/level.js",
+        "src/tanks/map/pathmap.js",
+        
+        "src/tanks/thing/thing.js",
+        "src/tanks/thing/bullet.js",
+        "src/tanks/thing/tank.js",
+        
+        "src/tanks/ui/grid.js",
+        "src/tanks/ui/player.js",
+        
+        "src/tanks/game/game.js",
+        "src/tanks/game/map.game.js"
+    );
+    
+    static $libScripts = array(
+        "lib/jquery-1.4.3.js",
+        "lib/jquery.sparkline.min.js",
+        "lib/jquery.hotkeys.js",
+        
+        // "http://static.ukijs.org/pkg/0.3.8/uki.js",
+        // "http://static.ukijs.org/pkg/0.3.8/uki-more.js",
+        
+        "src/lessly/future.js",
+        
+        "src/Y/y.js.php",
+        "src/Y/modules/y.event.js",
+        
+        "src/evt/evt.class.js",
+        
+        "src/portal/math/math.js",
+        "src/portal/math/vec.js",
+        "src/portal/math/line.js",
+        
+        "src/portal/layer.js",
+        "src/portal/shape/shape.js",
+        "src/portal/shape/circle.js",
+        "src/portal/shape/rect.js",
+        "src/portal/shape/line.js",
+        "src/portal/shape/polygon.js",
+        
+        "src/portal/util/tree/quadtree.js",
+        
+        "src/portal/loop/eventloop.js",
+        "src/portal/loop/fps.js",
+        "src/portal/loop/cooldown.js",
+    );
+    
+    static function writeTags($scripts=null, $prefix="") {
+        $scripts = $scripts ? $scripts : Tanks::SRC_AND_LIB;
+        if ($scripts & Tanks::LIB_SCRIPTS)  foreach (self::$libScripts  as $s) js($s, $prefix);
+        if ($scripts & Tanks::SRC_SCRIPTS)  foreach (self::$srcScripts  as $s) js($s, $prefix);
+        if ($scripts & Tanks::MAIN_SCRIPTS) foreach (self::$mainScripts as $s) js($s, $prefix);
+    }
+    
+}
+
+function js($src, $prefix="") {
+    echo "    <script src=\"$prefix$src\" type=\"text/javascript\"></script>\n";
+}
+
+
+
+?>
+
index 2c6a179..c4ea7f5 100644 (file)
@@ -63,37 +63,15 @@ h1 { position:fixed; top:0; right:0; margin:0; padding:0; font-size:3em; color:#
 
 <div id="scripts">
 <?php
-$scripts = array(
-    "lib/jquery-1.4.3.js",
-    "lib/jquery.sparkline.min.js",
-    "lib/jquery.hotkeys.js",
-    
-    // "http://static.ukijs.org/pkg/0.3.8/uki.js",
-    // "http://static.ukijs.org/pkg/0.3.8/uki-more.js",
-    
-    "src/lessly/future.js",
-    "src/Y/y.js.php",
-    "src/Y/modules/y.event.js",
-    
-    "src/evt/evt.class.js",
-    
-    "src/portal/math/math.js",
-    "src/portal/math/vec.js",
-    "src/portal/math/line.js",
-    
-    "src/portal/util/loc.js",
-    "src/portal/layer.js",
-    "src/portal/shape.js",
-    "src/tanks/util/grid.js",
-    
-    "test/math/math.test.js"
-);
 
-function js($src) {
-    echo "    <script src=\"../../$src\" type=\"text/javascript\"></script>\n";
-}
+require "../../tanks.php";
+Tanks::writeTags(null, "../../");
 
+$scripts = array(
+    "math.test.js"
+);
 foreach ($scripts as $s) js($s);
+
 ?>
 </div>
 </body>