PhysicsScreenEvent.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. require "Polycode/Event"
  2. class "PhysicsScreenEvent" (Event)
  3. EVENT_NEW_SHAPE_COLLISION = 0
  4. EVENT_END_SHAPE_COLLISION = 1
  5. function PhysicsScreenEvent:__index__(name)
  6. if name == "localCollisionNormal" then
  7. retVal = Physics2D.PhysicsScreenEvent_get_localCollisionNormal(self.__ptr)
  8. if Polycore.__ptr_lookup[retVal] ~= nil then
  9. return Polycore.__ptr_lookup[retVal]
  10. else
  11. Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
  12. Polycore.__ptr_lookup[retVal].__ptr = retVal
  13. return Polycore.__ptr_lookup[retVal]
  14. end
  15. elseif name == "worldCollisionNormal" then
  16. retVal = Physics2D.PhysicsScreenEvent_get_worldCollisionNormal(self.__ptr)
  17. if Polycore.__ptr_lookup[retVal] ~= nil then
  18. return Polycore.__ptr_lookup[retVal]
  19. else
  20. Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
  21. Polycore.__ptr_lookup[retVal].__ptr = retVal
  22. return Polycore.__ptr_lookup[retVal]
  23. end
  24. elseif name == "localCollisionPoint" then
  25. retVal = Physics2D.PhysicsScreenEvent_get_localCollisionPoint(self.__ptr)
  26. if Polycore.__ptr_lookup[retVal] ~= nil then
  27. return Polycore.__ptr_lookup[retVal]
  28. else
  29. Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
  30. Polycore.__ptr_lookup[retVal].__ptr = retVal
  31. return Polycore.__ptr_lookup[retVal]
  32. end
  33. elseif name == "impactStrength" then
  34. return Physics2D.PhysicsScreenEvent_get_impactStrength(self.__ptr)
  35. elseif name == "frictionStrength" then
  36. return Physics2D.PhysicsScreenEvent_get_frictionStrength(self.__ptr)
  37. end
  38. end
  39. function PhysicsScreenEvent:__set_callback(name,value)
  40. if name == "impactStrength" then
  41. Physics2D.PhysicsScreenEvent_set_impactStrength(self.__ptr, value)
  42. return true
  43. elseif name == "frictionStrength" then
  44. Physics2D.PhysicsScreenEvent_set_frictionStrength(self.__ptr, value)
  45. return true
  46. end
  47. return false
  48. end
  49. function PhysicsScreenEvent:PhysicsScreenEvent(...)
  50. if type(arg[1]) == "table" and count(arg) == 1 then
  51. if ""..arg[1]:class() == "Event" then
  52. self.__ptr = arg[1].__ptr
  53. return
  54. end
  55. end
  56. for k,v in pairs(arg) do
  57. if type(v) == "table" then
  58. if v.__ptr ~= nil then
  59. arg[k] = v.__ptr
  60. end
  61. end
  62. end
  63. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  64. self.__ptr = Physics2D.PhysicsScreenEvent(unpack(arg))
  65. Polycore.__ptr_lookup[self.__ptr] = self
  66. end
  67. end
  68. function PhysicsScreenEvent:getFirstEntity()
  69. local retVal = Physics2D.PhysicsScreenEvent_getFirstEntity(self.__ptr)
  70. if retVal == nil then return nil end
  71. if Polycore.__ptr_lookup[retVal] ~= nil then
  72. return Polycore.__ptr_lookup[retVal]
  73. else
  74. Polycore.__ptr_lookup[retVal] = ScreenEntity("__skip_ptr__")
  75. Polycore.__ptr_lookup[retVal].__ptr = retVal
  76. return Polycore.__ptr_lookup[retVal]
  77. end
  78. end
  79. function PhysicsScreenEvent:getSecondEntity()
  80. local retVal = Physics2D.PhysicsScreenEvent_getSecondEntity(self.__ptr)
  81. if retVal == nil then return nil end
  82. if Polycore.__ptr_lookup[retVal] ~= nil then
  83. return Polycore.__ptr_lookup[retVal]
  84. else
  85. Polycore.__ptr_lookup[retVal] = ScreenEntity("__skip_ptr__")
  86. Polycore.__ptr_lookup[retVal].__ptr = retVal
  87. return Polycore.__ptr_lookup[retVal]
  88. end
  89. end
  90. function PhysicsScreenEvent:__delete()
  91. Polycore.__ptr_lookup[self.__ptr] = nil
  92. Physics2D.delete_PhysicsScreenEvent(self.__ptr)
  93. end