CCPUDoPlacementParticleEventHandlerTranslator.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /****************************************************************************
  2. Copyright (C) 2013 Henry van Merode. All rights reserved.
  3. Copyright (c) 2015-2017 Chukong Technologies Inc.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #include "CCPUDoPlacementParticleEventHandlerTranslator.h"
  22. #include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
  23. #include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
  24. #include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
  25. NS_CC_BEGIN
  26. PUDoPlacementParticleEventHandlerTranslator::PUDoPlacementParticleEventHandlerTranslator()
  27. {
  28. }
  29. //-------------------------------------------------------------------------
  30. bool PUDoPlacementParticleEventHandlerTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
  31. {
  32. PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
  33. PUEventHandler* evt = static_cast<PUEventHandler *>(prop->parent->context);
  34. PUDoPlacementParticleEventHandler* handler = static_cast<PUDoPlacementParticleEventHandler*>(evt);
  35. if (prop->name == token[TOKEN_DOPLACE_FORCE_EMITTER])
  36. {
  37. // Property: force_emitter
  38. if (passValidateProperty(compiler, prop, token[TOKEN_DOPLACE_FORCE_EMITTER], VAL_STRING))
  39. {
  40. std::string val;
  41. if(getString(*prop->values.front(), &val))
  42. {
  43. handler->setForceEmitterName(val);
  44. return true;
  45. }
  46. }
  47. }
  48. else if (prop->name == token[TOKEN_DOPLACE_NUMBER_OF_PARTICLES])
  49. {
  50. // Property: number_of_particles
  51. if (passValidateProperty(compiler, prop, token[TOKEN_DOPLACE_NUMBER_OF_PARTICLES], VAL_UINT))
  52. {
  53. unsigned int val = 0;
  54. if(getUInt(*prop->values.front(), &val))
  55. {
  56. handler->setNumberOfParticles(val);
  57. return true;
  58. }
  59. }
  60. }
  61. else if (prop->name == token[TOKEN_INHERIT_POSITION])
  62. {
  63. // Property: inherit_position
  64. if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_POSITION], VAL_BOOL))
  65. {
  66. bool val;
  67. if(getBoolean(*prop->values.front(), &val))
  68. {
  69. handler->setInheritPosition(val);
  70. return true;
  71. }
  72. }
  73. }
  74. else if (prop->name == token[TOKEN_INHERIT_DIRECTION])
  75. {
  76. // Property: inherit_direction
  77. if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_DIRECTION], VAL_BOOL))
  78. {
  79. bool val;
  80. if(getBoolean(*prop->values.front(), &val))
  81. {
  82. handler->setInheritDirection(val);
  83. return true;
  84. }
  85. }
  86. }
  87. else if (prop->name == token[TOKEN_INHERIT_ORIENTATION])
  88. {
  89. // Property: inherit_orientation
  90. if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_ORIENTATION], VAL_BOOL))
  91. {
  92. bool val;
  93. if(getBoolean(*prop->values.front(), &val))
  94. {
  95. handler->setInheritOrientation(val);
  96. return true;
  97. }
  98. }
  99. }
  100. else if (prop->name == token[TOKEN_INHERIT_TIME_TO_LIVE])
  101. {
  102. // Property: inherit_time_to_live
  103. if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_TIME_TO_LIVE], VAL_BOOL))
  104. {
  105. bool val;
  106. if(getBoolean(*prop->values.front(), &val))
  107. {
  108. handler->setInheritTimeToLive(val);
  109. return true;
  110. }
  111. }
  112. }
  113. else if (prop->name == token[TOKEN_INHERIT_MASS])
  114. {
  115. // Property: inherit_mass
  116. if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_MASS], VAL_BOOL))
  117. {
  118. bool val;
  119. if(getBoolean(*prop->values.front(), &val))
  120. {
  121. handler->setInheritMass(val);
  122. return true;
  123. }
  124. }
  125. }
  126. else if (prop->name == token[TOKEN_INHERIT_TEXTURE_COORDINATE])
  127. {
  128. // Property: inherit_texture_coord
  129. if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_TEXTURE_COORDINATE], VAL_BOOL))
  130. {
  131. bool val;
  132. if(getBoolean(*prop->values.front(), &val))
  133. {
  134. handler->setInheritTextureCoordinate(val);
  135. return true;
  136. }
  137. }
  138. }
  139. else if (prop->name == token[TOKEN_INHERIT_COLOUR])
  140. {
  141. // Property: inherit_colour
  142. if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_COLOUR], VAL_BOOL))
  143. {
  144. bool val;
  145. if(getBoolean(*prop->values.front(), &val))
  146. {
  147. handler->setInheritColour(val);
  148. return true;
  149. }
  150. }
  151. }
  152. else if (prop->name == token[TOKEN_INHERIT_WIDTH])
  153. {
  154. // Property: inherit_width
  155. if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_WIDTH], VAL_BOOL))
  156. {
  157. bool val;
  158. if(getBoolean(*prop->values.front(), &val))
  159. {
  160. handler->setInheritParticleWidth(val);
  161. return true;
  162. }
  163. }
  164. }
  165. else if (prop->name == token[TOKEN_INHERIT_HEIGHT])
  166. {
  167. // Property: inherit_height
  168. if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_HEIGHT], VAL_BOOL))
  169. {
  170. bool val;
  171. if(getBoolean(*prop->values.front(), &val))
  172. {
  173. handler->setInheritParticleHeight(val);
  174. return true;
  175. }
  176. }
  177. }
  178. else if (prop->name == token[TOKEN_INHERIT_DEPTH])
  179. {
  180. // Property: inherit_depth
  181. if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_DEPTH], VAL_BOOL))
  182. {
  183. bool val;
  184. if(getBoolean(*prop->values.front(), &val))
  185. {
  186. handler->setInheritParticleDepth(val);
  187. return true;
  188. }
  189. }
  190. }
  191. return false;
  192. }
  193. bool PUDoPlacementParticleEventHandlerTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
  194. {
  195. // No objects
  196. return false;
  197. }
  198. NS_CC_END