CCPUTextureAnimatorTranslator.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /****************************************************************************
  2. Copyright (C) 2013 Henry van Merode. All rights reserved.
  3. Copyright (c) 2015-2016 Chukong Technologies Inc.
  4. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  5. http://www.cocos2d-x.org
  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. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. #include "CCPUTextureAnimatorTranslator.h"
  23. #include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
  24. #include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
  25. #include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
  26. NS_CC_BEGIN
  27. PUTextureAnimatorTranslator::PUTextureAnimatorTranslator()
  28. {
  29. }
  30. //-------------------------------------------------------------------------
  31. bool PUTextureAnimatorTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
  32. {
  33. PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
  34. PUAffector* af = static_cast<PUAffector*>(prop->parent->context);
  35. PUTextureAnimator* affector = static_cast<PUTextureAnimator*>(af);
  36. if (prop->name == token[TOKEN_TIME_STEP])
  37. {
  38. // Property: time_step
  39. if (passValidateProperty(compiler, prop, token[TOKEN_TIME_STEP], VAL_REAL))
  40. {
  41. float val = 0.0f;
  42. if(getFloat(*prop->values.front(), &val))
  43. {
  44. affector->setAnimationTimeStep(val);
  45. return true;
  46. }
  47. }
  48. }
  49. else if (prop->name == token[TOKEN_TEXANIM_TIME_STEP])
  50. {
  51. // Property: time_step_animation (deprecated and replaced by 'time_step')
  52. if (passValidateProperty(compiler, prop, token[TOKEN_TEXANIM_TIME_STEP], VAL_REAL))
  53. {
  54. float val = 0.0f;
  55. if(getFloat(*prop->values.front(), &val))
  56. {
  57. affector->setAnimationTimeStep(val);
  58. return true;
  59. }
  60. }
  61. }
  62. else if (prop->name == token[TOKEN_START_TEXANIM_TEXCOORDS_RANGE])
  63. {
  64. // Property: start_texture_coords_range
  65. if (passValidateProperty(compiler, prop, token[TOKEN_START_TEXANIM_TEXCOORDS_RANGE], VAL_UINT))
  66. {
  67. unsigned int val = 0;
  68. if(getUInt(*prop->values.front(), &val))
  69. {
  70. affector->setTextureCoordsStart(val);
  71. return true;
  72. }
  73. }
  74. }
  75. else if (prop->name == token[TOKEN_TEXANIM_TEXCOORDS_START])
  76. {
  77. // Property: texture_coords_start (deprecated and replaced by start_texture_coords_range)
  78. if (passValidateProperty(compiler, prop, token[TOKEN_TEXANIM_TEXCOORDS_START], VAL_UINT))
  79. {
  80. unsigned int val = 0;
  81. if(getUInt(*prop->values.front(), &val))
  82. {
  83. affector->setTextureCoordsStart(val);
  84. return true;
  85. }
  86. }
  87. }
  88. else if (prop->name == token[TOKEN_END_TEXANIM_TEXCOORDS_RANGE])
  89. {
  90. // Property: texture_coords_end
  91. if (passValidateProperty(compiler, prop, token[TOKEN_END_TEXANIM_TEXCOORDS_RANGE], VAL_UINT))
  92. {
  93. unsigned int val = 0;
  94. if(getUInt(*prop->values.front(), &val))
  95. {
  96. affector->setTextureCoordsEnd(val);
  97. return true;
  98. }
  99. }
  100. }
  101. else if (prop->name == token[TOKEN_TEXANIM_TEXCOORDS_END])
  102. {
  103. // Property: texture_coords_end (deprecated and replaced by end_texture_coords_range)
  104. if (passValidateProperty(compiler, prop, token[TOKEN_TEXANIM_TEXCOORDS_END], VAL_UINT))
  105. {
  106. unsigned int val = 0;
  107. if(getUInt(*prop->values.front(), &val))
  108. {
  109. affector->setTextureCoordsEnd(val);
  110. return true;
  111. }
  112. }
  113. }
  114. else if (prop->name == token[TOKEN_TEXANIM_ANIMATION_TYPE])
  115. {
  116. // Property: texture_animation_type
  117. if (passValidateProperty(compiler, prop, token[TOKEN_TEXANIM_ANIMATION_TYPE], VAL_STRING))
  118. {
  119. std::string val;
  120. if(getString(*prop->values.front(), &val))
  121. {
  122. if (val == token[TOKEN_TEXANIM_LOOP])
  123. {
  124. affector->setTextureAnimationType(PUTextureAnimator::TAT_LOOP);
  125. return true;
  126. }
  127. else if (val == token[TOKEN_TEXANIM_UP_DOWN])
  128. {
  129. affector->setTextureAnimationType(PUTextureAnimator::TAT_UP_DOWN);
  130. return true;
  131. }
  132. else if (val == token[TOKEN_TEXANIM_RANDOM])
  133. {
  134. affector->setTextureAnimationType(PUTextureAnimator::TAT_RANDOM);
  135. return true;
  136. }
  137. }
  138. }
  139. }
  140. else if (prop->name == token[TOKEN_TEXANIM_START_RANDOM])
  141. {
  142. // Property: texture_start_random
  143. if (passValidateProperty(compiler, prop, token[TOKEN_TEXANIM_START_RANDOM], VAL_BOOL))
  144. {
  145. bool val;
  146. if(getBoolean(*prop->values.front(), &val))
  147. {
  148. affector->setStartRandom(val);
  149. return true;
  150. }
  151. }
  152. }
  153. return false;
  154. }
  155. bool PUTextureAnimatorTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
  156. {
  157. // No objects
  158. return false;
  159. }
  160. NS_CC_END