Merge pull request #596 from argonui/import-instructions
Import Instructions: Bugfixes and QoL
This commit is contained in:
commit
2186d5f07e
@ -299,8 +299,8 @@ do
|
||||
local pos = string.find(description, "++SCED import instructions++")
|
||||
if not pos then return end
|
||||
|
||||
-- remove everything before instructions (including newline)
|
||||
local tempStr = string.sub(description, pos + 30)
|
||||
-- remove everything before instructions
|
||||
local tempStr = string.sub(description, pos)
|
||||
|
||||
-- parse each line in instructions
|
||||
for line in tempStr:gmatch("([^\n]+)") do
|
||||
@ -321,7 +321,10 @@ do
|
||||
break
|
||||
end
|
||||
|
||||
if instructor == "" or (instructor ~= "add:" and instructor ~= "remove:") then break end
|
||||
-- go to the next line if no valid instructor found
|
||||
if instructor ~= "add:" and instructor ~= "remove:" then
|
||||
goto nextLine
|
||||
end
|
||||
|
||||
-- remove instructor from line
|
||||
line = line:gsub(instructor, "")
|
||||
@ -332,15 +335,13 @@ do
|
||||
slots[str] = (slots[str] or 0) + 1
|
||||
elseif instructor == "remove:" then
|
||||
if slots[str] == nil then
|
||||
internal.maybePrint("Tried to remove " .. str .. ", but didn't find card in deck.", playerColor)
|
||||
break
|
||||
end
|
||||
internal.maybePrint("Tried to remove card ID " .. str .. ", but didn't find card in deck.", playerColor)
|
||||
else
|
||||
slots[str] = math.max(slots[str] - 1, 0)
|
||||
|
||||
-- fully remove cards that have a quantity of 0
|
||||
if slots[str] == 0 then
|
||||
slots[str] = nil
|
||||
end
|
||||
|
||||
-- also remove related minicard
|
||||
slots[str .. "-m"] = nil
|
||||
@ -349,6 +350,11 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
-- jump mark at the end of the loop
|
||||
::nextLine::
|
||||
end
|
||||
end
|
||||
|
||||
-- Process the slot list and looks for any cards which are bonded to those in the deck. Adds those cards to the slot list.
|
||||
---@param slots table The slot list for cards in this deck. Table key is the cardId, value is the number of those cards which will be spawned
|
||||
internal.extractBondedCards = function(slots)
|
||||
|
@ -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(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(deepObj.GMNotes, deepObj.Nickname, playerColor)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -46,14 +49,12 @@ function generate(_, playerColor)
|
||||
-- sort the idList
|
||||
table.sort(idList, sortById)
|
||||
|
||||
-- construct the string
|
||||
local description = "++SCED import instructions++\n- add: "
|
||||
-- construct the string (new line for each instruction)
|
||||
local description = "++SCED import instructions++"
|
||||
for _, entry in ipairs(idList) do
|
||||
description = description .. entry.id .. " (**" .. entry.name .. "**)" .. ", "
|
||||
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
|
||||
|
||||
@ -66,12 +67,12 @@ function getIdFromData(metadata)
|
||||
end
|
||||
end
|
||||
|
||||
function processCard(metadata, name)
|
||||
if metadata then
|
||||
local id = getIdFromData(metadata)
|
||||
function processCard(notes, name, playerColor)
|
||||
local id = getIdFromData(JSON.decode(notes) or {})
|
||||
if id then
|
||||
table.insert(idList, {id = id, name = name})
|
||||
end
|
||||
else
|
||||
broadcastToColor("Couldn't get ID for " .. name .. ".", playerColor, "Red")
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user