if (!o)
return o;
if (arguments.length === 1)
- names = core.map(o, op.nth(1));
+ names = Object.keys(o);
else if ( !isArray(names) )
names = slice.call(arguments, 1);
core.forEach(names, bindName, o);
, cls = A.callee
, caller = unwrap(cls.caller)
, args = (caller === instantiate) ? A[0] : A
+ , init = instance.init
;
// Not subclassing
'args' : Y(args)
}, instance);
- var initialise = instance.__initialise__;
- if ( typeof initialise == 'function' )
- initialise.apply(instance, args);
+ if ( typeof init == 'function' )
+ init.apply(instance, args);
cls.emit('created', instance, {
'instance' : instance,
function createInitialise(cls){
function initialise(){
var instance = this
- , proto = cls.fn
- , binds = proto.__bind__ // list of names to bind
- , init = proto.init
- , inits = proto.__inits__
+ , proto = cls.fn // use prototype so super() calls pick up the right lists
+ , binds = proto.__bind__ // list of names to bind
+ , inits = proto.__inits__ // init functions
+ , super = cls.__super__
, args = Y(arguments)
;
if (binds)
Y.bindAll(instance, binds);
- if ( typeof init == 'function' && init !== arguments.callee )
- init.apply(instance, args);
-
if ( inits && inits.length )
inits.invoke('apply', instance, args);
+ else if (super && super.init )
+ super.init.apply(instance, args);
instance.emit('init', instance, {
'instance' : instance,
;
// Fix Constructors
- NewClass.__super__ = SuperClass; // don't override NewClass.constructor -- it should be Function
- NewClass.__bases__ = NewClass.fn.__bases__ = Y(mixins).concat( [SuperClass], SuperClass.__bases__ || [ Class, Object ] );
+ NewClass.__super__ = SuperClass; // don't override NewClass.constructor -- it should be Function
+ NewClass.__bases__ = prototype.__bases__ = Y(mixins).concat( [SuperClass], SuperClass.__bases__ || [ Class, Object ] );
prototype.constructor = prototype.__class__ = NewClass;
- prototype.__inits__ = new Y.YArray();
- NewClass.init = prototype.__initialise__ = createInitialise(NewClass);
-
+ var initialise = NewClass.init = prototype.init = createInitialise(NewClass)
+ , inits = NewClass.__inits__ = prototype.__inits__ = new Y.YArray();
+ if (members.init) NewClass.__inits__.push(members.init);
+ delete members.init;
// Record for metaprogramming
KNOWN_CLASSES[className] = NewClass;
if ( typeof members == 'function' ) {
// body fn is responsible for calling mixin, attaching statics, etc
members.call(prototype, NewClass);
-
+ var init = prototype.init;
+ if (init) {
+ NewClass.__inits__.remove(init).unshift(init);
+ prototype.init = initialise;
+ }
// Or add new instance methods
} else {
for (var k in members)
var mproto = (typeof mxn === "function") ? mxn.fn : mxn
, statics = mxn.__static__ || {}
, binds = mxn.__bind__
- , init = mproto.init
+ , inits = mproto.__inits__
, onCreate = mproto.onCreate
, firstMix = (bases && bases.indexOf(mxn) === -1)
;
cls.__bind__ = proto.__bind__ = cbinds.concat(binds).unique();
// Wrap init call
- if ( typeof init == 'function' )
- cinits.remove(init).unshift(init);
+ if ( inits.length )
+ cinits.extend(inits);
// Only perform these actions the first time we mix into this class
if (!firstMix)
exports['fabricate'] = Y.fabricate;
exports['lookupClass'] = lookupClass;
exports['mixin'] = mixin;
-exports['aggregate'] = aggregate;
\ No newline at end of file
+exports['aggregate'] = aggregate;
init : function initLayer(props, attrs, html){
- this.setup(props, attrs, html);
-
+ // Layer.init.call(this, props, attrs, html);
}
})
/// Setup ///
- setup : function setupLayer(props, attrs, html){
+ init : function initLayerable(props, attrs, html){
if (props !== undefined && props !== null) {
switch (typeof props) {
case 'boolean' : this.hasCanvas = props; break;
Game =
exports['Game'] =
evt.subclass('Game', {
+ __bind__ : [ 'setGame', 'addUnit', 'killUnit', 'tick' ],
+
// Config
gameoverDelay : null,
init : function initGame(levelId){
- Y.bindAll(this);
+ // Y.bindAll(this);
if (levelId) this.levelId = levelId;
/// Setup ///
hasUI : true,
reqs : null,
+ max : 1,
+ cols : 4,
// highlightIconOnOpen : true, // Whether to highlight the inventory icon when bag is open
/// Bookkeeping ///
Item.init.call(this);
},
-
/**
* @return {this}
*/
- showUI : function showUI(){
- if (!this.hasUI)
- return this;
- if (!this.ui)
+ createUI : function createUI(){
+ if (this.hasUI && !this.ui)
this.ui = new ContainerUI(this.owner, this, { 'name':this.bagName })
+ .hide()
.appendTo(this.owner.game.root)
.refresh();
- this.ui.show();
+ return this;
+ },
+
+ /**
+ * @return {this}
+ */
+ showUI : function showUI(){
+ if (this.hasUI) this.createUI().ui.show();
return this;
},
hideUI : function hideUI(){
- if (this.ui)
- this.ui.hide();
+ if (this.ui) this.ui.hide();
return this;
},
onAcquired : function onAcquired(evt, container){
Item.fn.onAcquired.apply(this, arguments);
- // this.parent = container;
- // this.showUI();
+ this.createUI();
},
onLost : function onLost(evt){
this.bagbag = new BagBag(this, owner);
- // TODO: Add saved items
- var backpack = tanks.data.items.backpack.instantiate();
- this.bagbag.addItem(backpack);
+ // TODO: Restore saved items
+ var backpack = this.defaultBag = tanks.data.items.backpack.instantiate();
+ this.addBag(backpack);
this.bagbag.ui.refresh();
// instantiate:
- // - equip slots
+ // - equip slots (w bookkeeping: equipment, equipBags)
// - belt
},
* @return {this}
*/
addItem : function addItem(item, bag){
+ if (!item)
+ throw new Error('Cannot move item: no item supplied!');
+
bag = this.getBag(bag, true);
if ( !bag )
throw new Error('Cannot add item: unknown bag '+bag+'!');
+ if ( !bag.checkReqs(item) )
+ throw new Error('Cannot move item '+item+' to container '+bag+'!');
+
+ this.items[item.__id__] = item;
return bag.addItem(item);
},
if ( !bag.checkReqs(item) )
throw new Error('Cannot move item '+item+' to container '+bag+'!');
+ this.items[item.__id__] = item;
idx = (idx !== undefined ? idx : bag._getEmptySlot());
return bag.moveItem(item, idx);
},
removeItem : function removeItem(item, bag, options){
if ( !this.hasItem(item, bag) )
return null;
+
item = this.getItem(item, bag);
if ( !item )
return null;
-
+
+ delete this.items[item.__id__];
return item.inv.bag.removeItem(item, options);
// TODO: Fire event?
},
},
addBag : function addBag(bag){
+ if (!bag) // TODO: Errorz!
+ return this;
+ var id = bag.__id__;
+ this.items[id] = bag;
+ this.bags[id] = bag;
+ if (bag.bagName)
+ this.namedBags[bag.bagName] = bag;
this.bagbag.addItem(bag);
return this;
},
Level =
exports['Level'] =
-new evt.Class('Level', {
+Rect.subclass('Level', {
__mixins__ : [ Speciated ],
_layerClasses : 'ezl layer level',
this.game = game;
this.map = new Map(0,0, this.width, this.height, capacity, buffer_size);
- var shape = this.shape = new Rect(this.width,this.height).fill('transparent');
- shape.layer.attr('class', this._layerClasses);
- this.bbox = shape.bbox;
+ Rect.init.call(this, this.width,this.height);
+ this.fill('transparent');
+ // var shape = this.shape = new Rect(this.width,this.height).fill('transparent');
+ // shape.layer.attr('class', this._layerClasses);
+ // this.bbox = shape.bbox;
},
setup : function setup(repo){
this.currentPassive = new Y.YArray();
this.inv = new ContainerMeta();
- this.activateGauge = new CooldownGauge(this.cooldowns.activate, REF_SIZE+1,REF_SIZE+1);
+ if (this.cooldowns.activate)
+ this.activateGauge = new CooldownGauge(this.cooldowns.activate, REF_SIZE+1,REF_SIZE+1);
this.on('collide', this.onCollide);
this.on('item.acquire', this.onAcquired);
return this;
},
- // TODO: Add to correct container
onCollide : function onCollide(evt){
- var unit = evt.data.unit;
- if (unit.hasInventory && unit.canAddItem())
- unit.addItem(this);
+ var unit = evt.data.unit
+ , inv = unit.inventory
+ if ( inv && inv.canAddItem(this) )
+ inv.addItem(this);
},
onAcquired : function onAcquired(evt, container){
this.layer.addClass('occupied');
var icon = item.art && item.art.inv_icon
- , src = this.itemEl =
+ , img = this.img =
jQuery('<img />')
.width(this.artWidth)
.height(this.artHeight)
revert : 'invalid',
zIndex : 10
})
- .attr('title', '<b>'+item.name+'</b><br/>'+item.desc)
+ .attr('title', '<b>'+item.name+'</b>'+(item.desc ? '<br/>'+item.desc : ''))
.tipsy({ 'html':true, 'gravity':$.fn.tipsy.autoNS })
;
- if (icon) src.attr('src', icon);
+ if (icon)
+ img.attr('src', icon);
- this.inner.append(item.activateGauge);
+ if (item.activateGauge)
+ this.inner.append(item.activateGauge);
this.inner.layer.bind('click', this.onActivate);
return this;
}
this.item = null;
- this.itemEl = null;
+ this.img = null;
return this;
},
if (icon) src.attr('src', icon);
- this.inner.append(item.activateGauge);
+ if (item.activateGauge)
+ this.inner.append(item.activateGauge);
this.inner.layer.bind('click', this.onActivate);
return this;
$('#loading').clone()
.attr('id', 'pause')
.hide()
- .css({ 'top':'1em', 'left':'1em', 'margin':0, 'width':'auto' })
+ // .css({ 'top':'1em', 'left':'1em', 'margin':0, 'width':'auto' })
.appendTo( $('body') )
.find('.box').html('<h1>Paused!</h1>');
.countdown { position:fixed; overflow:hidden; z-index:2000; text-align:center; border:10px solid #fff; color:#fff; }
#loading h2 { text-align:center; }
#welcome .box { cursor:pointer; }
+#pause { top:1em; left:1em; margin:0; width:auto; }
#notes { /* position:fixed; top:4em; right:1em; color:#BFBFBF;*/ }
#notes ul, #notes ol, #notes li { list-style:circle ! important; }
#notes li { margin-left:1em; }
.debug { z-index:5000; }
.debug .inner { top:0; right:0; padding:1em; }
-#info { position:absolute; top:1em; right:1em; }
+#info { position:absolute; top:1em; left:1em; }
#info .box { width:150px; }
#info #state { font-weight:bold; }
#info label { display:block; float:left; width:4em; margin-right:0.5em; color:#787878; }