Merge pull request #691 from argonui/drawing-tool

Updated Drawing Tool
This commit is contained in:
dscarpac 2024-05-21 08:11:15 -05:00 committed by GitHub
commit 749720d845
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 61 additions and 50 deletions

View File

@ -20,6 +20,7 @@
"Note": "", "Note": "",
"ObjectStates_order": [ "ObjectStates_order": [
"GUIDReferenceHandler.123456", "GUIDReferenceHandler.123456",
"GameKeyHandler.fce69c",
"TokenSpawnTracker.e3ffc9", "TokenSpawnTracker.e3ffc9",
"HandTrigger.5fe087", "HandTrigger.5fe087",
"HandTrigger.be2f17", "HandTrigger.be2f17",
@ -196,7 +197,6 @@
"Fan-MadeExpansionOverview.de7cae", "Fan-MadeExpansionOverview.de7cae",
"OptionPanelSource.830bd0", "OptionPanelSource.830bd0",
"SoundCube.3c988f", "SoundCube.3c988f",
"GameKeyHandler.fce69c",
"TokenSpawningReference.f8b3a7", "TokenSpawningReference.f8b3a7",
"3DText.d628cc", "3DText.d628cc",
"NavigationOverlayHandler.797ede", "NavigationOverlayHandler.797ede",

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, playerColor)
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 = playerColor .. "_draw_from",
function_name = "draw_from",
parameters = { player = Player[playerColor] },
delay = 1
}
end end
-- called for long press of numpad 0, draws lines from hovered object to selected objects function draw_from(params)
function draw_from(player) local source = params.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(params.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, playerColor)
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.
if not Wait.stop(TimerID) then return end
local items = Player[player_color].getSelectedObjects() -- returns true only if there is a timer to cancel. If this is false then we've waited longer than a second.
if #items < 2 then if not Timer.destroy(playerColor .. "_draw_from") then return end
broadcastToColor("You must have at least two items selected (currently: " .. #items .. ").", player_color, "Red")
return local items = Player[playerColor].getSelectedObjects()
end if #items < 2 then 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