Added object unselection to context menus

This commit is contained in:
Chr1Z93 2024-06-28 14:02:41 +02:00
parent df71f95383
commit ee0600f8e4
14 changed files with 63 additions and 51 deletions

View File

@ -42,10 +42,11 @@ function onLoad(savedData)
color = { r = 0, g = 0, b = 0, a = 0 } color = { r = 0, g = 0, b = 0, a = 0 }
}) })
self.addContextMenuItem("toggle broadcasting", updateBroadcast) self.addContextMenuItem("Toggle Broadcasting", updateBroadcast)
end end
function updateBroadcast() function updateBroadcast(playerColor)
Player[playerColor].clearSelectedObjects()
for _, tracker in ipairs(getObjectsWithTag("LinkedPhaseTracker")) do for _, tracker in ipairs(getObjectsWithTag("LinkedPhaseTracker")) do
tracker.setVar("broadcastChange", not broadcastChange) tracker.setVar("broadcastChange", not broadcastChange)
end end

View File

@ -32,7 +32,7 @@ function onload(savedData)
isSetup = false isSetup = false
movingCards = false movingCards = false
self.addContextMenuItem('Reset helper', resetHelper) self.addContextMenuItem('Reset Helper', resetHelper)
if savedData and savedData ~= '' then if savedData and savedData ~= '' then
local loaded_data = JSON.decode(savedData) local loaded_data = JSON.decode(savedData)
@ -242,7 +242,8 @@ function finish()
0.75) 0.75)
end end
function resetHelper() function resetHelper(playerColor)
Player[playerColor].clearSelectedObjects()
for i, card in ipairs(self.getObjects()) do for i, card in ipairs(self.getObjects()) do
self.takeObject({ self.takeObject({
index = 0, index = 0,
@ -269,7 +270,5 @@ function resetHelper()
isSetup = false isSetup = false
movingCards = false movingCards = false
self.reset()
print('Underworld Market Helper: Helper has been reset.') print('Underworld Market Helper: Helper has been reset.')
end end

View File

@ -78,7 +78,7 @@ function onCollisionEnter(collisionInfo)
local localPos = self.positionToLocal(object.getPosition()) local localPos = self.positionToLocal(object.getPosition())
if inArea(localPos, ENCOUNTER_DECK_AREA) or inArea(localPos, ENCOUNTER_DISCARD_AREA) then if inArea(localPos, ENCOUNTER_DECK_AREA) or inArea(localPos, ENCOUNTER_DISCARD_AREA) then
Wait.frames(function() tokenSpawnTrackerApi.resetTokensSpawned(object.getGUID()) end, 1) Wait.frames(function() tokenSpawnTrackerApi.resetTokensSpawned(object) end, 1)
removeTokensFromObject(object) removeTokensFromObject(object)
end end
end end
@ -100,7 +100,7 @@ end
function onObjectEnterContainer(container, object) function onObjectEnterContainer(container, object)
local localPos = self.positionToLocal(container.getPosition()) local localPos = self.positionToLocal(container.getPosition())
if inArea(localPos, ENCOUNTER_DECK_AREA) or inArea(localPos, ENCOUNTER_DISCARD_AREA) then if inArea(localPos, ENCOUNTER_DECK_AREA) or inArea(localPos, ENCOUNTER_DISCARD_AREA) then
tokenSpawnTrackerApi.resetTokensSpawned(object.getGUID()) tokenSpawnTrackerApi.resetTokensSpawned(object)
removeTokensFromObject(object) removeTokensFromObject(object)
end end
end end

View File

@ -202,6 +202,7 @@ end
function addContextMenu() function addContextMenu()
self.addContextMenuItem("Change color", function(playerColor) self.addContextMenuItem("Change color", function(playerColor)
Player[playerColor].clearSelectedObjects()
local currentClassDisplayName = listOfClassDisplayNames[getIndexOfValue(listOfClasses, class)] local currentClassDisplayName = listOfClassDisplayNames[getIndexOfValue(listOfClasses, class)]
Player[playerColor].showOptionsDialog("Choose color", listOfClassDisplayNames, currentClassDisplayName, Player[playerColor].showOptionsDialog("Choose color", listOfClassDisplayNames, currentClassDisplayName,
function(_, selectedIndex) function(_, selectedIndex)
@ -210,6 +211,7 @@ function addContextMenu()
end) end)
self.addContextMenuItem("Change 1st symbol", function(playerColor) self.addContextMenuItem("Change 1st symbol", function(playerColor)
Player[playerColor].clearSelectedObjects()
local symbolList = getSymbolList() local symbolList = getSymbolList()
Player[playerColor].showOptionsDialog("Choose symbol", listOfSymbols, symbolList[1], function(newSymbol) Player[playerColor].showOptionsDialog("Choose symbol", listOfSymbols, symbolList[1], function(newSymbol)
if newSymbol == "None" then if newSymbol == "None" then
@ -229,6 +231,7 @@ function addContextMenu()
end) end)
self.addContextMenuItem("Change 2nd symbol", function(playerColor) self.addContextMenuItem("Change 2nd symbol", function(playerColor)
Player[playerColor].clearSelectedObjects()
local symbolList = getSymbolList() local symbolList = getSymbolList()
Player[playerColor].showOptionsDialog("Choose 2nd symbol", listOfSymbols, symbolList[2] or symbolList[1], Player[playerColor].showOptionsDialog("Choose 2nd symbol", listOfSymbols, symbolList[2] or symbolList[1],
function(newSymbol) function(newSymbol)

View File

@ -211,10 +211,11 @@ do
if tokenType == "clue" then if tokenType == "clue" then
offsets = internal.buildClueOffsets(card, tokenCount) offsets = internal.buildClueOffsets(card, tokenCount)
else else
-- only up to 12 offset tables defined (TODO: stack more than 12 tokens and generate offsets dynamically) -- only up to 12 offset tables defined
if tokenCount > 12 then if tokenCount > 12 then
printToAll("Spawning maximum of 12 tokens.") printToAll("Attempting to spawn " .. tokenCount .. " tokens. Spawning clickable counter instead.")
tokenCount = 12 TokenManager.spawnResourceCounterToken(card, tokenCount)
return
end end
for i = 1, tokenCount do for i = 1, tokenCount do
offsets[i] = card.positionToWorld(PLAYER_CARD_TOKEN_OFFSETS[tokenCount][i]) offsets[i] = card.positionToWorld(PLAYER_CARD_TOKEN_OFFSETS[tokenCount][i])
@ -297,20 +298,13 @@ do
-- Checks a card for metadata to maybe replenish it -- Checks a card for metadata to maybe replenish it
---@param card tts__Object Card object to be replenished ---@param card tts__Object Card object to be replenished
---@param uses table The already decoded metadata.uses (to avoid decoding again) ---@param uses table The already decoded metadata.uses (to avoid decoding again)
---@param mat tts__Object The playermat the card is placed on (for rotation and casting) TokenManager.maybeReplenishCard = function(card, uses)
TokenManager.maybeReplenishCard = function(card, uses, mat)
-- TODO: support for cards with multiple uses AND replenish (as of yet, no official card needs that) -- TODO: support for cards with multiple uses AND replenish (as of yet, no official card needs that)
if uses[1].count and uses[1].replenish then if uses[1].count and uses[1].replenish then
internal.replenishTokens(card, uses, mat) internal.replenishTokens(card, uses)
end end
end end
-- Delegate function to the token spawn tracker. Exists to avoid circular dependencies in some callers
---@param card tts__Object Card object to reset the tokens for
TokenManager.resetTokensSpawned = function(card)
tokenSpawnTrackerApi.resetTokensSpawned(card.getGUID())
end
-- Pushes new player card data into the local copy of the Data Helper player data. -- Pushes new player card data into the local copy of the Data Helper player data.
---@param dataTable table Key/Value pairs following the DataHelper style ---@param dataTable table Key/Value pairs following the DataHelper style
TokenManager.addPlayerCardData = function(dataTable) TokenManager.addPlayerCardData = function(dataTable)
@ -483,16 +477,16 @@ do
---@param card tts__Object Card object to be replenished ---@param card tts__Object Card object to be replenished
---@param uses table The already decoded metadata.uses (to avoid decoding again) ---@param uses table The already decoded metadata.uses (to avoid decoding again)
---@param mat tts__Object The playermat the card is placed on (for rotation and casting) internal.replenishTokens = function(card, uses)
internal.replenishTokens = function(card, uses, mat) -- get current amount of matching resource tokens on the card
-- get current amount of resource tokens on the card
local clickableResourceCounter = nil local clickableResourceCounter = nil
local foundTokens = 0 local foundTokens = 0
local searchType = string.lower(uses[1].type)
for _, obj in ipairs(searchLib.onObject(card, "isTileOrToken")) do for _, obj in ipairs(searchLib.onObject(card, "isTileOrToken")) do
local memo = obj.getMemo() local memo = obj.getMemo()
if (stateTable[memo] or 0) > 0 then if searchType == memo then
foundTokens = foundTokens + math.abs(obj.getQuantity()) foundTokens = foundTokens + math.abs(obj.getQuantity())
obj.destruct() obj.destruct()
elseif memo == "resourceCounter" then elseif memo == "resourceCounter" then

View File

@ -22,8 +22,8 @@ function markTokensSpawned(cardGuid)
spawnedCardGuids[cardGuid] = true spawnedCardGuids[cardGuid] = true
end end
function resetTokensSpawned(cardGuid) function resetTokensSpawned(card)
spawnedCardGuids[cardGuid] = nil spawnedCardGuids[card.getGUID()] = nil
end end
function resetAll() spawnedCardGuids = {} end function resetAll() spawnedCardGuids = {} end
@ -52,6 +52,6 @@ end
-- Listener to reset card token spawns when they enter a hand. -- Listener to reset card token spawns when they enter a hand.
function onObjectEnterZone(zone, enterObject) function onObjectEnterZone(zone, enterObject)
if zone.type == "Hand" and enterObject.type == "Card" then if zone.type == "Hand" and enterObject.type == "Card" then
resetTokensSpawned(enterObject.getGUID()) resetTokensSpawned(enterObject)
end end
end end

View File

@ -14,8 +14,8 @@ do
return getSpawnTracker().call("markTokensSpawned", cardGuid) return getSpawnTracker().call("markTokensSpawned", cardGuid)
end end
TokenSpawnTracker.resetTokensSpawned = function(cardGuid) TokenSpawnTracker.resetTokensSpawned = function(card)
return getSpawnTracker().call("resetTokensSpawned", cardGuid) return getSpawnTracker().call("resetTokensSpawned", card)
end end
TokenSpawnTracker.resetAllAssetAndEvents = function() TokenSpawnTracker.resetAllAssetAndEvents = function()

View File

@ -5,7 +5,8 @@ function onLoad()
end end
-- rotates the alt_view_angle -- rotates the alt_view_angle
function rotatePreview() function rotatePreview(playerColor)
Player[playerColor].clearSelectedObjects()
local angle = self.alt_view_angle local angle = self.alt_view_angle
if angle.y == 0 then if angle.y == 0 then
angle.y = 180 angle.y = 180
@ -16,7 +17,7 @@ function rotatePreview()
end end
-- rotates this card and the preview -- rotates this card and the preview
function rotateSelfAndPreview() function rotateSelfAndPreview(playerColor)
self.setRotationSmooth(self.getRotation() + Vector(0, 180, 0)) self.setRotationSmooth(self.getRotation() + Vector(0, 180, 0))
rotatePreview() rotatePreview(playerColor)
end end

View File

@ -6,9 +6,21 @@ local clickableResourceCounter = nil
local foundTokens = 0 local foundTokens = 0
function onLoad() function onLoad()
self.addContextMenuItem("Add 4 resources", function(playerColor) add4(playerColor) end) self.addContextMenuItem("Add 4 resources",
self.addContextMenuItem("Take all resources", function(playerColor) takeAll(playerColor) end) function(playerColor)
self.addContextMenuItem("Discard all resources", function(playerColor) loseAll(playerColor) end) Player[playerColor].clearSelectedObjects()
add4(playerColor)
end)
self.addContextMenuItem("Take all resources",
function(playerColor)
Player[playerColor].clearSelectedObjects()
takeAll(playerColor)
end)
self.addContextMenuItem("Discard all resources",
function(playerColor)
Player[playerColor].clearSelectedObjects()
loseAll(playerColor)
end)
end end
function searchSelf() function searchSelf()
@ -34,15 +46,10 @@ function add4(playerColor)
local newCount = foundTokens + 4 local newCount = foundTokens + 4
if clickableResourceCounter then if clickableResourceCounter then
clickableResourceCounter.call("updateVal", newCount) clickableResourceCounter.call("updateVal", newCount)
else
if newCount > 12 then
printToColor("Count increased to " .. newCount .. " resources. Spawning clickable counter instead.", playerColor)
tokenManager.spawnResourceCounterToken(self, newCount)
else else
tokenManager.spawnTokenGroup(self, "resource", newCount) tokenManager.spawnTokenGroup(self, "resource", newCount)
end end
end end
end
function takeAll(playerColor) function takeAll(playerColor)
searchSelf() searchSelf()

View File

@ -61,6 +61,7 @@ end
-- Create dialog window to choose sigil and create sigil-drawing button -- Create dialog window to choose sigil and create sigil-drawing button
function chooseSigil(playerColor) function chooseSigil(playerColor)
Player[playerColor].clearSelectedObjects()
self.clearContextMenu() self.clearContextMenu()
self.addContextMenuItem("Clear Helper", deleteButtons) self.addContextMenuItem("Clear Helper", deleteButtons)
@ -80,7 +81,8 @@ function chooseSigil(playerColor)
end end
-- Delete button and remove sigil -- Delete button and remove sigil
function deleteButtons() function deleteButtons(playerColor)
Player[playerColor].clearSelectedObjects()
self.clearContextMenu() self.clearContextMenu()
self.addContextMenuItem("Enable Helper", chooseSigil) self.addContextMenuItem("Enable Helper", chooseSigil)
self.UI.setXml("") self.UI.setXml("")

View File

@ -17,6 +17,7 @@ function onLoad()
end end
function contextFunc(playerColor, amount) function contextFunc(playerColor, amount)
Player[playerColor].clearSelectedObjects()
deckData = {} deckData = {}
local options = {} local options = {}

View File

@ -5,7 +5,8 @@ function onLoad()
end end
-- called by context menu entry -- called by context menu entry
function shortSupply(color) function shortSupply(playerColor)
Player[playerColor].clearSelectedObjects()
local matColor = playermatApi.getMatColorByPosition(self.getPosition()) local matColor = playermatApi.getMatColorByPosition(self.getPosition())
-- get draw deck and discard position -- get draw deck and discard position
@ -15,20 +16,20 @@ function shortSupply(color)
-- error handling -- error handling
if discardPos == nil then if discardPos == nil then
broadcastToColor("Couldn't retrieve discard position from playermat!", color, "Red") broadcastToColor("Couldn't retrieve discard position from playermat!", playerColor, "Red")
return return
end end
if drawDeck == nil then if drawDeck == nil then
broadcastToColor("Deck not found!", color, "Yellow") broadcastToColor("Deck not found!", playerColor, "Yellow")
return return
elseif drawDeck.type ~= "Deck" then elseif drawDeck.type ~= "Deck" then
broadcastToColor("Deck only contains a single card!", color, "Yellow") broadcastToColor("Deck only contains a single card!", playerColor, "Yellow")
return return
end end
-- discard cards, waiting 0.7 seconds between each discard to give players visiblity of the cards -- discard cards, waiting 0.7 seconds between each discard to give players visiblity of the cards
broadcastToColor("Discarding top 10 cards for player color '" .. matColor .. "'.", color, "White") broadcastToColor("Discarding top 10 cards for player color '" .. matColor .. "'.", playerColor, "White")
for i = 1, 10 do for i = 1, 10 do
Wait.time(function() drawDeck.takeObject({ flip = true, position = { discardPos.x, 2 + 0.075 * i, discardPos.z } }) end, .7 * (i - 1)) Wait.time(function() drawDeck.takeObject({ flip = true, position = { discardPos.x, 2 + 0.075 * i, discardPos.z } }) end, .7 * (i - 1))
end end

View File

@ -7,7 +7,8 @@ function onLoad()
end end
-- uses the tekeli-li helper to place this card at the bottom of the deck -- uses the tekeli-li helper to place this card at the bottom of the deck
function returnSelf() function returnSelf(playerColor)
Player[playerColor].clearSelectedObjects()
local helper = getTekeliliHelper() local helper = getTekeliliHelper()
if helper == nil then if helper == nil then
printToAll("Couldn't find Tekeli-li Helper!") printToAll("Couldn't find Tekeli-li Helper!")
@ -18,6 +19,7 @@ end
-- places this card below the deck of the player that triggered it -- places this card below the deck of the player that triggered it
function placeBelowDeck(playerColor) function placeBelowDeck(playerColor)
Player[playerColor].clearSelectedObjects()
local matColor = playermatApi.getMatColor(playerColor) local matColor = playermatApi.getMatColor(playerColor)
local deckPos = playermatApi.getDrawPosition(matColor) local deckPos = playermatApi.getDrawPosition(matColor)
local deckRot = playermatApi.returnRotation(matColor) local deckRot = playermatApi.returnRotation(matColor)

View File

@ -6,6 +6,7 @@ local navigationOverlayApi = require("core/NavigationOverlayApi")
local searchLib = require("util/SearchLib") local searchLib = require("util/SearchLib")
local tokenChecker = require("core/token/TokenChecker") local tokenChecker = require("core/token/TokenChecker")
local tokenManager = require("core/token/TokenManager") local tokenManager = require("core/token/TokenManager")
local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi")
-- we use this to turn off collision handling until onLoad() is complete -- we use this to turn off collision handling until onLoad() is complete
local collisionEnabled = false local collisionEnabled = false
@ -344,7 +345,7 @@ function doUpkeep(_, clickedByColor, isRightClick)
end end
-- maybe replenish uses on certain cards (don't continue for cards on the deck (Norman) or in the discard pile) -- maybe replenish uses on certain cards (don't continue for cards on the deck (Norman) or in the discard pile)
if cardMetadata.uses ~= nil and self.positionToLocal(obj.getPosition()).x < -1 then if cardMetadata.uses ~= nil and self.positionToLocal(obj.getPosition()).x > -1 then
tokenManager.maybeReplenishCard(obj, cardMetadata.uses, self) tokenManager.maybeReplenishCard(obj, cardMetadata.uses, self)
end end
elseif obj.type == "Deck" and forcedLearning == false then elseif obj.type == "Deck" and forcedLearning == false then
@ -823,7 +824,7 @@ function onCollisionEnter(collisionInfo)
local localCardPos = self.positionToLocal(object.getPosition()) local localCardPos = self.positionToLocal(object.getPosition())
if inArea(localCardPos, DECK_DISCARD_AREA) then if inArea(localCardPos, DECK_DISCARD_AREA) then
tokenManager.resetTokensSpawned(object) tokenSpawnTrackerApi.resetTokensSpawned(object)
removeTokensFromObject(object) removeTokensFromObject(object)
elseif shouldSpawnTokens(object) then elseif shouldSpawnTokens(object) then
spawnTokensFor(object) spawnTokensFor(object)
@ -867,7 +868,7 @@ function onObjectEnterContainer(container, object)
local localCardPos = self.positionToLocal(object.getPosition()) local localCardPos = self.positionToLocal(object.getPosition())
if inArea(localCardPos, DECK_DISCARD_AREA) then if inArea(localCardPos, DECK_DISCARD_AREA) then
tokenManager.resetTokensSpawned(object) tokenSpawnTrackerApi.resetTokensSpawned(object)
removeTokensFromObject(object) removeTokensFromObject(object)
end end
end end