SkeletonData.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. -------------------------------------------------------------------------------
  2. -- Spine Runtimes Software License v2.5
  3. --
  4. -- Copyright (c) 2013-2016, Esoteric Software
  5. -- All rights reserved.
  6. --
  7. -- You are granted a perpetual, non-exclusive, non-sublicensable, and
  8. -- non-transferable license to use, install, execute, and perform the Spine
  9. -- Runtimes software and derivative works solely for personal or internal
  10. -- use. Without the written permission of Esoteric Software (see Section 2 of
  11. -- the Spine Software License Agreement), you may not (a) modify, translate,
  12. -- adapt, or develop new applications using the Spine Runtimes or otherwise
  13. -- create derivative works or improvements of the Spine Runtimes or (b) remove,
  14. -- delete, alter, or obscure any trademarks or any copyright, trademark, patent,
  15. -- or other intellectual property or proprietary rights notices on or in the
  16. -- Software, including any copy thereof. Redistributions in binary or source
  17. -- form must include this license and terms.
  18. --
  19. -- THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
  20. -- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. -- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  22. -- EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. -- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
  25. -- USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  26. -- IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. -- POSSIBILITY OF SUCH DAMAGE.
  29. -------------------------------------------------------------------------------
  30. local setmetatable = setmetatable
  31. local SkeletonData = {}
  32. SkeletonData.__index = SkeletonData
  33. function SkeletonData.new ()
  34. local self = {
  35. name,
  36. bones = {},
  37. slots = {},
  38. skins = {},
  39. defaultSkin = nil,
  40. events = {},
  41. animations = {},
  42. ikConstraints = {},
  43. transformConstraints = {},
  44. pathConstraints = {},
  45. width, height,
  46. version, hash, imagesPath,
  47. slotNameIndices = {}
  48. }
  49. setmetatable(self, SkeletonData)
  50. return self
  51. end
  52. function SkeletonData:findBone (boneName)
  53. if not boneName then error("boneName cannot be nil.", 2) end
  54. for _,bone in ipairs(self.bones) do
  55. if bone.name == boneName then return bone end
  56. end
  57. return nil
  58. end
  59. function SkeletonData:findBoneIndex (boneName)
  60. if not boneName then error("boneName cannot be nil.", 2) end
  61. for i,bone in ipairs(self.bones) do
  62. if bone.name == boneName then return i end
  63. end
  64. return -1
  65. end
  66. function SkeletonData:findSlot (slotName)
  67. if not slotName then error("slotName cannot be nil.", 2) end
  68. for i,slot in ipairs(self.slots) do
  69. if slot.name == slotName then return slot end
  70. end
  71. return nil
  72. end
  73. function SkeletonData:findSlotIndex (slotName)
  74. if not slotName then error("slotName cannot be nil.", 2) end
  75. return self.slotNameIndices[slotName] or -1
  76. end
  77. function SkeletonData:findSkin (skinName)
  78. if not skinName then error("skinName cannot be nil.", 2) end
  79. for _,skin in ipairs(self.skins) do
  80. if skin.name == skinName then return skin end
  81. end
  82. return nil
  83. end
  84. function SkeletonData:findEvent (eventName)
  85. if not eventName then error("eventName cannot be nil.", 2) end
  86. for _,event in ipairs(self.events) do
  87. if event.name == eventName then return event end
  88. end
  89. return nil
  90. end
  91. function SkeletonData:findAnimation (animationName)
  92. if not animationName then error("animationName cannot be nil.", 2) end
  93. for _,animation in ipairs(self.animations) do
  94. if animation.name == animationName then return animation end
  95. end
  96. return nil
  97. end
  98. function SkeletonData:findIkConstraint (constraintName)
  99. if not constraintName then error("constraintName cannot be nil.", 2) end
  100. for _,constraint in ipairs(self.ikConstraints) do
  101. if constraint.name == constraintName then return constraint end
  102. end
  103. return nil
  104. end
  105. function SkeletonData:findTransformConstraint (constraintName)
  106. if not constraintName then error("constraintName cannot be nil.", 2) end
  107. for _,constraint in ipairs(self.transformConstraints) do
  108. if constraint.name == constraintName then return constraint end
  109. end
  110. return nil
  111. end
  112. function SkeletonData:findPathConstraint (constraintName)
  113. if not constraintName then error("constraintName cannot be nil.", 2) end
  114. for _,constraint in ipairs(self.pathConstraints) do
  115. if constraint.name == constraintName then return constraint end
  116. end
  117. return nil
  118. end
  119. function SkeletonData:findPathConstraintIndex (constraintName)
  120. if not constraintName then error("constraintName cannot be nil.", 2) end
  121. for i,constraint in ipairs(self.pathConstraints) do
  122. if constraint.name == constraintName then return i end
  123. end
  124. return -1
  125. end
  126. return SkeletonData