addded feedback to instruction generator

This commit is contained in:
Chr1Z93 2024-02-16 10:38:58 +01:00
parent 2c7bba922f
commit aabaf52d96

View File

@ -3,6 +3,7 @@ local searchLib = require("util/SearchLib")
local idList = {}
function onLoad()
-- "generate" button
local buttonParameters = {}
buttonParameters.function_owner = self
buttonParameters.height = 200
@ -13,6 +14,7 @@ function onLoad()
buttonParameters.position = { 0, 0.06, 1.55 }
self.createButton(buttonParameters)
-- "output" text field
local inputParameters = {}
inputParameters.label = "Click button above"
inputParameters.input_function = "none"
@ -24,14 +26,15 @@ function onLoad()
self.createInput(inputParameters)
end
-- generates a string for the ArkhamDB deck notes that will instruct the deck import to add the specified cards
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())
processCard(JSON.decode(obj.getGMNotes()), obj.getName(), playerColor)
elseif obj.type == "Deck" then
for _, deepObj in ipairs(obj.getData().ContainedObjects) do
processCard(JSON.decode(deepObj.GMNotes), deepObj.Nickname)
processCard(JSON.decode(deepObj.GMNotes), deepObj.Nickname, playerColor)
end
end
end
@ -66,11 +69,13 @@ function getIdFromData(metadata)
end
end
function processCard(metadata, name)
function processCard(metadata, name, playerColor)
if metadata then
local id = getIdFromData(metadata)
if id then
table.insert(idList, {id = id, name = name})
else
broadcastToColor("Couldn't get ID for " .. name .. ".", playerColor, "Red")
end
end
end