deletor.lua 518 B

123456789101112131415161718
  1. local Deletor = class()
  2. local function invoke(x, k, ...) return x.editor[k](x, ...) end
  3. function Deletor:keypressed(key)
  4. if key == 'delete' then
  5. table.each(ctx.map.props, function(p)
  6. if math.inside(ctx.view:worldMouseX(), ctx.view:worldMouseY(), invoke(p, 'boundingBox')) then
  7. ctx.view:unregister(p)
  8. ctx.map.props = table.filter(ctx.map.props, function(prop) return p ~= prop end)
  9. ctx.event:emit('prop.destroy', p)
  10. return true
  11. end
  12. end)
  13. end
  14. end
  15. return Deletor