Skeleton.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. require "Polycode/SceneEntity"
  2. class "Skeleton" (SceneEntity)
  3. function Skeleton:Skeleton(...)
  4. if type(arg[1]) == "table" and count(arg) == 1 then
  5. if ""..arg[1]:class() == "SceneEntity" then
  6. self.__ptr = arg[1].__ptr
  7. return
  8. end
  9. end
  10. for k,v in pairs(arg) do
  11. if type(v) == "table" then
  12. if v.__ptr ~= nil then
  13. arg[k] = v.__ptr
  14. end
  15. end
  16. end
  17. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  18. self.__ptr = Polycore.Skeleton(unpack(arg))
  19. Polycore.__ptr_lookup[self.__ptr] = self
  20. end
  21. end
  22. function Skeleton:loadSkeleton(fileName)
  23. local retVal = Polycore.Skeleton_loadSkeleton(self.__ptr, fileName.__ptr)
  24. end
  25. function Skeleton:playAnimation(animName)
  26. local retVal = Polycore.Skeleton_playAnimation(self.__ptr, animName.__ptr)
  27. end
  28. function Skeleton:playAnimationByIndex(index)
  29. local retVal = Polycore.Skeleton_playAnimationByIndex(self.__ptr, index)
  30. end
  31. function Skeleton:addAnimation(name, fileName)
  32. local retVal = Polycore.Skeleton_addAnimation(self.__ptr, name.__ptr, fileName.__ptr)
  33. end
  34. function Skeleton:getAnimation(name)
  35. local retVal = Polycore.Skeleton_getAnimation(self.__ptr, name.__ptr)
  36. if retVal == nil then return nil end
  37. if Polycore.__ptr_lookup[retVal] ~= nil then
  38. return Polycore.__ptr_lookup[retVal]
  39. else
  40. Polycore.__ptr_lookup[retVal] = SkeletonAnimation("__skip_ptr__")
  41. Polycore.__ptr_lookup[retVal].__ptr = retVal
  42. return Polycore.__ptr_lookup[retVal]
  43. end
  44. end
  45. function Skeleton:Update()
  46. local retVal = Polycore.Skeleton_Update(self.__ptr)
  47. end
  48. function Skeleton:getBoneByName(name)
  49. local retVal = Polycore.Skeleton_getBoneByName(self.__ptr, name.__ptr)
  50. if retVal == nil then return nil end
  51. if Polycore.__ptr_lookup[retVal] ~= nil then
  52. return Polycore.__ptr_lookup[retVal]
  53. else
  54. Polycore.__ptr_lookup[retVal] = Bone("__skip_ptr__")
  55. Polycore.__ptr_lookup[retVal].__ptr = retVal
  56. return Polycore.__ptr_lookup[retVal]
  57. end
  58. end
  59. function Skeleton:bonesVisible(val)
  60. local retVal = Polycore.Skeleton_bonesVisible(self.__ptr, val)
  61. end
  62. function Skeleton:enableBoneLabels(labelFont, size, scale, labelColor)
  63. local retVal = Polycore.Skeleton_enableBoneLabels(self.__ptr, labelFont.__ptr, size, scale, labelColor.__ptr)
  64. end
  65. function Skeleton:getNumBones()
  66. local retVal = Polycore.Skeleton_getNumBones(self.__ptr)
  67. return retVal
  68. end
  69. function Skeleton:getBone(index)
  70. local retVal = Polycore.Skeleton_getBone(self.__ptr, index)
  71. if retVal == nil then return nil end
  72. if Polycore.__ptr_lookup[retVal] ~= nil then
  73. return Polycore.__ptr_lookup[retVal]
  74. else
  75. Polycore.__ptr_lookup[retVal] = Bone("__skip_ptr__")
  76. Polycore.__ptr_lookup[retVal].__ptr = retVal
  77. return Polycore.__ptr_lookup[retVal]
  78. end
  79. end
  80. function Skeleton:getCurrentAnimation()
  81. local retVal = Polycore.Skeleton_getCurrentAnimation(self.__ptr)
  82. if retVal == nil then return nil end
  83. if Polycore.__ptr_lookup[retVal] ~= nil then
  84. return Polycore.__ptr_lookup[retVal]
  85. else
  86. Polycore.__ptr_lookup[retVal] = SkeletonAnimation("__skip_ptr__")
  87. Polycore.__ptr_lookup[retVal].__ptr = retVal
  88. return Polycore.__ptr_lookup[retVal]
  89. end
  90. end
  91. function Skeleton:__delete()
  92. Polycore.__ptr_lookup[self.__ptr] = nil
  93. Polycore.delete_Skeleton(self.__ptr)
  94. end