name: items
defaults:
symbol: tanks/thing/item.Item
+ passives: []
+ effects: []
+ cooldowns: []
+ art:
+ map_icon: ''
+ inv_icon: ''
types:
+ backpack:
+ name: Backpack
+ bagName: backpack
+ desc: Your backpack.
+ tags: [ 'bag', 'backpack' ]
+ symbol: tanks/inventory/bag.Bag
+ max: 12
+ art:
+ inv_icon: '/img/items/backpack.jpg'
nitro:
name: Nitro
desc: Speeds up your tank temporarily.
return args.reduce(_extend, A);
}
function _extend(A, donor){ return reduce(donor, attrvk, A); }
-function attrvk(o, v, k){ return attr(o, k, v, o[k]); }
+function attrvk(o, v, k){ return (v === undefined && o[k] === undefined) ? o : attr(o, k, v, o[k]); }
/**
* Fetches the descriptor for each property that is an accessor (getter/setter).
Thing.on('destroy', this.killUnit);
this.on('tick', this.tick);
- this.level.setup();
+ this.level.setup(tanks.data);
// if (this.player) {
// this.backpack = new Backpack(this.player)
/// Setup ///
hasUI : true,
- uiOptions : null,
reqs : null,
// highlightIconOnOpen : true, // Whether to highlight the inventory icon when bag is open
ui : null, // ContainerUI
- init : function initBag(owner, bagName){
- this.bagName = bagName;
- this.owner = owner;
+ init : function initBag(owner, bagName, options){
+ if (options) Y.core.extend(this, options);
+ if (owner) this.owner = owner;
+ if (bagName) this.bagName = bagName;
Item.init.call(this);
},
onAcquired : function onAcquired(evt, container){
Item.fn.onAcquired.apply(this, arguments);
// this.parent = container;
- this.showUI();
+ // this.showUI();
},
onLost : function onLost(evt){
BagBag =
exports['BagBag'] =
Bag.subclass('BagBag', {
- __mixins__ : [],
- __bind__ : [],
- __static__ : {},
/// Setup ///
hasUI : true,
- uiOptions : null,
+ max : 1,
+ cols : 3,
reqs : 'bag', // TODO: parse, enforce reqs
// highlightIconOnOpen : true, // Whether to highlight the inventory icon when bag is open
ui : null, // ContainerUI
- init : function initBagBag(inventory, player){
+ init : function initBagBag(inventory, player, options){
this.inventory = inventory;
- Bag.init.call(this, player, 'bagbag');
+ Bag.init.call(this, player, 'bagbag', options);
this.showUI();
if (this.ui) this.ui.layer.addClass('bagbag bag');
}
// Note item we're displacing, if any
, dispItem = this.slots[idx]
- , didDisplace = dispItem && dispItem !== item
- , sameOwner = this.owner && item.owner && this.owner === item.owner
+ , didDisplace = !!(dispItem && dispItem !== item)
+ , sameOwner = !!(this.owner && item.owner && this.owner === item.owner)
, newPickup = !(oldBag && sameOwner)
, inventoryMove = sameOwner && !this.hasItem(item)
, localMove = sameOwner && !inventoryMove
}
var eq = this.equipsContents
- , oldEq = oldBag.equipsContents
+ , oldEq = !!(oldBag && oldBag.equipsContents)
, isEquipped = sameOwner && oldEq
, evt = 'item'+(newPickup ? '.acquire' : '.move')+(eq ? (!isEquipped ? '.equip' : '') : (isEquipped ? '.unequip' : ''))
, dispEvt = 'item.move'+(!eq ? (oldEq ? '.equip' : '') : (!oldEq ? '.unequip' : ''))
if ( didDisplace ) {
oldBag._putItem(dispItem, oldIdx);
- oldBag._emitItemChange('item.move', dispItem, { 'idx':oldIdx, 'oldBag':this, 'oldIdx':idx });
- }
-
- if ( inventoryMove ) {
- if ( didDisplace ) {
- oldBag._putItem(dispItem, oldIdx);
- oldBag._emitItemChange('item.move', dispItem, { 'idx':oldIdx, 'oldBag':this, 'oldIdx':idx });
- }
- this._emitItemChange('item.move', item, { 'idx':idx, 'oldBag':inv.bag, 'oldIdx':inv.idx });
- } else {
- evt =
- dispEvt = 'item.'+(oldBag.equipsContents ? '.equip' : '');
- this._emitItemChange(evt, item, { 'idx':idx, 'oldBag':inv.bag, 'oldIdx':inv.idx });
+ oldBag._emitItemChange(dispEvt, dispItem, { 'idx':oldIdx, 'oldBag':this, 'oldIdx':idx });
}
return this;
;
// Bag bounds check
- if ( 0 <= idx && idx < this.max )
+ if ( idx < 0 || idx >= this.max )
return false;
if ( this.items[id] )
* @return {this}
*/
_emitItemChange : function _emitItemChange(evt, item, data){
- data = Y.extend({ 'item':item, 'bag':this, 'unit':this.owner }, data || {});
+ data = Y.core.extend({ 'item':item, 'bag':this, 'unit':this.owner }, data || {});
this.emit(evt, item, data, item);
item.emit(evt, this, data, this);
// unit.emit(evt, item, data); // inventory should take care of this
this.bagbag = new BagBag(this, owner);
+ // TODO: Add saved items
+ var backpack = tanks.data.items.backpack.instantiate();
+ this.bagbag.addItem(backpack);
+ this.bagbag.ui.refresh();
+
// instantiate:
- // - backpack
// - equip slots
// - belt
},
this.bbox = shape.bbox;
},
- setup : function setup(isReplay){
+ setup : function setup(repo){
var game = this.game;
this.bounds =
return Wall.createApply(wall.type, wall.args);
});
- var data = tanks.data.units;
+ var data = repo.units;
this.units.map(function(x){
- // if (isReplay && x.type === 'player')
- // return null;
var obj = data[x.type].instantiate(x.align);
return game.addUnit(obj, x.loc[0], x.loc[1]);
});
- var data = tanks.data.items;
+ var data = repo.items;
this.items.map(function(x){
var obj = data[x.type].instantiate();
return game.addUnit(obj, x.loc[0], x.loc[1]);
__bind__ : [ 'onItemUpdated', 'onDrop' ],
_layerClasses : 'item-container hud',
+ inherit : 'name title showTitle max cols'.split(' '),
+
name : null,
title : null,
showTitle : false,
defaultContainer : false,
max : 1,
- reqs : null,
+ cols : 3,
unit : null,
-
+ slots : null,
init : function initContainerUI(unit, container, options){
+ var keys = (options||{}).inherit || this.inherit;
+ for (var i=0, L=keys.length, k=keys[i]; i<L; k=keys[++i])
+ if (container[k]) this[k] = container[k];
+
if (options) Y.core.extend(this, options);
this.unit = unit;
this.container = container;
- if (!this._layerId && this.name) this._layerId = this.name+'_slot';
+ if (!this._layerId && this.name) this._layerId = this.name;
HtmlLayer.init.call(this);
if (this.showTitle)
this.layer.append( '<h3>'+(this.title || this.name.toLowerCase())+'</h3>' );
this.slots = new Y(0, this.max).map(this._makeSlot, this);
+ this.layer.append('<div class="clearer"/>');
if (this.defaultContainer) {
unit.on('item.acquire', this.onItemUpdated);
},
refresh : function refresh(){
+ var len = this.slots.length
+ , el = this.slots[0].layer
+ , cols = Math.min(this.cols,len)
+ , rows = Math.ceil(len / cols)
+ , w = el.outerWidth()
+ , m = parseInt(el.css('margin-left').slice(0,-2))
+ ;
+ this.layer.width( w*cols + m*2*cols );
+
this.slots.invoke('refresh');
this.layer.find('.slot')
.droppable({
ContainerUISlot =
exports['ContainerUISlot'] =
Layer.subclass('ContainerUISlot', {
- _layerClasses : 'item-container slot hud ',
+ _layerClasses : 'item-container slot hud',
hasCanvas : false,
artWidth : 50,
item : null,
- init : function initContainerUISlot(container, idx){
+ init : function initContainerUISlot(parent, idx){
Y.bindAll(this, 'onActivate', 'onDragStart');
Layer.init.call(this);
- this.container = container;
- this.inventory = container.inventory;
+ this.parent = parent;
+ this.container = parent.container;
this.idx = idx;
this.layer.addClass('slot'+idx);
this.inner =
},
toString : function(){
- return this.className+'(idx='+this.idx+', item='+this.item+')';
+ return 'ContainerUISlot(idx='+this.idx+', item='+this.item+')';
}
})
#game { position:absolute; width:100%; height:100%; margin:0; padding:0; }
#viewport { position:relative; margin:1em auto; cursor:crosshair; width:auto; /* width:500px; height:500px; overflow:hidden; top:50px; left:50px; */ }
#viewport .layer.grid { outline:1px solid rgba(255,255,255,0.1); }
-#backpack { position:absolute; bottom:1em; right:1em; width:304px; height:254px; }
-.item-container {}
+.item-container { position:absolute; }
.item-container h3 { color:#fff; margin:0.25em; padding:0.5em 0; }
.item-container .slot { float:left; position:relative; width:50px; height:50px; margin:0.25em; border:1px solid transparent; }
.item-container .slot.drophover { border:1px solid #FFF6AE; }
+#backpack { position:absolute; bottom:82px; right:1em; /* width:304px; height:254px; */ }
+#bagbag { bottom:1em; right:1em; }
.debug { z-index:5000; }