--- --- Generated by Luanalysis --- Created by Whimsical. --- DateTime: 2022-01-01 12:32 a.m. --- local lines = {} function onload(data) if data then local info = JSON.decode(data) if info then lines = info.lines process_lines() end end end function onSave() return JSON.encode({lines = lines}) end ---@param index number ---@param player_color string function onScriptingButtonDown(index, player_color) if index~=10 then return end Timer.create { identifier = player_color .. "_draw_from", function_name = "draw_from", parameters = { player = Player[player_color]}, delay = 1 } end ---@param params table function draw_from(params) local player = params.player local source = player:getHoverObject() local selections = player:getSelectedObjects() if not source then return end for _, item in ipairs(selections) do if item:getGUID() ~= source:getGUID() then if item:getGUID() > source:getGUID() then draw_with_pair(item, source) else draw_with_pair(source, item) end end end process_lines() end ---@param index number ---@param player_color string function onScriptingButtonUp(index, player_color) if index~=10 then return end -- Returns true only if there is a timer to cancel. If this is false then we've waited longer than a second. if not Timer.destroy(player_color .. "_draw_from") then return end ---@type Player local player = Player[player_color] local items = player:getSelectedObjects() if #items < 2 then -- broadcastToColor("You must have exactly 2 items select. You currently have " .. #items .. ".", player_color, Color.Red) return end table.sort(items, function (a,b) return a:getGUID() > b:getGUID() end) for f =1, #items do local first = items[f] for s = f, #items do local second = items[s] draw_with_pair(first, second) end end process_lines() end ---@param first TTSObject ---@param second TTSObject function draw_with_pair(first, second) local guid_first, guid_second = first:getGUID(), second:getGUID() if not lines[guid_first] then lines[guid_first] = {} end if lines[guid_first][guid_second] then lines[guid_first][guid_second] = nil else lines[guid_first][guid_second] = { points = {first:getPosition(), second:getPosition()}, color = Color.White } end end function process_lines() local drawing = {} for _, first in pairs(lines) do for _, data in pairs(first) do table.insert(drawing, data) end end Global.setVectorLines(drawing) end