Curtain.lua 1016 B

1234567891011121314151617181920212223242526272829303132333435
  1. local Element = require('elements/Element')
  2. ---@class Curtain : Element
  3. local Curtain = class(Element)
  4. function Curtain:new() return Class.new(self) --[[@as Curtain]] end
  5. function Curtain:init()
  6. Element.init(self, 'curtain', {render_order = 999})
  7. self.opacity = 0
  8. ---@type string[]
  9. self.dependents = {}
  10. end
  11. ---@param id string
  12. function Curtain:register(id)
  13. self.dependents[#self.dependents + 1] = id
  14. if #self.dependents == 1 then self:tween_property('opacity', self.opacity, 1) end
  15. end
  16. ---@param id string
  17. function Curtain:unregister(id)
  18. self.dependents = itable_filter(self.dependents, function(item) return item ~= id end)
  19. if #self.dependents == 0 then self:tween_property('opacity', self.opacity, 0) end
  20. end
  21. function Curtain:render()
  22. if self.opacity == 0 or config.opacity.curtain == 0 then return end
  23. local ass = assdraw.ass_new()
  24. ass:rect(0, 0, display.width, display.height, {
  25. color = config.color.curtain, opacity = config.opacity.curtain * self.opacity,
  26. })
  27. return ass
  28. end
  29. return Curtain