Merge pull request #596 from argonui/import-instructions
Import Instructions: Bugfixes and QoL
This commit is contained in:
commit
2186d5f07e
@ -299,9 +299,9 @@ do
|
|||||||
local pos = string.find(description, "++SCED import instructions++")
|
local pos = string.find(description, "++SCED import instructions++")
|
||||||
if not pos then return end
|
if not pos then return end
|
||||||
|
|
||||||
-- remove everything before instructions (including newline)
|
-- remove everything before instructions
|
||||||
local tempStr = string.sub(description, pos + 30)
|
local tempStr = string.sub(description, pos)
|
||||||
|
|
||||||
-- parse each line in instructions
|
-- parse each line in instructions
|
||||||
for line in tempStr:gmatch("([^\n]+)") do
|
for line in tempStr:gmatch("([^\n]+)") do
|
||||||
-- remove dashes at the start
|
-- remove dashes at the start
|
||||||
@ -321,7 +321,10 @@ do
|
|||||||
break
|
break
|
||||||
end
|
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
|
-- remove instructor from line
|
||||||
line = line:gsub(instructor, "")
|
line = line:gsub(instructor, "")
|
||||||
@ -332,20 +335,23 @@ do
|
|||||||
slots[str] = (slots[str] or 0) + 1
|
slots[str] = (slots[str] or 0) + 1
|
||||||
elseif instructor == "remove:" then
|
elseif instructor == "remove:" then
|
||||||
if slots[str] == nil then
|
if slots[str] == nil then
|
||||||
internal.maybePrint("Tried to remove " .. str .. ", but didn't find card in deck.", playerColor)
|
internal.maybePrint("Tried to remove card ID " .. str .. ", but didn't find card in deck.", playerColor)
|
||||||
break
|
else
|
||||||
end
|
slots[str] = math.max(slots[str] - 1, 0)
|
||||||
slots[str] = math.max(slots[str] - 1, 0)
|
|
||||||
|
|
||||||
-- fully remove cards that have a quantity of 0
|
-- fully remove cards that have a quantity of 0
|
||||||
if slots[str] == 0 then
|
if slots[str] == 0 then
|
||||||
slots[str] = nil
|
slots[str] = nil
|
||||||
end
|
|
||||||
|
|
||||||
-- also remove related minicard
|
-- also remove related minicard
|
||||||
slots[str .. "-m"] = nil
|
slots[str .. "-m"] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- jump mark at the end of the loop
|
||||||
|
::nextLine::
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ local searchLib = require("util/SearchLib")
|
|||||||
local idList = {}
|
local idList = {}
|
||||||
|
|
||||||
function onLoad()
|
function onLoad()
|
||||||
|
-- "generate" button
|
||||||
local buttonParameters = {}
|
local buttonParameters = {}
|
||||||
buttonParameters.function_owner = self
|
buttonParameters.function_owner = self
|
||||||
buttonParameters.height = 200
|
buttonParameters.height = 200
|
||||||
@ -13,6 +14,7 @@ function onLoad()
|
|||||||
buttonParameters.position = { 0, 0.06, 1.55 }
|
buttonParameters.position = { 0, 0.06, 1.55 }
|
||||||
self.createButton(buttonParameters)
|
self.createButton(buttonParameters)
|
||||||
|
|
||||||
|
-- "output" text field
|
||||||
local inputParameters = {}
|
local inputParameters = {}
|
||||||
inputParameters.label = "Click button above"
|
inputParameters.label = "Click button above"
|
||||||
inputParameters.input_function = "none"
|
inputParameters.input_function = "none"
|
||||||
@ -24,14 +26,15 @@ function onLoad()
|
|||||||
self.createInput(inputParameters)
|
self.createInput(inputParameters)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- generates a string for the ArkhamDB deck notes that will instruct the deck import to add the specified cards
|
||||||
function generate(_, playerColor)
|
function generate(_, playerColor)
|
||||||
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
|
||||||
processCard(JSON.decode(obj.getGMNotes()), obj.getName())
|
processCard(obj.getGMNotes(), obj.getName(), playerColor)
|
||||||
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
|
||||||
processCard(JSON.decode(deepObj.GMNotes), deepObj.Nickname)
|
processCard(deepObj.GMNotes, deepObj.Nickname, playerColor)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -46,14 +49,12 @@ function generate(_, playerColor)
|
|||||||
-- sort the idList
|
-- sort the idList
|
||||||
table.sort(idList, sortById)
|
table.sort(idList, sortById)
|
||||||
|
|
||||||
-- construct the string
|
-- construct the string (new line for each instruction)
|
||||||
local description = "++SCED import instructions++\n- add: "
|
local description = "++SCED import instructions++"
|
||||||
for _, entry in ipairs(idList) do
|
for _, entry in ipairs(idList) do
|
||||||
description = description .. entry.id .. " (**" .. entry.name .. "**)" .. ", "
|
description = description .. "\n- add: " .. entry.id .. " (**" .. entry.name .. "**)"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- remove last delimiter (last two characters)
|
|
||||||
description = description:sub(1, -3)
|
|
||||||
self.editInput({index = 0, value = description})
|
self.editInput({index = 0, value = description})
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -66,12 +67,12 @@ function getIdFromData(metadata)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function processCard(metadata, name)
|
function processCard(notes, name, playerColor)
|
||||||
if metadata then
|
local id = getIdFromData(JSON.decode(notes) or {})
|
||||||
local id = getIdFromData(metadata)
|
if id then
|
||||||
if id then
|
table.insert(idList, {id = id, name = name})
|
||||||
table.insert(idList, {id = id, name = name})
|
else
|
||||||
end
|
broadcastToColor("Couldn't get ID for " .. name .. ".", playerColor, "Red")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user