ah_sce_unpacked/unpacked/Custom_Token Drawing Tool 280086.ttslua

134 lines
3.6 KiB
Plaintext
Raw Normal View History

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)
__bundle_register("util/ConnectionDrawingTool", function(require, _LOADED, __bundle_register, __bundle_modules)
2023-04-22 16:56:01 -04:00
local lines = {}
2022-10-19 19:07:47 -04:00
-- save "lines" to be able to remove them after loading
2023-04-22 16:56:01 -04:00
function onSave()
return JSON.encode(lines)
end
function onLoad(savedData)
lines = JSON.decode(savedData) or {}
2022-10-19 19:07:47 -04:00
end
-- create timer when numpad 0 is pressed
function onScriptingButtonDown(index, player_color)
2023-04-22 16:56:01 -04:00
if index ~= 10 then return end
TimerID = Wait.time(function() draw_from(Player[player_color]) end, 1)
2022-10-19 19:07:47 -04:00
end
-- called for long press of numpad 0, draws lines from hovered object to selected objects
function draw_from(player)
2023-04-22 16:56:01 -04:00
local source = player.getHoverObject()
if not source then return end
for _, item in ipairs(player.getSelectedObjects()) 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
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
2023-04-22 16:56:01 -04:00
process_lines()
2022-10-19 19:07:47 -04:00
end
-- general drawing of all lines between selected objects
function onScriptingButtonUp(index, player_color)
2023-04-22 16:56:01 -04:00
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 Wait.stop(TimerID) then return end
2022-10-19 19:07:47 -04:00
2023-04-22 16:56:01 -04:00
local items = Player[player_color].getSelectedObjects()
if #items < 2 then
broadcastToColor("You must have at least two items selected (currently: " .. #items .. ").", player_color, "Red")
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)
for f = 1, #items - 1 do
for s = f + 1, #items do
draw_with_pair(items[f], items[s])
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
2023-04-22 16:56:01 -04:00
process_lines()
2022-10-19 19:07:47 -04:00
end
-- adds two objects to table of vector lines
function draw_with_pair(first, second)
2023-04-22 16:56:01 -04:00
local guid_first = first.getGUID()
local guid_second = second.getGUID()
2022-10-19 19:07:47 -04:00
2023-04-22 16:56:01 -04:00
if Global.getVectorLines() == nil then lines = {} end
if not lines[guid_first] then lines[guid_first] = {} end
2022-10-19 19:07:47 -04:00
2023-04-22 16:56:01 -04:00
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 = "White" }
end
2022-10-19 19:07:47 -04:00
end
-- updates the global vector lines based on "lines"
function process_lines()
2023-04-22 16:56:01 -04:00
local drawing = {}
2022-10-19 19:07:47 -04:00
2023-04-22 16:56:01 -04:00
for _, first in pairs(lines) do
for _, data in pairs(first) do
table.insert(drawing, data)
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
2023-04-22 16:56:01 -04:00
Global.setVectorLines(drawing)
2022-12-13 14:02:30 -05:00
end
end)
2024-02-17 19:48:30 -05:00
__bundle_register("__root", function(require, _LOADED, __bundle_register, __bundle_modules)
require("util/ConnectionDrawingTool")
end)
2022-12-13 14:02:30 -05:00
return __bundle_require("__root")