added support for decks in hotfix bags

This commit is contained in:
Chr1Z93 2023-12-18 16:19:51 +01:00
parent 85526429f0
commit 7cd29deca1
4 changed files with 68 additions and 22 deletions

View File

@ -13,7 +13,7 @@
"g": 0.36652,
"r": 0.70588
},
"Description": "Put any cards in here to add them to the indices for the player card panel and deck importer.\n\nThis can be used for custom cards too.",
"Description": "Put any cards in here to add them to the indices for the player card panel and deck importer.\n\nSelect the 'update index' entry in the context menu of this bag once you've added all cards.\n\nThis can be used for custom cards too.",
"DragSelectable": true,
"GMNotes": "",
"GUID": "2cba6b",

View File

@ -11,18 +11,5 @@ local allCardsBagApi = require("playercards/AllCardsBagApi")
function onLoad()
allCardsBagApi.rebuildIndexForHotfix()
end
-- update with small delay to allow multiple cards being added at once
function onObjectEnterContainer(container, object)
if container == self then
Wait.time(function() allCardsBagApi.rebuildIndexForHotfix() end, 1)
end
end
-- update with small delay to allow multiple cards being removed at once
function onObjectLeaveContainer(container, object)
if container == self then
Wait.time(function() allCardsBagApi.rebuildIndexForHotfix() end, 1)
end
self.addContextMenuItem("Update card index", function() allCardsBagApi.rebuildIndexForHotfix() end)
end

View File

@ -1,4 +1,4 @@
local
local searchLib = require("util/SearchLib")
function onLoad()
local buttonParameters = {}
@ -13,7 +13,7 @@ function onLoad()
local inputParameters = {}
inputParameters.label = "Click button above"
inputParameters.input_function = "input_func"
inputParameters.input_function = "none"
inputParameters.function_owner = self
inputParameters.position = { 0, 0.05, 1.95 }
inputParameters.width = 1200
@ -22,6 +22,56 @@ function onLoad()
self.createInput(inputParameters)
end
function generate()
function generate(_, playerColor)
local idList = {}
for _, obj in ipairs(searchLib.onObject(self, "isCardOrDeck")) do
if obj.type == "Card" then
local cardMetadata = JSON.decode(obj.getGMNotes())
if cardMetadata then
local id = getIdFromData(cardMetadata)
if id then
table.insert(idList, id)
end
end
elseif obj.type == "Deck" then
for _, deepObj in ipairs(obj.getData().ContainedObjects) do
local cardMetadata = JSON.decode(deepObj.GMNotes)
if cardMetadata then
local id = getIdFromData(cardMetadata)
if id then
table.insert(idList, id)
end
end
end
end
end
end
if #idList == 0 then
broadcastToColor("Didn't find any valid cards.", playerColor, "Red")
return
else
broadcastToColor("Created deck instruction for " .. #idList .. " card(s). Copy it from the input field.", playerColor, "Green")
end
-- construct the string
local description = "++SCED import instructions++\n- add: "
for _, id in ipairs(idList) do
description = description .. id .. ", "
end
-- remove last delimiter (last two characters)
description = description:sub(1, -3)
self.editInput({index = 0, value = description})
end
-- use the ZoopGuid as fallback if no id present
function getIdFromData(metadata)
if metadata.id then
return metadata.id
elseif metadata.TtsZoopGuid then
return metadata.TtsZoopGuid
end
end
function none() end

View File

@ -86,9 +86,18 @@ function buildIndex()
for _, hotfixBag in ipairs(hotfixBags) do
if (#hotfixBag.getObjects() > 0) then
for i, cardData in ipairs(hotfixBag.getData().ContainedObjects) do
local cardMetadata = JSON.decode(cardData.GMNotes)
if (cardMetadata ~= nil) then
addCardToIndex(cardData, cardMetadata)
if cardData.ContainedObjects then
for j, deepCardData in ipairs(cardData.ContainedObjects) do
local deepCardMetadata = JSON.decode(deepCardData.GMNotes)
if deepCardMetadata ~= nil then
addCardToIndex(deepCardData, deepCardMetadata)
end
end
else
local cardMetadata = JSON.decode(cardData.GMNotes)
if cardMetadata ~= nil then
addCardToIndex(cardData, cardMetadata)
end
end
end
end