AtlasAttachmentLoader.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. -------------------------------------------------------------------------------
  2. -- Spine Runtimes License Agreement
  3. -- Last updated January 1, 2020. Replaces all prior versions.
  4. --
  5. -- Copyright (c) 2013-2020, Esoteric Software LLC
  6. --
  7. -- Integration of the Spine Runtimes into software or otherwise creating
  8. -- derivative works of the Spine Runtimes is permitted under the terms and
  9. -- conditions of Section 2 of the Spine Editor License Agreement:
  10. -- http://esotericsoftware.com/spine-editor-license
  11. --
  12. -- Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. -- or otherwise create derivative works of the Spine Runtimes (collectively,
  14. -- "Products"), provided that each user of the Products must obtain their own
  15. -- Spine Editor license and redistribution of the Products in any form must
  16. -- include this license and copyright notice.
  17. --
  18. -- THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
  19. -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. -- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. -- DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
  22. -- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
  24. -- BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
  25. -- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. -- THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. -------------------------------------------------------------------------------
  29. local setmetatable = setmetatable
  30. local AttachmentType = require "spine-lua.attachments.AttachmentType"
  31. local RegionAttachment = require "spine-lua.attachments.RegionAttachment"
  32. local BoundingBoxAttachment = require "spine-lua.attachments.BoundingBoxAttachment"
  33. local MeshAttachment = require "spine-lua.attachments.MeshAttachment"
  34. local PathAttachment = require "spine-lua.attachments.PathAttachment"
  35. local PointAttachment = require "spine-lua.attachments.PointAttachment"
  36. local ClippingAttachment = require "spine-lua.attachments.ClippingAttachment"
  37. local TextureAtlas = require "spine-lua.TextureAtlas"
  38. local AtlasAttachmentLoader = {}
  39. AtlasAttachmentLoader.__index = AtlasAttachmentLoader
  40. function AtlasAttachmentLoader.new (atlas)
  41. local self = {
  42. atlas = atlas
  43. }
  44. setmetatable(self, AtlasAttachmentLoader)
  45. return self
  46. end
  47. function AtlasAttachmentLoader:newRegionAttachment (skin, name, path)
  48. local region = self.atlas:findRegion(path)
  49. if not region then error("Region not found in atlas: " .. path .. " (region attachment: " .. name .. ")") end
  50. region.renderObject = region
  51. local attachment = RegionAttachment.new(name)
  52. attachment:setRegion(region)
  53. attachment.region = region
  54. return attachment
  55. end
  56. function AtlasAttachmentLoader:newMeshAttachment (skin, name, path)
  57. local region = self.atlas:findRegion(path)
  58. if not region then error("Region not found in atlas: " .. path .. " (mesh attachment: " .. name .. ")") end
  59. region.renderObject = region
  60. local attachment = MeshAttachment.new(name)
  61. attachment.region = region
  62. return attachment
  63. end
  64. function AtlasAttachmentLoader:newBoundingBoxAttachment (skin, name)
  65. return BoundingBoxAttachment.new(name)
  66. end
  67. function AtlasAttachmentLoader:newPathAttachment(skin, name)
  68. return PathAttachment.new(name)
  69. end
  70. function AtlasAttachmentLoader:newPointAttachment(skin, name)
  71. return PointAttachment.new(name)
  72. end
  73. function AtlasAttachmentLoader:newClippingAttachment(skin, name)
  74. return ClippingAttachment.new(name)
  75. end
  76. return AtlasAttachmentLoader