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 -- remove spaces
line = line:gsub("%s", "") line = line:gsub("%s", "")
-- remove balanced brackets
line = line:gsub("%b()", "")
line = line:gsub("%b[]", "")
-- get instructor -- get instructor
local instructor = "" local instructor = ""
for word in line:gmatch("%a+:") do for word in line:gmatch("%a+:") do

View File

@ -1,5 +1,7 @@
local searchLib = require("util/SearchLib") local searchLib = require("util/SearchLib")
local idList = {}
function onLoad() function onLoad()
local buttonParameters = {} local buttonParameters = {}
buttonParameters.function_owner = self buttonParameters.function_owner = self
@ -23,26 +25,13 @@ function onLoad()
end end
function generate(_, playerColor) function generate(_, playerColor)
local idList = {} idList = {}
for _, obj in ipairs(searchLib.onObject(self, "isCardOrDeck")) do for _, obj in ipairs(searchLib.onObject(self, "isCardOrDeck")) do
if obj.type == "Card" then if obj.type == "Card" then
local cardMetadata = JSON.decode(obj.getGMNotes()) processCard(JSON.decode(obj.getGMNotes()), obj.getName())
if cardMetadata then
local id = getIdFromData(cardMetadata)
if id then
table.insert(idList, id)
end
end
elseif obj.type == "Deck" then elseif obj.type == "Deck" then
for _, deepObj in ipairs(obj.getData().ContainedObjects) do for _, deepObj in ipairs(obj.getData().ContainedObjects) do
local cardMetadata = JSON.decode(deepObj.GMNotes) processCard(JSON.decode(deepObj.GMNotes), deepObj.Nickname)
if cardMetadata then
local id = getIdFromData(cardMetadata)
if id then
table.insert(idList, id)
end
end
end end
end 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") broadcastToColor("Created deck instruction for " .. #idList .. " card(s). Copy it from the input field.", playerColor, "Green")
end end
-- sort the idList
table.sort(idList, sortById)
-- construct the string -- construct the string
local description = "++SCED import instructions++\n- add: " local description = "++SCED import instructions++\n- add: "
for _, id in ipairs(idList) do for _, entry in ipairs(idList) do
description = description .. id .. ", " description = description .. entry.id .. " (**" .. entry.name .. "**)" .. ", "
end end
-- remove last delimiter (last two characters) -- remove last delimiter (last two characters)
@ -74,4 +66,24 @@ function getIdFromData(metadata)
end end
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 function none() end