local searchLib = require("util/SearchLib") local idList = {} 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" inputParameters.input_function = "none" 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 function generate(_, playerColor) idList = {} for _, obj in ipairs(searchLib.onObject(self, "isCardOrDeck")) do if obj.type == "Card" then processCard(JSON.decode(obj.getGMNotes()), obj.getName()) elseif obj.type == "Deck" then for _, deepObj in ipairs(obj.getData().ContainedObjects) do processCard(JSON.decode(deepObj.GMNotes), deepObj.Nickname) end end end 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 -- sort the idList table.sort(idList, sortById) -- construct the string (new line for each instruction) local description = "++SCED import instructions++" for _, entry in ipairs(idList) do description = description .. "\n- add: " .. entry.id .. " (**" .. entry.name .. "**)" .. ", " 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 processCard(metadata, name) if metadata then local id = getIdFromData(metadata) if id then table.insert(idList, {id = id, name = name}) end end end function sortById(a, b) local numA = tonumber(a.id) local numB = tonumber(b.id) if numA and numB then return numA < numB else return a.name < b.name end end function none() end