From 7e2a4d71d5369ed62a0bbe5cb0365d6d29413bde Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Mon, 18 Dec 2023 12:56:10 +0100 Subject: [PATCH] added arkhamdb deck description parsing --- src/arkhamdb/ArkhamDb.ttslua | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/arkhamdb/ArkhamDb.ttslua b/src/arkhamdb/ArkhamDb.ttslua index 6e766d2f..fc5882ba 100644 --- a/src/arkhamdb/ArkhamDb.ttslua +++ b/src/arkhamdb/ArkhamDb.ttslua @@ -145,6 +145,7 @@ do loadAltInvestigator = internal.addInvestigatorCards(deck, slots) end + internal.maybeModifyDeckFromDescription(slots, deck.description_md) internal.maybeAddSummonedServitor(slots) internal.maybeAddOnTheMend(slots, playerColor) internal.maybeAddRealityAcidReference(slots) @@ -285,6 +286,49 @@ do end end + -- Processes the deck description from ArkhamDB and modifies the slot list accordingly + ---@param slots Table The slot list for cards in this deck. Table key is the cardId, value is the number + ---@param description String The deck desription from ArkhamDB + internal.maybeModifyDeckFromDescription = function(slots, description) + -- check for import instructions + 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) + + -- parse each line in instructions + for line in tempStr:gmatch("([^\n]+)") do + -- remove dashes at the start + line = line:gsub("%- ", "") + + -- remove spaces + line = line:gsub("%s", "") + + -- get instructor + local instructor = "" + for word in line:gmatch("%a+:") do + instructor = word + break + end + + if instructor == "" or (instructor ~= "add:" and instructor ~= "remove:") then return end + + -- remove instructor from line + line = line:gsub(instructor, "") + + -- evaluate instructions + local cardIds = {} + for str in line:gmatch("([^,]+)") do + if instructor == "add:" then + slots[str] = (slots[str] or 0) + 1 + elseif instructor == "remove:" then + slots[str] = math.max(slots[str] - 1, 0) + end + end + 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)