From bedcf6459be9ae66e207f519f6bf8b749b222f33 Mon Sep 17 00:00:00 2001 From: dsc Date: Sun, 5 Dec 2010 05:29:28 -0800 Subject: [PATCH] The great module refactor continues -- seems mostly done. --- index.html | 2 +- src/Y/core.cjs | 69 +++++++++------------------- src/Y/delegate.cjs | 110 ++++++++++++++++++++++++++++++++++++++++++++ src/Y/index.cjs | 21 ++++----- src/Y/modules/y.kv.cjs | 29 +++++++----- src/Y/op.cjs | 11 +---- src/Y/type.cjs | 2 +- src/Y/types/array.cjs | 2 +- src/Y/types/collection.cjs | 33 +++++++------ src/Y/types/function.cjs | 64 ++++++++++--------------- src/Y/types/string.cjs | 13 +++-- src/Y/utils.cjs | 19 +------ src/ezl/layer.cjs | 2 +- src/tanks/index.js | 5 ++- src/tanks/map/level.cjs | 1 + src/tanks/map/pathmap.cjs | 4 +- src/tanks/thing/tank.cjs | 2 +- src/tanks/ui/main.cjs | 6 +- src/tanks/util/config.cjs | 2 +- tags.html | 4 +- tanks.php | 6 +- 21 files changed, 236 insertions(+), 171 deletions(-) create mode 100644 src/Y/delegate.cjs diff --git a/index.html b/index.html index 5fff680..fcf29d6 100644 --- a/index.html +++ b/index.html @@ -62,7 +62,7 @@
- +
diff --git a/src/Y/core.cjs b/src/Y/core.cjs index ee42dc3..72fa583 100644 --- a/src/Y/core.cjs +++ b/src/Y/core.cjs @@ -1,21 +1,13 @@ // Generic Collection Functions + var undefined , globals = (function(){ return this; })() , _Function = globals.Function , _Array = globals.Array -, PT = "prototype" -, slice = _Array[PT].slice -, type = require('Y/type') -; - -// function slice(a){ -// return _asl.apply(a, _asl.call(arguments, 1)); -// } +, slice = _Array.prototype.slice -function notWrapped(fn){ - var self = arguments.callee.caller; - return fn && fn !== self && fn.__wraps__ !== self; -} +, type = require('Y/type') +; function reduce(o, fn, acc){ if ( !o ) @@ -23,12 +15,12 @@ function reduce(o, fn, acc){ fn = _Function.toFunction(fn); var cxt = arguments[3] || o; - if ( notWrapped(o.reduce) ) - return o.reduce.apply(o, [fn, acc, cxt]); + + if ( o instanceof _Array ) + return o.reduce.call(o, fn, acc, cxt); for ( var name in o ) acc = fn.call(cxt, acc, o[name], name, o); - return acc; } @@ -38,17 +30,23 @@ function map(o, fn){ fn = _Function.toFunction(fn); var acc = {}, cxt = arguments[2] || o; - if ( notWrapped(o.map) ) - return o.map.apply(o, [fn, cxt]); + + if ( o instanceof _Array ) + return o.map(fn, cxt); for ( var name in o ) acc[name] = fn.call(cxt, o[name], name, o); - return acc; } function forEach(o, fn){ - map(o, fn, arguments[2] || o); + var cxt = arguments[2] || o; + + if ( o instanceof _Array ) + o.forEach(fn, cxt); + else + map(o, fn, cxt); + return o; } @@ -58,13 +56,13 @@ function filter(o, fn){ fn = _Function.toFunction(fn); var acc = {}, cxt = arguments[2] || o; - if ( notWrapped(o.filter) ) - return o.filter.apply(o, [fn, cxt]); + + if ( o instanceof _Array ) + return o.filter(fn, cxt); for ( var name in o ) if ( fn.call(cxt, o[name], name, o) ) acc[name] = o[name]; - return acc; } @@ -77,13 +75,6 @@ function set(o, key, value, def){ return o; } -function dset(o, key, value, def){ - if ( o && notWrapped(o.set) ) - return o.set.apply(o, slice.call(arguments,1)); - else - return set(o, key, value, def); -} - function attr(o, key, value, def){ if ( !o || key === undefined ) return o; @@ -91,30 +82,17 @@ function attr(o, key, value, def){ return extend(o, key); if ( value !== undefined || def !== undefined ){ - return dset(o, key, value, def); + return set(o, key, value, def); } else return o[key]; } -function dattr(o, key, value, def){ - if ( o && notWrapped(o.attr) ) - return o.attr.apply(o, slice.call(arguments,1)); - else - return attr(o, key, value, def); -} - function extend( A, B ){ 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); -} -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; @@ -125,7 +103,4 @@ exports['set'] = set; exports['attr'] = attr; exports['extend'] = extend; -exports['dset'] = dset; -exports['dattr'] = dattr; -exports['dextend'] = dextend; -exports['slice'] = slice; \ No newline at end of file +exports['slice'] = slice; diff --git a/src/Y/delegate.cjs b/src/Y/delegate.cjs new file mode 100644 index 0000000..016be83 --- /dev/null +++ b/src/Y/delegate.cjs @@ -0,0 +1,110 @@ +// Delegating Collection Functions +var undefined +, _Function = Function +, type = require('Y/type') +, core = require('Y/core') +, slice = core.slice +; + +function notWrapped(fn){ + var self = arguments.callee.caller; + return fn && fn !== self && fn.__wraps__ !== self; +} + +function reduce(o, fn, acc){ + if ( !o ) + return acc; + + fn = _Function.toFunction(fn); + var cxt = arguments[3] || o; + + if ( notWrapped(o.reduce) ) + return o.reduce.call(o, fn, acc, cxt); + + for ( var name in o ) + acc = fn.call(cxt, acc, o[name], name, o); + + return acc; +} + +function map(o, fn){ + if ( !o ) + return o; + + fn = _Function.toFunction(fn); + var acc = {}, cxt = arguments[2] || o; + + if ( notWrapped(o.map) ) + return o.map.call(o, fn, cxt); + + for ( var name in o ) + acc[name] = fn.call(cxt, o[name], name, o); + + return acc; +} + +function forEach(o, fn){ + var cxt = arguments[2] || o; + + if ( notWrapped(o.forEach) ) + o.forEach.call(o, fn, cxt); + else + map(o, fn, cxt); + + return o; +} + +function filter(o, fn){ + if ( !o ) + return o; + + fn = _Function.toFunction(fn); + var acc = {}, cxt = arguments[2] || o; + + if ( notWrapped(o.filter) ) + return o.filter.call(o, fn, cxt); + + for ( var name in o ) + if ( fn.call(cxt, o[name], name, o) ) + acc[name] = o[name]; + + return acc; +} + +function set(o, key, value, def){ + if ( o && notWrapped(o.set) ) + return o.set.apply(o, slice.call(arguments,1)); + else + return core.set(o, key, value, def); +} + +function attr(o, key, value, def){ + if ( !o || key === undefined ) return o; + + if ( notWrapped(o.attr) ) + return o.attr.apply(o, slice.call(arguments,1)); + + if ( type.isPlainObject(key) ) + return extend(o, key); + + if ( value !== undefined || def !== undefined ){ + return set(o, key, value, def); + } else + return o[key]; +} + +function extend( A, B ){ + 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]); } + + +exports['reduce'] = reduce; +exports['map'] = map; +exports['forEach'] = forEach; +exports['filter'] = filter; + +exports['set'] = set; +exports['attr'] = attr; +exports['extend'] = extend; diff --git a/src/Y/index.cjs b/src/Y/index.cjs index 41ecf34..387f5d7 100644 --- a/src/Y/index.cjs +++ b/src/Y/index.cjs @@ -16,15 +16,11 @@ exports['Y'] = Y; // same name as its namespace core.extend(type.type, type); -// Attach core & type to Y -core.extend(Y, core, type); -delete Y.slice; // grr - -// Make top-level setters refer to the delegating versions -Y['core'] = core; -Y['set'] = core.dset; -Y['attr'] = core.dattr; -Y['extend'] = core.dextend; +// Attach delegate-core & type to Y +var del = require('Y/delegate'); +core.extend(Y, type, del); +Y['core'] = core; +Y['delegate'] = del; /// Patch modules that weren't available earlier /// @@ -35,6 +31,7 @@ var yfn = require('Y/types/function') YFunction(Y); core.forEach(core, YFunction); +core.forEach(del, YFunction); YFunction(Y.type); Y['is'] = YFunction(Y.is).curry(); @@ -42,12 +39,10 @@ addNames('curry methodize genericize compose chain memoize', yfn); // Curry all operators var op = require('Y/op'); -core.forEach(op, YFunction); -// Y['op'] = op['curried'] = op.extend({}, core.map(op, yfn.curry)); Y['op'] = op['curried'] = core.reduce(op, function(Yop, fn, k){ - Yop[k] = fn.curry(); + Yop[k] = YFunction(fn).curry(); return Yop; }, {}); @@ -61,6 +56,8 @@ addNames('YObject', require('Y/types/object')); addNames('YString', require('Y/types/string')); addNames('YNumber range', require('Y/types/number')); +var utils = require('Y/utils'); +Y['bindAll'] = utils.bindAll; function addName(name){ Y[name] = this[name]; } function addNames(names, ns){ names.split(' ').forEach(addName, ns); } diff --git a/src/Y/modules/y.kv.cjs b/src/Y/modules/y.kv.cjs index a05be23..15a456a 100644 --- a/src/Y/modules/y.kv.cjs +++ b/src/Y/modules/y.kv.cjs @@ -5,22 +5,27 @@ var Y = require('Y').Y Y.YCollection.prototype.toKV = function toKV(del){ - return this.reduce(function(acc, v, k){ - return acc.push( enc(k) + '=' + enc(v) ); - }, Y([])) - .join(del !== undefined ? del : "&"); + return this + .reduce(encoder, Y([])) + .join(del !== undefined ? del : "&"); }; Y.YString.prototype.toObject = Y.YString.prototype.fromKV = function fromKV(del){ - return Y(this.split(del || '&')) - .reduce(function(acc, pair){ - var idx = pair.indexOf('=') - , k = dec(pair.slice(0,idx)) - , v = dec(pair.slice(idx+1)) ; - if (k) acc[k] = v; - return acc; - }, {}); + return this + .split(del || '&') + .reduce(decoder, {}); }; + +function encoder(acc, v, k){ + return acc.push( enc(k) + '=' + enc(v) ); +} +function decoder(acc, pair){ + var idx = pair.indexOf('=') + , k = dec(pair.slice(0,idx)) + , v = dec(pair.slice(idx+1)) ; + if (k) acc[k] = v; + return acc; +} \ No newline at end of file diff --git a/src/Y/op.cjs b/src/Y/op.cjs index e52348b..3b2971c 100644 --- a/src/Y/op.cjs +++ b/src/Y/op.cjs @@ -61,19 +61,12 @@ var core = require('Y/core') var args = slice.call(arguments,1); return function(obj){ if (obj && obj[name]) - return obj[name].apply( obj, args.concat(slice.call(arguments)) ); + return obj[name].apply( obj, args.concat(slice.call(arguments,0)) ); else return obj; }; - }, - extend : function extend(A,B){ - return slice.call(arguments,1).reduce(extender, A); } }; -function extender(target, donor){ - return core.reduce(donor, op.vkset, target); -} - -op.extend(exports, op); +core.extend(exports, op); diff --git a/src/Y/type.cjs b/src/Y/type.cjs index 9996392..966aab8 100644 --- a/src/Y/type.cjs +++ b/src/Y/type.cjs @@ -93,7 +93,7 @@ function type( o ) { function is( A, B ){ if ( isArray(B) ) - return B.map( is.bind(this,A) ).any(); + return B.map( is.bind(this,A) ).any(); // XXX: implicitly depends on YFunction, but we'll just quietly not use it else { var AT = type(A), BT = type(B); return (A instanceof BT || B instanceof AT || AT === BT); diff --git a/src/Y/types/array.cjs b/src/Y/types/array.cjs index c1f568b..abbab0c 100644 --- a/src/Y/types/array.cjs +++ b/src/Y/types/array.cjs @@ -8,7 +8,7 @@ YCollection.subclass('YArray', function(YArray){ mixin(YArray, { donor:Array, chain:true, names:'push unshift sort splice reverse'.split(' ') }); - mixin(YArray, { donor:Array, wrap:YArray, + mixin(YArray, { donor:Array, wrap:YArray.instantiate.bind(YArray), names:'map forEach filter slice'.split(' ') }); mixin(YArray, { donor:Array, names:'reduce some every indexOf lastIndexOf shift pop join'.split(' ') }); diff --git a/src/Y/types/collection.cjs b/src/Y/types/collection.cjs index 56eb0b9..529a329 100644 --- a/src/Y/types/collection.cjs +++ b/src/Y/types/collection.cjs @@ -1,18 +1,19 @@ -/** YCollection is the core of Y. */ +/** + * A generic collection (which also provides the majority of core functionality for YObject). + * Specializations are provided by subclasses. All subclasses must implement reduce(). + */ -var YBase = require('Y/class').YBase -, isFunction = require('Y/type').isFunction -, core = require('Y/core') -, op = require('Y/op') -, slice = core.slice -, extend = core.extend -, attr = core.attr -, bool = op.bool +var YBase = require('Y/class').YBase +// , type = require('Y/type') +, core = require('Y/core') +, del = require('Y/delegate') +, op = require('Y/op') +, slice = core.slice ; function extendY(){ - extend.apply(this, [this._o].concat(slice.call(arguments))); + del.extend.apply(this, [this._o].concat(slice.call(arguments))); return this; } @@ -23,7 +24,7 @@ YBase.subclass('YCollection', { }, 'attr' : function attr(k, v, def){ - var r = attr(this._o, k, v, def); + var r = del.attr(this._o, k, v, def); if (r === this._o) return this; else @@ -80,6 +81,7 @@ YBase.subclass('YCollection', { return new this.constructor().extend(this); }, + // Dependence on YArray closes the loop // 'remove' : function remove(v){ // var o = this._o // , toRemove = new Y(arguments); @@ -111,14 +113,14 @@ YBase.subclass('YCollection', { }, 'every' : function every( fn ){ - var self = this, fn = fn || bool; + var self = this, fn = fn || op.bool; return this.reduce(function(acc, v, k, o){ return acc && fn.call(self, v, k, o); }, true); }, 'any' : function any( fn ){ - var self = this, fn = fn || bool; + var self = this, fn = fn || op.bool; return this.reduce(function(acc, v, k, o){ return acc || fn.call(self, v, k, o); }, false); @@ -134,13 +136,14 @@ YBase.subclass('YCollection', { 'pluck' : function pluck(key){ return this.map(function(v){ - return v && (isFunction(v.attr) ? v.attr(key) : v[key]); + return del.attr(v, key); + // return v && (type.isFunction(v.attr) ? v.attr(key) : v[key]); }); }, 'invoke' : function invoke(name){ var args = slice.call(arguments,1); - return core.map(this, function(o){ + return del.map(this, function(o){ return o && o[name].apply(o, args); }); }, diff --git a/src/Y/types/function.cjs b/src/Y/types/function.cjs index 7d8f570..05d704d 100644 --- a/src/Y/types/function.cjs +++ b/src/Y/types/function.cjs @@ -38,7 +38,10 @@ core.extend( YFP, { }); - +function wraps(wrapper, fn) { + wrapper[WRAPS] = fn; + return YFunction(wrapper); +} function unwrap(fn){ return ( fn && isFunction(fn) ) ? unwrap(fn[WRAPS]) || fn : fn; @@ -63,9 +66,8 @@ function curry(fn){ return curry.apply(this, [fn].concat(_args)); } - curried[WRAPS] = fn; curried.__curried__ = args; - return curried; + return wraps(curried, fn); } @@ -80,8 +82,7 @@ function methodize(fn) { function methodized(){ return fn.apply(this, [this].concat( slice.call(arguments) )); }; - m[WRAPS] = fn; - return m; + return wraps(m, fn); } function genericize( fn ) { @@ -96,8 +97,7 @@ function genericize( fn ) { var args = slice.call(arguments); return fn.apply(args.shift(), args); }; - g[WRAPS] = fn; - return g; + return wraps(g, fn); }; @@ -131,7 +131,8 @@ function chain(f,g){ // function lazy(fn){ // var args = slice.call(arguments, 1) // , L = unwrap(fn).length -// , lazied = function(){ +// , lazied = +// function lazied(){ // var _args = slice.call(arguments) // , f = _args[0]; // @@ -146,19 +147,16 @@ function chain(f,g){ // return fn.apply(this, args); // else // return arguments.callee; -// } -// ; -// lazied[WRAPS] = fn; +// }; +// // lazied.__args = args; -// return lazied(); +// return wraps(lazied, fn)(); // } var _bind = _Function.prototype.bind; function bind(fn, context, args){ - var bound = _bind.apply(fn, slice.call(arguments,1)); - bound[WRAPS] = fn; - return YFunction(bound); + return wraps(_bind.apply(fn, slice.call(arguments,1)), fn); } @@ -169,8 +167,7 @@ function partial(fn){ function partially(){ return fn.apply( this, args.concat(slice.call(arguments)) ); }; - partially[WRAPS] = fn; - return YFunction(partially); + return wraps(partially, fn); } @@ -197,15 +194,14 @@ function memoize(fn){ return cache[key]; }; - m[WRAPS] = fn; m.purge = function purge(){ var cache = this.cache; this.cache = {}; return cache; }; - m.purge(); - return m; + + return wraps(m, fn); } // Memorized to reduce eval costs @@ -214,12 +210,13 @@ _ofArityWrapper = YFunction._ofArityWrapper = memoize(function(n, limit){ var i = n, args = []; - while (i-- > 0) args.unshift('$'+i); - // range(n).map( op.add('$') ).join(',') - return eval('(function '+(limit ? 'limited' : 'artized')+'(fn){ '+ - 'return function('+args.join(',')+'){ '+ - 'return fn.apply(this,' + (limit ? 'slice.call(arguments, 0,'+n+')' : 'arguments')+ - '); }; })'); + while (i-- > 0) args.unshift('$'+i); // Can't use Y.range due to deps + return eval( + '(function '+(limit ? 'limited' : 'artized')+'(fn){ '+ + 'return wraps(function('+args.join(',')+'){ '+ + 'return fn.apply(this,' + (limit ? 'slice.call(arguments, 0,'+n+')' : 'arguments') + '); '+ + '}, fn); '+ + '})'); }); function aritize(fn, n){ @@ -272,7 +269,7 @@ function getName( fn ){ - +exports['wraps'] = wraps; exports['unwrap'] = unwrap; exports['curry'] = curry; exports['methodize'] = methodize; @@ -288,18 +285,7 @@ exports['getName'] = getName; // 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; diff --git a/src/Y/types/string.cjs b/src/Y/types/string.cjs index f8f608f..7edcac7 100644 --- a/src/Y/types/string.cjs +++ b/src/Y/types/string.cjs @@ -2,16 +2,17 @@ var YCollection = require('Y/types/collection').YCollection , mixin = require('Y/utils').mixin , op = require('Y/op') , core = require('Y/core') +, del = require('Y/delegate') , slice = core.slice ; exports['YString'] = YCollection.subclass('YString', function(YString){ - mixin(YString, { donor:String, wrap:YString, - names:'slice split substr substring concat replace toLowerCase toUpperCase'.split(' ') }); + mixin(YString, { donor:String, wrap:YString.instantiate.bind(YString), + names:'slice substr substring concat replace toLowerCase toUpperCase'.split(' ') }); mixin(YString, { donor:String, - names:'indexOf lastIndexOf charAt charCodeAt'.split(' ') }); + names:'split indexOf lastIndexOf charAt charCodeAt'.split(' ') }); function trim(val){ var s = this._o+''; @@ -24,7 +25,7 @@ YCollection.subclass('YString', function(YString){ return s; } - op.extend(this, { + core.extend(this, { init : function init(o){ if (!o) o = ""; this._o = o; @@ -121,7 +122,7 @@ YCollection.subclass('YString', function(YString){ var s = this._o; // set if ( value !== undefined || def !== undefined ) - return core.dattr(this, key, value, def); + return del.attr(this, key, value, def); // get else { @@ -133,7 +134,7 @@ YCollection.subclass('YString', function(YString){ return s[key]; } }; - this.attr.__wraps__ = core.dattr; + this.attr.__wraps__ = del.attr; this.reduce = function reduce(fn, acc){ fn = Function.toFunction(fn); diff --git a/src/Y/utils.cjs b/src/Y/utils.cjs index 6afbee3..cf0a5e0 100644 --- a/src/Y/utils.cjs +++ b/src/Y/utils.cjs @@ -2,6 +2,7 @@ var YFunction = require('Y/types/function').YFunction , isFunction = require('Y/type').isFunction , core = require('Y/core') , op = require('Y/op') +, slice = core.slice ; @@ -18,7 +19,7 @@ function bindAll(o, names){ names = core.map(o, op.nth(1)); else names = slice.call(arguments, 1); - names.forEach(bindName, o); + core.forEach(names, bindName, o); return o; } @@ -31,7 +32,7 @@ var defaults = { 'chain' : false }; function mixin(o, options){ - var opt = op.extend({}, defaults, options), Donor = opt.donor + var opt = core.extend({}, defaults, options), Donor = opt.donor , target = ( isFunction(o) ? o.prototype : o ) , proto = ( isFunction(Donor) ? Donor.prototype : Donor ) , names = opt.names @@ -50,19 +51,5 @@ function mixin(o, options){ return o; } - -// function chainDelegates(type, names){ -// var proto = type.prototype; -// names.forEach(function(name){ -// proto[name] = function(){ -// var o = this._o || this; -// o[name].apply(o, arguments); -// return this; -// }; -// }); -// return type; -// } -// exports['chainDelegates'] = chainDelegates; - exports['bindAll'] = bindAll; exports['mixin'] = mixin; diff --git a/src/ezl/layer.cjs b/src/ezl/layer.cjs index 1c5396c..0f5c5f2 100644 --- a/src/ezl/layer.cjs +++ b/src/ezl/layer.cjs @@ -51,7 +51,7 @@ Y.subclass('Layer', { this.negBleed = new Loc(0,0); this.posBleed = new Loc(0,0); - this.boundingBox = new Loc.BoundingBox(0,0, 0,0); + this.boundingBox = new BoundingBox(0,0, 0,0); this.transform = { origin : new Loc('50%','50%'), // rotational origin diff --git a/src/tanks/index.js b/src/tanks/index.js index deeb351..1083c58 100644 --- a/src/tanks/index.js +++ b/src/tanks/index.js @@ -1,11 +1,14 @@ +//#ensure "Y" //#ensure "tanks/globals" + var Y = require('Y').Y , ezl = require('ezl') ; require('tanks/globals'); -tanks = exports.tanks = { +// exports.tanks = +tanks = { 'config' : require('tanks/config'), 'ui' : require('tanks/ui'), 'Game' : require('tanks/game').Game, diff --git a/src/tanks/map/level.cjs b/src/tanks/map/level.cjs index 66075d0..8b752a2 100644 --- a/src/tanks/map/level.cjs +++ b/src/tanks/map/level.cjs @@ -3,6 +3,7 @@ var Y = require('Y').Y , Tank = require('tanks/thing/tank').Tank , PlayerTank = require('tanks/thing/player').PlayerTank , PathMap = require('tanks/map/pathmap').PathMap +, Wall = require('tanks/map/wall').Wall , diff --git a/src/tanks/map/pathmap.cjs b/src/tanks/map/pathmap.cjs index afa0177..9b002d9 100644 --- a/src/tanks/map/pathmap.cjs +++ b/src/tanks/map/pathmap.cjs @@ -1,6 +1,8 @@ // -*- mode: JavaScript; tab-width: 4; indent-tabs-mode: nil; -*- -var Y = require('Y').Y +var Y = require('Y').Y +, Vec = require('ezl/math/vec').Vec , QuadTree = require('ezl/util/tree/quadtree').QuadTree +, Bullet = require('tanks/thing/bullet').Bullet , PathMap = diff --git a/src/tanks/thing/tank.cjs b/src/tanks/thing/tank.cjs index 34c1644..8e43118 100644 --- a/src/tanks/thing/tank.cjs +++ b/src/tanks/thing/tank.cjs @@ -177,7 +177,7 @@ Thing.subclass('Tank', { }, willCollide : function willCollide(bullets, wiggle){ - bullets = ( !Y.isArray(bullets) ? [bullets] : bullets ); + bullets = ( !(Y.isArray(bullets) || bullets instanceof Y.YArray) ? [bullets] : bullets ); wiggle = wiggle || 0; var tank = this, bb = this.boundingBox diff --git a/src/tanks/ui/main.cjs b/src/tanks/ui/main.cjs index 19080f0..134e339 100644 --- a/src/tanks/ui/main.cjs +++ b/src/tanks/ui/main.cjs @@ -1,6 +1,8 @@ //#ensure "jquery" //#ensure "jquery.hotkeys.min" +require("Y/modules/y.kv"); + var Y = require('Y').Y , config = require('tanks/config') , uiconfig = require('tanks/ui/config') @@ -9,12 +11,11 @@ var Y = require('Y').Y , FpsSparkline = require('ezl/loop').FpsSparkline ; -qkv = Y(window.location.search.slice(1)).fromKV().end(); +qkv = Y(window.location.search.slice(1)).fromKV(); // Main method is only executed once, so we'll setup things // that don't change between games. function main(){ - console.log('main!'); /// Debug /// if (qkv.ai) { @@ -264,7 +265,6 @@ exports['toggleGame'] = toggleGame; exports['resizeGame'] = resizeGame; exports['gameover'] = gameover; exports['countdown'] = countdown; -exports['tickDown'] = tickDown; exports['readyToStart'] = readyToStart; exports['updateInfo'] = updateInfo; diff --git a/src/tanks/util/config.cjs b/src/tanks/util/config.cjs index f4b319d..2b90bba 100644 --- a/src/tanks/util/config.cjs +++ b/src/tanks/util/config.cjs @@ -7,7 +7,7 @@ Config = exports.Config = Y.YObject.subclass('Config', function(){ - Y.op.extend(this, { + Y.core.extend(this, { init : function initConfig(defaults){ this._defaults = defaults; diff --git a/tags.html b/tags.html index a988a4f..550439e 100644 --- a/tags.html +++ b/tags.html @@ -4,6 +4,7 @@ + @@ -42,15 +43,16 @@ + - + diff --git a/tanks.php b/tanks.php index cdcb047..60ca22d 100644 --- a/tanks.php +++ b/tanks.php @@ -104,13 +104,13 @@ class Tanks { $modules = ($modules ? $modules : self::$modules); $PYTHONPATH = "PYTHONPATH='/Users/dsc/.python/lib/python:/usr/local/lib/python2.7/site-packages:/usr/local/lib/python2.6/site-packages'"; error_reporting(E_ALL); - echo ""; - include "build/tags.html"; + echo "\n-->\n"; + include "tags.html"; } static function writeLoaders($modules=null, $recompile=true){ -- 1.7.0.4