Skip to content

Commit

Permalink
小调整
Browse files Browse the repository at this point in the history
  • Loading branch information
zsxsoft committed Mar 21, 2015
1 parent ace9bf2 commit f97b0c8
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/cache
/webkitbuilds

# Logs
logs
*.log
Expand Down Expand Up @@ -73,3 +76,4 @@ $RECYCLE.BIN/

# Windows shortcuts
*.lnk

52 changes: 52 additions & 0 deletions build/config.gypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Do not edit. File was generated by nw-gyp's "configure" step
{
"target_defaults": {
"cflags": [],
"default_configuration": "Release",
"defines": [],
"include_dirs": [],
"libraries": []
},
"variables": {
"clang": 0,
"host_arch": "x64",
"icu_data_file": "icudt54l.dat",
"icu_data_in": "../../deps/icu/source/data/in\\icudt54l.dat",
"icu_endianness": "l",
"icu_gyp_path": "tools/icu/icu-generic.gyp",
"icu_locales": "en,root",
"icu_path": "deps\\icu",
"icu_small": "true",
"icu_ver_major": "54",
"node_has_winsdk": "true",
"node_install_npm": "true",
"node_prefix": "",
"node_shared_cares": "false",
"node_shared_http_parser": "false",
"node_shared_libuv": "false",
"node_shared_openssl": "false",
"node_shared_v8": "false",
"node_shared_zlib": "false",
"node_tag": "",
"node_use_dtrace": "false",
"node_use_etw": "true",
"node_use_mdb": "false",
"node_use_openssl": "true",
"node_use_perfctr": "true",
"openssl_no_asm": 0,
"python": "C:\\Python27\\python.exe",
"target_arch": "x64",
"uv_library": "static_library",
"v8_enable_gdbjit": 0,
"v8_enable_i18n_support": 1,
"v8_no_strict_aliasing": 1,
"v8_optimized_debug": 0,
"v8_random_seed": 0,
"v8_use_snapshot": "false",
"visibility": "",
"want_separate_host_toolset": 0,
"nodedir": "C:\\Users\\sx\\.nw-gyp\\0.12.0",
"copy_dev_lib": "true",
"standalone_static_library": 1
}
}
3 changes: 2 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module.exports = {
socket: {
url: "http://127.0.0.1:3000",
password: "123456",
room: "default"
room: "default",
heartbeat: 3000
},
display: {
comment: {
Expand Down
44 changes: 44 additions & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';

module.exports = function(grunt) {
var packageJson = grunt.file.readJSON('package.json');
var encode = grunt.option('encode') || 'utf8';
var language = grunt.option('language') || 'node';
var doNotCompile = grunt.option("without-compile") || false;
language = language.toLowerCase();

grunt.initConfig({
pkg: packageJson,
nodewebkit: {
options: {
platforms: ['win'],
buildDir: './webkitbuilds',
appName: "nw"
},
src: ['./*', './lib/**', './node_modules/socket.io-client/**', './node_modules/nw-penetrate/**'], // Your node-webkit app

},
jshint: {
options: {
"-W061": true
},
src: ['./app.js', './lib/*'],
},
});


grunt.loadNpmTasks('grunt-node-webkit-builder');
grunt.loadNpmTasks('grunt-contrib-jshint');


grunt.registerTask('default', 'danmu-client', function() {
var tasks = [];
tasks.push("jshint", "nodewebkit");
grunt.task.run(tasks);

// 懒得用grunt插件了

});


};
18 changes: 9 additions & 9 deletions lib/danmu/danmu/commentframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ module.exports = {
*/
function generateSpeed(style, x, y, lifeTime) {
if (style == "Scroll") {
return speed = {
return {
x: -(x + width) / lifeTime, //-(移动距离+文本宽度)/(移动时间*帧数)
y: 0
};
} else if (style == "Static") {
return speed = {
return {
x: 0,
y: 0
};
Expand All @@ -108,7 +108,7 @@ module.exports = {
} else if (style == "Static") {
return (that.width - textWidth) / 2;
}
};
}

/**
* 检查是否与当前Frame中其他弹幕重叠
Expand All @@ -126,7 +126,7 @@ module.exports = {
}
}
return false; //没有重叠
};
}
/**
* 确定弹幕的y坐标
* @param style 弹幕类型
Expand All @@ -142,11 +142,11 @@ module.exports = {

while (typeof that.layers[index] == "undefined") { //如果当前弹幕层还不存在
//增加弹幕层
that.layers.push(new Array());
that.layers.push([]);
}

var y = 0;
if (style == "Scroll") { //滚动字幕尽量向顶部聚集,但不重叠
var y = 0;
while (y < that.height - size) {
if (checkDanmu(y, size, index)) {
y++;
Expand All @@ -158,7 +158,7 @@ module.exports = {
}
}
} else if (style == "Static") { //底部字幕尽量向底部聚集,但不重叠
var y = that.height - height - 8; //从底部-文字高度-底部边距的位置开始往上排,默认底部边距是8.
y = that.height - height - 8; //从底部-文字高度-底部边距的位置开始往上排,默认底部边距是8.
while (y > 0) {
if (checkDanmu(y, size, index)) {
y--;
Expand All @@ -172,7 +172,7 @@ module.exports = {
}
//没有合适位置,再次调用本方法
return generateY(style, size, index + 1);
};
}
};

/**
Expand All @@ -186,7 +186,7 @@ module.exports = {
var customSprite = new CustomComment(param);

while (typeof this.layers[this.layers.length - 1] == "undefined") { //如果当前弹幕层还不存在
this.layers.push(new Array()); //增加弹幕层
this.layers.push([]); //增加弹幕层
}
this.layers[this.layers.length - 1].push(customSprite);
};
Expand Down
2 changes: 1 addition & 1 deletion lib/danmu/danmu/ddloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ var plugins = [
];
for (var i = 0; i <= plugins.length - 1; i++) {
plugins[i].init.call(this, DD);
};
}
module.exports = DD;
11 changes: 6 additions & 5 deletions lib/danmu/danmu/ddplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ var DD = DD || {


DD.extend = function(obj, source) {
var prop;
// ECMAScript5 compatibility based on: http://www.nczonline.net/blog/2012/12/11/are-your-mixins-ecmascript-5-compatible/
if (Object.keys) {
var keys = Object.keys(source);
for (var i = 0, il = keys.length; i < il; i++) {
var prop = keys[i];
prop = keys[i];
Object.defineProperty(obj, prop, Object.getOwnPropertyDescriptor(source, prop));
}
} else {
var safeHasOwnProperty = {}.hasOwnProperty;
for (var prop in source) {
for (prop in source) {
if (safeHasOwnProperty.call(source, prop)) {
obj[prop] = source[prop];
}
Expand All @@ -31,7 +32,7 @@ for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
}

if (window.requestAnimationFrame === undefined && window['setTimeout'] !== undefined) {
if (window.requestAnimationFrame === undefined && window.setTimeout !== undefined) {
window.requestAnimationFrame = function(callback) {
var currTime = Date.now(),
timeToCall = Math.max(0, 16 - (currTime - lastTime));
Expand All @@ -43,9 +44,9 @@ if (window.requestAnimationFrame === undefined && window['setTimeout'] !== undef
};
}

if (window.cancelAnimationFrame === undefined && window['clearTimeout'] !== undefined) {
if (window.cancelAnimationFrame === undefined && window.clearTimeout !== undefined) {
window.cancelAnimationFrame = function(id) {
window.clearTimeout(id)
window.clearTimeout(id);
};
}

Expand Down
4 changes: 2 additions & 2 deletions lib/danmu/danmu/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* 开始动画
*/
begin: function() {
if (this.renderTimer != null) return; //防止重复启动
if (this.renderTimer !== null) return; //防止重复启动

//使用html5新增的requestAnimFrame API
var that = this;
Expand All @@ -58,7 +58,7 @@
* 停止动画
*/
stop: function() {
if (this.renderTimer == null) return;
if (this.renderTimer === null) return;
window.cancelAnimationFrame(this.renderTimer);
this.renderTimer = null;
},
Expand Down
2 changes: 1 addition & 1 deletion lib/danmu/danmu/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ module.exports = {
* 发送弹幕
*/
sendDanmus: function(url, vid, uid, text, style, color, font) {
if (text == null || text.trim() == "") return; //空弹幕返回
if (text === null || text.trim() === "") return; //空弹幕返回

var content = {
'start': 0,
Expand Down
6 changes: 3 additions & 3 deletions lib/danmu/danmu/sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = {
move: function() {
this.x += this.speed.x;
this.y += this.speed.y;
if (this.children != null) {
if (this.children !== null) {
for (var i = 0; i < this.children.length; i++) {
this.children[i].speed = this.speed;
this.children[i].move();
Expand All @@ -53,7 +53,7 @@ module.exports = {
* 向此精灵添加一个子精灵
*/
appendChild: function(sprite) {
if (this.children == null) {
if (this.children === null) {
this.children = [];
}
this.children.push(sprite);
Expand All @@ -63,7 +63,7 @@ module.exports = {
* 渲染子精灵
*/
drawChildren: function() {
if (this.children != null) {
if (this.children !== null) {
for (var i = 0; i < this.children.length; i++) {
this.children[i].draw();
}
Expand Down
8 changes: 4 additions & 4 deletions lib/danmu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var player;
coordinator.on("gotDanmu", function(data) {
player.parseDanmus(data, player);
player.controlDanmu("update");
})
});

var showSingleBarrage = function(param) {
player.parseDanmus([{
Expand All @@ -31,7 +31,7 @@ var showSingleBarrage = function(param) {
'lifeTime': param.lifeTime
}], player);
player.controlDanmu("update");
}
};

// 测试用代码
window.barrage = showSingleBarrage;
Expand All @@ -40,9 +40,9 @@ window.tryDanmu = function() {
showSingleBarrage({
text: "Hello World",
color: "rgb(" + parseInt(Math.random() * 255) + "," + parseInt(Math.random() * 255) + "," + parseInt(Math.random() * 255) + ")"
})
});
}, 10);
}
};

module.exports = {
init: function(config, listener, object) {
Expand Down
3 changes: 2 additions & 1 deletion lib/listener/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
init: function(cfg) {
config = cfg;
io = require("socket.io-client")(config.socket.url);
io.heartbeatTimeout = config.socket.heartbeat;
realInit();
}
};
Expand All @@ -24,6 +25,6 @@
io.on("danmu", function(data) {
console.log(data.data);
coordinator.emit("gotDanmu", data.data);
})
});
};
})();
2 changes: 1 addition & 1 deletion lib/penetrate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
//window.tryDanmu();
}, 1000);
}
}
};
})();
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
"nw-penetrate": "*"
},
"dev-dependencies": {
"nw-gyp": "*"
"nw-gyp": "*",
"grunt": "~0.4.1",
"grunt-node-webkit-builder": "*",
"grunt-contrib-jshint": "*"
},
"window": {
"transparent": true,
Expand Down

0 comments on commit f97b0c8

Please sign in to comment.