SkeletonData.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. local setmetatable = setmetatable
  30. local SkeletonData = {}
  31. SkeletonData.__index = SkeletonData
  32. function SkeletonData.new ()
  33. local self = {
  34. name,
  35. bones = {},
  36. slots = {},
  37. skins = {},
  38. defaultSkin = nil,
  39. events = {},
  40. animations = {},
  41. ikConstraints = {},
  42. transformConstraints = {},
  43. pathConstraints = {},
  44. x, y, width, height,
  45. version, hash, imagesPath,
  46. slotNameIndices = {}
  47. }
  48. setmetatable(self, SkeletonData)
  49. return self
  50. end
  51. function SkeletonData:findBone (boneName)
  52. if not boneName then error("boneName cannot be nil.", 2) end
  53. for _,bone in ipairs(self.bones) do
  54. if bone.name == boneName then return bone end
  55. end
  56. return nil
  57. end
  58. function SkeletonData:findBoneIndex (boneName)
  59. if not boneName then error("boneName cannot be nil.", 2) end
  60. for i,bone in ipairs(self.bones) do
  61. if bone.name == boneName then return i end
  62. end
  63. return -1
  64. end
  65. function SkeletonData:findSlot (slotName)
  66. if not slotName then error("slotName cannot be nil.", 2) end
  67. for i,slot in ipairs(self.slots) do
  68. if slot.name == slotName then return slot end
  69. end
  70. return nil
  71. end
  72. function SkeletonData:findSlotIndex (slotName)
  73. if not slotName then error("slotName cannot be nil.", 2) end
  74. return self.slotNameIndices[slotName] or -1
  75. end
  76. function SkeletonData:findSkin (skinName)
  77. if not skinName then error("skinName cannot be nil.", 2) end
  78. for _,skin in ipairs(self.skins) do
  79. if skin.name == skinName then return skin end
  80. end
  81. return nil
  82. end
  83. function SkeletonData:findEvent (eventName)
  84. if not eventName then error("eventName cannot be nil.", 2) end
  85. for _,event in ipairs(self.events) do
  86. if event.name == eventName then return event end
  87. end
  88. return nil
  89. end
  90. function SkeletonData:findAnimation (animationName)
  91. if not animationName then error("animationName cannot be nil.", 2) end
  92. for _,animation in ipairs(self.animations) do
  93. if animation.name == animationName then return animation end
  94. end
  95. return nil
  96. end
  97. function SkeletonData:findIkConstraint (constraintName)
  98. if not constraintName then error("constraintName cannot be nil.", 2) end
  99. for _,constraint in ipairs(self.ikConstraints) do
  100. if constraint.name == constraintName then return constraint end
  101. end
  102. return nil
  103. end
  104. function SkeletonData:findTransformConstraint (constraintName)
  105. if not constraintName then error("constraintName cannot be nil.", 2) end
  106. for _,constraint in ipairs(self.transformConstraints) do
  107. if constraint.name == constraintName then return constraint end
  108. end
  109. return nil
  110. end
  111. function SkeletonData:findPathConstraint (constraintName)
  112. if not constraintName then error("constraintName cannot be nil.", 2) end
  113. for _,constraint in ipairs(self.pathConstraints) do
  114. if constraint.name == constraintName then return constraint end
  115. end
  116. return nil
  117. end
  118. function SkeletonData:findPathConstraintIndex (constraintName)
  119. if not constraintName then error("constraintName cannot be nil.", 2) end
  120. for i,constraint in ipairs(self.pathConstraints) do
  121. if constraint.name == constraintName then return i end
  122. end
  123. return -1
  124. end
  125. return SkeletonData