skin_meta_api.lua 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. skins.meta = {}
  2. local skin_class = {}
  3. skin_class.__index = skin_class
  4. -----------------------
  5. -- Class methods
  6. -----------------------
  7. -- constructor
  8. function skins.new(key, object)
  9. assert(key, 'Unique skins key required, like "character_1"')
  10. local self = object or {}
  11. setmetatable(self, skin_class)
  12. self.__index = skin_class
  13. self._key = key
  14. self._sort_id = 0
  15. skins.meta[key] = self
  16. return self
  17. end
  18. -- getter
  19. function skins.get(key)
  20. return skins.meta[key]
  21. end
  22. -- Skin methods
  23. -- In this implementation it is just access to attrubutes wrapped
  24. -- but this way allow to redefine the functionality for more complex skins provider
  25. function skin_class:get_key()
  26. return self._key
  27. end
  28. function skin_class:set_meta(key, value)
  29. self[key] = value
  30. end
  31. function skin_class:get_meta(key)
  32. return self[key]
  33. end
  34. function skin_class:get_meta_string(key)
  35. return tostring(self:get_meta(key) or "")
  36. end
  37. function skin_class:set_texture(value)
  38. self._texture = value
  39. end
  40. function skin_class:get_texture()
  41. return self._texture
  42. end
  43. function skin_class:set_preview(value)
  44. self._preview = value
  45. end
  46. function skin_class:get_preview()
  47. return self._preview or "player.png"
  48. end
  49. function skin_class:set_skin(player)
  50. player:set_properties({
  51. visual_size = {
  52. x = 1,
  53. y = 1
  54. }
  55. })
  56. player:set_properties({
  57. textures = {self:get_texture()},
  58. })
  59. end