diff --git a/edge.lua b/edge.lua index b51355a..8cf0772 100644 --- a/edge.lua +++ b/edge.lua @@ -8,7 +8,7 @@ local edge_data = { y = 10, width = 80, height = 10, - lines = {{'fill', {0, 10, 80, 10, 40, 0}}}, + lines = {'fill', {0, 10, 80, 10, 40, 0}}, }, down = { @@ -16,7 +16,7 @@ local edge_data = { y = 220, width = 80, height = 10, - lines = {{'fill', {0, 0, 80, 0, 40, 10}}}, + lines = {'fill', {0, 0, 80, 0, 40, 10}}, }, left = { @@ -24,7 +24,7 @@ local edge_data = { y = 80, width = 10, height = 80, - lines = {{'fill', {10, 0, 10, 80, 0, 40}}}, + lines = {'fill', {10, 0, 10, 80, 0, 40}}, }, right = { @@ -32,7 +32,7 @@ local edge_data = { y = 80, width = 10, height = 80, - lines = {{'fill', {0, 0, 0, 80, 10, 40}}}, + lines = {'fill', {0, 0, 0, 80, 10, 40}}, } } diff --git a/entity.lua b/entity.lua index 4893017..eecd0cc 100644 --- a/entity.lua +++ b/entity.lua @@ -27,28 +27,36 @@ function m:setpos(x, y) self.y = y end +local function draw_line(l) + local mode = l[1] + local segs = l[2] + + if mode == 'line' then + love.graphics.line(segs) + elseif mode == 'fill' then + local ts = love.math.triangulate(segs) + love.graphics.setColor(0, 0, 0) + for i, t in ipairs(ts) do + love.graphics.polygon('fill', t) + end + + love.graphics.setColor(1, 1, 1) + love.graphics.polygon('line', segs) + else + error(string.format("mode must be one of line or fill, not %s", mode)) + end +end + function m:draw() love.graphics.push('all') love.graphics.translate(self.x, self.y) love.graphics.setLineWidth(3) - for _, l in ipairs(self.lines) do - local mode = l[1] - local segs = l[2] - - if mode == 'line' then - love.graphics.line(segs) - elseif mode == 'fill' then - local ts = love.math.triangulate(segs) - love.graphics.setColor(0, 0, 0) - for i, t in ipairs(ts) do - love.graphics.polygon('fill', t) - end - - love.graphics.setColor(1, 1, 1) - love.graphics.polygon('line', segs) - else - error(string.format("mode must be one of line or fill, not %s", mode)) + if type(self.lines[1]) == 'string' then + draw_line(self.lines) + else + for _, l in ipairs(self.lines) do + draw_line(l) end end