1 /**************************************************************************** 2 Copyright (c) 2011-2012 cocos2d-x.org 3 Copyright (c) 2013-2014 Chukong Technologies Inc. 4 5 http://www.cocos2d-x.org 6 7 Permission is hereby granted, free of charge, to any person obtaining a copy 8 of this software and associated documentation files (the "Software"), to deal 9 in the Software without restriction, including without limitation the rights 10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 copies of the Software, and to permit persons to whom the Software is 12 furnished to do so, subject to the following conditions: 13 14 The above copyright notice and this permission notice shall be included in 15 all copies or substantial portions of the Software. 16 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 THE SOFTWARE. 24 ****************************************************************************/ 25 26 //BlendType 27 /** 28 * The value of the blend type of normal 29 * @constant 30 * @type Number 31 */ 32 ccs.BLEND_TYPE_NORMAL = 0; 33 34 /** 35 * The value of the blend type of layer 36 * @constant 37 * @type Number 38 */ 39 ccs.BLEND_TYPE_LAYER = 1; 40 41 /** 42 * The value of the blend type of darken 43 * @constant 44 * @type Number 45 */ 46 ccs.BLEND_TYPE_DARKEN = 2; 47 48 /** 49 * The value of the blend type of multiply 50 * @constant 51 * @type Number 52 */ 53 ccs.BLEND_TYPE_MULTIPLY = 3; 54 55 /** 56 * The value of the blend type of lighten 57 * @constant 58 * @type Number 59 */ 60 ccs.BLEND_TYPE_LIGHTEN = 4; 61 62 /** 63 * The value of the blend type of screen 64 * @constant 65 * @type Number 66 */ 67 ccs.BLEND_TYPE_SCREEN = 5; 68 69 /** 70 * The value of the blend type of overlay 71 * @constant 72 * @type Number 73 */ 74 ccs.BLEND_TYPE_OVERLAY = 6; 75 76 /** 77 * The value of the blend type of highlight 78 * @constant 79 * @type Number 80 */ 81 ccs.BLEND_TYPE_HIGHLIGHT = 7; 82 83 /** 84 * The value of the blend type of add 85 * @constant 86 * @type Number 87 */ 88 ccs.BLEND_TYPE_ADD = 8; 89 90 /** 91 * The value of the blend type of subtract 92 * @constant 93 * @type Number 94 */ 95 ccs.BLEND_TYPE_SUBTRACT = 9; 96 97 /** 98 * The value of the blend type of difference 99 * @constant 100 * @type Number 101 */ 102 ccs.BLEND_TYPE_DIFFERENCE = 10; 103 104 /** 105 * The value of the blend type of invert 106 * @constant 107 * @type Number 108 */ 109 ccs.BLEND_TYPE_INVERT = 11; 110 111 /** 112 * The value of the blend type of alpha 113 * @constant 114 * @type Number 115 */ 116 ccs.BLEND_TYPE_ALPHA = 12; 117 118 /** 119 * The value of the blend type of erase 120 * @constant 121 * @type Number 122 */ 123 ccs.BLEND_TYPE_ERASE = 13; 124 125 126 //DisplayType 127 ccs.DISPLAY_TYPE_SPRITE = 0; 128 ccs.DISPLAY_TYPE_ARMATURE = 1; 129 ccs.DISPLAY_TYPE_PARTICLE = 2; 130 ccs.DISPLAY_TYPE_MAX = 3; 131 132 /** 133 * Base class for ccs.BaseData objects. 134 * @class 135 * @extends ccs.Class 136 */ 137 ccs.BaseData = ccs.Class.extend(/** @lends ccs.BaseData# */{ 138 x:0, 139 y:0, 140 zOrder:0, 141 skewX:0, 142 skewY:0, 143 scaleX:1, 144 scaleY:1, 145 tweenRotate:0, 146 isUseColorInfo:false, 147 r:255, 148 g:255, 149 b:255, 150 a:255, 151 152 ctor:function () { 153 this.x = 0; 154 this.y = 0; 155 this.zOrder = 0; 156 this.skewX = 0; 157 this.skewY = 0; 158 this.scaleX = 1; 159 this.scaleY = 1; 160 this.tweenRotate = 0; 161 this.isUseColorInfo = false; 162 this.r = 255; 163 this.g = 255; 164 this.b = 255; 165 this.a = 255; 166 }, 167 168 169 /** 170 * Copy data from node 171 * @function 172 * @param {ccs.BaseData} node 173 */ 174 copy:function (node) { 175 this.x = node.x; 176 this.y = node.y; 177 this.zOrder = node.zOrder; 178 this.scaleX = node.scaleX; 179 this.scaleY = node.scaleY; 180 this.skewX = node.skewX; 181 this.skewY = node.skewY; 182 this.tweenRotate = node.tweenRotate; 183 this.isUseColorInfo = node.isUseColorInfo; 184 this.r = node.r; 185 this.g = node.g; 186 this.b = node.b; 187 this.a = node.a; 188 }, 189 190 /** 191 * color setter 192 * @function 193 * @param {cc.Color} color 194 */ 195 setColor:function(color){ 196 this.r = color.r; 197 this.g = color.g; 198 this.b = color.b; 199 this.a = color.a; 200 }, 201 202 /** 203 * color getter 204 * @function 205 * @returns {cc.Color} 206 */ 207 getColor:function(){ 208 return cc.color(this.r, this.g, this.b, this.a); 209 }, 210 211 /** 212 * Calculate two baseData's between value(to - from) and set to self 213 * @function 214 * @param {ccs.BaseData} from 215 * @param {ccs.BaseData} to 216 * @param {Boolean} limit 217 */ 218 subtract:function (from, to, limit) { 219 this.x = to.x - from.x; 220 this.y = to.y - from.y; 221 this.scaleX = to.scaleX - from.scaleX; 222 this.scaleY = to.scaleY - from.scaleY; 223 this.skewX = to.skewX - from.skewX; 224 this.skewY = to.skewY - from.skewY; 225 226 if (this.isUseColorInfo || from.isUseColorInfo || to.isUseColorInfo) { 227 this.a = to.a - from.a; 228 this.r = to.r - from.r; 229 this.g = to.g - from.g; 230 this.b = to.b - from.b; 231 this.isUseColorInfo = true; 232 } else { 233 this.a = this.r = this.g = this.b = 0; 234 this.isUseColorInfo = false; 235 } 236 237 if (limit) { 238 if (this.skewX > cc.PI) { 239 this.skewX -= ccs.M_PI_X_2; 240 } 241 if (this.skewX < -cc.PI) { 242 this.skewX += ccs.M_PI_X_2; 243 } 244 if (this.skewY > cc.PI) { 245 this.skewY -= ccs.M_PI_X_2; 246 } 247 if (this.skewY < -cc.PI) { 248 this.skewY += ccs.M_PI_X_2; 249 } 250 } 251 252 if (to.tweenRotate) { 253 this.skewX += to.tweenRotate * ccs.M_PI_X_2; 254 this.skewY -= to.tweenRotate * ccs.M_PI_X_2; 255 } 256 } 257 }); 258 259 /** 260 * Base class for ccs.DisplayData objects. 261 * @class 262 * @extends ccs.Class 263 */ 264 ccs.DisplayData = ccs.Class.extend(/** @lends ccs.DisplayData# */{ 265 displayType:ccs.DISPLAY_TYPE_MAX, 266 displayName:"", 267 ctor:function () { 268 this.displayType = ccs.DISPLAY_TYPE_MAX; 269 }, 270 /** 271 * change display name to texture type 272 * @function 273 * @param {String} displayName 274 * @returns {String} 275 */ 276 changeDisplayToTexture:function (displayName) { 277 // remove .xxx 278 var textureName = displayName; 279 var startPos = textureName.lastIndexOf("."); 280 281 if (startPos != -1) { 282 textureName = textureName.substring(0, startPos); 283 } 284 return textureName; 285 }, 286 /** 287 * copy data 288 * @function 289 * @param {ccs.DisplayData} displayData 290 */ 291 copy:function (displayData) { 292 this.displayName = displayData.displayName; 293 this.displayType = displayData.displayType; 294 } 295 }); 296 297 /** 298 * Base class for ccs.SpriteDisplayData objects. 299 * @class 300 * @extends ccs.DisplayData 301 */ 302 ccs.SpriteDisplayData = ccs.DisplayData.extend(/** @lends ccs.SpriteDisplayData# */{ 303 skinData:null, 304 ctor:function () { 305 this.skinData = new ccs.BaseData(); 306 this.displayType = ccs.DISPLAY_TYPE_SPRITE; 307 }, 308 /** 309 * copy data 310 * @function 311 * @param {ccs.SpriteDisplayData} displayData 312 */ 313 copy:function (displayData) { 314 ccs.DisplayData.prototype.copy.call(this,displayData); 315 this.skinData = displayData.skinData; 316 } 317 }); 318 319 /** 320 * Base class for ccs.ArmatureDisplayData objects. 321 * @class ccs.ArmatureDisplayData 322 * @extends ccs.DisplayData 323 */ 324 ccs.ArmatureDisplayData = ccs.DisplayData.extend(/** @lends ccs.ArmatureDisplayData# */{ 325 displayName:"", 326 ctor:function () { 327 this.displayName = ""; 328 this.displayType = ccs.DISPLAY_TYPE_ARMATURE; 329 } 330 }); 331 332 /** 333 * Base class for ccs.ParticleDisplayData objects. 334 * @class ccs.ParticleDisplayData 335 * @extends ccs.DisplayData 336 */ 337 ccs.ParticleDisplayData = ccs.DisplayData.extend(/** @lends ccs.ParticleDisplayData# */{ 338 ctor:function () { 339 this.displayType = ccs.DISPLAY_TYPE_PARTICLE; 340 } 341 }); 342 343 /** 344 * Base class for ccs.BoneData objects. 345 * @class ccs.BoneData 346 * @extends ccs.BaseData 347 */ 348 ccs.BoneData = ccs.BaseData.extend(/** @lends ccs.BoneData# */{ 349 displayDataList:null, 350 name:"", 351 parentName:"", 352 boneDataTransform:null, 353 ctor:function () { 354 this.displayDataList = []; 355 this.name = ""; 356 this.parentName = ""; 357 this.boneDataTransform = null; 358 359 }, 360 init:function () { 361 362 }, 363 /** 364 * add display data 365 * @function 366 * @param {ccs.DisplayData} displayData 367 */ 368 addDisplayData:function (displayData) { 369 this.displayDataList.push(displayData); 370 }, 371 372 /** 373 * get display data 374 * @function 375 * @param {Number} index 376 * @returns {ccs.DisplayData} 377 */ 378 getDisplayData:function (index) { 379 return this.displayDataList[index]; 380 } 381 }); 382 383 /** 384 * Base class for ccs.ArmatureData objects. 385 * @class ccs.ArmatureData 386 * @extends ccs.Class 387 */ 388 ccs.ArmatureData = ccs.Class.extend(/** @lends ccs.ArmatureData# */{ 389 boneDataDic:null, 390 name:"", 391 dataVersion:0.1, 392 ctor:function () { 393 this.boneDataDic = {}; 394 this.name = ""; 395 this.dataVersion = 0.1; 396 }, 397 init:function () { 398 return true; 399 }, 400 /** 401 * add bone data 402 * @function 403 * @param {ccs.BoneData} boneData 404 */ 405 addBoneData:function (boneData) { 406 this.boneDataDic[boneData.name] = boneData; 407 }, 408 /** 409 * get bone datas 410 * @function 411 * @returns {Object} 412 */ 413 getBoneDataDic:function () { 414 return this.boneDataDic; 415 }, 416 /** 417 * get bone data by bone name 418 * @function 419 * @param {String} boneName 420 * @returns {ccs.BoneData} 421 */ 422 getBoneData:function (boneName) { 423 return this.boneDataDic[boneName]; 424 } 425 }); 426 427 /** 428 * Base class for ccs.FrameData objects. 429 * @class ccs.FrameData 430 * @extends ccs.BaseData 431 */ 432 ccs.FrameData = ccs.BaseData.extend(/** @lends ccs.FrameData# */{ 433 duration:0, 434 tweenEasing:0, 435 easingParamNumber: 0, 436 easingParams: null, 437 displayIndex:-1, 438 movement:"", 439 event:"", 440 sound:"", 441 soundEffect:"", 442 blendFunc:0, 443 frameID:0, 444 isTween:true, 445 ctor:function () { 446 ccs.BaseData.prototype.ctor.call(this); 447 this.duration = 1; 448 this.tweenEasing = ccs.TweenType.linear; 449 this.easingParamNumber = 0; 450 this.easingParams = []; 451 this.displayIndex = 0; 452 this.movement = ""; 453 this.event = ""; 454 this.sound = ""; 455 this.soundEffect = ""; 456 this.blendFunc = new cc.BlendFunc(cc.BLEND_SRC, cc.BLEND_DST); 457 this.frameID = 0; 458 this.isTween = true; 459 }, 460 461 /** 462 * copy data 463 * @function 464 * @param frameData 465 */ 466 copy:function (frameData) { 467 ccs.BaseData.prototype.copy.call(this, frameData); 468 this.duration = frameData.duration; 469 this.tweenEasing = frameData.tweenEasing; 470 this.displayIndex = frameData.displayIndex; 471 this.movement = frameData.movement; 472 this.event = frameData.event; 473 this.sound = frameData.sound; 474 this.soundEffect = frameData.soundEffect; 475 this.blendFunc = frameData.blendFunc; 476 this.isTween = frameData.isTween; 477 478 this.easingParamNumber = frameData.easingParamNumber; 479 this.easingParams = []; 480 if (this.easingParamNumber != 0) { 481 for (var i = 0; i<this.easingParamNumber; i++) { 482 this.easingParams[i] = frameData.easingParams[i]; 483 } 484 } 485 } 486 } 487 ); 488 489 /** 490 * Base class for ccs.MovementBoneData objects. 491 * @class ccs.MovementBoneData 492 * @extends ccs.Class 493 */ 494 ccs.MovementBoneData = ccs.Class.extend(/** @lends ccs.MovementBoneData# */{ 495 delay:0, 496 scale:1, 497 duration:0, 498 frameList:null, 499 name:"", 500 ctor:function () { 501 this.delay = 0; 502 this.scale = 1; 503 this.duration = 0; 504 this.frameList = []; 505 this.name = ""; 506 }, 507 init:function () { 508 this.frameList = []; 509 }, 510 /** 511 * add frame data 512 * @function 513 * @param {ccs.FrameData} frameData 514 */ 515 addFrameData:function (frameData) { 516 this.frameList.push(frameData); 517 }, 518 /** 519 * get frame data 520 * @function 521 * @param {Number} index 522 * @returns {ccs.FrameData} 523 */ 524 getFrameData:function (index) { 525 return this.frameList[index]; 526 } 527 }); 528 529 /** 530 * Base class for ccs.MovementData objects. 531 * @class ccs.MovementData 532 * @extends ccs.Class 533 */ 534 ccs.MovementData = ccs.Class.extend(/** @lends ccs.MovementData# */{ 535 movBoneDataDic:null, 536 duration:0, 537 scale:1, 538 durationTo:0, 539 durationTween:ccs.TweenType.linear, 540 loop:true, 541 tweenEasing:2, 542 name:"", 543 ctor:function () { 544 this.name = ""; 545 this.duration = 0; 546 this.scale = 1; 547 this.durationTo = 0; 548 this.durationTween = 0; 549 this.loop = true; 550 this.tweenEasing = ccs.TweenType.linear; 551 this.movBoneDataDic = {}; 552 }, 553 554 /** 555 * add movement bone data 556 * @function 557 * @param {ccs.MovementBoneData} movBoneData 558 */ 559 addMovementBoneData:function (movBoneData) { 560 this.movBoneDataDic[ movBoneData.name] = movBoneData; 561 }, 562 563 /** 564 * get movement bone data 565 * @function 566 * @param {String} boneName 567 * @returns {ccs.MovementBoneData} 568 */ 569 getMovementBoneData:function (boneName) { 570 return this.movBoneDataDic[boneName]; 571 } 572 }); 573 574 /** 575 * Base class for ccs.AnimationData objects. 576 * @class ccs.AnimationData 577 * @extends ccs.Class 578 */ 579 ccs.AnimationData = ccs.Class.extend(/** @lends ccs.AnimationData# */{ 580 moveDataDic:null, 581 movementNames:null, 582 name:"", 583 ctor:function () { 584 this.moveDataDic = {}; 585 this.movementNames = []; 586 }, 587 /** 588 * add movement data 589 * @function 590 * @param {ccs.MovementData} moveData 591 */ 592 addMovement:function (moveData) { 593 this.moveDataDic[moveData.name] = moveData; 594 this.movementNames.push(moveData.name); 595 }, 596 /** 597 * get movement data 598 * @function 599 * @param {String} moveName 600 * @returns {ccs.MovementData} 601 */ 602 getMovement:function (moveName) { 603 return this.moveDataDic[moveName]; 604 }, 605 /** 606 * @function 607 * @returns {Number} 608 */ 609 getMovementCount:function () { 610 return Object.keys(this.moveDataDic).length; 611 } 612 }); 613 614 /** 615 * contour vertex 616 * @class ccs.ContourVertex2 617 * @param {Number} x 618 * @param {Number} y 619 * @constructor 620 */ 621 ccs.ContourVertex2 = function (x, y) { 622 this.x = x || 0; 623 this.y = y || 0; 624 }; 625 626 /** 627 * Base class for ccs.ContourData objects. 628 * @class ccs.ContourData 629 * @extends ccs.Class 630 */ 631 ccs.ContourData = ccs.Class.extend({ 632 vertexList:null, 633 ctor:function () { 634 this.vertexList = []; 635 }, 636 637 init:function () { 638 this.vertexList = []; 639 return true; 640 }, 641 642 /** 643 * add vertex 644 * @function 645 * @param {cc.Point} p 646 */ 647 addVertex: function (p) { 648 var v = ccs.ContourVertex2(p.x, p.y); 649 this.vertexList.push(v); 650 } 651 }); 652 653 /** 654 * Base class for ccs.TextureData objects. 655 * @class ccs.TextureData 656 * @extends ccs.Class 657 */ 658 ccs.TextureData = ccs.Class.extend(/** @lends ccs.TextureData# */{ 659 height:0, 660 width:0, 661 pivotX:0, 662 pivotY:0, 663 name:"", 664 contourDataList:null, 665 ctor:function () { 666 this.height = 0; 667 this.width = 0; 668 this.pivotX = 0.5; 669 this.pivotY = 0.5; 670 this.name = ""; 671 this.contourDataList = []; 672 }, 673 674 init:function () { 675 this.contourDataList = []; 676 }, 677 678 /** 679 * set contourData 680 * @function 681 * @param {ccs.ContourData} contourData 682 */ 683 addContourData:function (contourData) { 684 this.contourDataList.push(contourData); 685 }, 686 687 /** 688 * get contourData 689 * @function 690 * @param {Number} index 691 * @returns {ccs.ContourData} 692 */ 693 getContourData:function (index) { 694 return this.contourDataList[index]; 695 } 696 }); 697