Merge pull request #584 from argonui/import-instructions

Updated import instructions
This commit is contained in:
Entrox-Licher 2024-02-13 11:22:23 -05:00 committed by GitHub
commit aea49173d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 18 deletions

View File

@ -307,6 +307,10 @@ do
-- remove spaces
line = line:gsub("%s", "")
-- remove balanced brackets
line = line:gsub("%b()", "")
line = line:gsub("%b[]", "")
-- get instructor
local instructor = ""
for word in line:gmatch("%a+:") do

View File

@ -1,5 +1,7 @@
local searchLib = require("util/SearchLib")
local idList = {}
function onLoad()
local buttonParameters = {}
buttonParameters.function_owner = self
@ -23,26 +25,13 @@ function onLoad()
end
function generate(_, playerColor)
local idList = {}
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
processCard(JSON.decode(obj.getGMNotes()), obj.getName())
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
processCard(JSON.decode(deepObj.GMNotes), deepObj.Nickname)
end
end
end
@ -54,10 +43,13 @@ function generate(_, playerColor)
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
local description = "++SCED import instructions++\n- add: "
for _, id in ipairs(idList) do
description = description .. id .. ", "
for _, entry in ipairs(idList) do
description = description .. entry.id .. " (**" .. entry.name .. "**)" .. ", "
end
-- remove last delimiter (last two characters)
@ -74,4 +66,24 @@ function getIdFromData(metadata)
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