added hightling button
This commit is contained in:
parent
8bef677eda
commit
94deae2848
@ -55,6 +55,8 @@ local draggingGuids = {}
|
||||
local locationData
|
||||
local currentScenario
|
||||
|
||||
local missingData = {}
|
||||
|
||||
---------------------------------------------------------
|
||||
-- general code
|
||||
---------------------------------------------------------
|
||||
@ -95,7 +97,12 @@ function onCollisionEnter(collisionInfo)
|
||||
local objType = obj.name
|
||||
|
||||
-- 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
|
||||
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
|
||||
-- Ignore any collision where the centerpoint isn't in the area
|
||||
if isInPlayArea(card) then
|
||||
local metadata = JSON.decode(card.getGMNotes()) or { }
|
||||
if metadata.type == "Location" then
|
||||
if card.is_face_down then
|
||||
locations[card.getGUID()] = metadata.locationBack
|
||||
else
|
||||
locations[card.getGUID()] = metadata.locationFront
|
||||
end
|
||||
local metadata = JSON.decode(card.getGMNotes())
|
||||
if metadata == nil then
|
||||
table.insert(missingData, card)
|
||||
else
|
||||
if metadata.type == "Location" then
|
||||
if card.is_face_down then
|
||||
locations[card.getGUID()] = metadata.locationBack
|
||||
else
|
||||
locations[card.getGUID()] = metadata.locationFront
|
||||
end
|
||||
|
||||
-- only draw connection lines for not-excluded scenarios
|
||||
if showLocationLinks() then
|
||||
rebuildConnectionList()
|
||||
drawBaseConnections()
|
||||
-- only draw connection lines for not-excluded scenarios
|
||||
if showLocationLinks() then
|
||||
rebuildConnectionList()
|
||||
drawBaseConnections()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -588,6 +599,20 @@ function searchOnObj(obj)
|
||||
})
|
||||
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)
|
||||
function buildSnaps()
|
||||
local upperleft = { x = 1.53, z = -1.09}
|
||||
|
@ -60,6 +60,12 @@ do
|
||||
return getObjectFromGUID(PLAY_AREA_GUID).call("countVP")
|
||||
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)
|
||||
PlayAreaApi.isInPlayArea = function(object)
|
||||
return getObjectFromGUID(PLAY_AREA_GUID).call("isInPlayArea", object)
|
||||
|
@ -1,6 +1,8 @@
|
||||
local playAreaApi = require("core/PlayAreaApi")
|
||||
local pendingCall = false
|
||||
local messageSent = {}
|
||||
local currentlyHighlighting = false
|
||||
local missingData = {}
|
||||
|
||||
-- button creation when loading the game
|
||||
function onLoad()
|
||||
@ -25,6 +27,20 @@ function onLoad()
|
||||
buttonParameters.position.x = 1.69
|
||||
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
|
||||
Wait.time(updateCount, 1)
|
||||
end
|
||||
@ -104,6 +120,7 @@ end
|
||||
|
||||
-- counts the VP in the victory display and request the VP count from the play area
|
||||
function updateCount()
|
||||
missingData = {}
|
||||
local victoryPoints = {}
|
||||
victoryPoints.display = 0
|
||||
victoryPoints.playArea = playAreaApi.countVP()
|
||||
@ -111,18 +128,15 @@ function updateCount()
|
||||
-- count cards in victory display
|
||||
for _, v in ipairs(searchOnObj(self)) do
|
||||
local obj = v.hit_object
|
||||
local cardVP = 0
|
||||
|
||||
-- check metadata for VP
|
||||
if obj.tag == "Card" then
|
||||
cardVP = getCardVP(obj.is_face_down, JSON.decode(obj.getGMNotes()))
|
||||
victoryPoints.display = victoryPoints.display + addOrSendMessage(cardVP, obj.getName())
|
||||
victoryPoints.display = victoryPoints.display + getCardVP(obj, JSON.decode(obj.getGMNotes()))
|
||||
|
||||
-- handling for stacked cards
|
||||
elseif obj.tag == "Deck" then
|
||||
for _, deepObj in ipairs(obj.getObjects()) do
|
||||
cardVP = getCardVP(true, JSON.decode(deepObj.gm_notes))
|
||||
victoryPoints.display = victoryPoints.display + addOrSendMessage(cardVP, deepObj.nickname)
|
||||
victoryPoints.display = victoryPoints.display + getCardVP(obj, JSON.decode(deepObj.gm_notes))
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -136,19 +150,8 @@ function updateCount()
|
||||
pendingCall = false
|
||||
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
|
||||
function getCardVP(faceDown, notes)
|
||||
function getCardVP(obj, notes)
|
||||
local cardVP
|
||||
if notes ~= nil then
|
||||
-- enemy, treachery etc.
|
||||
@ -157,14 +160,31 @@ function getCardVP(faceDown, notes)
|
||||
-- location
|
||||
if not cardVP then
|
||||
-- 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)
|
||||
elseif notes.locationBack ~= nil then
|
||||
cardVP = tonumber(notes.locationBack.victory)
|
||||
end
|
||||
end
|
||||
else
|
||||
table.insert(missingData, obj)
|
||||
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
|
||||
|
||||
---------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user