Page 1 of 1

LuaRendering#draw_polyline

Posted: Sat Jul 10, 2021 10:45 am
by PFQNiet
I'd like to request the ability to draw a polyline.

It would use all of the parameters of draw_line, but instead of "from" and "to", it would use draw_polygon's "vertices" (named "points") and "target". Optionally have a "closed" parameter that connects the last vertex with the first.

Currently drawing a path requires drawing each individual line segment, but with a polyline this could be done with a single rendering element. It would also make changing the colour/style/visibility of the path a trivial operation, rather than having to update every single element (or more realistically, destroy and re-draw the path).

Example: drawing a dashed-outline square

Code: Select all

-- current
-- note last vertex is duplicated to close the shape
---@type Position[]
local vertices = {{-10,-10}, {10,-10}, {10,10}, {-10,10}, {-10,-10}}
local graphics = {}
for i=2,#vertices do
  table.insert(graphics, rendering.draw_line{
    surface = game.surfaces[1],
    from = vertices[i-1],
    to = vertices[i],
    color = {1,1,0},
    width = 1,
    dash_length = 1,
    gap_length = 1
  })
end

Code: Select all

-- proposed new
---@type ScriptRenderVertexTarget[]
local vertices = {
  {target = {-10,-10}},
  {target = {10,-10}},
  {target = {10,10}},
  {target = {-10,10}}
}
local graphic = rendering.draw_polyline{
  surface = game.surfaces[1],
  points = vertices,
  closed = true,
  color = {1,1,0},
  width = 1,
  dash_length = 1,
  gap_length = 1
}