Updated drawing tool

This commit is contained in:
Chr1Z93 2024-05-21 11:23:11 +02:00
parent dedd50aedd
commit c61d6dc6d5
3 changed files with 53 additions and 42 deletions

View File

@ -1,6 +1,6 @@
{ {
"1": { "1": {
"body": "Welcome to Arkham Horror LCG - Super Complete Edition!\n\nMake sure to take the tour that can be started with the token in the middle of the main playarea. Some basic notes:\n\nDECKBUILDING\n- All currently existing investigators and player cards are accessible via the player card panel in the upper left corner of the table.\n\n- On the leftside underneath the Investigators, you will find the ArkhamDB Deckimporter. Insert your deck ID and it will build the deck automatically for you.\n\nSCENARIOS & SETUP\n- Arkham Horror LCG comes with a core campaign (Night of the Zealot) and several expansions. Within each box you will find all the cards required for each scenario setup, as well as a the official campaign guide PDF.\n\n2. Each scenario is setup differently, and while some of the work has been prepared beforehand (such as building encounter decks), you will have to refer to the Campaign Guide for specific instructions on how to set up each scenario.\n\nINVESTIGATOR PLAYMAT AND GAMEPLAY\n- Playermats are scripted to automate most of the gameplay for you.", "body": "Welcome to Arkham Horror LCG - Super Complete Edition!\n\nMake sure to take the tour that can be started with the token in the middle of the main playarea. Some basic notes:\n\nDECKBUILDING\n- All currently existing investigators and player cards are accessible via the player card panel in the upper left corner of the table.\n\n- On the leftside underneath the Investigators, you will find the ArkhamDB Deckimporter. Insert your deck ID and it will build the deck automatically for you.\n\nSCENARIOS \u0026 SETUP\n- Arkham Horror LCG comes with a core campaign (Night of the Zealot) and several expansions. Within each box you will find all the cards required for each scenario setup, as well as a the official campaign guide PDF.\n\n2. Each scenario is setup differently, and while some of the work has been prepared beforehand (such as building encounter decks), you will have to refer to the Campaign Guide for specific instructions on how to set up each scenario.\n\nINVESTIGATOR PLAYMAT AND GAMEPLAY\n- Playermats are scripted to automate most of the gameplay for you.",
"color": "Grey", "color": "Grey",
"id": 1, "id": 1,
"title": "Basic Intro", "title": "Basic Intro",

View File

@ -34,7 +34,7 @@
"LayoutGroupSortIndex": 0, "LayoutGroupSortIndex": 0,
"Locked": true, "Locked": true,
"LuaScript": "require(\"util/ConnectionDrawingTool\")", "LuaScript": "require(\"util/ConnectionDrawingTool\")",
"LuaScriptState": "{\"e8e04b\":[]}", "LuaScriptState": "{\"connections\":[]}",
"MeasureMovement": false, "MeasureMovement": false,
"Name": "Custom_Token", "Name": "Custom_Token",
"Nickname": "Drawing Tool", "Nickname": "Drawing Tool",

View File

@ -1,87 +1,98 @@
local lines = {} local connections = {}
-- save "lines" to be able to remove them after loading
function onSave() function onSave()
return JSON.encode(lines) return JSON.encode({ connections = connections })
end end
function onLoad(savedData) function onLoad(savedData)
if savedData and savedData ~= "" then if savedData and savedData ~= "" then
lines = JSON.decode(savedData) or {} local loadedData = JSON.decode(savedData) or {}
connections = loadedData.connections
processLines()
end end
addHotkey("Drawing Tool: Reset", function() connections = {} processLines() end)
addHotkey("Drawing Tool: Redraw", processLines)
end end
-- create timer when numpad 0 is pressed
function onScriptingButtonDown(index, player_color) function onScriptingButtonDown(index, player_color)
if index ~= 10 then return end if index ~= 10 then return end
TimerID = Wait.time(function() draw_from(Player[player_color]) end, 1)
Timer.create {
identifier = player_color .. "_draw_from",
function_name = "draw_from",
parameters = { Player[player_color] },
delay = 1
}
end end
-- called for long press of numpad 0, draws lines from hovered object to selected objects
function draw_from(player) function draw_from(player)
local source = player.getHoverObject() local source = player.getHoverObject()
if not source then return end if not source then return end
for _, item in ipairs(player.getSelectedObjects()) do for _, item in ipairs(player.getSelectedObjects()) do
if item.getGUID() ~= source.getGUID() then if item ~= source then
if item.getGUID() > source.getGUID() then if item.getGUID() > source.getGUID() then
draw_with_pair(item, source) addPair(item, source)
else else
draw_with_pair(source, item) addPair(source, item)
end end
end end
end end
process_lines() processLines()
end end
-- general drawing of all lines between selected objects
function onScriptingButtonUp(index, player_color) function onScriptingButtonUp(index, player_color)
if index ~= 10 then return end 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. -- 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 if not Timer.destroy(player_color .. "_draw_from") then return end
local items = Player[player_color].getSelectedObjects() local items = Player[player_color].getSelectedObjects()
if #items < 2 then if #items < 2 then return end
broadcastToColor("You must have at least two items selected (currently: " .. #items .. ").", player_color, "Red")
return
end
table.sort(items, function(a, b) return a.getGUID() > b.getGUID() end) table.sort(items, function(a, b) return a.getGUID() > b.getGUID() end)
for f = 1, #items - 1 do for i = 1, #items do
for s = f + 1, #items do local first = items[i]
draw_with_pair(items[f], items[s])
for j = i, #items do
local second = items[j]
addPair(first, second)
end end
end end
process_lines() processLines()
end end
-- adds two objects to table of vector lines function addPair(first, second)
function draw_with_pair(first, second) local first_guid = first.getGUID()
local guid_first = first.getGUID() local second_guid = second.getGUID()
local guid_second = second.getGUID()
if Global.getVectorLines() == nil then lines = {} end if not connections[first_guid] then connections[first_guid] = {} end
if not lines[guid_first] then lines[guid_first] = {} end connections[first_guid][second_guid] = not connections[first_guid][second_guid]
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
end end
-- updates the global vector lines based on "lines" function processLines()
function process_lines() local lines = {}
local drawing = {}
for _, first in pairs(lines) do for source_guid, target_guids in pairs(connections) do
for _, data in pairs(first) do local source = getObjectFromGUID(source_guid)
table.insert(drawing, data)
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
end end
end end
Global.setVectorLines(drawing) Global.setVectorLines(lines)
end end