CCPUSineForceAffectorTranslator.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "CCPUSineForceAffectorTranslator.h"
  23. #include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
  24. #include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
  25. #include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
  26. #include "extensions/Particle3D/PU/CCPUBaseForceAffectorTranslator.h"
  27. NS_CC_BEGIN
  28. PUSineForceAffectorTranslator::PUSineForceAffectorTranslator()
  29. {
  30. }
  31. //-------------------------------------------------------------------------
  32. bool PUSineForceAffectorTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
  33. {
  34. PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
  35. PUAffector* af = static_cast<PUAffector*>(prop->parent->context);
  36. PUSineForceAffector* affector = static_cast<PUSineForceAffector*>(af);
  37. if (prop->name == token[TOKEN_MIN_FREQUENCY])
  38. {
  39. // Property: min_frequency
  40. if (passValidateProperty(compiler, prop, token[TOKEN_MIN_FREQUENCY], VAL_REAL))
  41. {
  42. float val = 0.0f;
  43. if(getFloat(*prop->values.front(), &val))
  44. {
  45. affector->setFrequencyMin(val);
  46. return true;
  47. }
  48. }
  49. }
  50. else if (prop->name == token[TOKEN_SINE_MIN_FREQUENCY])
  51. {
  52. // Property: sinef_aff_frequency_min (deprecated and replaced by 'min_frequency')
  53. if (passValidateProperty(compiler, prop, token[TOKEN_SINE_MIN_FREQUENCY], VAL_REAL))
  54. {
  55. float val = 0.0f;
  56. if(getFloat(*prop->values.front(), &val))
  57. {
  58. affector->setFrequencyMin(val);
  59. return true;
  60. }
  61. }
  62. }
  63. else if (prop->name == token[TOKEN_MAX_FREQUENCY])
  64. {
  65. // Property: max_frequency
  66. if (passValidateProperty(compiler, prop, token[TOKEN_MAX_FREQUENCY], VAL_REAL))
  67. {
  68. float val = 0.0f;
  69. if(getFloat(*prop->values.front(), &val))
  70. {
  71. affector->setFrequencyMax(val);
  72. return true;
  73. }
  74. }
  75. }
  76. else if (prop->name == token[TOKEN_SINE_MAX_FREQUENCY])
  77. {
  78. // Property: sinef_aff_frequency_max (deprecated and replaced by 'max_frequency')
  79. if (passValidateProperty(compiler, prop, token[TOKEN_SINE_MAX_FREQUENCY], VAL_REAL))
  80. {
  81. float val = 0.0f;
  82. if(getFloat(*prop->values.front(), &val))
  83. {
  84. affector->setFrequencyMax(val);
  85. return true;
  86. }
  87. }
  88. }
  89. else
  90. {
  91. // Parse the BaseForceAffector
  92. PUBaseForceAffectorTranslator BaseForceAffectorTranslator;
  93. return BaseForceAffectorTranslator.translateChildProperty(compiler, node); // Must be the last
  94. }
  95. return false;
  96. }
  97. bool PUSineForceAffectorTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
  98. {
  99. // No objects
  100. return false;
  101. }
  102. NS_CC_END