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