2022-12-13 14:02:30 -05:00
|
|
|
-- Bundled by luabundle {"version":"1.6.0"}
|
|
|
|
local __bundle_require, __bundle_loaded, __bundle_register, __bundle_modules = (function(superRequire)
|
|
|
|
local loadingPlaceholder = {[{}] = true}
|
|
|
|
|
|
|
|
local register
|
|
|
|
local modules = {}
|
|
|
|
|
|
|
|
local require
|
|
|
|
local loaded = {}
|
|
|
|
|
|
|
|
register = function(name, body)
|
|
|
|
if not modules[name] then
|
|
|
|
modules[name] = body
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
require = function(name)
|
|
|
|
local loadedModule = loaded[name]
|
|
|
|
|
|
|
|
if loadedModule then
|
|
|
|
if loadedModule == loadingPlaceholder then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if not modules[name] then
|
|
|
|
if not superRequire then
|
|
|
|
local identifier = type(name) == 'string' and '\"' .. name .. '\"' or tostring(name)
|
|
|
|
error('Tried to require ' .. identifier .. ', but no such module has been registered')
|
|
|
|
else
|
|
|
|
return superRequire(name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
loaded[name] = loadingPlaceholder
|
|
|
|
loadedModule = modules[name](require, loaded, register, modules)
|
|
|
|
loaded[name] = loadedModule
|
|
|
|
end
|
|
|
|
|
|
|
|
return loadedModule
|
|
|
|
end
|
|
|
|
|
|
|
|
return require, loaded, register, modules
|
|
|
|
end)(nil)
|
2024-03-10 09:56:22 -04:00
|
|
|
__bundle_register("__root", function(require, _LOADED, __bundle_register, __bundle_modules)
|
|
|
|
require("util/ConnectionDrawingTool")
|
|
|
|
end)
|
2022-12-13 14:02:30 -05:00
|
|
|
__bundle_register("util/ConnectionDrawingTool", function(require, _LOADED, __bundle_register, __bundle_modules)
|
2024-07-27 21:47:52 -04:00
|
|
|
local connections = {}
|
2022-10-19 19:07:47 -04:00
|
|
|
|
2023-04-22 16:56:01 -04:00
|
|
|
function onSave()
|
2024-07-27 21:47:52 -04:00
|
|
|
return JSON.encode({ connections = connections })
|
2023-04-22 16:56:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function onLoad(savedData)
|
2024-06-09 10:10:21 -04:00
|
|
|
if savedData and savedData ~= "" then
|
2024-07-27 21:47:52 -04:00
|
|
|
local loadedData = JSON.decode(savedData) or {}
|
|
|
|
connections = loadedData.connections
|
|
|
|
processLines()
|
2024-06-09 10:10:21 -04:00
|
|
|
end
|
2024-07-27 21:47:52 -04:00
|
|
|
|
|
|
|
addHotkey("Drawing Tool: Reset", function() connections = {} processLines() end)
|
|
|
|
addHotkey("Drawing Tool: Redraw", processLines)
|
2022-10-19 19:07:47 -04:00
|
|
|
end
|
|
|
|
|
2024-07-27 21:47:52 -04:00
|
|
|
function onScriptingButtonDown(index, playerColor)
|
2023-04-22 16:56:01 -04:00
|
|
|
if index ~= 10 then return end
|
2024-07-27 21:47:52 -04:00
|
|
|
|
|
|
|
Timer.create {
|
|
|
|
identifier = playerColor .. "_draw_from",
|
|
|
|
function_name = "draw_from",
|
|
|
|
parameters = { player = Player[playerColor] },
|
|
|
|
delay = 1
|
|
|
|
}
|
2022-10-19 19:07:47 -04:00
|
|
|
end
|
|
|
|
|
2024-07-27 21:47:52 -04:00
|
|
|
function draw_from(params)
|
|
|
|
local source = params.player.getHoverObject()
|
2023-04-22 16:56:01 -04:00
|
|
|
if not source then return end
|
|
|
|
|
2024-07-27 21:47:52 -04:00
|
|
|
for _, item in ipairs(params.player.getSelectedObjects()) do
|
|
|
|
if item ~= source then
|
2023-04-22 16:56:01 -04:00
|
|
|
if item.getGUID() > source.getGUID() then
|
2024-07-27 21:47:52 -04:00
|
|
|
addPair(item, source)
|
2023-04-22 16:56:01 -04:00
|
|
|
else
|
2024-07-27 21:47:52 -04:00
|
|
|
addPair(source, item)
|
2023-04-22 16:56:01 -04:00
|
|
|
end
|
2022-10-19 19:07:47 -04:00
|
|
|
end
|
2023-04-22 16:56:01 -04:00
|
|
|
end
|
2022-10-19 19:07:47 -04:00
|
|
|
|
2024-07-27 21:47:52 -04:00
|
|
|
processLines()
|
2022-10-19 19:07:47 -04:00
|
|
|
end
|
|
|
|
|
2024-07-27 21:47:52 -04:00
|
|
|
function onScriptingButtonUp(index, playerColor)
|
2023-04-22 16:56:01 -04:00
|
|
|
if index ~= 10 then return end
|
2024-07-27 21:47:52 -04:00
|
|
|
|
2023-04-22 16:56:01 -04:00
|
|
|
-- returns true only if there is a timer to cancel. If this is false then we've waited longer than a second.
|
2024-07-27 21:47:52 -04:00
|
|
|
if not Timer.destroy(playerColor .. "_draw_from") then return end
|
2022-10-19 19:07:47 -04:00
|
|
|
|
2024-07-27 21:47:52 -04:00
|
|
|
local items = Player[playerColor].getSelectedObjects()
|
|
|
|
if #items < 2 then return end
|
2022-10-19 19:07:47 -04:00
|
|
|
|
2023-04-22 16:56:01 -04:00
|
|
|
table.sort(items, function(a, b) return a.getGUID() > b.getGUID() end)
|
|
|
|
|
2024-07-27 21:47:52 -04:00
|
|
|
for i = 1, #items do
|
|
|
|
local first = items[i]
|
|
|
|
|
|
|
|
for j = i, #items do
|
|
|
|
local second = items[j]
|
|
|
|
addPair(first, second)
|
2022-10-19 19:07:47 -04:00
|
|
|
end
|
2023-04-22 16:56:01 -04:00
|
|
|
end
|
2022-10-19 19:07:47 -04:00
|
|
|
|
2024-07-27 21:47:52 -04:00
|
|
|
processLines()
|
2022-10-19 19:07:47 -04:00
|
|
|
end
|
|
|
|
|
2024-07-27 21:47:52 -04:00
|
|
|
function addPair(first, second)
|
|
|
|
local first_guid = first.getGUID()
|
|
|
|
local second_guid = second.getGUID()
|
2022-10-19 19:07:47 -04:00
|
|
|
|
2024-07-27 21:47:52 -04:00
|
|
|
if not connections[first_guid] then connections[first_guid] = {} end
|
|
|
|
connections[first_guid][second_guid] = not connections[first_guid][second_guid]
|
2022-10-19 19:07:47 -04:00
|
|
|
end
|
|
|
|
|
2024-07-27 21:47:52 -04:00
|
|
|
function processLines()
|
|
|
|
local lines = {}
|
|
|
|
|
|
|
|
for source_guid, target_guids in pairs(connections) do
|
|
|
|
local source = getObjectFromGUID(source_guid)
|
2022-10-19 19:07:47 -04:00
|
|
|
|
2024-07-27 21:47:52 -04:00
|
|
|
for target_guid, exists in pairs(target_guids) do
|
|
|
|
if exists then
|
|
|
|
local target = getObjectFromGUID(target_guid)
|
|
|
|
|
|
|
|
if source and target then
|
|
|
|
table.insert(lines, {
|
|
|
|
points = { source.getPosition(), target.getPosition() },
|
|
|
|
color = Color.White
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2022-10-19 19:07:47 -04:00
|
|
|
end
|
2023-04-22 16:56:01 -04:00
|
|
|
end
|
2022-10-19 19:07:47 -04:00
|
|
|
|
2024-07-27 21:47:52 -04:00
|
|
|
Global.setVectorLines(lines)
|
2022-12-13 14:02:30 -05:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
return __bundle_require("__root")
|