Merge pull request #193 from argonui/custom-bug

Check for card types when updating customizable data
This commit is contained in:
Chr1Z 2023-01-16 11:35:53 +01:00 committed by GitHub
commit 9e3a6c454d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -458,16 +458,18 @@ end
function syncCustomizableMetadata(card) function syncCustomizableMetadata(card)
local cardMetadata = JSON.decode(card.getGMNotes()) or { } local cardMetadata = JSON.decode(card.getGMNotes()) or { }
if cardMetadata ~= nil and cardMetadata.customizations ~= nil then if cardMetadata ~= nil and cardMetadata.customizations ~= nil then
for _, obj in ipairs(searchArea(PLAY_ZONE_POSITION, PLAY_ZONE_SCALE)) do for _, collision in ipairs(searchArea(PLAY_ZONE_POSITION, PLAY_ZONE_SCALE)) do
local obj = obj.hit_object local obj = collision.hit_object
local notes = JSON.decode(obj.getGMNotes()) or { } if obj.name == "Card" or obj.name == "CardCustom" then
if notes.id == (cardMetadata.id .. "-c") then local notes = JSON.decode(obj.getGMNotes()) or { }
for i, customization in ipairs(cardMetadata.customizations) do if notes.id == (cardMetadata.id .. "-c") then
if obj.getVar("markedBoxes")[i] == customization.xp for i, customization in ipairs(cardMetadata.customizations) do
and customization.replaces ~= nil if obj.getVar("markedBoxes")[i] == customization.xp
and customization.replaces.uses ~= nil then and customization.replaces ~= nil
cardMetadata.uses = customization.replaces.uses and customization.replaces.uses ~= nil then
card.setGMNotes(JSON.encode(cardMetadata)) cardMetadata.uses = customization.replaces.uses
card.setGMNotes(JSON.encode(cardMetadata))
end
end end
end end
end end