SpinePathConstraint.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated April 5, 2025. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2025, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
  24. * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. #include "SpinePathConstraint.h"
  30. #include "SpineBone.h"
  31. #include "SpineCommon.h"
  32. #include "SpineSprite.h"
  33. void SpinePathConstraint::_bind_methods() {
  34. ClassDB::bind_method(D_METHOD("update"), &SpinePathConstraint::update);
  35. ClassDB::bind_method(D_METHOD("get_order"), &SpinePathConstraint::get_order);
  36. ClassDB::bind_method(D_METHOD("get_position"), &SpinePathConstraint::get_position);
  37. ClassDB::bind_method(D_METHOD("set_position", "v"), &SpinePathConstraint::set_position);
  38. ClassDB::bind_method(D_METHOD("get_spacing"), &SpinePathConstraint::get_spacing);
  39. ClassDB::bind_method(D_METHOD("set_spacing", "v"), &SpinePathConstraint::set_spacing);
  40. ClassDB::bind_method(D_METHOD("get_mix_rotate"), &SpinePathConstraint::get_mix_rotate);
  41. ClassDB::bind_method(D_METHOD("set_mix_rotate", "v"), &SpinePathConstraint::set_mix_rotate);
  42. ClassDB::bind_method(D_METHOD("get_mix_x"), &SpinePathConstraint::get_mix_x);
  43. ClassDB::bind_method(D_METHOD("set_mix_x", "v"), &SpinePathConstraint::set_mix_x);
  44. ClassDB::bind_method(D_METHOD("get_mix_y"), &SpinePathConstraint::get_mix_y);
  45. ClassDB::bind_method(D_METHOD("set_mix_y", "v"), &SpinePathConstraint::set_mix_y);
  46. ClassDB::bind_method(D_METHOD("get_bones"), &SpinePathConstraint::get_bones);
  47. ClassDB::bind_method(D_METHOD("get_target"), &SpinePathConstraint::get_target);
  48. ClassDB::bind_method(D_METHOD("set_target", "v"), &SpinePathConstraint::set_target);
  49. ClassDB::bind_method(D_METHOD("get_data"), &SpinePathConstraint::get_data);
  50. ClassDB::bind_method(D_METHOD("is_active"), &SpinePathConstraint::is_active);
  51. ClassDB::bind_method(D_METHOD("set_active", "v"), &SpinePathConstraint::set_active);
  52. }
  53. void SpinePathConstraint::update() {
  54. SPINE_CHECK(get_spine_object(), )
  55. get_spine_object()->update(spine::Physics_Update);
  56. }
  57. int SpinePathConstraint::get_order() {
  58. SPINE_CHECK(get_spine_object(), 0)
  59. return get_spine_object()->getOrder();
  60. }
  61. float SpinePathConstraint::get_position() {
  62. SPINE_CHECK(get_spine_object(), 0)
  63. return get_spine_object()->getPosition();
  64. }
  65. void SpinePathConstraint::set_position(float v) {
  66. SPINE_CHECK(get_spine_object(), )
  67. get_spine_object()->setPosition(v);
  68. }
  69. float SpinePathConstraint::get_spacing() {
  70. SPINE_CHECK(get_spine_object(), 0)
  71. return get_spine_object()->getSpacing();
  72. }
  73. void SpinePathConstraint::set_spacing(float v) {
  74. SPINE_CHECK(get_spine_object(), )
  75. get_spine_object()->setSpacing(v);
  76. }
  77. float SpinePathConstraint::get_mix_rotate() {
  78. SPINE_CHECK(get_spine_object(), 0)
  79. return get_spine_object()->getMixRotate();
  80. }
  81. void SpinePathConstraint::set_mix_rotate(float v) {
  82. SPINE_CHECK(get_spine_object(), )
  83. get_spine_object()->setMixRotate(v);
  84. }
  85. float SpinePathConstraint::get_mix_x() {
  86. SPINE_CHECK(get_spine_object(), 0)
  87. return get_spine_object()->getMixX();
  88. }
  89. void SpinePathConstraint::set_mix_x(float v) {
  90. SPINE_CHECK(get_spine_object(), )
  91. get_spine_object()->setMixX(v);
  92. }
  93. float SpinePathConstraint::get_mix_y() {
  94. SPINE_CHECK(get_spine_object(), 0)
  95. return get_spine_object()->getMixY();
  96. }
  97. void SpinePathConstraint::set_mix_y(float v) {
  98. SPINE_CHECK(get_spine_object(), )
  99. get_spine_object()->setMixY(v);
  100. }
  101. Array SpinePathConstraint::get_bones() {
  102. Array result;
  103. SPINE_CHECK(get_spine_object(), result)
  104. auto &bones = get_spine_object()->getBones();
  105. result.resize((int) bones.size());
  106. for (int i = 0; i < bones.size(); ++i) {
  107. auto bone = bones[i];
  108. Ref<SpineBone> bone_ref(memnew(SpineBone));
  109. bone_ref->set_spine_object(get_spine_owner(), bone);
  110. result[i] = bone_ref;
  111. }
  112. return result;
  113. }
  114. Ref<SpineSlot> SpinePathConstraint::get_target() {
  115. SPINE_CHECK(get_spine_object(), nullptr)
  116. auto target = get_spine_object()->getTarget();
  117. if (!target) return nullptr;
  118. Ref<SpineSlot> target_ref(memnew(SpineSlot));
  119. target_ref->set_spine_object(get_spine_owner(), target);
  120. return target_ref;
  121. }
  122. void SpinePathConstraint::set_target(Ref<SpineSlot> v) {
  123. SPINE_CHECK(get_spine_object(), )
  124. get_spine_object()->setTarget(v.is_valid() && v->get_spine_object() ? v->get_spine_object() : nullptr);
  125. }
  126. Ref<SpinePathConstraintData> SpinePathConstraint::get_data() {
  127. SPINE_CHECK(get_spine_object(), nullptr)
  128. auto &data = get_spine_object()->getData();
  129. Ref<SpinePathConstraintData> data_ref(memnew(SpinePathConstraintData));
  130. data_ref->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), &data);
  131. return data_ref;
  132. }
  133. bool SpinePathConstraint::is_active() {
  134. SPINE_CHECK(get_spine_object(), false)
  135. return get_spine_object()->isActive();
  136. }
  137. void SpinePathConstraint::set_active(bool v) {
  138. SPINE_CHECK(get_spine_object(), )
  139. get_spine_object()->setActive(v);
  140. }