Skip to content

Commit c760a2b

Browse files
committed
Fix bug with animation time calculation. Causes animations to end too soon.
1 parent d8fde4d commit c760a2b

11 files changed

Lines changed: 145 additions & 113 deletions

dist/CommentCoreLibrary.js

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ var CoreComment = (function () {
161161
if (init === void 0) { init = {}; }
162162
this.mode = 1;
163163
this.stime = 0;
164-
this.text = "";
164+
this.text = '';
165165
this.ttl = 4000;
166166
this.dur = 4000;
167167
this.cindex = -1;
@@ -176,43 +176,43 @@ var CoreComment = (function () {
176176
this._color = 0xffffff;
177177
this._border = false;
178178
this._shadow = true;
179-
this._font = "";
179+
this._font = '';
180180
this._transform = null;
181181
if (!parent) {
182-
throw new Error("Comment not bound to comment manager.");
182+
throw new Error('Comment not bound to comment manager.');
183183
}
184184
else {
185185
this.parent = parent;
186186
}
187-
if (init.hasOwnProperty("stime")) {
188-
this.stime = init["stime"];
187+
if (init.hasOwnProperty('stime')) {
188+
this.stime = init['stime'];
189189
}
190-
if (init.hasOwnProperty("mode")) {
191-
this.mode = init["mode"];
190+
if (init.hasOwnProperty('mode')) {
191+
this.mode = init['mode'];
192192
}
193193
else {
194194
this.mode = 1;
195195
}
196-
if (init.hasOwnProperty("dur")) {
197-
this.dur = init["dur"];
196+
if (init.hasOwnProperty('dur')) {
197+
this.dur = init['dur'];
198198
this.ttl = this.dur;
199199
}
200200
this.dur *= this.parent.options.global.scale;
201201
this.ttl *= this.parent.options.global.scale;
202-
if (init.hasOwnProperty("text")) {
203-
this.text = init["text"];
202+
if (init.hasOwnProperty('text')) {
203+
this.text = init['text'];
204204
}
205-
if (init.hasOwnProperty("motion")) {
205+
if (init.hasOwnProperty('motion')) {
206206
this._motionStart = [];
207207
this._motionEnd = [];
208-
this.motion = init["motion"];
208+
this.motion = init['motion'];
209209
var head = 0;
210210
for (var i = 0; i < init['motion'].length; i++) {
211211
this._motionStart.push(head);
212212
var maxDur = 0;
213213
for (var k in init['motion'][i]) {
214214
var m = init['motion'][i][k];
215-
maxDur = Math.max(m.dur, maxDur);
215+
maxDur = Math.max(m.dur + m.delay, maxDur);
216216
if (m.easing === null || m.easing === undefined) {
217217
init['motion'][i][k]['easing'] = CoreComment.LINEAR;
218218
}
@@ -228,29 +228,29 @@ var CoreComment = (function () {
228228
if (init.hasOwnProperty('size')) {
229229
this._size = init['size'];
230230
}
231-
if (init.hasOwnProperty("border")) {
232-
this._border = init["border"];
231+
if (init.hasOwnProperty('border')) {
232+
this._border = init['border'];
233233
}
234-
if (init.hasOwnProperty("opacity")) {
235-
this._alpha = init["opacity"];
234+
if (init.hasOwnProperty('opacity')) {
235+
this._alpha = init['opacity'];
236236
}
237-
if (init.hasOwnProperty("alpha")) {
238-
this._alphaMotion = init["alpha"];
237+
if (init.hasOwnProperty('alpha')) {
238+
this._alphaMotion = init['alpha'];
239239
}
240-
if (init.hasOwnProperty("font")) {
241-
this._font = init["font"];
240+
if (init.hasOwnProperty('font')) {
241+
this._font = init['font'];
242242
}
243-
if (init.hasOwnProperty("x")) {
244-
this._x = init["x"];
243+
if (init.hasOwnProperty('x')) {
244+
this._x = init['x'];
245245
}
246-
if (init.hasOwnProperty("y")) {
247-
this._y = init["y"];
246+
if (init.hasOwnProperty('y')) {
247+
this._y = init['y'];
248248
}
249-
if (init.hasOwnProperty("shadow")) {
250-
this._shadow = init["shadow"];
249+
if (init.hasOwnProperty('shadow')) {
250+
this._shadow = init['shadow'];
251251
}
252-
if (init.hasOwnProperty("align")) {
253-
this.align = init["align"];
252+
if (init.hasOwnProperty('align')) {
253+
this.align = init['align'];
254254
}
255255
if (init.hasOwnProperty('axis')) {
256256
this.axis = init['axis'];
@@ -491,7 +491,7 @@ var CoreComment = (function () {
491491
set: function (s) {
492492
this._shadow = s;
493493
if (!this._shadow) {
494-
this.dom.className = this.parent.options.global.className + " noshadow";
494+
this.dom.className = this.parent.options.global.className + ' noshadow';
495495
}
496496
},
497497
enumerable: true,
@@ -902,7 +902,7 @@ var CommentSpaceAllocator = (function () {
902902
return;
903903
}
904904
if (comment.cindex >= this._pools.length) {
905-
throw new Error("cindex out of bounds");
905+
throw new Error('cindex out of bounds');
906906
}
907907
var index = this._pools[comment.cindex].indexOf(comment);
908908
if (index < 0)
@@ -1389,6 +1389,22 @@ var CommentFilter = (function () {
13891389
this.rules.push(rule);
13901390
};
13911391

1392+
/**
1393+
* Removes a rule
1394+
*
1395+
* @param rule - the rule that was added
1396+
* @return true if the rule was removed, false if not found
1397+
*/
1398+
CommentFilter.prototype.removeRule = function (rule) {
1399+
var index = this.rules.indexOf(rule);
1400+
if (index >= 0) {
1401+
this.rules.splice(index, 1);
1402+
return true;
1403+
} else {
1404+
return false;
1405+
}
1406+
};
1407+
13921408
/**
13931409
* Adds a modifier to be used
13941410
*

dist/CommentCoreLibrary.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/css/style.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,26 @@
5555

5656
/** Aliases for Chinese named fonts because they don't work on *nix **/
5757
@font-face{
58-
font-family: "\9ED1\4F53";
58+
font-family: '\9ED1\4F53';
5959
src:local('SimHei');
6060
}
6161

6262
@font-face{
63-
font-family: "\5B8B\4F53";
63+
font-family: '\5B8B\4F53';
6464
src:local('SimSun');
6565
}
6666

6767
@font-face{
68-
font-family: "\534E\6587\6977\4F53";
68+
font-family: '\534E\6587\6977\4F53';
6969
src:local('SimKai');
7070
}
7171

7272
@font-face{
73-
font-family: "\5E7C\5706";
73+
font-family: '\5E7C\5706';
7474
src:local('YouYuan');
7575
}
7676

7777
@font-face{
78-
font-family: "\5FAE\8F6F\96C5\9ED1";
78+
font-family: '\5FAE\8F6F\96C5\9ED1';
7979
src:local('Microsoft YaHei');
8080
}

dist/css/style.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/CommentProperties.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ Object 进行实现。
171171

172172
还有一个可选参数 `easing`,以补间函数形式提供。默认不提供时采用线性补间。
173173

174-
注意: `delay` 算在 `dur` 内。如 `dur=1000, delay=300`,则参数在 0-300ms 不动,在
175-
300-1000ms 时线性从 `from` 变化到 `to`。整个关键帧的长度由各个属性内,最大的 `dur`值决定。
174+
注意: `delay` 不算在 `dur` 内。如 `dur=1000, delay=300`,则参数在 0-300ms 不动,在
175+
300-1300ms 时线性从 `from` 变化到 `to`。整个关键帧的长度由各个属性内,最大的 `dur`值决定。
176176

177177
### alpha
178178
类型限制:mode > 6 or mode == 4 or mode == 5

src/core/Comment.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
* @license MIT License
66
* @description Comment abstraction based on DOM implementation
77
*/
8-
/// <reference path="Core.d.ts" />
9-
/// <reference path="CommentUtils.ts" />
8+
/// <reference path='Core.d.ts' />
9+
/// <reference path='CommentUtils.ts' />
1010
class CoreComment implements IComment {
1111
public static LINEAR:Function = function (t:number, b:number, c:number, d:number):number {
1212
return t * c / d + b;
1313
};
1414

1515
public mode:number = 1;
1616
public stime:number = 0;
17-
public text:string = "";
17+
public text:string = '';
1818
public ttl:number = 4000;
1919
public dur:number = 4000;
2020
public cindex:number = -1;
@@ -53,46 +53,46 @@ class CoreComment implements IComment {
5353
private _color:number = 0xffffff;
5454
private _border:boolean = false;
5555
private _shadow:boolean = true;
56-
private _font:string = "";
56+
private _font:string = '';
5757
private _transform:CommentUtils.Matrix3D = null;
5858

5959
public parent:ICommentManager;
6060
public dom:HTMLDivElement;
6161

6262
constructor(parent:ICommentManager, init:Object = {}) {
6363
if (!parent) {
64-
throw new Error("Comment not bound to comment manager.");
64+
throw new Error('Comment not bound to comment manager.');
6565
} else {
6666
this.parent = parent;
6767
}
68-
if (init.hasOwnProperty("stime")) {
69-
this.stime = init["stime"];
68+
if (init.hasOwnProperty('stime')) {
69+
this.stime = init['stime'];
7070
}
71-
if (init.hasOwnProperty("mode")) {
72-
this.mode = init["mode"];
71+
if (init.hasOwnProperty('mode')) {
72+
this.mode = init['mode'];
7373
} else {
7474
this.mode = 1;
7575
}
76-
if (init.hasOwnProperty("dur")) {
77-
this.dur = init["dur"];
76+
if (init.hasOwnProperty('dur')) {
77+
this.dur = init['dur'];
7878
this.ttl = this.dur;
7979
}
8080
this.dur *= this.parent.options.global.scale;
8181
this.ttl *= this.parent.options.global.scale;
82-
if (init.hasOwnProperty("text")) {
83-
this.text = init["text"];
82+
if (init.hasOwnProperty('text')) {
83+
this.text = init['text'];
8484
}
85-
if (init.hasOwnProperty("motion")) {
85+
if (init.hasOwnProperty('motion')) {
8686
this._motionStart = [];
8787
this._motionEnd = [];
88-
this.motion = init["motion"];
88+
this.motion = init['motion'];
8989
var head = 0;
9090
for (var i = 0; i < init['motion'].length; i++) {
9191
this._motionStart.push(head);
9292
var maxDur = 0;
9393
for (var k in init['motion'][i]) {
9494
var m = <IMotion> init['motion'][i][k];
95-
maxDur = Math.max(m.dur, maxDur);
95+
maxDur = Math.max(m.dur + m.delay, maxDur);
9696
if (m.easing === null || m.easing === undefined) {
9797
init['motion'][i][k]['easing'] = CoreComment.LINEAR;
9898
}
@@ -108,29 +108,29 @@ class CoreComment implements IComment {
108108
if (init.hasOwnProperty('size')) {
109109
this._size = init['size'];
110110
}
111-
if (init.hasOwnProperty("border")) {
112-
this._border = init["border"];
111+
if (init.hasOwnProperty('border')) {
112+
this._border = init['border'];
113113
}
114-
if (init.hasOwnProperty("opacity")) {
115-
this._alpha = init["opacity"];
114+
if (init.hasOwnProperty('opacity')) {
115+
this._alpha = init['opacity'];
116116
}
117-
if (init.hasOwnProperty("alpha")) {
118-
this._alphaMotion = init["alpha"];
117+
if (init.hasOwnProperty('alpha')) {
118+
this._alphaMotion = init['alpha'];
119119
}
120-
if (init.hasOwnProperty("font")) {
121-
this._font = init["font"];
120+
if (init.hasOwnProperty('font')) {
121+
this._font = init['font'];
122122
}
123-
if (init.hasOwnProperty("x")) {
124-
this._x = init["x"];
123+
if (init.hasOwnProperty('x')) {
124+
this._x = init['x'];
125125
}
126-
if (init.hasOwnProperty("y")) {
127-
this._y = init["y"];
126+
if (init.hasOwnProperty('y')) {
127+
this._y = init['y'];
128128
}
129-
if (init.hasOwnProperty("shadow")) {
130-
this._shadow = init["shadow"];
129+
if (init.hasOwnProperty('shadow')) {
130+
this._shadow = init['shadow'];
131131
}
132-
if (init.hasOwnProperty("align")) {
133-
this.align = init["align"];
132+
if (init.hasOwnProperty('align')) {
133+
this.align = init['align'];
134134
}
135135
if (init.hasOwnProperty('axis')) {
136136
this.axis = init['axis'];
@@ -353,7 +353,7 @@ class CoreComment implements IComment {
353353
set shadow(s:boolean) {
354354
this._shadow = s;
355355
if (!this._shadow) {
356-
this.dom.className = this.parent.options.global.className + " noshadow";
356+
this.dom.className = this.parent.options.global.className + ' noshadow';
357357
}
358358
}
359359

src/core/CommentSpaceAllocator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class CommentSpaceAllocator implements ISpaceAllocator {
147147
return;
148148
}
149149
if (comment.cindex >= this._pools.length) {
150-
throw new Error("cindex out of bounds");
150+
throw new Error('cindex out of bounds');
151151
}
152152
var index = this._pools[comment.cindex].indexOf(comment);
153153
if (index < 0)

0 commit comments

Comments
 (0)