SpineSlot.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated January 1, 2020. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2020, 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 "SpineSlot.h"
  30. #include "SpineBone.h"
  31. #include "SpineSkeleton.h"
  32. void SpineSlot::_bind_methods() {
  33. ClassDB::bind_method(D_METHOD("set_to_setup_pos"), &SpineSlot::set_to_setup_pos);
  34. ClassDB::bind_method(D_METHOD("get_data"), &SpineSlot::get_data);
  35. ClassDB::bind_method(D_METHOD("get_bone"), &SpineSlot::get_bone);
  36. ClassDB::bind_method(D_METHOD("get_skeleton"), &SpineSlot::get_skeleton);
  37. ClassDB::bind_method(D_METHOD("get_color"), &SpineSlot::get_color);
  38. ClassDB::bind_method(D_METHOD("set_color"), &SpineSlot::set_color);
  39. ClassDB::bind_method(D_METHOD("get_dark_color"), &SpineSlot::get_dark_color);
  40. ClassDB::bind_method(D_METHOD("set_dark_color", "v"), &SpineSlot::set_dark_color);
  41. ClassDB::bind_method(D_METHOD("has_dark_color"), &SpineSlot::has_dark_color);
  42. ClassDB::bind_method(D_METHOD("get_attachment"), &SpineSlot::get_attachment);
  43. ClassDB::bind_method(D_METHOD("set_attachment", "v"), &SpineSlot::set_attachment);
  44. ClassDB::bind_method(D_METHOD("get_attachment_state"), &SpineSlot::get_attachment_state);
  45. ClassDB::bind_method(D_METHOD("set_attachment_state", "v"), &SpineSlot::set_attachment_state);
  46. ClassDB::bind_method(D_METHOD("get_deform"), &SpineSlot::get_deform);
  47. ClassDB::bind_method(D_METHOD("set_deform", "v"), &SpineSlot::set_deform);
  48. }
  49. SpineSlot::SpineSlot():slot(NULL) {}
  50. SpineSlot::~SpineSlot() {}
  51. void SpineSlot::set_to_setup_pos(){
  52. slot->setToSetupPose();
  53. }
  54. Ref<SpineSlotData> SpineSlot::get_data(){
  55. auto &sd = slot->getData();
  56. Ref<SpineSlotData> gd_sd(memnew(SpineSlotData));
  57. gd_sd->set_spine_object(&sd);
  58. return gd_sd;
  59. }
  60. Ref<SpineBone> SpineSlot::get_bone(){
  61. auto &b = slot->getBone();
  62. Ref<SpineBone> gd_b(memnew(SpineBone));
  63. gd_b->set_spine_object(&b);
  64. return gd_b;
  65. }
  66. Ref<SpineSkeleton> SpineSlot::get_skeleton(){
  67. auto &s = slot->getSkeleton();
  68. Ref<SpineSkeleton> gd_s(memnew(SpineSkeleton));
  69. gd_s->set_spine_object(&s);
  70. return gd_s;
  71. }
  72. Color SpineSlot::get_color(){
  73. auto &c = slot->getColor();
  74. return Color(c.r, c.g, c.b, c.a);
  75. }
  76. void SpineSlot::set_color(Color v){
  77. auto &c = slot->getColor();
  78. c.set(v.r, v.g, v.b, v.a);
  79. }
  80. Color SpineSlot::get_dark_color(){
  81. auto &c = slot->getDarkColor();
  82. return Color(c.r, c.g, c.b, c.a);
  83. }
  84. void SpineSlot::set_dark_color(Color v){
  85. auto &c = slot->getDarkColor();
  86. c.set(v.r, v.g, v.b, v.a);
  87. }
  88. bool SpineSlot::has_dark_color(){
  89. return slot->hasDarkColor();
  90. }
  91. Ref<SpineAttachment> SpineSlot::get_attachment(){
  92. auto a = slot->getAttachment();
  93. if(a == NULL) return NULL;
  94. Ref<SpineAttachment> gd_a(memnew(SpineAttachment));
  95. gd_a->set_spine_object(a);
  96. return gd_a;
  97. }
  98. void SpineSlot::set_attachment(Ref<SpineAttachment> v){
  99. if(v.is_valid()){
  100. slot->setAttachment(v->get_spine_object());
  101. }else{
  102. slot->setAttachment(NULL);
  103. }
  104. }
  105. int SpineSlot::get_attachment_state(){
  106. return slot->getAttachmentState();
  107. }
  108. void SpineSlot::set_attachment_state(int v){
  109. slot->setAttachmentState(v);
  110. }
  111. float SpineSlot::get_attachment_time(){
  112. return slot->getAttachmentTime();
  113. }
  114. void SpineSlot::set_attachment_time(float v){
  115. slot->setAttachmentTime(v);
  116. }
  117. Array SpineSlot::get_deform(){
  118. auto &ds = slot->getDeform();
  119. Array gd_ds;
  120. gd_ds.resize(ds.size());
  121. for(size_t i=0; i < ds.size(); ++i){
  122. gd_ds[i] = ds[i];
  123. }
  124. return gd_ds;
  125. }
  126. void SpineSlot::set_deform(Array gd_ds){
  127. auto &ds = slot->getDeform();
  128. ds.setSize(gd_ds.size(), 0);
  129. for(size_t i=0; i < gd_ds.size(); ++i){
  130. ds[i] = gd_ds[i];
  131. }
  132. }