All pastes #967130 Raw Edit

pointplacement.lua

public lua v1 · immutable
·published 2008-04-02 06:11 UTC
rendered paste body
function widget:GetInfo()  return {    name      = "Point Placement",    desc      = "Outputs a list of coordinates for user-placed points.",    author    = "lurker (Dylan Petonke)",    date      = "April 1, 2008",    license   = "GNU GPL, v2 or later",    layer     = 1,    enabled   = false  -- loaded by default?  }endlocal points = {}local configfilefunction widget:Initialize()    Spring.CreateDir("LuaUI/Config/ControlPoints")    configfile,_ = string.gsub(Game.mapName, ".smf$", ".lua")    if VFS.FileExists("LuaUI/Config/ControlPoints/" .. configfile) then        points = include("Config/ControlPoints/" .. configfile)        for i,p in pairs(points) do            Spring.MarkerAddPoint(p.x, p.y, p.z, "loaded point")        end    endendfunction widget:MapDrawCmd(...)    x = arg[3]    y = arg[4]    z = arg[5]    if (arg[2] == "point") then        for i,p in pairs(points) do            if math.abs(x - p.x) + math.abs(y - p.y) + math.abs(z - p.z) < 1 then                if arg[6] == "loaded point" then                    return false                else                    return true                end            end        end        table.insert(points, { x=x, y=y, z=z })    elseif (arg[2] == "erase" ) then        for i,p in pairs(points) do            if (math.sqrt((x - p.x)*(x - p.x) + (y - p.y)*(y - p.y) + (z - p.z)*(z - p.z)) < arg[6]) then                points[i] = nil            end        end    endendfunction widget:Shutdown()    local f, err = io.open("LuaUI/Config/ControlPoints/" .. configfile, 'w')    if (f == nil) then        Spring.Echo(err)    else        f:write('return {\n')        for i,p in pairs(points) do            f:write('    { x='.. p.x ..', y='.. p.y ..', z='.. p.z ..' },\n')        end        f:write('}\n')        f:close()    end    points = {}end