Merge branch 'argonui:main' into main

This commit is contained in:
Entrox-Licher 2023-03-06 18:40:42 -05:00 committed by GitHub
commit 392c7f94b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 88 additions and 8 deletions

View File

@ -57,6 +57,7 @@ local locationData
local currentScenario local currentScenario
local missingData = {} local missingData = {}
local countedVP = {}
--------------------------------------------------------- ---------------------------------------------------------
-- general code -- general code
@ -569,6 +570,9 @@ function countVP()
local cardVP = tonumber(metadata.victory) or 0 local cardVP = tonumber(metadata.victory) or 0
if cardVP ~= 0 and not cardHasClues(cardId) then if cardVP ~= 0 and not cardHasClues(cardId) then
totalVP = totalVP + cardVP totalVP = totalVP + cardVP
if cardVP >0 then
table.insert(countedVP, getObjectFromGUID(cardId))
end
end end
end end
end end
@ -617,6 +621,22 @@ function highlightMissingData(state)
end end
end end
-- highlights all locations in the play area with VP
---@param state Boolean True if highlighting should be enabled
function highlightCountedVP(state)
for i, obj in pairs(countedVP) do
if obj ~= nil then
if state then
obj.highlightOff("Green")
else
obj.highlightOn("Green")
end
else
countedVP[i] = nil
end
end
end
-- rebuilds local snap points (could be useful in the future again) -- rebuilds local snap points (could be useful in the future again)
function buildSnaps() function buildSnaps()
local upperleft = { x = 1.53, z = -1.09} local upperleft = { x = 1.53, z = -1.09}

View File

@ -66,6 +66,12 @@ do
return getObjectFromGUID(PLAY_AREA_GUID).call("highlightMissingData", state) return getObjectFromGUID(PLAY_AREA_GUID).call("highlightMissingData", state)
end end
-- highlights all locations in the play area with VP
---@param state Boolean True if highlighting should be enabled
PlayAreaApi.highlightCountedVP = function(state)
return getObjectFromGUID(PLAY_AREA_GUID).call("highlightCountedVP", state)
end
-- Checks if an object is in the play area (returns true or false) -- Checks if an object is in the play area (returns true or false)
PlayAreaApi.isInPlayArea = function(object) PlayAreaApi.isInPlayArea = function(object)
return getObjectFromGUID(PLAY_AREA_GUID).call("isInPlayArea", object) return getObjectFromGUID(PLAY_AREA_GUID).call("isInPlayArea", object)

View File

@ -1,8 +1,10 @@
local playAreaApi = require("core/PlayAreaApi") local playAreaApi = require("core/PlayAreaApi")
local pendingCall = false local pendingCall = false
local messageSent = {} local messageSent = {}
local currentlyHighlighting = false
local missingData = {} local missingData = {}
local countedVP = {}
local highlightMissing = false
local highlightCounted = false
-- button creation when loading the game -- button creation when loading the game
function onLoad() function onLoad()
@ -27,7 +29,7 @@ function onLoad()
buttonParameters.position.x = 1.69 buttonParameters.position.x = 1.69
self.createButton(buttonParameters) self.createButton(buttonParameters)
-- index 3: highlighting button -- index 3: highlighting button (missing data)
self.createButton({ self.createButton({
label = "!", label = "!",
click_function = "highlightMissingData", click_function = "highlightMissingData",
@ -41,6 +43,22 @@ function onLoad()
font_color = { 1, 1, 1 }, font_color = { 1, 1, 1 },
position = { x = 1.82, y = 0.06, z = -1.32 } position = { x = 1.82, y = 0.06, z = -1.32 }
}) })
-- index 4: highlighting button (counted VP)
self.createButton({
label = "?",
click_function = "highlightCountedVP",
tooltip = "Enable highlighting of cards with VP.",
function_owner = self,
scale = { 0.15, 0.15, 0.15 },
color = { 0, 1, 0 },
width = 700,
height = 800,
font_size = 700,
font_color = { 1, 1, 1 },
position = { x = 1.5, y = 0.06, z = -1.32 }
})
-- update the display label once -- update the display label once
Wait.time(updateCount, 1) Wait.time(updateCount, 1)
end end
@ -121,6 +139,7 @@ end
-- counts the VP in the victory display and request the VP count from the play area -- counts the VP in the victory display and request the VP count from the play area
function updateCount() function updateCount()
missingData = {} missingData = {}
countedVP = {}
local victoryPoints = {} local victoryPoints = {}
victoryPoints.display = 0 victoryPoints.display = 0
victoryPoints.playArea = playAreaApi.countVP() victoryPoints.playArea = playAreaApi.countVP()
@ -131,12 +150,24 @@ function updateCount()
-- check metadata for VP -- check metadata for VP
if obj.tag == "Card" then if obj.tag == "Card" then
victoryPoints.display = victoryPoints.display + getCardVP(obj, JSON.decode(obj.getGMNotes())) local VP = getCardVP(obj, JSON.decode(obj.getGMNotes()))
victoryPoints.display = victoryPoints.display + VP
if VP > 0 then
table.insert(countedVP, obj)
end
-- handling for stacked cards -- handling for stacked cards
elseif obj.tag == "Deck" then elseif obj.tag == "Deck" then
local VP = 0
for _, deepObj in ipairs(obj.getObjects()) do for _, deepObj in ipairs(obj.getObjects()) do
victoryPoints.display = victoryPoints.display + getCardVP(obj, JSON.decode(deepObj.gm_notes)) local deepVP = getCardVP(obj, JSON.decode(deepObj.gm_notes))
victoryPoints.display = victoryPoints.display + deepVP
if deepVP > 0 then
VP = VP + 1
end
end
if VP > 0 then
table.insert(countedVP, obj)
end end
end end
end end
@ -166,6 +197,9 @@ function getCardVP(obj, notes)
cardVP = tonumber(notes.locationBack.victory) cardVP = tonumber(notes.locationBack.victory)
end end
end end
if cardVP > 0 then
table.insert(countedVP, obj)
end
else else
table.insert(missingData, obj) table.insert(missingData, obj)
end end
@ -176,20 +210,40 @@ end
function highlightMissingData() function highlightMissingData()
self.editButton({ self.editButton({
index = 3, index = 3,
tooltip = (currentlyHighlighting and "Enable" or "Disable") .. tooltip = (highlightMissing and "Enable" or "Disable") ..
" highlighting of cards without metadata (VP on these is not counted)." " highlighting of cards without metadata (VP on these is not counted)."
}) })
for _, obj in pairs(missingData) do for _, obj in pairs(missingData) do
if obj ~= nil then if obj ~= nil then
if currentlyHighlighting then if highlightMissing then
obj.highlightOff("Red") obj.highlightOff("Red")
else else
obj.highlightOn("Red") obj.highlightOn("Red")
end end
end end
end end
playAreaApi.highlightMissingData(currentlyHighlighting) playAreaApi.highlightMissingData(highlightMissing)
currentlyHighlighting = not currentlyHighlighting highlightMissing = not highlightMissing
end
-- toggles the highlight for objects that were counted
function highlightCountedVP()
self.editButton({
index = 4,
tooltip = (highlightCounted and "Enable" or "Disable") ..
" highlighting of cards with VP."
})
for _, obj in pairs(countedVP) do
if obj ~= nil then
if highlightCounted then
obj.highlightOff("Green")
else
obj.highlightOn("Green")
end
end
end
playAreaApi.highlightCountedVP(highlightCounted)
highlightCounted = not highlightCounted
end end
--------------------------------------------------------- ---------------------------------------------------------