SkeletonData.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. -------------------------------------------------------------------------------
  2. -- Spine Runtimes Software License
  3. -- Version 2.1
  4. --
  5. -- Copyright (c) 2013, Esoteric Software
  6. -- All rights reserved.
  7. --
  8. -- You are granted a perpetual, non-exclusive, non-sublicensable and
  9. -- non-transferable license to install, execute and perform the Spine Runtimes
  10. -- Software (the "Software") solely for internal use. Without the written
  11. -- permission of Esoteric Software (typically granted by licensing Spine), you
  12. -- may not (a) modify, translate, adapt or otherwise create derivative works,
  13. -- improvements of the Software or develop new applications using the Software
  14. -- or (b) remove, delete, alter or obscure any trademarks or any copyright,
  15. -- trademark, patent or other intellectual property or proprietary rights
  16. -- notices on or in the Software, including any copy thereof. Redistributions
  17. -- in binary or source 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 SOFTARE 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; LOSS OF USE, DATA, OR PROFITS;
  25. -- OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  26. -- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  27. -- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  28. -- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. -------------------------------------------------------------------------------
  30. local SkeletonData = {}
  31. function SkeletonData.new ()
  32. local self = {
  33. version = 0, hash = 0,
  34. width = 0, height = 0,
  35. bones = {},
  36. slots = {},
  37. slotNameIndices = {},
  38. skins = {},
  39. events = {},
  40. animations = {},
  41. ikConstraints = {},
  42. defaultSkin = nil
  43. }
  44. function self:findBone (boneName)
  45. if not boneName then error("boneName cannot be nil.", 2) end
  46. for i,bone in ipairs(self.bones) do
  47. if bone.name == boneName then return bone end
  48. end
  49. return nil
  50. end
  51. function self:findBoneIndex (boneName)
  52. if not boneName then error("boneName cannot be nil.", 2) end
  53. for i,bone in ipairs(self.bones) do
  54. if bone.name == boneName then return i end
  55. end
  56. return -1
  57. end
  58. function self:findSlot (slotName)
  59. if not slotName then error("slotName cannot be nil.", 2) end
  60. for i,slot in ipairs(self.slots) do
  61. if slot.name == slotName then return slot end
  62. end
  63. return nil
  64. end
  65. function self:findSlotIndex (slotName)
  66. if not slotName then error("slotName cannot be nil.", 2) end
  67. return self.slotNameIndices[slotName] or -1
  68. end
  69. function self:findSkin (skinName)
  70. if not skinName then error("skinName cannot be nil.", 2) end
  71. for i,skin in ipairs(self.skins) do
  72. if skin.name == skinName then return skin end
  73. end
  74. return nil
  75. end
  76. function self:findEvent (eventName)
  77. if not eventName then error("eventName cannot be nil.", 2) end
  78. for i,event in ipairs(self.events) do
  79. if event.name == eventName then return event end
  80. end
  81. return nil
  82. end
  83. function self:findAnimation (animationName)
  84. if not animationName then error("animationName cannot be nil.", 2) end
  85. for i,animation in ipairs(self.animations) do
  86. if animation.name == animationName then return animation end
  87. end
  88. return nil
  89. end
  90. function self:findIkConstraint (ikConstraintName)
  91. if not ikConstraintName then error("ikConstraintName cannot be nil.", 2) end
  92. for i,ikConstraint in ipairs(self.ikConstraints) do
  93. if ikConstraint.name == ikConstraintName then return ikConstraint end
  94. end
  95. return nil
  96. end
  97. return self
  98. end
  99. return SkeletonData