@@ -280,12 +280,22 @@ var CoreComment = (function () {
280280 if ( init . hasOwnProperty ( "motion" ) ) {
281281 this . _motionStart = [ ] ;
282282 this . _motionEnd = [ ] ;
283+ this . motion = init [ "motion" ] ;
284+ var head = 0 ;
283285 for ( var i = 0 ; i < init [ "motion" ] . length ; i ++ ) {
286+ this . _motionStart . push ( head ) ;
284287 var maxDur = 0 ;
285288 for ( var k in init [ "motion" ] [ i ] ) {
286- maxDur = Math . max ( init [ "motion" ] [ i ] [ k ] . dur , maxDur ) ;
289+ var m = init [ "motion" ] [ i ] [ k ] ;
290+ maxDur = Math . max ( m . dur , maxDur ) ;
291+ if ( m . easing === null || m . easing === undefined ) {
292+ init [ "motion" ] [ i ] [ k ] [ "easing" ] = CoreComment . LINEAR ;
293+ }
287294 }
295+ head += maxDur ;
296+ this . _motionEnd . push ( head ) ;
288297 }
298+ this . _curMotion = 0 ;
289299 }
290300 if ( init . hasOwnProperty ( "color" ) ) {
291301 this . _color = init [ "color" ] ;
@@ -341,6 +351,9 @@ var CoreComment = (function () {
341351 if ( this . _y !== undefined ) {
342352 this . y = this . _y ;
343353 }
354+ if ( this . _alpha !== 1 ) {
355+ this . alpha = this . _alpha ;
356+ }
344357 } ;
345358
346359 Object . defineProperty ( CoreComment . prototype , "x" , {
@@ -569,7 +582,20 @@ var CoreComment = (function () {
569582 * groups.
570583 */
571584 CoreComment . prototype . animate = function ( ) {
572- for ( var i = 0 ; i < this . motion . length ; i ++ ) {
585+ if ( this . motion . length === 0 ) {
586+ return ;
587+ }
588+ if ( this . dur - this . ttl > this . _motionEnd [ this . _curMotion ] ) {
589+ this . _curMotion ++ ;
590+ } else {
591+ var currentMotion = this . motion [ this . _curMotion ] ;
592+ var time = ( this . dur - Math . max ( this . ttl , 0 ) ) - this . _motionStart [ this . _curMotion ] ;
593+ for ( var prop in currentMotion ) {
594+ if ( currentMotion . hasOwnProperty ( prop ) ) {
595+ var m = currentMotion [ prop ] ;
596+ this [ prop ] = m . easing ( Math . max ( time - m . delay , 0 ) , m . from , m . to - m . from , m . dur ) ;
597+ }
598+ }
573599 }
574600 } ;
575601
@@ -579,6 +605,17 @@ var CoreComment = (function () {
579605 CoreComment . prototype . finish = function ( ) {
580606 this . parent . finish ( this ) ;
581607 } ;
608+
609+ /**
610+ * Returns string representation of comment
611+ * @returns {string }
612+ */
613+ CoreComment . prototype . toString = function ( ) {
614+ return [ "[" , this . stime , "|" , this . ttl , "/" , this . dur , "]" , "(" , this . mode , ")" , this . text ] . join ( "" ) ;
615+ } ;
616+ CoreComment . LINEAR = function ( t , b , c , d ) {
617+ return t * c / d + b ;
618+ } ;
582619 return CoreComment ;
583620} ) ( ) ;
584621
@@ -1020,26 +1057,31 @@ function BilibiliParser(xmlDoc, text, warn){
10201057 try {
10211058 adv = JSON . parse ( format ( text ) ) ;
10221059 obj . shadow = true ;
1023- obj . x = parseInt ( adv [ 0 ] ) ;
1024- obj . y = parseInt ( adv [ 1 ] ) ;
1060+ obj . x = parseInt ( adv [ 0 ] , 10 ) ;
1061+ obj . y = parseInt ( adv [ 1 ] , 10 ) ;
10251062 obj . text = adv [ 4 ] . replace ( / ( \/ n | \\ n | \n | \r \n ) / g, "\n" ) ;
10261063 obj . rZ = 0 ;
10271064 obj . rY = 0 ;
10281065 if ( adv . length >= 7 ) {
1029- obj . rZ = parseInt ( adv [ 5 ] ) ;
1030- obj . rY = parseInt ( adv [ 6 ] ) ;
1066+ obj . rZ = parseInt ( adv [ 5 ] , 10 ) ;
1067+ obj . rY = parseInt ( adv [ 6 ] , 10 ) ;
10311068 }
1069+ obj . motion = [ ] ;
10321070 obj . movable = false ;
10331071 if ( adv . length >= 11 ) {
10341072 obj . movable = true ;
1035- obj . toX = adv [ 7 ] ;
1036- obj . toY = adv [ 8 ] ;
1037- obj . moveDuration = 500 ;
1038- obj . moveDelay = 0 ;
1039- if ( adv [ 9 ] != '' )
1040- obj . moveDuration = adv [ 9 ] ;
1041- if ( adv [ 10 ] != "" )
1042- obj . moveDelay = adv [ 10 ] ;
1073+ var motion = {
1074+ x :{ from : obj . x , to :parseInt ( adv [ 7 ] , 10 ) , dur :500 , delay :0 } ,
1075+ y :{ from : obj . y , to :parseInt ( adv [ 8 ] , 10 ) , dur :500 , delay :0 } ,
1076+ }
1077+ if ( adv [ 9 ] !== '' ) {
1078+ motion . x . dur = parseInt ( adv [ 9 ] , 10 ) ;
1079+ motion . y . dur = parseInt ( adv [ 9 ] , 10 ) ;
1080+ }
1081+ if ( adv [ 10 ] !== '' ) {
1082+ motion . x . delay = parseInt ( adv [ 10 ] , 10 ) ;
1083+ motion . y . delay = parseInt ( adv [ 10 ] , 10 ) ;
1084+ }
10431085 if ( adv . length > 11 ) {
10441086 obj . shadow = adv [ 11 ] ;
10451087 if ( obj . shadow === "true" ) {
@@ -1048,20 +1090,27 @@ function BilibiliParser(xmlDoc, text, warn){
10481090 if ( obj . shadow === "false" ) {
10491091 obj . shadow = false ;
10501092 }
1051- if ( adv [ 12 ] != null )
1093+ if ( adv [ 12 ] != null ) {
10521094 obj . font = adv [ 12 ] ;
1095+ }
10531096 }
1097+ obj . motion . push ( motion ) ;
10541098 }
1055- obj . duration = 2500 ;
1099+ obj . dur = 2500 ;
10561100 if ( adv [ 3 ] < 12 ) {
1057- obj . duration = adv [ 3 ] * 1000 ;
1101+ obj . dur = adv [ 3 ] * 1000 ;
10581102 }
1059- obj . alphaFrom = 1 ;
1060- obj . alphaTo = 1 ;
10611103 var tmp = adv [ 2 ] . split ( '-' ) ;
10621104 if ( tmp != null && tmp . length > 1 ) {
1063- obj . alphaFrom = parseFloat ( tmp [ 0 ] ) ;
1064- obj . alphaTo = parseFloat ( tmp [ 1 ] ) ;
1105+ var alphaFrom = parseFloat ( tmp [ 0 ] ) ;
1106+ var alphaTo = parseFloat ( tmp [ 1 ] ) ;
1107+ obj . opacity = alphaFrom ;
1108+ var alphaObj = { from :alphaFrom , to :alphaTo , dur :obj . dur , delay :0 } ;
1109+ if ( obj . motion . length > 0 ) {
1110+ obj . motion [ 0 ] [ "alpha" ] = alphaObj ;
1111+ } else {
1112+ obj . motion . push ( { alpha :alphaObj } ) ;
1113+ }
10651114 }
10661115 } catch ( e ) {
10671116 console . log ( '[Err] Error occurred in JSON parsing' ) ;
0 commit comments