added message for cards without VP in VP display

This commit is contained in:
Chr1Z93 2023-01-27 20:12:26 +01:00
parent b40c6e6d9e
commit 9113c32325

View File

@ -1,3 +1,5 @@
local messageSent = {}
function onLoad() function onLoad()
local buttonParameters = {} local buttonParameters = {}
buttonParameters.label = "0 (Display) + 0 (Play Area) = 0 VP" buttonParameters.label = "0 (Display) + 0 (Play Area) = 0 VP"
@ -51,13 +53,13 @@ function updateCount()
-- check metadata for VP -- check metadata for VP
if obj.tag == "Card" then if obj.tag == "Card" then
cardVP = getCardVP(obj.is_face_down, JSON.decode(obj.getGMNotes())) cardVP = getCardVP(obj.is_face_down, JSON.decode(obj.getGMNotes()))
victoryPoints.display = victoryPoints.display + cardVP victoryPoints.display = victoryPoints.display + AddOrSendMessage(cardVP, obj.getName())
-- handling for stacked cards -- handling for stacked cards
elseif obj.tag == "Deck" then elseif obj.tag == "Deck" then
for _, deepObj in ipairs(obj.getObjects()) do for _, deepObj in ipairs(obj.getObjects()) do
cardVP = getCardVP(true, JSON.decode(deepObj.gm_notes)) cardVP = getCardVP(true, JSON.decode(deepObj.gm_notes))
victoryPoints.display = victoryPoints.display + cardVP victoryPoints.display = victoryPoints.display + AddOrSendMessage(cardVP, deepObj.nickname)
end end
end end
end end
@ -69,7 +71,7 @@ function updateCount()
local cardVP = 0 local cardVP = 0
if obj.hasTag("Location") then if obj.hasTag("Location") then
cardVP = getCardVP(obj.is_face_down, JSON.decode(obj.getGMNotes())) cardVP = getCardVP(obj.is_face_down, JSON.decode(obj.getGMNotes())) or 0
if cardVP and not cardHasClues(obj) then if cardVP and not cardHasClues(obj) then
victoryPoints.playArea = victoryPoints.playArea + cardVP victoryPoints.playArea = victoryPoints.playArea + cardVP
end end
@ -84,6 +86,16 @@ function updateCount()
}) })
end end
function AddOrSendMessage(addition, name)
if tonumber(addition) ~= nil then
return tonumber(addition)
elseif not tableContains(messageSent, name) then
printToAll("Info: No victory points counted for '" .. name .. "'.", "White")
table.insert(messageSent, name)
end
return 0
end
-- checks if a card has clues on it -- checks if a card has clues on it
function cardHasClues(card) function cardHasClues(card)
for _, v in ipairs(searchOnObj(card)) do for _, v in ipairs(searchOnObj(card)) do
@ -109,14 +121,14 @@ function getCardVP(faceDown, notes)
-- location -- location
if not cardVP then if not cardVP then
if not faceDown then if not faceDown and notes.locationFront ~= nil then
cardVP = tonumber(notes.locationFront.victory) cardVP = tonumber(notes.locationFront.victory)
else elseif notes.locationBack ~= nil then
cardVP = tonumber(notes.locationBack.victory) cardVP = tonumber(notes.locationBack.victory)
end end
end end
end end
return cardVP or 0 return cardVP
end end
function searchOnObj(obj) function searchOnObj(obj)
@ -129,3 +141,12 @@ function searchOnObj(obj)
}) })
end end
-- search a table for a value, return true if found (else returns false)
function tableContains(table, value)
for _, v in ipairs(table) do
if v == value then
return true
end
end
return false
end