Пример #1
0
  this.on('change', function() {
    var hex = [0, 0, 0]

    // Convert the [1, 1, 1] color to CSS hex value
    hex[0] = zfill(Math.round(self.value[0] * 255).toString(16), 2)
    hex[1] = zfill(Math.round(self.value[1] * 255).toString(16), 2)
    hex[2] = zfill(Math.round(self.value[2] * 255).toString(16), 2)

    display.style.background = '#' + hex.join('')
  })
Пример #2
0
    downloadAlbum: function (album) {
        var count = 1;
        for (var track in album['tracks']){
            if (album['tracks'].hasOwnProperty(track)) {
                var track_meta = {
                    'artist': album['artist'],
                    'album': album['title'],
                    'title': album['tracks'][track]['title'],
                    'track': album['tracks'][track]['track'],
                    'date': album['date'],
                    'cover': album['art']
                };

                if (process.env.NODE_ENV == 'dev') {
                    logger.format('Accessing track ' + count + ' of ' + album['tracks'].length);
                }

                var dirname = this.createDirectory(this.templateToPath(track_meta));
                var filename = utf8.encode(zfill(track_meta['track'], 2) + ' - ' + slugify(track_meta['title']) + '.mp3');

                try{
                    var track_url = album['tracks'][track]['url'];

                    //Check and see if HTTP is in the track_url
                    if (track_url.indexOf('http') < 0) {
                        track_url = 'http:' + track_url;
                    }
                    download(track_url, dirname + filename, filename, dirname, track_meta['track'], album);

                    //this.write_id3_tags(filename, track_meta);
                }
                catch (e){
                    if (process.env.NODE_ENV == 'dev') {
                        logger.format(e);
                        logger.format('Downloading failed..');
                    }
                    return false;
                }

                count++;
            }
        }
        return true;
    }
Пример #3
0
Color.prototype.toString = function() {
  return "#" + zfill(this.red.toString(16), 2) +
    zfill(this.green.toString(16), 2) +
    zfill(this.blue.toString(16), 2);
};
Пример #4
0
module.exports = values.reduce(function(map, name, i) {
  map[name] = zfill(i, 2) + '-' + name
  return map
}, {})
Пример #5
0
describe("packets", function() {
  var client, server, serverClient;
  before(function(done) {
    server = new Server();
    server.once('listening', function() {
      server.once('connection', function(c) {
        serverClient = c;
        done();
      });
      client = new Client();
      client.setSocket(net.connect(25565, 'localhost'));
    });
    server.listen(25565, 'localhost');
  });
  after(function(done) {
    client.on('end', function() {
      server.on('close', done);
      server.close();
    });
    client.end();
  });
  var packetId, packetInfo, field;
  for(packetId in protocol.packets) {
    packetId = parseInt(packetId, 10);
    packetInfo = protocol.packets[packetId];
    it("0x" + zfill(parseInt(packetId, 10).toString(16), 2),
        callTestPacket(packetId, packetInfo));
  }
  function callTestPacket(packetId, packetInfo) {
    return function(done) {
      var batch = new Batch();
      batch.push(function(done) {
        testPacket(packetId, protocol.get(packetId, false), done);
      });
      batch.push(function(done) {
        testPacket(packetId, protocol.get(packetId, true), done);
      });
      batch.end(function(err, results) {
        done();
      });
    };
  }
  function testPacket(packetId, packetInfo, done) {
    // empty object uses default values
    var packet = {};
    packetInfo.forEach(function(field) {
      var value = field.type;
      packet[field.name] = values[field.type];
    });
    serverClient.once(packetId, function(receivedPacket) {
      delete receivedPacket.id;
      assertPacketsMatch(packet, receivedPacket);
      client.once(packetId, function(clientReceivedPacket) {
        delete clientReceivedPacket.id;
        assertPacketsMatch(receivedPacket, clientReceivedPacket);
        done();
      });
      serverClient.write(packetId, receivedPacket);
    });
    client.write(packetId, packet);
  }
  function assertPacketsMatch(p1, p2) {
    packetInfo.forEach(function(field) {
      assert.deepEqual(p1[field], p2[field]);
    });
    var field, cmp;
    for (field in p1) {
      assert.ok(field in p2, "field " + field + " missing in p2");
    }
    for (field in p2) {
      assert.ok(field in p1, "field " + field + " missing in p1");
    }
  }
});
Пример #6
0
describe("packets", function() {
  var client, server, serverClient;
  before(function(done) {
    server = new Server();
    server.once('listening', function() {
      server.once('connection', function(c) {
        serverClient = c;
        done();
      });
      client = new Client();
      client.setSocket(net.connect(25565, 'localhost'));
    });
    server.listen(25565, 'localhost');
  });
  after(function(done) {
    client.on('end', function() {
      server.on('close', done);
      server.close();
    });
    client.end();
  });
  var packetId, packetInfo, field;
  for(state in protocol.packetFields) {
    if (!protocol.packetFields.hasOwnProperty(state)) continue;
    for(packetId in protocol.packetFields[state].toServer) {
      if (!protocol.packetFields[state].toServer.hasOwnProperty(packetId)) continue;
      packetId = parseInt(packetId, 10);
      packetInfo = protocol.get(packetId, state, true);
      it(state + ",ServerBound,0x" + zfill(parseInt(packetId, 10).toString(16), 2),
        callTestPacket(packetId, packetInfo, state, true));
    }
    for(packetId in protocol.packetFields[state].toClient) {
      if (!protocol.packetFields[state].toClient.hasOwnProperty(packetId)) continue;
      packetId = parseInt(packetId, 10);
      packetInfo = protocol.get(packetId, state, false);
      it(state + ",ClientBound,0x" + zfill(parseInt(packetId, 10).toString(16), 2),
        callTestPacket(packetId, packetInfo, state, false));
    }
  }
  function callTestPacket(packetId, packetInfo, state, toServer) {
    return function(done) {
      client.state = state;
      serverClient.state = state;
      testPacket(packetId, packetInfo, state, toServer, done);
     };
  }
  function testPacket(packetId, packetInfo, state, toServer, done) {
    // empty object uses default values
    var packet = {};
    packetInfo.forEach(function(field) {
      if (!field.hasOwnProperty("condition") || field.condition(packet)) {
        var fieldVal = values[field.type];
        if (typeof fieldVal === "undefined") {
          throw new Error("No value for type " + field.type);
        }
        if (typeof fieldVal === "function") {
          fieldVal = fieldVal(field.typeArgs);
        }
        packet[field.name] = fieldVal;
      }
    });
    if (toServer) {
      serverClient.once([state, packetId], function(receivedPacket) {
        delete receivedPacket.id;
        assertPacketsMatch(packet, receivedPacket);
        done();
      });
      client.write(packetId, packet);
    } else {
      client.once([state, packetId], function(receivedPacket) {
        delete receivedPacket.id;
        assertPacketsMatch(packet, receivedPacket);
        done();
      });
      serverClient.write(packetId, packet);
    }
  }
  function assertPacketsMatch(p1, p2) {
    packetInfo.forEach(function(field) {
      assert.deepEqual(p1[field], p2[field]);
    });
    var field;
    for (field in p1) {
      assert.ok(field in p2, "field " + field + " missing in p2");
    }
    for (field in p2) {
      assert.ok(field in p1, "field " + field + " missing in p1");
    }
  }
});