Commits

Rob Williams committed d14e755

refactored views
eliminated dead code in views
removed test on view

  • Participants
  • Parent commits ec0f941

Comments (0)

Files changed (7)

File web/cdn/analyzer/GemPower.js

         assert.isRequiredType('theGem', theGem, 'Gem', Gem);
         this.gem = theGem;
         this.id = theGem.id;
-        GemPower.all.set(this.gem.key, this);
+        // Establish direct & indirect navigation
+        this.key = GemPower.key(this.id);
+        GemPower[this.key] = this;
+        GemPower.all.set(this.key, this);
     }
 });
 
 GemPower.initialize = function() {
     GemPower.all = new Hash();
 }
+
+GemPower.key = function(theId) {
+    return theId.capitalize().replace(/\s/g, '');
+}

File web/cdn/analyzer/GemPowerView.js

+// Integrated with Mootools 1.2.3
+// Requires gem classes
+
+var GemPowerView = new Class({
+    iconSource: function() {
+        var aBuffer = [];
+        aBuffer.push(GemPowerView.source);
+        if (this.gem.isSpecial) {
+            aBuffer.push('specials/');
+        }
+        if (this.iconName) {
+            aBuffer.push(this.iconName);
+        } else {
+            aBuffer.push(this.gem.key.toLowerCase());
+        }
+        aBuffer.push('.jpg');
+        return aBuffer.join('');
+    },
+
+    newCell: function() {
+        var aReturn = new Element('td', {});
+        aReturn.adopt(this.newIcon());
+        return aReturn;
+    },
+
+    newIcon: function() {
+        return new Element('img', {
+            alt: this.gem.id,
+            src: this.iconSource(),
+            title: this.gem.id,
+            height: this.iconHeight,
+            width: this.iconWidth
+        });
+    },
+
+    initialize: function(theGem) {
+        assert.isRequiredType('theGem', theGem, 'Gem', Gem);
+        this.gem = theGem;
+        this.iconHeight = 26;
+        this.iconWidth = 26;
+        // Establish direct & indirect navigation
+        this.key = theGem.key;
+        GemPowerView[this.key] = this;
+        GemPowerView.all.set(this.key, this);
+    }
+});
+
+GemPowerView.addAll = function() {
+    Gem.getAll().each(function(theGem) {
+        new GemPowerView(theGem);
+    });
+    GemPowerView.RedCrystalFacet.iconName = 'redfacet';
+    GemPowerView.RoseQuartzCrystal.iconName = 'redquartzcrystal';
+}
+
+GemPowerView.initialize = function() {
+    GemPowerView.sourceLocal = '../../cdn/3rd/GTD/';
+    GemPowerView.sourceRemote = 'http://gemtowerdefense.com/gems/';
+    GemPowerView.source = GemPowerView.sourceRemote;
+    GemPowerView.source = GemPowerView.sourceLocal;
+
+    GemPowerView.all = new Hash();
+    GemPowerView.addAll();
+}

File web/cdn/analyzer/GemView.js

     GemView.RoseQuartzCrystal.iconName = 'redquartzcrystal';
 }
 
-GemView.getAll = function() {
-    return GemView.all;
-}
-
-GemView.getRecipes = function() {
-    return GemView.all.filter(function(theView) {
-        return theView.gem.isRecipe;
-    });
-}
-
-GemView.getRegulars = function() {
-    return GemView.all.filter(function(theView) {
-        return theView.gem.isRegular;
-    });
-}
-
-GemView.getUpgrades = function() {
-    return GemView.all.filter(function(theView) {
-        return theView.gem.isUpgrade;
-    });
-}
-
 GemView.initialize = function() {
     GemView.sourceLocal = '../../cdn/3rd/GTD/';
     GemView.sourceRemote = 'http://gemtowerdefense.com/gems/';

File web/cdn/analyzer/presentation.js

 
         this.business = new BusinessTier();
         GemView.initialize();
+        GemPowerView.initialize();
 
-        $('ourCombinations').adopt(this.newCombinationTable());
-        $('ourPower'       ).adopt(this.newPowerTable()      );
-        $('ourRegulars'    ).adopt(this.newRegularTable()    );
+        $('ourCombinations').adopt(this.newCombinationTable() );
+        $('ourPowerDetail' ).adopt(this.newPowerDetailTable() );
+        $('ourPowerSummary').adopt(this.newPowerSummaryTable());
+        $('ourRegulars'    ).adopt(this.newRegularTable()     );
 /*
-        $('ourRecipes'     ).adopt(this.newRecipeTable()     );
-        $('ourUpgrades'    ).adopt(this.newUpgradeTable()    );
+        $('ourRecipes'     ).adopt(this.newRecipeTable()      );
+        $('ourUpgrades'    ).adopt(this.newUpgradeTable()     );
 */
 
         log.ended('main()', aBegan);
         return aReturn;
     },
 
+    newPowerDetailTable: function() {
+        var aReturn = new Element('table', {'class': 'power'});
+        GemPower.getAllByNatural().each(
+            function(theGemPower) {
+                aReturn.adopt(this.newPowerRow(theGemPower));
+            }, this
+        );
+        return aReturn;
+    },
+
     newPowerRow: function(theGemPower) {
         var aReturn = new Element('tr', {'class': 'power'});
         aReturn.adopt(GemView[theGemPower.gem.key].newCell());
         return aReturn;
     },
 
-    newPowerTable: function() {
+    newPowerSummaryTable: function() {
         var aReturn = new Element('table', {'class': 'power'});
+        var aRow = new Element('tr', {'class': 'power'});
+        aReturn.adopt(aRow);
         GemPower.getAllByNatural().each(
             function(theGemPower) {
-                aReturn.adopt(this.newPowerRow(theGemPower));
+                aRow.adopt(GemPowerView[theGemPower.key].newCell());
             }, this
         );
         return aReturn;

File web/cdn/analyzer/test.js

     },
     'Test all upgrade gems via Gem.getUpgrades()'
 );
-
-ourTestRunner.addTest(
-    function testViews() {
-        var aBiz = new BusinessTier();
-        GemView.initialize();
-        assert.isDefined('GemView.getAll()', GemView.getAll());
-        var aViews = GemView.getAll();
-        assert.areSame('$type(aViews)', $type(aViews), 'hash');
-        assert.areEqual(
-            'aViews.getLength()', aViews.getLength(), Gem.getAll().getLength()
-        );
-        aViews.each(function(v) {
-            assert.isRequiredType('v', v, 'GemView', GemView);
-            assert.isRequiredType('v.gem', v.gem, 'Gem', Gem);
-            assert.isPresentString('v.key', v.key);
-        });
-    },
-    'Test all gem views via GemView.getAll()'
-);

File web/www/analyzer/analyzer.html

     <script type="text/javascript" src="../../cdn/analyzer/business.js"></script>
     <script type="text/javascript" src="../../cdn/analyzer/data.js"></script>
     <script type="text/javascript" src="../../cdn/analyzer/GemView.js"></script>
+    <script type="text/javascript" src="../../cdn/analyzer/GemPowerView.js"></script>
     <script type="text/javascript" src="../../cdn/analyzer/presentation.js"></script>
     <script type="text/javascript">
       //<![CDATA[
         <td id="ourRegulars"></td>
       </tr>
     </table>
-    <div id="ourPower"></div>
+    <div id="ourPowerSummary"></div>
+    <div id="ourPowerDetail"></div>
   </body>
 </html>

File web/www/analyzer/test.html

     <script type="text/javascript" src="../../cdn/analyzer/business.js"></script>
     <script type="text/javascript" src="../../cdn/analyzer/data.js"></script>
     <script type="text/javascript" src="../../cdn/analyzer/GemView.js"></script>
+    <script type="text/javascript" src="../../cdn/analyzer/GemPowerView.js"></script>
     <script type="text/javascript" src="../../cdn/analyzer/test.js"></script>
     <style type="text/css" media="screen">
       @import url('../../cdn/common/TestRunner.css');