Moves datafile list into data/loadlist.yaml, and out of source.
authordsc <david.schoonover@gmail.com>
Fri, 25 Feb 2011 05:03:02 +0000 (21:03 -0800)
committerdsc <david.schoonover@gmail.com>
Fri, 25 Feb 2011 05:03:02 +0000 (21:03 -0800)
15 files changed:
data/campaign.yaml [moved from data/game.yaml with 100% similarity]
data/loadlist.yaml [new file with mode: 0644]
data/types/buffs.yaml
data/types/items.yaml
data/types/player.yaml [new file with mode: 0644]
data/types/weapons.yaml [new file with mode: 0644]
pavement.py
src/tanks/config.cjs
src/tanks/game.cjs
src/tanks/inventory/inventory.cjs
src/tanks/map/pathing/map-pathing.cjs
src/tanks/thing/bullet.cjs
src/tanks/thing/item.cjs
src/tanks/thing/player.cjs
src/tanks/ui/main.cjs

similarity index 100%
rename from data/game.yaml
rename to data/campaign.yaml
diff --git a/data/loadlist.yaml b/data/loadlist.yaml
new file mode 100644 (file)
index 0000000..b5336e9
--- /dev/null
@@ -0,0 +1,9 @@
+- types/buffs
+- types/bullets
+- types/items
+# - types/weapons
+- types/units
+- types/levels
+# - types/player
+# - campaign
+# - hotkeys
index 05c4bce..5943194 100644 (file)
@@ -1,6 +1,8 @@
 name: buffs
 defaults:
     symbol: tanks/effects/buff.Buff
+    desc: ''
+    tags: []
     timeout: -1 # the YAML .Inf (Infinity literal) is not valid JSON according to the native decoders
     priority: 0
     stack_limit: 1
@@ -12,12 +14,8 @@ types:
     speedup:
         name: Speed Up
         desc: Speeds up your tank temporarily.
-        tags: [ 'movement' ]
+        tags: []
         timeout: 3.0
         stats:
             move: 0.5
-        effects: []
-        art:
-            icon: ''
-            inv_icon: ''
     
index b22d509..31211d7 100644 (file)
@@ -1,6 +1,7 @@
 name: items
 defaults:
     symbol: tanks/thing/item.Item
+    desc: ''
     passives: []
     effects: []
     cooldowns: []
@@ -11,7 +12,6 @@ types:
     backpack:
         name: Backpack
         bagName: backpack
-        desc: Your backpack.
         tags: [ 'bag', 'backpack' ]
         symbol: tanks/inventory/bag.Bag
         max: 12
@@ -21,7 +21,7 @@ types:
     nitro:
         name: Nitro
         desc: Speeds up your tank temporarily.
-        tags: [ 'movement' ]
+        tags: []
         passives: []
         # effects: [ 'speedup' ]
         effects:
diff --git a/data/types/player.yaml b/data/types/player.yaml
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/data/types/weapons.yaml b/data/types/weapons.yaml
new file mode 100644 (file)
index 0000000..e69de29
index 5b850e6..01d62e3 100755 (executable)
@@ -69,6 +69,7 @@ def sourceTags(tags=None):
 @task
 def build_data():
     "Converts all data files and core injects config."
+    
     info('Building data files...')
     for dirpath, dirs, files in os.walk(DATA_DIR):
         indir  = path(dirpath)
@@ -82,14 +83,19 @@ def build_data():
                 with in_.open('rU') as infile, out.open('w') as outfile:
                     json.dump(yaml.load(infile), outfile, indent=4)
     
-    info('Injecting config JSON...')
-    conf = path('build/tanks/config.js')
-    conf_json = path('build/data/config.json')
-    with conf.open('rU') as f:
-        conf_txt = f.read()
-    with conf_json.open('rU') as jf, conf.open('w') as out:
-        conf_data = jf.read()
-        out.write( conf_txt.replace('/*CONFIG_JSON*/', conf_data) )
+    info('Injecting config values...')
+    
+    def inject_json(into, data, replacing):
+        into = path(into)
+        data = path(data)
+        with into.open('rU') as f:
+            into_txt = f.read()
+        with data.open('rU') as df, into.open('w') as f:
+            data_txt = df.read()
+            f.write( into_txt.replace(replacing, data_txt) )
+    
+    inject_json(into='build/tanks/config.js', data='build/data/config.json',   replacing='/*CONFIG_DEFAULTS*/')
+    inject_json(into='build/tanks/config.js', data='build/data/loadlist.json', replacing='/*DATA_LOAD_LIST*/')
 
 @task
 def build_scripts():
index 433d37b..c7e91a6 100644 (file)
@@ -9,11 +9,10 @@ var Y        = require('Y').Y
 ,   Loader   = require('ezl/util/data/loader').Loader
 ,
 
-/// Config (Inserted Here) ///
-
+/// Config ///
 
 defaults =
-exports['defaults'] = /*CONFIG_JSON*/
+exports['defaults'] = /*CONFIG_DEFAULTS*/
 ,
 
 config =
@@ -22,28 +21,38 @@ exports['config'] = new Config(defaults)
 
 // Updates the midpoint square when square-size changes
 config.on('set:pathing.pathSquare', function(evt){
-    var sq = evt.data.newval;
-    config.set('pathing.pathSquareMid', new Vec(sq/2, sq/2));
+    var sq = evt.data.newval, half = sq/2;
+    config.set('pathing.pathSquareMid', new Vec(half, half));
 });
 config.set('pathing.pathSquare', config.get('pathing.pathSquare'));
 
 
 /// Load Data Files ///
 
-var loader;
-exports['dataLoader'] = function dataLoader(){
-    if (!loader){
-        var files = 
-            'types/buffs types/items types/bullets types/units types/levels' // levels game
-                .split(' ')
-                .map(function(type){
-                    var name = type.split('/').pop();
-                    ensure(tanks.data, name);
-                    return new DataFile('build/data/'+type+'.json', tanks.data[name]);
-                });
-        loader = new Loader(files);
+var
+loadlist =
+exports['loadlist'] = /*DATA_LOAD_LIST*/
+,
+
+loader =
+exports['loader'] = null
+,
+
+getLoader =
+exports['getLoader'] =
+    function getLoader(){
+        if (!loader){
+            var datafiles =
+                loadlist.map(
+                    function(path){
+                        var name = path.split('/').pop();
+                        ensure(tanks.data, name);
+                        return new DataFile('build/data/'+path+'.json', tanks.data[name]);
+                    });
+            loader = exports['loader'] = new Loader(datafiles);
+        }
+        return loader;
     }
-    return loader;
-};
+;
 
 
index 31183f3..b225073 100644 (file)
@@ -41,8 +41,6 @@ evt.subclass('Game', {
     
     
     init : function initGame(levelId){
-        // Y.bindAll(this);
-        
         if (levelId) this.levelId = levelId;
         
         this.byId = {};
@@ -85,20 +83,13 @@ evt.subclass('Game', {
         this.on('tick',     this.tick);
         
         this.level.setup(tanks.data);
-        
-        // if (this.player) {
-        //     this.backpack = new Backpack(this.player)
-        //             .appendTo( this.root )
-        //             .refresh();
-        // }
-        
         this.emit('ready', this);
     },
     
     destroy : function destroy(){
         this.stop();
         if (this.player) this.player.destroy();
-        Thing.removeListener('create',  this.noteUnit);
+        Thing.removeListener('create',  this.setGame);
         Thing.removeListener('created', this.addUnit);
         Thing.removeListener('destroy', this.killUnit);
         this.root.remove();
index 7ddf0f9..0a5f134 100644 (file)
@@ -73,10 +73,7 @@ evt.subclass('Inventory', {
         this._equipSlots.pluck('ui').invoke('refresh');
         this.equipSlots = this._equipSlots.end();
         
-        
-        // instantiate:
-        // - equip slots (w bookkeeping: equipment, equipBags)
-        // - belt
+        // TODO: belt
         
         this.owner.game.ui.layer.append('<div class="clearer"/>');
     },
index b60503a..6a34f1e 100644 (file)
@@ -155,12 +155,11 @@ Y.core.extend(Map.fn, {
         return new Vec(floor(x)*SIZE, floor(y)*SIZE);
     }
     
-})
-,
+});
 
 
 // Would be nice if I could make this an inner class (for once)
-Square =
+var Square =
 exports['Square'] =
 Y.subclass('Square', new Vec(0,0), {
     pathId : null, // instance of A* being run, to track when to reset
index 2c23beb..790799d 100644 (file)
@@ -67,6 +67,7 @@ Thing.subclass('Bullet', {
     },
     
     createStats : function createStats(){
+        // createStats() will copy owner's stats, and then apply values from prototype
         this.stats = stat.createStats(this.owner.stats, this.stats);
     },
     
index e69ea7c..40a69e5 100644 (file)
@@ -192,8 +192,9 @@ Thing.subclass('Item', {
 Item.on('speciate',
     function onSpeciate(evt){
         var NewItem = evt.data.species
-        ,   proto = NewItem.fn;
+        ,   proto   = NewItem.fn
+        ;
         proto.passives = Y(proto.passives.map(Buff.lookupOrSpeciate, Buff));
-        proto.effects  = Y(proto.effects.map(Buff.lookupOrSpeciate, Buff));
+        proto.effects  = Y(proto.effects.map(Buff.lookupOrSpeciate,  Buff));
     });
 
index e4a42e5..471cea1 100644 (file)
@@ -44,18 +44,11 @@ Tank.subclass('Player', {
         this.activeKeys = new Y.YArray();
         this.inventory = new Inventory(this);
         
-        // this.keydown   = this.keydown.bind(this);
-        // this.keyup     = this.keyup.bind(this);
-        // this.mousedown = this.mousedown.bind(this);
-        // this.mouseup   = this.mouseup.bind(this);
-        // this.mousemove = this.mousemove.bind(this);
-        
         if (this.replayMode) {
             this.replay = replay
             this.nextMove = replay.shift();
             
         } else {
-            
             $(document)
                 .bind('keydown',   this.keydown)
                 .bind('keyup',     this.keyup)
index e30b087..5ca519a 100644 (file)
@@ -75,7 +75,7 @@ function main(){
         });
     
     // Load all data files
-    cfg.dataLoader()
+    cfg.getLoader()
         .on('complete', function(evt){
             $('#loading').hide();
             $('#welcome').show();