Skeleton.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. require "Polycode/Entity"
  2. class "Skeleton" (Entity)
  3. function Skeleton:Skeleton(...)
  4. local arg = {...}
  5. if type(arg[1]) == "table" and count(arg) == 1 then
  6. if ""..arg[1].__classname == "Entity" then
  7. self.__ptr = arg[1].__ptr
  8. return
  9. end
  10. end
  11. for k,v in pairs(arg) do
  12. if type(v) == "table" then
  13. if v.__ptr ~= nil then
  14. arg[k] = v.__ptr
  15. end
  16. end
  17. end
  18. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  19. self.__ptr = Polycode.Skeleton(unpack(arg))
  20. end
  21. end
  22. function Skeleton:loadSkeleton(fileName)
  23. local retVal = Polycode.Skeleton_loadSkeleton(self.__ptr, fileName)
  24. end
  25. function Skeleton:playAnimationByName(animName, weight, once, restartIfPlaying)
  26. local retVal = Polycode.Skeleton_playAnimationByName(self.__ptr, animName, weight, once, restartIfPlaying)
  27. end
  28. function Skeleton:setBaseAnimationByName(animName)
  29. local retVal = Polycode.Skeleton_setBaseAnimationByName(self.__ptr, animName)
  30. end
  31. function Skeleton:stopAllAnimations()
  32. local retVal = Polycode.Skeleton_stopAllAnimations(self.__ptr)
  33. end
  34. function Skeleton:addAnimation(name, fileName)
  35. local retVal = Polycode.Skeleton_addAnimation(self.__ptr, name, fileName)
  36. end
  37. function Skeleton:stopAnimationByName(name)
  38. local retVal = Polycode.Skeleton_stopAnimationByName(self.__ptr, name)
  39. end
  40. function Skeleton:Update()
  41. local retVal = Polycode.Skeleton_Update(self.__ptr)
  42. end
  43. function Skeleton:getBoneByName(name)
  44. local retVal = Polycode.Skeleton_getBoneByName(self.__ptr, name)
  45. if retVal == nil then return nil end
  46. local __c = _G["shared_ptr<Bone>"]("__skip_ptr__")
  47. __c.__ptr = retVal
  48. return __c
  49. end
  50. function Skeleton:bonesVisible(val)
  51. local retVal = Polycode.Skeleton_bonesVisible(self.__ptr, val)
  52. end
  53. function Skeleton:getNumBones()
  54. local retVal = Polycode.Skeleton_getNumBones(self.__ptr)
  55. return retVal
  56. end
  57. function Skeleton:getBone(index)
  58. local retVal = Polycode.Skeleton_getBone(self.__ptr, index)
  59. if retVal == nil then return nil end
  60. local __c = _G["shared_ptr<Bone>"]("__skip_ptr__")
  61. __c.__ptr = retVal
  62. return __c
  63. end
  64. function Skeleton:addBone(bone)
  65. local retVal = Polycode.Skeleton_addBone(self.__ptr, bone.__ptr)
  66. end
  67. function Skeleton:removeBone(bone)
  68. local retVal = Polycode.Skeleton_removeBone(self.__ptr, bone.__ptr)
  69. end
  70. function Skeleton:getBoneIndexByBone(bone)
  71. local retVal = Polycode.Skeleton_getBoneIndexByBone(self.__ptr, bone.__ptr)
  72. return retVal
  73. end
  74. function Skeleton:__delete()
  75. if self then Polycode.delete_Skeleton(self.__ptr) end
  76. end