added hightling button

This commit is contained in:
Chr1Z93 2023-02-04 03:11:26 +01:00
parent 8bef677eda
commit 94deae2848
3 changed files with 82 additions and 31 deletions

View File

@ -55,6 +55,8 @@ local draggingGuids = {}
local locationData local locationData
local currentScenario local currentScenario
local missingData = {}
--------------------------------------------------------- ---------------------------------------------------------
-- general code -- general code
--------------------------------------------------------- ---------------------------------------------------------
@ -95,7 +97,12 @@ function onCollisionEnter(collisionInfo)
local objType = obj.name local objType = obj.name
-- only continue for cards -- only continue for cards
if not collisionEnabled or (objType ~= "Card" and objType ~= "CardCustom") then return end if not collisionEnabled or (objType ~= "Card" and objType ~= "CardCustom") then
if objType == "Deck" then
table.insert(missingData, obj)
end
return
end
-- check if we should spawn clues here and do so according to playercount -- check if we should spawn clues here and do so according to playercount
local card = collisionInfo.collision_object local card = collisionInfo.collision_object
@ -192,18 +199,22 @@ function maybeTrackLocation(card)
-- Collision checks for any part of the card overlap, but our other tracking is centerpoint -- Collision checks for any part of the card overlap, but our other tracking is centerpoint
-- Ignore any collision where the centerpoint isn't in the area -- Ignore any collision where the centerpoint isn't in the area
if isInPlayArea(card) then if isInPlayArea(card) then
local metadata = JSON.decode(card.getGMNotes()) or { } local metadata = JSON.decode(card.getGMNotes())
if metadata.type == "Location" then if metadata == nil then
if card.is_face_down then table.insert(missingData, card)
locations[card.getGUID()] = metadata.locationBack else
else if metadata.type == "Location" then
locations[card.getGUID()] = metadata.locationFront if card.is_face_down then
end locations[card.getGUID()] = metadata.locationBack
else
locations[card.getGUID()] = metadata.locationFront
end
-- only draw connection lines for not-excluded scenarios -- only draw connection lines for not-excluded scenarios
if showLocationLinks() then if showLocationLinks() then
rebuildConnectionList() rebuildConnectionList()
drawBaseConnections() drawBaseConnections()
end
end end
end end
end end
@ -588,6 +599,20 @@ function searchOnObj(obj)
}) })
end end
-- highlights all locations in the play area without metadata
---@param state Boolean True if highlighting should be enabled
function highlightMissingData(state)
for _, obj in pairs(missingData) do
if obj ~= nil then
if state then
obj.highlightOff("Red")
else
obj.highlightOn("Red")
end
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

@ -59,6 +59,12 @@ do
PlayAreaApi.countVP = function() PlayAreaApi.countVP = function()
return getObjectFromGUID(PLAY_AREA_GUID).call("countVP") return getObjectFromGUID(PLAY_AREA_GUID).call("countVP")
end end
-- highlights all locations in the play area without metadata
---@param state Boolean True if highlighting should be enabled
PlayAreaApi.highlightMissingData = function(state)
return getObjectFromGUID(PLAY_AREA_GUID).call("highlightMissingData", 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)

View File

@ -1,6 +1,8 @@
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 = {}
-- button creation when loading the game -- button creation when loading the game
function onLoad() function onLoad()
@ -25,6 +27,20 @@ function onLoad()
buttonParameters.position.x = 1.69 buttonParameters.position.x = 1.69
self.createButton(buttonParameters) self.createButton(buttonParameters)
-- index 3: hightling button
self.createButton({
label = "!",
click_function = "highlightMissingData",
tooltip = "Enable / Disable highlighting of cards without metadata (VP on these is not counted).",
function_owner = self,
scale = { 0.15, 0.15, 0.15 },
color = { 1, 0, 0 },
width = 700,
height = 800,
font_size = 700,
font_color = { 1, 1, 1 },
position = { x = 1.82, 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
@ -104,6 +120,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 = {}
local victoryPoints = {} local victoryPoints = {}
victoryPoints.display = 0 victoryPoints.display = 0
victoryPoints.playArea = playAreaApi.countVP() victoryPoints.playArea = playAreaApi.countVP()
@ -111,18 +128,15 @@ function updateCount()
-- count cards in victory display -- count cards in victory display
for _, v in ipairs(searchOnObj(self)) do for _, v in ipairs(searchOnObj(self)) do
local obj = v.hit_object local obj = v.hit_object
local cardVP = 0
-- 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())) victoryPoints.display = victoryPoints.display + getCardVP(obj, JSON.decode(obj.getGMNotes()))
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)) victoryPoints.display = victoryPoints.display + getCardVP(obj, JSON.decode(deepObj.gm_notes))
victoryPoints.display = victoryPoints.display + addOrSendMessage(cardVP, deepObj.nickname)
end end
end end
end end
@ -136,19 +150,8 @@ function updateCount()
pendingCall = false pendingCall = false
end end
-- sends a message for cards in the victory display that don't have VP
function addOrSendMessage(addition, name)
if tonumber(addition) ~= nil then
return tonumber(addition)
elseif not tableContains(messageSent, name) then
printToAll("No VP counted for '" .. name .. "'.", "White")
table.insert(messageSent, name)
end
return 0
end
-- gets the VP count from the notes -- gets the VP count from the notes
function getCardVP(faceDown, notes) function getCardVP(obj, notes)
local cardVP local cardVP
if notes ~= nil then if notes ~= nil then
-- enemy, treachery etc. -- enemy, treachery etc.
@ -157,14 +160,31 @@ function getCardVP(faceDown, notes)
-- location -- location
if not cardVP then if not cardVP then
-- check the correct side of the location -- check the correct side of the location
if not faceDown and notes.locationFront ~= nil then if not obj.is_face_down and notes.locationFront ~= nil then
cardVP = tonumber(notes.locationFront.victory) cardVP = tonumber(notes.locationFront.victory)
elseif notes.locationBack ~= nil then elseif notes.locationBack ~= nil then
cardVP = tonumber(notes.locationBack.victory) cardVP = tonumber(notes.locationBack.victory)
end end
end end
else
table.insert(missingData, obj)
end end
return cardVP return cardVP or 0
end
-- toggles the highlight for objects with missing metadata
function highlightMissingData()
for _, obj in pairs(missingData) do
if obj ~= nil then
if currentlyHighlighting then
obj.highlightOff("Red")
else
obj.highlightOn("Red")
end
end
end
playAreaApi.highlightMissingData(currentlyHighlighting)
currentlyHighlighting = not currentlyHighlighting
end end
--------------------------------------------------------- ---------------------------------------------------------