Fixes errors with display and bindall in webkit.
authordsc <david.schoonover@gmail.com>
Thu, 24 Feb 2011 21:43:02 +0000 (13:43 -0800)
committerdsc <david.schoonover@gmail.com>
Thu, 24 Feb 2011 21:43:02 +0000 (13:43 -0800)
src/Y/utils.cjs
src/evt.cjs
src/tanks/game.cjs
src/tanks/inventory/inventory.cjs
src/tanks/ui/inventory/containerui.cjs
www/css/lttl.css

index f517d16..d3b94a1 100644 (file)
@@ -1,6 +1,7 @@
 var YFunction  = require('Y/types/function').YFunction
 ,   type       = require('Y/type')
 ,   core       = require('Y/core')
+,   delegate   = require('Y/delegate')
 ,   op         = require('Y/op')
 ,   slice      = core.slice
 ,   isFunction = type.isFunction
@@ -26,7 +27,7 @@ function bindAll(o, names){
         names = Object.keys(o);
     else if ( !isArray(names) )
         names = slice.call(arguments, 1);
-    core.forEach(names, bindName, o);
+    delegate.forEach(names, bindName, o);
     return o;
 }
 
index cce95ee..d386765 100644 (file)
@@ -23,12 +23,11 @@ Class Methods
 Note: Metaprogramming events cannot depend on Class.
 */
 
-var Y       = require('Y').Y
-,   core    = require('Y/core')
-,   Emitter
-,   _Emitter = require('Y/modules/y.event').Emitter
-,   PolyEmitter = Emitter = require('Y/modules/y.polyevent').PolyEmitter
-,   unwrap  = require('Y/types/function').unwrap
+var Y           = require('Y').Y
+,   core        = require('Y/core')
+,   Emitter     = require('Y/modules/y.event').Emitter
+,   PolyEmitter = require('Y/modules/y.polyevent').PolyEmitter
+,   unwrap      = require('Y/types/function').unwrap
 
 // ,   isFunction      = Y.isFunction
 ,   KNOWN_CLASSES   = Class.KNOWN_CLASSES = exports['KNOWN_CLASSES'] = {}
@@ -40,8 +39,9 @@ var Y       = require('Y').Y
 ,   getDesc  = _Object.getOwnPropertyDescriptor
 ,   setDesc  = _Object.defineProperty
 
-,   objToString   = _Object[P].toString
-,   classToString = function toString(){ return this.className+"()"; }
+,   objToString      = _Object[P].toString
+,   classToString    = function(){ return "[class "+this.className+"]"; }
+,   instanceToString = function(){ return this.className+"()"; }
 
 ,   classStatics = [ 'instantiate', 'fabricate', 'subclass' ]
 ,   classMagic = [
@@ -83,7 +83,7 @@ function ConstructorTemplate() {
         instance.__id__ = GLOBAL_ID++;
         
         // Perform actions that should only happen once in Constructor
-        instance.__emitter__ = new Emitter(instance, cls);
+        instance.__emitter__ = new PolyEmitter(instance, cls);
         
         cls.emit('create', instance, {
             'instance' : instance,
@@ -215,15 +215,15 @@ function Class(className, Parent, members){
             prototype[k] = parentMembers[k];
     }
     
-    if ( prototype.toString === objToString ) // check SuperClass.fn.toString
-        prototype.toString = classToString;
-    
     NewClass.className = prototype.className = className;
     NewClass.prototype = NewClass.fn = prototype;
+    NewClass.toString = classToString;
+    if ( prototype.toString === objToString ) // XXX: check SuperClass.fn.toString
+        prototype.toString = instanceToString;
     
     // Add class emitter
     var ParentEmitter = (Parent.__emitter__ ? Parent : ClassFactory)
-    ,   ClassEmitter  = NewClass.__emitter__ = new Emitter(NewClass, ParentEmitter)
+    ,   ClassEmitter  = NewClass.__emitter__ = new PolyEmitter(NewClass, ParentEmitter)
     ,   mixins  = members.__mixins__ || []
     ;
     
@@ -305,7 +305,7 @@ function Class(className, Parent, members){
 // Decorate with emitter methods and
 // add metaprogramming data to Class object
 Class.__super__ = Object;
-Class.__emitter__ = new Emitter(Class);
+Class.__emitter__ = new PolyEmitter(Class);
 Class.fn = Class.prototype;
 Class.fn.__class__ = Class.fn.constructor = Class;
 Class.fn.__bases__ = Class.__bases__ = Y([ Object ]);
index 7f89224..31183f3 100644 (file)
@@ -152,6 +152,13 @@ evt.subclass('Game', {
             }, this.gameoverDelay);
     },
     
+    tickAnimations : function tickAnimations(animation){
+        var running = animation.tick(ELAPSED, NOW, TICKS);
+        if (!running)
+            animation.remove();
+        return running;
+    },
+    
     _filterLivingAllies : function filterLivingAllies(unit){
         return unit.align === this.playerAlign && !unit.dead;
     },
@@ -168,13 +175,6 @@ evt.subclass('Game', {
         }
     },
     
-    tickAnimations : function tickAnimations(animation){
-        var running = animation.tick(ELAPSED, NOW, TICKS);
-        if (!running)
-            animation.remove();
-        return running;
-    },
-    
     
     
     // *** Agent Management *** //
@@ -186,16 +186,20 @@ evt.subclass('Game', {
     },
     
     setGame : function setGame(unit){
-        if (unit instanceof Event)
+        if (unit instanceof Event) {
+            var evt = unit;
             unit = unit.data.instance;
+        }
         
         unit.game = this;
         return unit;
     },
     
     noteUnit : function noteUnit(unit){
-        if (unit instanceof Event)
-            unit = unit.trigger;
+        if (unit instanceof Event) {
+            var evt = unit;
+            unit = unit.data.instance || unit.trigger;
+        }
         
         unit.game = this;
         if (unit.dead) return unit;
@@ -224,8 +228,10 @@ evt.subclass('Game', {
     },
     
     addUnit : function addUnit(unit, x,y){
-        if (unit instanceof Event)
-            unit = unit.trigger;
+        if (unit instanceof Event) {
+            var evt = unit;
+            unit = unit.data.instance || unit.trigger;
+        }
         
         if (unit.dead) return unit;
         
index bab8540..7ddf0f9 100644 (file)
@@ -73,9 +73,12 @@ evt.subclass('Inventory', {
         this._equipSlots.pluck('ui').invoke('refresh');
         this.equipSlots = this._equipSlots.end();
         
+        
         // instantiate:
         // - equip slots (w bookkeeping: equipment, equipBags)
         // - belt
+        
+        this.owner.game.ui.layer.append('<div class="clearer"/>');
     },
     
     
@@ -235,8 +238,13 @@ evt.subclass('Inventory', {
         return this.bagbag.canAddItem(bag);
     },
     
-    checkReqs : function checkReqs(bag){
-        return this.bagbag.checkReqs(bag);
+    checkReqs : function checkReqs(item, bag){
+        if (item === undefined)
+            return this.bagbag.checkReqs(bag);
+        else if (bag !== undefined)
+            return this.getBag(bag).checkReqs(item);
+        else
+            return false;
     },
     
     /**
index a80ce54..c381bdd 100644 (file)
@@ -83,20 +83,26 @@ HtmlLayer.subclass('ContainerUI', {
         var d = evt.data
         ,   oldBag = d.oldBag
         ;
-        this.slots[d.idx].refresh();
+        this.slots.get(d.idx).refresh();
         if (oldBag)
-            oldBag.ui.slots[d.oldIdx].refresh();
+            oldBag.ui.slots.get(d.oldIdx).refresh();
     },
     
     onDrop : function onDrop(evt, ui){
-        var item = ui.draggable.data('item')
+        var inv = this.unit.inventory
+        ,   item = ui.draggable.data('item')
         ,   toIdx = $(evt.target).data('idx')
         ;
         // console.log('onDrop(item='+item+', bag='+this+', toIdx='+toIdx+')', evt);
-        this.unit.inventory.moveItem(item, this.container, toIdx);
-        
-        // Clear flag preventing the drag from activing the item
-        setTimeout(function(){ item.dragging = false; }, 250);
+        if ( inv.checkReqs(item, this.container) ) {
+            inv.moveItem(item, this.container, toIdx);
+            
+            // Clear flag preventing the drag from activing the item
+            setTimeout(function(){ item.dragging = false; }, 250);
+        } else {
+            var slot = ui.draggable.parent().data('container-slot');
+            slot.refresh();
+        }
     },
     
     
index d244776..2220090 100644 (file)
@@ -55,7 +55,7 @@ td { text-align:center; vertical-align:middle; }
     .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; }
 
-#ui { position:absolute; bottom:0; right:0; left:auto; top:auto; }
+#ui { position:absolute; bottom:0; right:0; left:auto; top:auto; width:auto; }
     #ui > .bag { position:relative; float:right; margin:0 0 1em 1em; }
     #weapon_slot .slot { /* background-image:url(); */ }
     #armor_slot .slot  {}