Checkpoint on module refactor.
authordsc <david.schoonover@gmail.com>
Sat, 27 Nov 2010 23:03:53 +0000 (15:03 -0800)
committerdsc <david.schoonover@gmail.com>
Sat, 27 Nov 2010 23:03:53 +0000 (15:03 -0800)
64 files changed:
src/Y/_intro.js [deleted file]
src/Y/_outro.js [deleted file]
src/Y/alias.cjs [moved from src/Y/alias.js with 81% similarity]
src/Y/class.cjs [moved from src/Y/y-class.js with 91% similarity]
src/Y/core.cjs [moved from src/Y/core.js with 75% similarity]
src/Y/index.cjs [new file with mode: 0644]
src/Y/op.cjs [moved from src/Y/y-op.js with 86% similarity]
src/Y/tofunction.cjs [moved from src/Y/to-function.js with 100% similarity]
src/Y/type.cjs [moved from src/Y/type.js with 62% similarity]
src/Y/types/array.cjs [moved from src/Y/y-array.js with 78% similarity]
src/Y/types/collection.cjs [moved from src/Y/y-collection.js with 91% similarity]
src/Y/types/function.cjs [moved from src/Y/y-function.js with 67% similarity]
src/Y/types/number.cjs [moved from src/Y/y-number.js with 75% similarity]
src/Y/types/object.cjs [moved from src/Y/y-object.js with 95% similarity]
src/Y/types/string.cjs [moved from src/Y/y-string.js with 95% similarity]
src/Y/y.cjs [moved from src/Y/y-core.js with 68% similarity]
src/ezl/layer.js [moved from src/easel/layer.js with 100% similarity]
src/ezl/loop/cooldown.js [moved from src/easel/loop/cooldown.js with 100% similarity]
src/ezl/loop/eventloop.js [moved from src/easel/loop/eventloop.js with 100% similarity]
src/ezl/loop/fps.js [moved from src/easel/loop/fps.js with 100% similarity]
src/ezl/math/line.js [moved from src/easel/math/line.js with 100% similarity]
src/ezl/math/math.js [moved from src/easel/math/math.js with 100% similarity]
src/ezl/math/rect.cjs [new file with mode: 0644]
src/ezl/math/vec.js [moved from src/easel/math/vec.js with 100% similarity]
src/ezl/shape/circle.js [moved from src/easel/shape/circle.js with 100% similarity]
src/ezl/shape/line.js [moved from src/easel/shape/line.js with 100% similarity]
src/ezl/shape/polygon.js [moved from src/easel/shape/polygon.js with 100% similarity]
src/ezl/shape/rect.js [moved from src/easel/shape/rect.js with 100% similarity]
src/ezl/shape/shape.js [moved from src/easel/shape/shape.js with 100% similarity]
src/ezl/util/astar.js [moved from src/easel/util/astar.js with 100% similarity]
src/ezl/util/binaryheap.js [moved from src/easel/util/binaryheap.js with 100% similarity]
src/ezl/util/graph.js [moved from src/easel/util/graph.js with 100% similarity]
src/ezl/util/tree/pointquadtree.js [moved from src/easel/util/tree/pointquadtree.js with 100% similarity]
src/ezl/util/tree/quadtree.js [moved from src/easel/util/tree/quadtree.js with 100% similarity]
src/ezl/util/tree/rbtree.js [moved from src/easel/util/tree/rbtree.js with 100% similarity]
src/tanks/calc.cjs [moved from src/tanks/calc.js with 100% similarity]
src/tanks/config.cjs [new file with mode: 0644]
src/tanks/config.js [deleted file]
src/tanks/game.cjs [moved from src/tanks/game.js with 94% similarity]
src/tanks/globals.cjs [moved from src/tanks/globals.js with 99% similarity]
src/tanks/index.cjs [new file with mode: 0644]
src/tanks/map/index.cjs [new file with mode: 0644]
src/tanks/map/level.cjs [moved from src/tanks/map/level.js with 100% similarity]
src/tanks/map/loc/bbox.cjs [new file with mode: 0644]
src/tanks/map/loc/index.cjs [new file with mode: 0644]
src/tanks/map/loc/loc.cjs [moved from src/tanks/map/loc.js with 100% similarity]
src/tanks/map/loc/rect.cjs [new file with mode: 0644]
src/tanks/map/pathmap.cjs [moved from src/tanks/map/pathmap.js with 100% similarity]
src/tanks/map/trajectory.cjs [moved from src/tanks/map/trajectory.js with 100% similarity]
src/tanks/tanks.js [deleted file]
src/tanks/thing/bullet.cjs [moved from src/tanks/thing/bullet.js with 100% similarity]
src/tanks/thing/custom-tank.cjs [moved from src/tanks/thing/custom-tank.js with 100% similarity]
src/tanks/thing/index.cjs [new file with mode: 0644]
src/tanks/thing/player.cjs [moved from src/tanks/thing/player.js with 98% similarity]
src/tanks/thing/tank.cjs [moved from src/tanks/thing/tank.js with 100% similarity]
src/tanks/thing/thing.cjs [moved from src/tanks/thing/thing.js with 94% similarity]
src/tanks/ui/grid.cjs [moved from src/tanks/ui/grid.js with 100% similarity]
src/tanks/ui/index.cjs [new file with mode: 0644]
src/tanks/ui/main.cjs [moved from src/tanks/ui/main.js with 100% similarity]
src/tanks/ui/ui-config.cjs [moved from src/tanks/ui/ui-config.js with 100% similarity]
src/tanks/ui/ui.cjs [moved from src/tanks/ui/ui.js with 100% similarity]
src/tanks/util/config.cjs [moved from src/tanks/util/config.js with 100% similarity]
src/tanks/util/utils.cjs [moved from src/tanks/util/utils.js with 100% similarity]
tanks.php

diff --git a/src/Y/_intro.js b/src/Y/_intro.js
deleted file mode 100644 (file)
index 1fb369f..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-(function(){
-
-this.Y = Y;
-
diff --git a/src/Y/_outro.js b/src/Y/_outro.js
deleted file mode 100644 (file)
index 22a7560..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-
-})();
similarity index 81%
rename from src/Y/alias.js
rename to src/Y/alias.cjs
index 01249a8..6898c30 100644 (file)
@@ -1,4 +1,5 @@
-var globals   = this
+var undefined
+,   globals   = (function(){ return this; })()
 ,   _Object   = globals.Object
 ,   _Function = globals.Function
 ,   _Array    = globals.Array
@@ -6,7 +7,6 @@ var globals   = this
 ,   _Number   = globals.Number
 
 ,   slice    = _Array.prototype.slice
-,   toString = _Object.prototype.toString
 ,   hasOwn   = _Object.prototype.hasOwnProperty
 ,   getProto = _Object.getPrototypeOf
 ;
similarity index 91%
rename from src/Y/y-class.js
rename to src/Y/class.cjs
index 5c7aea0..9ca59ab 100644 (file)
@@ -1,6 +1,8 @@
 // Inspired by John Resig's "Simple Class Inheritence" -- http://ejohn.org/blog/simple-javascript-inheritance/
 
-var KNOWN_CLASSES = {}
+var Y = require('Y').Y
+,   type = require('Y/type')
+,   KNOWN_CLASSES = type.type.KNOWN_CLASSES
 ,   classToString = function toString(){ return this.className+"()"; }
 ;
 
@@ -12,7 +14,7 @@ function _Class() {
     ,   instance = this;
     
     // Not subclassing
-    if ( cls.caller !== Y.Class.fabricate ) {
+    if ( cls.caller !== Class.fabricate ) {
         if ( instance.init ){
             var result = instance.init.apply(instance, arguments);
             if (result) instance = result;
@@ -111,7 +113,7 @@ function Class(className, Parent, members) {
             prototype[k] = members[k];
     }
     
-    if (prototype.init) NewClass.init = prototype.init;
+    if (prototype.init) NewClass.init = Y(prototype.init);
     
     KNOWN_CLASSES[className] = NewClass;
     
@@ -125,9 +127,6 @@ Class.fn.__class__ = Class;
 Class.className = Class.fn.className = "Class";
 
 
-Y.Class = 
-Y.subclass = Class;
-
 /* Class Methods */
 
 /**
@@ -166,8 +165,7 @@ Class.fn.subclass =
 /**
  * Root-class for all Y-objects.
  */
-function YBase(){}
-YBase = Y.YBase = new Class("YBase", {
+var YBase = new Class("YBase", {
     __y__ : true
 });
 
@@ -178,20 +176,13 @@ YBase = Y.YBase = new Class("YBase", {
 
 function bindName(v, k){
     if ( isFunction(v) )
-        this[k] = Y(this[k]).bind(this);
+        this[k] = Y(v).bind(this);
 }
 // bindName = Y(bindName).curry();
 
-Y.bindAll = bindAll;
 function bindAll(o, names){
     var names = new Y(arguments, 1);
     Y(names.size() ? names.generate(Y.op.get(o)) : o).forEach( bindName, o );
-    
-    // if ( names.size() ){
-    //     names.forEach(binder);
-    // } else
-    //     for (var k in o) binder(k);
-    
     return o;
 }
 
@@ -226,4 +217,13 @@ function mixinNames(o, Donor, names, override, yWrap){
     return o;
 }
 
+exports['Class'] =
+exports['subclass']    = Class;
+exports['instantiate'] = Class.instantiate.bind(Class);
+exports['fabricate']   = Class.fabricate.bind(Class);
+
+exports['YBase']          = YBase;
+exports['bindAll']        = bindAll;
+exports['chainDelegates'] = chainDelegates;
+exports['mixinNames']     = mixinNames;
 
similarity index 75%
rename from src/Y/core.js
rename to src/Y/core.cjs
index 9f70f78..83f1594 100644 (file)
@@ -37,6 +37,7 @@ function map(o, fn){
 
 function forEach(o, fn){
     map(o, fn, cxt);
+    return o;
 }
 
 function filter(o, fn){
@@ -91,12 +92,27 @@ function dattr(o, key, value, def){
 }
 
 function extend( A, B ){
-    return slice.call(arguments,1).reduce(extend._extendall, A);
+    return slice.call(arguments,1).reduce(extendall, A);
+}
+function extendall(A, donor){ return reduce(donor, attrvk, A); }
+function attrvk(o, v, k){ return attr(o, k, v, o[k]); }
+
+function dextend( A, B ){
+    return slice.call(arguments,1).reduce(dextendall, A);
 }
-extend._extendall = function _extendall(A, donor){
-    return reduce(donor, extend._set, A);
-};
-extend._set = function _set(o, v, k){
-    return dattr(o, k, v, o[k]);
-};
+function dextendall(A, donor){ return reduce(donor, dattrvk, A); }
+function dattrvk(o, v, k){ return dattr(o, k, v, o[k]); }
+
+
+exports['reduce']  = reduce;
+exports['map']     = map;
+exports['forEach'] = forEach;
+exports['filter']  = filter;
+
+exports['set']     = set;
+exports['attr']    = attr;
+exports['extend']  = extend;
 
+exports['dset']    = dset;
+exports['dattr']   = dattr;
+exports['dextend'] = dextend;
diff --git a/src/Y/index.cjs b/src/Y/index.cjs
new file mode 100644 (file)
index 0000000..4b3e16b
--- /dev/null
@@ -0,0 +1,71 @@
+
+/// Import our external deps first ///
+require('lessly/future');
+require('functional/to-function');
+
+/// Set up core and utilities ///
+var core = require('Y/core')
+,   type = require('Y/type')
+,   Y    = require('Y/y').Y
+;
+
+exports['Y'] = Y;
+
+// Copy all our type utils onto the type function, as it has the
+// same name as its namespace
+core.extend(type.type, type);
+
+// Attach core & type to Y
+core.extend(Y, core, type);
+
+// Make top-level setters refer to the delegating versions
+Y['core']   = core;
+Y['set']    = core.dset;
+Y['attr']   = core.dattr;
+Y['extend'] = core.dextend;
+
+
+/// Patch modules that weren't available earlier ///
+
+// Attach YFunction methods to library functions
+var yfn = require('Y/types/function')
+,   YFunction = Y['YFunction'] = yfn.YFunction ;
+
+YFunction(Y);
+core.forEach(core, YFunction);
+YFunction(Y.type);
+Y['is'] = YFunction(Y.is).curry();
+
+addNames('curry methodize genericize compose chain memoize', yfn);
+
+// Curry all operators
+var op = require('Y/op');
+core.forEach(op, YFunction);
+Y['op'] = op.extend({}, core.map(yfn.curry, op));
+// Y['op'] = core.reduce(op, function(Yop, fn, k){
+//     Yop[k] = yfn.curry(fn);
+//     return Yop;
+// }, {});
+
+// var yclass = require('Y/types/class');
+addNames('Class subclass instantiate fabricate YBase',
+    require('Y/class'));
+
+
+/// Now start assembling the normal sub-modules ///
+addNames('YCollection',   require('Y/types/collection'));
+addNames('YArray',        require('Y/types/array'));
+addNames('YObject',       require('Y/types/object'));
+addNames('YString',       require('Y/types/string'));
+addNames('YNumber range', require('Y/types/number'));
+
+// var ycollection = require('Y/types/collection')
+// ,   yarray      = require('Y/types/array')
+// ,   yobject     = require('Y/types/object')
+// ,   ystring     = require('Y/types/string')
+// ,   ynumber     = require('Y/types/number')
+// ;
+
+
+function addName(name){ Y[name] = this[name]; }
+function addNames(names, ns){ names.split(' ').forEach(addName, ns); }
similarity index 86%
rename from src/Y/y-op.js
rename to src/Y/op.cjs
index 7d295ea..97ef023 100644 (file)
@@ -1,6 +1,8 @@
-
 /* A subset of the functional operators, used in Y's core */
-Y.op = { 
+
+var Y    = require('Y').Y
+,   core = require('Y/core')
+,   op = { // XXX: Make these function statements?
     
     // comparison
     cmp:    function(x,y){  return x == y ? 0 : (x > y ? 1 : -1); },
@@ -52,8 +54,8 @@ Y.op = {
     has:     function(o,k){     return k in o; },
     get:     function(o,k){     return o[k] },
     getdef:  function(o,k,def){ return (k in o ? o[k] : def); },
-    set:     set,  // set(  o, key, value, def )
-    attr:    attr, // attr( o, key, value, def )
+    set:     core.set,  // set(  o, key, value, def )
+    attr:    core.attr, // attr( o, key, value, def )
     method: function(name){
         var args = Y(arguments,1);
         return function(obj){
@@ -64,15 +66,13 @@ Y.op = {
         };
     },
     extend : function extend(A,B){
-        return slice.call(arguments,1).reduce('A donor -> Y.reduce(donor, Y.op.vkset, A)'.lambda(), A);
+        return slice.call(arguments,1).reduce(extender, A);
     }
     
 };
 
+function extender(target, donor){
+    return core.reduce(donor, op.vkset, target);
+}
 
-// Curry all operators
-Y.op = Y.reduce(Y.op, function(op, fn, k){
-    op[k] = Y( Y(fn).curry() );
-    return op;
-}, {});
-
+core.extend(exports, op);
similarity index 100%
rename from src/Y/to-function.js
rename to src/Y/tofunction.cjs
similarity index 62%
rename from src/Y/type.js
rename to src/Y/type.cjs
index a4be9df..0063683 100644 (file)
@@ -1,14 +1,34 @@
 // Type Utilities //
 // Much borrowed from jQuery
 
+var undefined
+,   globals   = (function(){ return this; })()
+,   _Object   = globals.Object
+,   _Function = globals.Function
+,   _Array    = globals.Array
+,   _String   = globals.String
+,   _Number   = globals.Number
+
+,   FN = "constructor"
+,   PT = "prototype"
+,   OP = _Object[PT]
+
+,   slice    = _Array[PT].slice
+,   getProto = _Object.getPrototypeOf
+,   hasOwn   = OP.hasOwnProperty
+,   toString = OP.toString
+,   hasOwn   = OP.hasOwnProperty
+
+,   KNOWN_CLASSES = {}
+;
+
 var class2name =
     "Boolean Number String Function Array Date RegExp Object"
         .split(" ")
         .reduce(function(class2name, name) {
             class2name[ "[object "+name+"]" ] = name.toLowerCase();
             return class2name;
-        }, {})
-;
+        }, {});
 
 function type_of(obj){
     return obj == null ?
@@ -16,6 +36,7 @@ function type_of(obj){
         class2name[ toString.call(obj) ] || "object";
 }
 
+isArray.types = [];
 function isArray(obj)    { return type_of(obj) === "array" || obj instanceof Y.YArray; }
 function isFunction(obj) { return type_of(obj) === "function"; }
 function isString(obj)   { return type_of(obj) === "string"; }
@@ -30,9 +51,9 @@ function isPlainObject( obj ){
         return false;
     
     // Not own constructor property must be Object
-    if ( obj.constructor &&
-        !hasOwn.call(obj, "constructor") &&
-        !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") )
+    if ( obj[FN] &&
+        !hasOwn.call(obj, FN) &&
+        !hasOwn.call(obj[FN][PT], "isPrototypeOf") )
             return false;
     
     
@@ -47,17 +68,17 @@ function isPlainObject( obj ){
 function type( o ) {
     switch ( typeof(o) ) {
         case "undefined" : return undefined;
-        case "string"    : return String;
-        case "number"    : return Number; // Note: NaN and Infinity are Number literals
-        case "boolean"   : return Boolean;
+        case "string"    : return _String;
+        case "number"    : return _Number; // Note: NaN and Infinity are Number literals
+        case "boolean"   : return _Boolean;
         
         case "function" :
             // If the function has a user-specified prototype, we can probably assume
             // it's meant to be a class constructor (and therefore, a type)
-            if ( o.prototype && o.prototype !== Function.prototype )
+            if ( o[PT] && o[PT] !== _Function[PT] )
                 return o;
             else
-                return Function;
+                return _Function;
         
         case "object" :
         default :
@@ -66,7 +87,7 @@ function type( o ) {
                 return null;
             
             return KNOWN_CLASSES[o.className] || o.__class__
-                || (o.constructor && o.constructor !== Object) ? o.constructor : Object;
+                || (o[FN] && o[FN] !== _Object) ? o[FN] : _Object;
     }
 }
 
@@ -78,3 +99,17 @@ function is( A, B ){
         return (A instanceof BT || B instanceof AT || AT === BT);
     }
 }
+
+exports['is']            = is;
+exports['type']          = type;
+exports['type_of']       = type_of;
+
+exports['isArray']       = isArray;
+exports['isFunction']    = isFunction;
+exports['isString']      = isString;
+exports['isNumber']      = isNumber;
+exports['isWindow']      = isWindow;
+exports['isPlainObject'] = isPlainObject;
+
+type['KNOWN_CLASSES'] = KNOWN_CLASSES;
+
similarity index 78%
rename from src/Y/y-array.js
rename to src/Y/types/array.cjs
index 8b72596..18b50e3 100644 (file)
@@ -1,7 +1,16 @@
-var
-YArray =
-Y.YArray =
-YCollection.subclass('YArray', function(YArray){
+var Y = require('Y').Y;
+
+exports['YArray'] =
+Y.YCollection.subclass('YArray', function(YArray){
+    var yclass = require('Y/class');
+    
+    yclass.chainDelegates(YArray, 'push', 'unshift', 'sort', 'splice', 'reverse');
+    yclass.mixinNames(YArray, Array, ['reduce', 'map', 'forEach', 'filter', 'slice', 'some', 'every'],    true, true);
+    yclass.mixinNames(YArray, Array, ['indexOf', 'lastIndexOf', 'shift', 'pop', 'join'], true, false);
+    
+    
+    
+    
     this.init = function(o){
         // YCollection.init.call(this, o || []);
         this._o = o || [];
@@ -12,7 +21,7 @@ YCollection.subclass('YArray', function(YArray){
     function concat( donor ){
         var A = this._o;
         new Y(arguments).forEach(function( donor ){
-            A = A.concat(donor instanceof Y.YArray ? donor.end() : donor);
+            A = A.concat(donor instanceof YArray ? donor.end() : donor);
         });
         return Y(A);
     };
@@ -43,7 +52,7 @@ YCollection.subclass('YArray', function(YArray){
                     acc.push(v);
                 return acc;
                 
-            }, new Y.YArray() );
+            }, new YArray() );
         
         // return this.filter(function(v, i){
         //     // Executes in the context of the new array, so
@@ -88,11 +97,6 @@ YCollection.subclass('YArray', function(YArray){
         return "Y[" + (this._o || "") + "]";
     };
     
-    
-    chainDelegates(YArray, 'push', 'unshift', 'sort', 'splice', 'reverse');
-    mixinNames(YArray, Array, ['reduce', 'map', 'forEach', 'filter', 'slice', 'some', 'every'],    true, true);
-    mixinNames(YArray, Array, ['indexOf', 'lastIndexOf', 'shift', 'pop', 'join'], true, false);
-    
     return this;
 });
 
similarity index 91%
rename from src/Y/y-collection.js
rename to src/Y/types/collection.cjs
index f027877..669f942 100644 (file)
@@ -1,20 +1,21 @@
-
 /** YCollection is the core of Y. */
 
-function bool(v){ return !!(v); }
+var Y = require('Y').Y
+,   isFunction = require('Y/type').isFunction
+,   extend     = require('Y/core').extend
+,   bool       = require('Y/op').bool
+;
+
 
 function extendY(){
-    extend.apply(this, [this._o].concat(Y(arguments)) );
+    extend.apply(this, [this._o].concat(Y(arguments)));
     return this;
 }
 
-var 
-YCollection =
-Y.YCollection =
-YBase.subclass('YCollection', {
+exports['YCollection'] =
+Y.YBase.subclass('YCollection', {
     'init' : function(o){
-        if (!o) return;
-        this._o = o;
+        this._o = o || {};
     },
     
     'attr'   : function attr(k, v, def){
similarity index 67%
rename from src/Y/y-function.js
rename to src/Y/types/function.cjs
index 6f1e873..f354cb3 100644 (file)
@@ -1,38 +1,44 @@
-var _ = globals._ = Y._ = YFunction._ = {}
-,   WRAPS = "__wraps__"
+var undefined
+,   WRAPS   = "__wraps__"
+,   globals = (function(){ return this; })()
+
+,   Y    = require('Y').Y
+,   core = require('Y/core')
+,   type = require('Y/type')
+
+,   isNumber      = type.isNumber
+,   isFunction    = type.isFunction
+,   isArray       = type.isArray
+,   isPlainObject = type.isPlainObject
+
+,   _   = exports._ = YFunction._ = {}
+,   YFP = YFunction.prototype
 ;
 
 function YFunction(fn){
-    if (!fn)
-        fn = function(){};
+    fn = fn || function(){};
     
     if (fn.__y__)
         return fn;
     
     fn.__y__ = true;
-    return Y.YFunction.install(fn);
+    
+    for (var k in YFP) {
+        var v = YFP[k];
+        if ( isFunction(v) && (k == 'bind' || !fn[k]) )
+            fn[k] = v;
+    }
+    return fn;
 }
 
-Y.YFunction = YFunction;
-Y.extend(YFunction.prototype, {
+core.extend( YFP, {
     init   : YFunction,
-    reduce : methodize(Y.reduce),
-    extend : methodize(Y.extend),
-    end : function end(){ return this; }
+    attr   : methodize(core.attr),
+    reduce : methodize(core.reduce),
+    extend : methodize(core.extend),
+    end    : function end(){ return this; }
 });
-YFunction.prototype.attr = methodize(Y.attr);
 
-YFunction.install =
-function install(target){
-    target = target || Function.prototype;
-    var proto = Y.YFunction.prototype;
-    
-    for (var k in proto) {
-        if ( Y.isFunction(proto[k]) && (k == 'bind' || !target[k]) )
-            target[k] = proto[k];
-    }
-    return target;
-};
 
 
 
@@ -40,8 +46,6 @@ function unwrap(fn){
     return ( fn && isFunction(fn) ) ? unwrap(fn[WRAPS]) || fn : fn;
 }
 
-Y.curry = curry;
-YFunction.prototype.curry = methodize(curry);
 function curry(fn){
     if (fn.__curried__)
         return fn.apply(this, Y(arguments,1));
@@ -67,8 +71,6 @@ function curry(fn){
 }
 
 
-Y.methodize = methodize;
-YFunction.prototype.methodize = methodize(methodize);
 function methodize(fn) {
     fn = fn.toFunction();
     var g = fn.__genericized__
@@ -84,8 +86,6 @@ function methodize(fn) {
     return m;
 }
 
-Y.genericize = genericize;
-YFunction.prototype.genericize = methodize(genericize); // heh
 function genericize( fn ) {
     fn = fn.toFunction();
     var g = fn.__genericized__
@@ -104,8 +104,6 @@ function genericize( fn ) {
 
 
 
-Y.compose = compose;
-YFunction.prototype.compose = methodize(compose);
 function _composer(x,fn){ return fn.call(this, x); }
 function compose(f,g){
     var fns = Y(arguments).map(Function.toFunction);
@@ -114,8 +112,6 @@ function compose(f,g){
     };
 }
 
-Y.chain = chain;
-YFunction.prototype.chain = methodize(chain);
 function chain(f,g){
     var fns = Y(arguments).map(Function.toFunction);
     
@@ -160,36 +156,28 @@ function chain(f,g){
 // }
 
 
-function splat(fn, x){
-    return fn[ isArray(x) ? "apply" : "call"](this, x);
-}
-
 var _bind = _Function.prototype.bind;
-YFunction.prototype.bind =
-    function bind(context, args){
-        var bound = _bind.apply(this, arguments);
-        bound[WRAPS] = this;
-        return Y(bound);
-    };
+function bind(fn, context, args){
+    var bound = _bind.apply(fn, Y(arguments,1));
+    bound[WRAPS] = fn;
+    return YFunction(bound);
+}
 
 
 // Remembers arguments but obeys current context
-YFunction.prototype.partial =
-    function partial(){
-        var fn = this
-        ,   args = Y(arguments)
-        ,   partially = function(){
-                return fn.apply( this, args.concat(Y(arguments)) );
-            };
-        partially[WRAPS] = fn;
-        return Y(partially);
-    };
+function partial(fn){
+    var args = Y(arguments,1)
+    ,   partially = 
+        function partially(){
+            return fn.apply( this, args.concat(Y(arguments)) );
+        };
+    partially[WRAPS] = fn;
+    return YFunction(partially);
+}
 
 
 // Only works for arguments whose toString is unique and stateless (for example, primitives, but not closures).
 // XXX: hashCode()
-Y.memoize = memoize;
-YFunction.prototype.memoize = methodize(memoize);
 
 /**
  * @param {Function} fn Function to memorize.
@@ -233,10 +221,8 @@ YFunction._ofArityWrapper =
             '); }; })');
     });
 
-YFunction.prototype.aritize = 
-function aritize(n){
-    var fn = this
-    ,   cache = fn.__aritized__ ;
+function aritize(fn, n){
+    var cache = fn.__aritized__ ;
     
     if (fn.length === n)
         return fn;
@@ -247,12 +233,10 @@ function aritize(n){
         return cache[n];
     
     return ( cache[n] = _ofArityWrapper(n, false)(fn) );
-};
+}
 
-YFunction.prototype.limit = 
-function limit(n){
-    var fn = this
-    ,   cache = fn.__limited__ ;
+function limit(fn, n){
+    var cache = fn.__limited__ ;
     
     if ( !cache )
         cache = fn.__limited__ = {};
@@ -260,7 +244,7 @@ function limit(n){
         return cache[n];
     
     return ( cache[n] = _ofArityWrapper(n, true)(fn) );
-};
+}
 
 
 /**
@@ -274,28 +258,51 @@ function limit(n){
 
 
 /** Returns the declared name of a function. */
-YFunction.prototype.getName = Y.getName
-    function getName( fn ){
-        if ( !fn && isFunction(this) )
-            fn = this;
-        if ( !isFunction(fn) )
-            return fn;
-        else
-            return fn.className || fn.name || (fn+'').match( /function\s*([^\(]*)\(/ )[1] || '';
-    }
+function getName( fn ){
+    if ( !isFunction(fn) )
+        return fn;
+    else
+        return fn.className || fn.name || (fn+'').match( /function\s*([^\(]*)\(/ )[1] || '';
+}
 
+function splat(fn, x){
+    return fn[ isArray(x) ? "apply" : "call"](this, x);
+}
 
-YFunction(Y);
-Y(Y.reduce);
-Y(Y.map);
-Y(Y.forEach);
-Y(Y.filter);
-Y(Y.set);
-Y(Y.attr);
-Y(Y.extend);
-Y(Y.type);
-Y.is = Y(Y.is).curry();
 
-Y.reduce(YFunction.prototype, function(_,fn,name){
-    YFunction(fn);
-});
+
+
+exports['unwrap']     = unwrap;
+exports['curry']      = curry;
+exports['methodize']  = methodize;
+exports['genericize'] = genericize;
+exports['compose']    = compose;
+exports['chain']      = chain;
+exports['bind']       = bind;
+exports['partial']    = partial;
+exports['memoize']    = memoize;
+exports['aritize']    = aritize;
+exports['limit']      = limit;
+exports['getName']    = getName;
+// exports['splat']      = splat;
+
+// Methodize and then attach to YFunction's prototype
+YFP.extend(core.map(exports, methodize));
+// YFP['unwrap']     = methodize(unwrap);
+// YFP['curry']      = methodize(curry);
+// YFP['methodize']  = methodize(methodize);
+// YFP['genericize'] = methodize(genericize); // heh
+// YFP['compose']    = methodize(compose);
+// YFP['chain']      = methodize(chain);
+// YFP['bind']       = methodize(bind);
+// YFP['partial']    = methodize(partial);
+// YFP['memoize']    = methodize(memoize);
+// YFP['aritize']    = methodize(aritize);
+// YFP['limit']      = methodize(limit);
+// YFP['getName']    = methodize(getName);
+
+// Export these last to avoid methodizing them
+exports['YFunction']  = YFunction;
+
+// Attach our methods to our exports!
+core.forEach(exports, YFunction);
similarity index 75%
rename from src/Y/y-number.js
rename to src/Y/types/number.cjs
index dba6137..875a641 100644 (file)
@@ -1,26 +1,7 @@
+var Y = require('Y').Y
+,   op = require('Y/op')
+;
 
-var
-YNumber =
-Y.YNumber =
-YCollection.subclass('YNumber', {
-    init: function(o){
-        if (!o) o = 0;
-        YCollection.init.call(this, o);
-    },
-    
-    compare : function compare(n){
-        var m = this._o;
-        return (m > n ?  1 :
-               (m < n ? -1 : 0 ));
-    },
-    
-    toString : function toString(){
-        return this.end()+'';
-    }
-});
-
-
-Y.range = range;
 function range(start, end, step){
     switch (arguments.length) {
         // range() -> []
@@ -55,3 +36,24 @@ function range(start, end, step){
     return r;
 }
 
+
+exports['YNumber'] =
+Y.YCollection.subclass('YNumber', {
+    init: function(o){
+        this._o = o || 0;
+    },
+    
+    compare : function compare(n){
+        return op.cmp(this._o, n);
+    },
+    
+    range : function range(end, step){
+        return range(this._o, end, step);
+    },
+    
+    toString : function toString(){
+        return this.end()+'';
+    }
+});
+
+exports['range'] = range;
similarity index 95%
rename from src/Y/y-object.js
rename to src/Y/types/object.cjs
index 2d6b497..3aeec15 100644 (file)
@@ -1,8 +1,10 @@
+var Y = require('Y').Y
+,   isArray = Y.isArray
+;
 
-var
-YObject =
-Y.YObject =
-YCollection.subclass('YObject', {
+
+exports['YObject'] =
+Y.YCollection.subclass('YObject', {
     
     'init': function initYObject(o){
         this._o = o || {};
similarity index 95%
rename from src/Y/y-string.js
rename to src/Y/types/string.cjs
index 72d17ab..cff211f 100644 (file)
@@ -1,8 +1,10 @@
+var Y = require('Y').Y
+,   mixinNames = require('Y/class').mixinNames
+,   op = require('Y/op')
+;
 
-var
-YString =
-Y.YString =
-YCollection.subclass('YString', function(YString){
+exports['YString'] =
+Y.YCollection.subclass('YString', function(YString){
     
     mixinNames(YString, String, [
             'slice', 'split',
@@ -23,7 +25,7 @@ YCollection.subclass('YString', function(YString){
             return s;
     }
     
-    Y.op.extend(this, {
+    op.extend(this, {
         init : function init(o){
             if (!o) o = "";
             this._o = o;
@@ -121,7 +123,7 @@ YCollection.subclass('YString', function(YString){
         
         // TODO: Should cache the new properties and re-applied them whenever we mutate _o,
         // as strings are immutable and they'll be lost otherwise.
-        Y.op.set(s, key, _val);
+        op.set(s, key, _val);
         return this;
     };
     
similarity index 68%
rename from src/Y/y-core.js
rename to src/Y/y.cjs
index 2abb48b..3241611 100644 (file)
@@ -1,22 +1,28 @@
+var undefined
+,   globals   = (function(){ return this; })()
+,   _Object   = globals.Object
+,   _Function = globals.Function
+,   _Array    = globals.Array
+,   _String   = globals.String
+,   _Number   = globals.Number
 
-Y.reduce  = reduce;
-Y.map     = map;
-Y.forEach = forEach;
-Y.filter  = filter;
-Y.set     = dset;
-Y.attr    = dattr;
-Y.extend  = extend;
-
-Y.type          = type;
-Y.is            = is;
-Y.isString      = isString;
-Y.isNumber      = isNumber;
-Y.isFunction    = isFunction;
-Y.isArray       = isArray;
-Y.isPlainObject = isPlainObject;
+,   FN = "constructor"
+,   PT = "prototype"
+,   OP = _Object[PT]
 
+,   slice    = _Array[PT].slice
+,   getProto = _Object.getPrototypeOf
+,   hasOwn   = OP.hasOwnProperty
+,   toString = OP.toString
+,   hasOwn   = OP.hasOwnProperty
 
+,   core = require('Y/core')
+,   extend = core.extend
 
+,   type = require('Y/type')
+,   type_of = type.type_of, isNumber = type.isNumber
+,   isPlainObject = type.isPlainObject, isArray = type.isArray
+;
 
 /**
  * Creates a Y wrapper around its input.
@@ -68,21 +74,16 @@ function Y(o){
     }
     
     // Do we have a type-specific wrapper?
-    var name   = type_of(o)
-    ,   yname  = 'Y' + name.charAt(0).toUpperCase() + name.slice(1)
+    var name  = type_of(o)
+    ,   yname = 'Y' + name.charAt(0).toUpperCase() + name.slice(1)
     ,   YType = Y[yname]
     ;
     
-    // if ( YType && YType !== Y.YObject || YType !== Y.YBase )
-    //     return new YType(o);
     if ( YType )
         return new YType(o);
     
-    // Add YFunction methods, since we can't subclass function
-    // if ( isFunction(o) )
-    //     return new Y.YFunction(o);
-    
     // Finally, Generic object wrapper
     return new Y.YObject(o);
 }
 
+exports['Y'] = Y;
similarity index 100%
rename from src/easel/layer.js
rename to src/ezl/layer.js
similarity index 100%
rename from src/easel/loop/fps.js
rename to src/ezl/loop/fps.js
similarity index 100%
rename from src/easel/math/line.js
rename to src/ezl/math/line.js
similarity index 100%
rename from src/easel/math/math.js
rename to src/ezl/math/math.js
diff --git a/src/ezl/math/rect.cjs b/src/ezl/math/rect.cjs
new file mode 100644 (file)
index 0000000..e69de29
similarity index 100%
rename from src/easel/math/vec.js
rename to src/ezl/math/vec.js
similarity index 100%
rename from src/tanks/calc.js
rename to src/tanks/calc.cjs
diff --git a/src/tanks/config.cjs b/src/tanks/config.cjs
new file mode 100644 (file)
index 0000000..e905a6b
--- /dev/null
@@ -0,0 +1,14 @@
+//  -*- mode: JavaScript; tab-width: 4; indent-tabs-mode: nil; -*-
+var defaults =
+exports.defaults = {
+    ui : {
+        showGridCoords : false,
+        showCountdown  : true
+    },
+    pathing : { 
+        overlayAIPaths    : false,
+        overlayPathmap    : false,
+        traceTrajectories : false
+    }
+};
+exports.values = Y(defaults).clone().end();
diff --git a/src/tanks/config.js b/src/tanks/config.js
deleted file mode 100644 (file)
index ed61e1b..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-//  -*- mode: JavaScript; tab-width: 4; indent-tabs-mode: nil; -*-
-tanks.config = {
-    defaults : {
-        ui : {
-            showGridCoords : false,
-            showCountdown  : true
-        },
-        pathing : { 
-            overlayAIPaths    : false,
-            overlayPathmap    : false,
-            traceTrajectories : false
-        }
-    }
-};
-
-tanks.config.values = Y(tanks.config.defaults).clone().end();
\ No newline at end of file
similarity index 94%
rename from src/tanks/game.js
rename to src/tanks/game.cjs
index 8839f36..f7a07f5 100644 (file)
@@ -1,4 +1,14 @@
-tanks.Game = Y.subclass('Game', {
+var tanks = require('tanks')
+,   map   = require('tanks/map')
+,   thing = require('tanks/thing')
+,   Grid  = require('tanks/ui/grid').Grid
+
+,   Level = map.Level
+,   Thing = thing.Thing, Tank = thing.Tank, Bullet = thing.Bullet
+
+;
+
+exports.Game = Y.subclass('Game', {
     overlayPathmap : false,
     
     
similarity index 99%
rename from src/tanks/globals.js
rename to src/tanks/globals.cjs
index 1506b90..67dfe05 100644 (file)
@@ -38,7 +38,7 @@ tanks.resetGlobals = function resetGlobals(){
     
     SECONDTH = ELAPSED / 1000;
     SQUARETH = REF_SIZE * SECONDTH;
-}
+};
 
 if (!window.console) {
     console = {
diff --git a/src/tanks/index.cjs b/src/tanks/index.cjs
new file mode 100644 (file)
index 0000000..4b77f3b
--- /dev/null
@@ -0,0 +1,2 @@
+var tanks = exports.tanks = {};
+tanks.config = require('tanks/config');
diff --git a/src/tanks/map/index.cjs b/src/tanks/map/index.cjs
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/tanks/map/loc/bbox.cjs b/src/tanks/map/loc/bbox.cjs
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/tanks/map/loc/index.cjs b/src/tanks/map/loc/index.cjs
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/tanks/map/loc/rect.cjs b/src/tanks/map/loc/rect.cjs
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/tanks/tanks.js b/src/tanks/tanks.js
deleted file mode 100644 (file)
index 89d6359..0000000
+++ /dev/null
@@ -1 +0,0 @@
-tanks = {};
diff --git a/src/tanks/thing/index.cjs b/src/tanks/thing/index.cjs
new file mode 100644 (file)
index 0000000..34bd5c2
--- /dev/null
@@ -0,0 +1,5 @@
+exports.Thing      = require('tanks/thing/thing').Thing;
+exports.Bullet     = require('tanks/thing/bullet').Bullet;
+exports.Tank       = require('tanks/thing/tank').Tank;
+exports.PlayerTank = require('tanks/thing/player').PlayerTank;
+
similarity index 98%
rename from src/tanks/thing/player.js
rename to src/tanks/thing/player.cjs
index ff4c8b4..26d276c 100644 (file)
@@ -1,6 +1,8 @@
-(function(){
 
-PlayerTank = Tank.subclass('PlayerTank', {
+var PlayerTank =
+exports.PlayerTank =
+Tank.subclass('PlayerTank', {
+    
     bodyColor   : '#E73075',
     turretColor : '#A72F5B',
     barrelColor : '#2E62C9',
@@ -195,6 +197,3 @@ var Key = {
     }
 };
 
-
-
-})();
similarity index 94%
rename from src/tanks/thing/thing.js
rename to src/tanks/thing/thing.cjs
index 82fcfbc..c29f1e0 100644 (file)
@@ -1,4 +1,11 @@
-Thing = new Evt.Class('Thing', {
+var loc      = require('tanks/map/loc')
+,   Cooldown = require('ezl/loop/cooldown').Cooldown
+,   Loc = loc.Loc, BoundingBox = loc.BoundingBox
+;
+
+var Thing =
+exports.Thing =
+new Evt.Class('Thing', {
     
     init : function init(align){
         this.id    = Thing.THING_ID++;
@@ -75,7 +82,7 @@ Thing = new Evt.Class('Thing', {
             this.shape.position(x,y);
         
         // this.createBoundingBox(x,y);
-        var bb = this.boundingBox = new Loc.BoundingBox(x1,y1, x2,y2);
+        var bb = this.boundingBox = new BoundingBox(x1,y1, x2,y2);
         this.midpoint = bb.midpoint();
         
         return this;
similarity index 100%
rename from src/tanks/ui/grid.js
rename to src/tanks/ui/grid.cjs
diff --git a/src/tanks/ui/index.cjs b/src/tanks/ui/index.cjs
new file mode 100644 (file)
index 0000000..e69de29
similarity index 100%
rename from src/tanks/ui/main.js
rename to src/tanks/ui/main.cjs
similarity index 100%
rename from src/tanks/ui/ui.js
rename to src/tanks/ui/ui.cjs
index 38ae17b..7809517 100644 (file)
--- a/tanks.php
+++ b/tanks.php
@@ -68,26 +68,26 @@ class Tanks {
         
         "src/evt/evt.class.js",
         
-        "src/easel/math/math.js",
-        "src/easel/math/vec.js",
-        "src/easel/math/line.js",
-        
-        "src/easel/layer.js",
-        "src/easel/shape/shape.js",
-        "src/easel/shape/circle.js",
-        "src/easel/shape/rect.js",
-        "src/easel/shape/line.js",
-        "src/easel/shape/polygon.js",
-        
-        "src/easel/util/binaryheap.js",
-        "src/easel/util/graph.js",
-        "src/easel/util/astar.js",
-        
-        "src/easel/util/tree/quadtree.js",
-        
-        "src/easel/loop/eventloop.js",
-        "src/easel/loop/fps.js",
-        "src/easel/loop/cooldown.js",
+        "src/ezl/math/math.js",
+        "src/ezl/math/vec.js",
+        "src/ezl/math/line.js",
+        
+        "src/ezl/layer.js",
+        "src/ezl/shape/shape.js",
+        "src/ezl/shape/circle.js",
+        "src/ezl/shape/rect.js",
+        "src/ezl/shape/line.js",
+        "src/ezl/shape/polygon.js",
+        
+        "src/ezl/util/binaryheap.js",
+        "src/ezl/util/graph.js",
+        "src/ezl/util/astar.js",
+        
+        "src/ezl/util/tree/quadtree.js",
+        
+        "src/ezl/loop/eventloop.js",
+        "src/ezl/loop/fps.js",
+        "src/ezl/loop/cooldown.js",
     );
     
     static function writeTags($scripts=null, $prefix="", $recompile=true) {