diff --git a/src/accessories/CardBackEnhancer.ttslua b/src/accessories/CardBackEnhancer.ttslua
index 5effbc19..284b7382 100644
--- a/src/accessories/CardBackEnhancer.ttslua
+++ b/src/accessories/CardBackEnhancer.ttslua
@@ -59,14 +59,19 @@ function processCard(cardData)
local customDeckId, customDeckData = next(cardData["CustomDeck"])
-- if this card already has the correct back settings
- if customDeckData["BackURL"] == newBack and customDeckData["BackIsHidden"] then return false end
+ if customDeckData["BackURL"] == newBack and customDeckData["BackIsHidden"] then
+ return false
+ end
-- skip cards with decksheets as back
- if (customDeckData["NumHeight"] == 1 and customDeckData["NumWidth"] == 1)
- or customDeckData["UniqueBack"] == false then
- customDeckData["BackIsHidden"] = true
- customDeckData["BackURL"] = newBack
- deckChanges[customDeckId] = newBack
+ if (customDeckData["NumHeight"] ~= 1 or customDeckData["NumWidth"] ~= 1)
+ and customDeckData["UniqueBack"] then
+ return false
end
+
+ -- update data
+ customDeckData["BackIsHidden"] = true
+ customDeckData["BackURL"] = newBack
+ deckChanges[customDeckId] = newBack
return true
end
diff --git a/src/arkhamdb/DeckInstructionGenerator.ttslua b/src/arkhamdb/DeckInstructionGenerator.ttslua
index 1b8e11be..7a333a34 100644
--- a/src/arkhamdb/DeckInstructionGenerator.ttslua
+++ b/src/arkhamdb/DeckInstructionGenerator.ttslua
@@ -3,17 +3,14 @@ local searchLib = require("util/SearchLib")
local idList = {}
+local cardWidth = 250
+local cardHeight = cardWidth * 1.4
local galleryTemplateStart = [[
-
\n]]
-local galleryTemplateMiddle = [[
\n]]
-local galleryTemplateEnd = [[
\n]]
+]]
+local templateCardRegular = [[
]]
+local templateCardSlice = [[
]]
+local galleryTemplateEnd = [[
]] .. "\n" .. [[]]
function onLoad()
- -- "generate" button
local buttonParameters = {}
buttonParameters.function_owner = self
buttonParameters.height = 200
@@ -70,7 +66,7 @@ function generate(_, playerColor)
end
-- sort the idList
- table.sort(idList, sortById)
+ table.sort(idList, sortByMetadata)
-- construct the string (new line for each instruction)
local descriptionParts = {}
@@ -108,17 +104,11 @@ function generate(_, playerColor)
-- maybe create a card gallery for included cards
if createGallery then
- table.insert(descriptionParts, "\n\n")
- table.insert(descriptionParts, galleryTemplateStart)
+ table.insert(descriptionParts, "\n\n" .. galleryTemplateStart .. "\n")
- -- add cards
+ addedImages = {}
for _, entry in ipairs(idList) do
- if entry.face then
- table.insert(descriptionParts, galleryTemplateMiddle:gsub("{{IMAGE_URL}}", entry.face))
- end
- if entry.back then
- table.insert(descriptionParts, galleryTemplateMiddle:gsub("{{IMAGE_URL}}", entry.back))
- end
+ maybeAddImageToGallery(descriptionParts, entry)
end
table.insert(descriptionParts, galleryTemplateEnd)
end
@@ -148,7 +138,7 @@ function generate(_, playerColor)
"\nAfter doing so, the Deck Importer will be able to spawn these cards IF they are added to the mod's card index (for example by " ..
"throwing them into the 'Additional Cards Box' next to the Player Cards Panel in the upper left corner of the table." ..
"\nIt also supports '- remove:' instructions to automatically remove placeholder cards.\nIf you are using a custom " ..
- "investigator, make sure to use a 'remove' instruction to remove the original one.\n" .. timestamp .. "\n" .. description
+ "investigator, make sure to use a 'remove' instruction to remove the original one.\n\n" .. timestamp .. "\n" .. description
})
end
@@ -161,19 +151,74 @@ function getIdFromData(metadata)
end
end
-function processCard(cardData, playerColor)
- local id = getIdFromData(JSON.decode(cardData.GMNotes) or {})
- if id then
- local cardDetails = { id = id, name = cardData.Nickname }
+function maybeAddImageToGallery(t, data)
+ if data.sheetH and data.sheetW then
+ -- add cards from decksheets
+ local element = templateCardSlice
+ element = element:gsub("{{SHEET_SIZE_1}}", data.sheetW * cardWidth):gsub("{{SHEET_SIZE_2}}", data.sheetH * cardHeight)
+ element = element:gsub("{{OFFSET_1}}", data.col * cardWidth):gsub("{{OFFSET_2}}", data.row * cardHeight)
- -- if this is not a decksheet, add its URL
- local _, customDeckData = next(cardData["CustomDeck"])
- if customDeckData["NumHeight"] == 1 and customDeckData["NumWidth"] == 1 then
+ maybeAddCardSlice(t, element, data.face, data.cardId)
+
+ if data.uniqueBack then
+ maybeAddCardSlice(t, element, data.back, data.cardId)
+ else
+ maybeAddCardRegular(t, data.back)
+ end
+ else
+ -- add regular cards
+ maybeAddCardRegular(t, data.face)
+ maybeAddCardRegular(t, data.back)
+ end
+end
+
+function maybeAddCardRegular(t, url)
+ if not url then return end
+
+ if not addedImages[url] then
+ addedImages[url] = true
+ table.insert(t, templateCardRegular:gsub("{{IMAGE_URL}}", url) .. "\n")
+ end
+end
+
+function maybeAddCardSlice(t, element, url, cardId)
+ if not url then return end
+
+ -- initialize table
+ addedImages[url] = addedImages[url] or {}
+
+ if not addedImages[url][cardId] then
+ addedImages[url][cardId] = true
+ table.insert(t, element:gsub("{{IMAGE_URL}}", url) .. "\n")
+ end
+end
+
+function processCard(cardData, playerColor)
+ local md = JSON.decode(cardData.GMNotes) or {}
+ local id = getIdFromData(md)
+ if id then
+ local cardDetails = {
+ id = id,
+ name = cardData.Nickname,
+ metadata = md,
+ cardId = math.floor(cardData.CardID % 100)
+ }
+
+ -- add images unless minicard
+ if md.type ~= "Minicard" then
+ local _, customDeckData = next(cardData["CustomDeck"])
cardDetails.face = customDeckData["FaceURL"]
+ if customDeckData["NumHeight"] > 1 or customDeckData["NumWidth"] > 1 then
+ cardDetails.sheetH = customDeckData["NumHeight"]
+ cardDetails.sheetW = customDeckData["NumWidth"]
+ cardDetails.row, cardDetails.col = getGridPosition(cardDetails.cardId, customDeckData["NumWidth"])
+ end
+
-- also add the back if it's not one of the regular backs
if customDeckData["BackURL"] ~= CARD_BACK_URL.PlayerCard and customDeckData["BackURL"] ~= CARD_BACK_URL.PlayerCard then
cardDetails.back = customDeckData["BackURL"]
+ cardDetails.uniqueBack = customDeckData["UniqueBack"]
end
end
@@ -183,13 +228,26 @@ function processCard(cardData, playerColor)
end
end
-function sortById(a, b)
+function sortByMetadata(a, b)
local numA = tonumber(a.id)
local numB = tonumber(b.id)
- if numA and numB then
+ local isInvestigatorA = (a.metadata.type == "Investigator")
+ local isInvestigatorB = (b.metadata.type == "Investigator")
+
+ if isInvestigatorA and not isInvestigatorB then
+ return true
+ elseif isInvestigatorB and not isInvestigatorA then
+ return false
+ elseif numA and numB then
return numA < numB
else
return a.name < b.name
end
end
+
+function getGridPosition(index, columns)
+ local row = math.floor(index / columns) + 1
+ local column = (index % columns) + 1
+ return row, column
+end