2023-12-18 10:19:51 -05:00
|
|
|
local searchLib = require("util/SearchLib")
|
2023-12-18 09:26:08 -05:00
|
|
|
|
|
|
|
function onLoad()
|
|
|
|
local buttonParameters = {}
|
|
|
|
buttonParameters.function_owner = self
|
|
|
|
buttonParameters.height = 200
|
|
|
|
buttonParameters.width = 1200
|
|
|
|
buttonParameters.font_size = 75
|
|
|
|
buttonParameters.click_function = "generate"
|
|
|
|
buttonParameters.label = "Generate instructions!"
|
|
|
|
buttonParameters.position = { 0, 0.06, 1.55 }
|
|
|
|
self.createButton(buttonParameters)
|
|
|
|
|
|
|
|
local inputParameters = {}
|
|
|
|
inputParameters.label = "Click button above"
|
2023-12-18 10:19:51 -05:00
|
|
|
inputParameters.input_function = "none"
|
2023-12-18 09:26:08 -05:00
|
|
|
inputParameters.function_owner = self
|
|
|
|
inputParameters.position = { 0, 0.05, 1.95 }
|
|
|
|
inputParameters.width = 1200
|
|
|
|
inputParameters.height = 130
|
|
|
|
inputParameters.font_size = 107
|
|
|
|
self.createInput(inputParameters)
|
|
|
|
end
|
|
|
|
|
2023-12-18 10:19:51 -05:00
|
|
|
function generate(_, playerColor)
|
|
|
|
local idList = {}
|
|
|
|
for _, obj in ipairs(searchLib.onObject(self, "isCardOrDeck")) do
|
|
|
|
if obj.type == "Card" then
|
|
|
|
local cardMetadata = JSON.decode(obj.getGMNotes())
|
|
|
|
|
|
|
|
if cardMetadata then
|
|
|
|
local id = getIdFromData(cardMetadata)
|
|
|
|
if id then
|
|
|
|
table.insert(idList, id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif obj.type == "Deck" then
|
|
|
|
for _, deepObj in ipairs(obj.getData().ContainedObjects) do
|
|
|
|
local cardMetadata = JSON.decode(deepObj.GMNotes)
|
|
|
|
if cardMetadata then
|
|
|
|
local id = getIdFromData(cardMetadata)
|
|
|
|
if id then
|
|
|
|
table.insert(idList, id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-12-18 09:26:08 -05:00
|
|
|
|
2023-12-18 10:19:51 -05:00
|
|
|
if #idList == 0 then
|
|
|
|
broadcastToColor("Didn't find any valid cards.", playerColor, "Red")
|
|
|
|
return
|
|
|
|
else
|
|
|
|
broadcastToColor("Created deck instruction for " .. #idList .. " card(s). Copy it from the input field.", playerColor, "Green")
|
|
|
|
end
|
|
|
|
|
|
|
|
-- construct the string
|
|
|
|
local description = "++SCED import instructions++\n- add: "
|
|
|
|
for _, id in ipairs(idList) do
|
|
|
|
description = description .. id .. ", "
|
|
|
|
end
|
|
|
|
|
|
|
|
-- remove last delimiter (last two characters)
|
|
|
|
description = description:sub(1, -3)
|
|
|
|
self.editInput({index = 0, value = description})
|
|
|
|
end
|
|
|
|
|
|
|
|
-- use the ZoopGuid as fallback if no id present
|
|
|
|
function getIdFromData(metadata)
|
|
|
|
if metadata.id then
|
|
|
|
return metadata.id
|
|
|
|
elseif metadata.TtsZoopGuid then
|
|
|
|
return metadata.TtsZoopGuid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function none() end
|