LuaRendering#draw_polyline

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
PFQNiet
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

LuaRendering#draw_polyline

Post 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
}

Post Reply

Return to “Modding interface requests”