Resource.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. require "Polycode/EventDispatcher"
  2. class "Resource" (EventDispatcher)
  3. Resource.RESOURCE_TEXTURE = 0
  4. Resource.RESOURCE_MATERIAL = 1
  5. Resource.RESOURCE_SHADER = 2
  6. Resource.RESOURCE_PROGRAM = 3
  7. Resource.RESOURCE_MESH = 5
  8. Resource.RESOURCE_CUBEMAP = 6
  9. Resource.RESOURCE_SPRITE = 7
  10. Resource.RESOURCE_ENTITY_INSTANCE = 8
  11. Resource.RESOURCE_FONT = 9
  12. Resource.RESOURCE_SCRIPT = 10
  13. function Resource:__getvar(name)
  14. if name == "reloadOnFileModify" then
  15. return Polycore.Resource_get_reloadOnFileModify(self.__ptr)
  16. elseif name == "resourceFileTime" then
  17. local retVal = Polycore.Resource_get_resourceFileTime(self.__ptr)
  18. if retVal == nil then return nil end
  19. local __c = _G["time_t"]("__skip_ptr__")
  20. __c.__ptr = retVal
  21. return __c
  22. elseif name == "platformData" then
  23. local retVal = Polycore.Resource_get_platformData(self.__ptr)
  24. if retVal == nil then return nil end
  25. local __c = _G["void"]("__skip_ptr__")
  26. __c.__ptr = retVal
  27. return __c
  28. end
  29. if EventDispatcher["__getvar"] ~= nil then
  30. return EventDispatcher.__getvar(self, name)
  31. end
  32. end
  33. function Resource:__setvar(name,value)
  34. if name == "reloadOnFileModify" then
  35. Polycore.Resource_set_reloadOnFileModify(self.__ptr, value)
  36. return true
  37. elseif name == "resourceFileTime" then
  38. Polycore.Resource_set_resourceFileTime(self.__ptr, value.__ptr)
  39. return true
  40. end
  41. if EventDispatcher["__setvar"] ~= nil then
  42. return EventDispatcher.__setvar(self, name, value)
  43. else
  44. return false
  45. end
  46. end
  47. function Resource:Resource(...)
  48. local arg = {...}
  49. if type(arg[1]) == "table" and count(arg) == 1 then
  50. if ""..arg[1].__classname == "EventDispatcher" then
  51. self.__ptr = arg[1].__ptr
  52. return
  53. end
  54. end
  55. for k,v in pairs(arg) do
  56. if type(v) == "table" then
  57. if v.__ptr ~= nil then
  58. arg[k] = v.__ptr
  59. end
  60. end
  61. end
  62. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  63. self.__ptr = Polycore.Resource(unpack(arg))
  64. end
  65. end
  66. function Resource:reloadResource()
  67. local retVal = Polycore.Resource_reloadResource(self.__ptr)
  68. end
  69. function Resource:getResourceName()
  70. local retVal = Polycore.Resource_getResourceName(self.__ptr)
  71. if retVal == nil then return nil end
  72. local __c = _G["String"]("__skip_ptr__")
  73. __c.__ptr = retVal
  74. return __c
  75. end
  76. function Resource:getResourceType()
  77. local retVal = Polycore.Resource_getResourceType(self.__ptr)
  78. return retVal
  79. end
  80. function Resource:setResourceName(newName)
  81. local retVal = Polycore.Resource_setResourceName(self.__ptr, newName)
  82. end
  83. function Resource:setResourcePath(path)
  84. local retVal = Polycore.Resource_setResourcePath(self.__ptr, path)
  85. end
  86. function Resource:getResourcePath()
  87. local retVal = Polycore.Resource_getResourcePath(self.__ptr)
  88. if retVal == nil then return nil end
  89. local __c = _G["String"]("__skip_ptr__")
  90. __c.__ptr = retVal
  91. return __c
  92. end
  93. function Resource:__delete()
  94. if self then Polycore.delete_Resource(self.__ptr) end
  95. end