Skeleton.lua 2.7 KB

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