Bugfixes for "Remove One Use" hotkey
This commit is contained in:
parent
ba8f6c9c3e
commit
09267294c6
@ -102,9 +102,11 @@ function takeCardIntoThreatArea(playerColor, hoveredObject)
|
|||||||
modifierY = -90
|
modifierY = -90
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- contruct feedback message
|
||||||
local cardName = hoveredObject.getName()
|
local cardName = hoveredObject.getName()
|
||||||
if cardName == "" then cardName = "card" end
|
if cardName == "" then cardName = "a card" end
|
||||||
broadcastToAll("Moved " .. cardName .. " to " .. getColoredName(playerColor) .. "'s threat area.", "White")
|
local playerName = getColoredName(playerColor)
|
||||||
|
broadcastToAll("Moved " .. cardName .. " to " .. playerName .. "'s threat area.", "White")
|
||||||
|
|
||||||
-- get new rotation (rounded)
|
-- get new rotation (rounded)
|
||||||
local cardRot = hoveredObject.getRotation()
|
local cardRot = hoveredObject.getRotation()
|
||||||
@ -256,27 +258,66 @@ function removeOneUse(playerColor, hoveredObject)
|
|||||||
if hoveredObject.type == "Tile" then
|
if hoveredObject.type == "Tile" then
|
||||||
targetObject = hoveredObject
|
targetObject = hoveredObject
|
||||||
elseif hoveredObject.type == "Card" then
|
elseif hoveredObject.type == "Card" then
|
||||||
-- grab the first use type from the metadata (or nil)
|
local searchResult = searchLib.onObject(hoveredObject, "isTileOrToken")
|
||||||
local notes = JSON.decode(hoveredObject.getGMNotes()) or {}
|
|
||||||
local usesData = notes.uses or {}
|
|
||||||
local useInfo = usesData[1] or {}
|
|
||||||
local searchForType = useInfo.type
|
|
||||||
if searchForType then searchForType = searchForType:lower() end
|
|
||||||
|
|
||||||
for _, obj in ipairs(searchLib.onObject(hoveredObject, "isTileOrToken")) do
|
if #searchResult == 0 then
|
||||||
if not obj.locked and obj.memo ~= "resourceCounter" then
|
broadcastToColor("No tokens found!", playerColor, "Yellow")
|
||||||
-- check for matching object, otherwise use the first hit
|
return
|
||||||
if obj.memo and obj.memo == searchForType then
|
end
|
||||||
|
|
||||||
|
-- index the found tokens by memo (only the first of each type)
|
||||||
|
local indexByMemo = {}
|
||||||
|
for _, obj in ipairs(searchResult) do
|
||||||
|
if not obj.locked then
|
||||||
|
if obj.memo and indexByMemo[obj.memo] == nil then
|
||||||
|
indexByMemo[obj.memo] = obj
|
||||||
|
elseif indexByMemo["NO_MEMO"] == nil then
|
||||||
|
indexByMemo["NO_MEMO"] = obj
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- use metadata (if present) to determine targetObject
|
||||||
|
local usesAreTypeOfResource = false
|
||||||
|
local notes = JSON.decode(hoveredObject.getGMNotes()) or {}
|
||||||
|
for _, useInfo in ipairs(notes.uses or {}) do
|
||||||
|
if useInfo.type then
|
||||||
|
local discardMemo = useInfo.type:lower()
|
||||||
|
if indexByMemo[discardMemo] then
|
||||||
|
targetObject = indexByMemo[discardMemo]
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if useInfo.token == "resource" then
|
||||||
|
usesAreTypeOfResource = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- check for alternatives (check resources first if tokens are a type of resource)
|
||||||
|
if not targetObject then
|
||||||
|
if usesAreTypeOfResource and indexByMemo["resource"] then
|
||||||
|
targetObject = indexByMemo["resource"]
|
||||||
|
else
|
||||||
|
for memo, obj in pairs(indexByMemo) do
|
||||||
|
if memo ~= "resourceCounter" and memo ~= "NO_MEMO" then
|
||||||
targetObject = obj
|
targetObject = obj
|
||||||
break
|
break
|
||||||
elseif not targetObject then
|
|
||||||
targetObject = obj
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- error handling
|
-- if there's still not a target check for clickable counter and token without memo
|
||||||
|
if not targetObject then
|
||||||
|
if indexByMemo["resourceCounter"] then
|
||||||
|
indexByMemo["resourceCounter"].call("modifyValue", -1)
|
||||||
|
return
|
||||||
|
elseif indexByMemo["NO_MEMO"] then
|
||||||
|
targetObject = indexByMemo["NO_MEMO"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if not targetObject then
|
if not targetObject then
|
||||||
broadcastToColor("No tokens found!", playerColor, "Yellow")
|
broadcastToColor("No tokens found!", playerColor, "Yellow")
|
||||||
return
|
return
|
||||||
@ -297,6 +338,16 @@ function removeOneUse(playerColor, hoveredObject)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- feedback message
|
-- feedback message
|
||||||
|
local cardName
|
||||||
|
if hoveredObject.type == "Card" then
|
||||||
|
cardName = hoveredObject.getName()
|
||||||
|
else
|
||||||
|
local searchResult = searchLib.belowPosition(targetObject.getPosition(), "isCard")
|
||||||
|
if #searchResult > 0 then
|
||||||
|
cardName = searchResult[1].getName()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local tokenName = targetObject.getName()
|
local tokenName = targetObject.getName()
|
||||||
if tokenName == "" then
|
if tokenName == "" then
|
||||||
if targetObject.memo ~= "" then
|
if targetObject.memo ~= "" then
|
||||||
@ -311,11 +362,18 @@ function removeOneUse(playerColor, hoveredObject)
|
|||||||
tokenName = titleCase(targetObject.memo)
|
tokenName = titleCase(targetObject.memo)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
tokenName = "Unknown"
|
tokenName = "unknown token"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
broadcastToAll(getColoredName(playerColor) .. " removed a token: " .. tokenName, playerColor)
|
-- construct feedback message
|
||||||
|
local playerName = getColoredName(playerColor)
|
||||||
|
local article = getArticle(tokenName)
|
||||||
|
local cardInfo = ""
|
||||||
|
if cardName and cardName ~= "" then
|
||||||
|
cardInfo = " from " .. cardName
|
||||||
|
end
|
||||||
|
broadcastToAll(playerName .. " removed" .. article .. tokenName .. cardInfo .. ".", "White")
|
||||||
|
|
||||||
local discardForMatColor = getColorToDiscardFor(hoveredObject, playerColor)
|
local discardForMatColor = getColorToDiscardFor(hoveredObject, playerColor)
|
||||||
playermatApi.discardListOfObjects(discardForMatColor, { targetObject })
|
playermatApi.discardListOfObjects(discardForMatColor, { targetObject })
|
||||||
@ -427,7 +485,7 @@ function takeClueFromLocation(playerColor, hoveredObject)
|
|||||||
end
|
end
|
||||||
elseif hoveredObject.type == "Infinite" and hoveredObject.getName() == "Clue tokens" then
|
elseif hoveredObject.type == "Infinite" and hoveredObject.getName() == "Clue tokens" then
|
||||||
clue = hoveredObject.takeObject()
|
clue = hoveredObject.takeObject()
|
||||||
cardName = "token pool"
|
cardName = "the token pool"
|
||||||
else
|
else
|
||||||
broadcastToColor("Hover a clue or card with clues and try again.", messageColor, "Yellow")
|
broadcastToColor("Hover a clue or card with clues and try again.", messageColor, "Yellow")
|
||||||
return
|
return
|
||||||
@ -460,11 +518,13 @@ function takeClueFromLocation(playerColor, hoveredObject)
|
|||||||
clue.setRotation(rot)
|
clue.setRotation(rot)
|
||||||
end
|
end
|
||||||
|
|
||||||
if cardName then
|
-- construct feedback message
|
||||||
broadcastToAll(getColoredName(playerColor) .. " took one clue from " .. cardName .. ".", "White")
|
local playerName = getColoredName(playerColor)
|
||||||
else
|
local cardInfo = ""
|
||||||
broadcastToAll(getColoredName(playerColor) .. " took one clue.", "White")
|
if cardName and cardName ~= "" then
|
||||||
|
cardInfo = " from " .. cardName
|
||||||
end
|
end
|
||||||
|
broadcastToAll(playerName .. " took one clue" .. cardInfo .. ".", "White")
|
||||||
|
|
||||||
victoryDisplayApi.update()
|
victoryDisplayApi.update()
|
||||||
end
|
end
|
||||||
@ -496,6 +556,13 @@ function titleCase(str)
|
|||||||
return first:upper() .. rest:lower()
|
return first:upper() .. rest:lower()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- gets the proper article (disregarding silent "h")
|
||||||
|
function getArticle(str)
|
||||||
|
local vowels = { a = true, e = true, i = true, o = true, u = true }
|
||||||
|
local firstLetter = string.lower(str:sub(1, 1))
|
||||||
|
return vowels[firstLetter] and " an " or " a "
|
||||||
|
end
|
||||||
|
|
||||||
-- returns the color of the first seated player
|
-- returns the color of the first seated player
|
||||||
function getFirstSeatedPlayer()
|
function getFirstSeatedPlayer()
|
||||||
for _, color in ipairs(getSeatedPlayers()) do
|
for _, color in ipairs(getSeatedPlayers()) do
|
||||||
|
@ -49,6 +49,10 @@ function updateVal(newVal)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function addOrSubtract(_, _, isRightClick)
|
function addOrSubtract(_, _, isRightClick)
|
||||||
val = math.min(math.max(val + (isRightClick and -1 or 1), MIN_VALUE), MAX_VALUE)
|
modifyValue(isRightClick and -1 or 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function modifyValue(mod)
|
||||||
|
val = math.min(math.max(val + tonumber(mod), MIN_VALUE), MAX_VALUE)
|
||||||
self.editButton({ index = 0, label = tostring(val) })
|
self.editButton({ index = 0, label = tostring(val) })
|
||||||
end
|
end
|
||||||
|
@ -113,7 +113,7 @@ function addUseToCard(card, useType)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local match = false
|
local match = false
|
||||||
for _, useInfo in ipairs(metadata.uses) do
|
for _, useInfo in ipairs(metadata.uses or {}) do
|
||||||
if useInfo.token == useType then
|
if useInfo.token == useType then
|
||||||
-- artificially create replenish data to re-use that existing functionality
|
-- artificially create replenish data to re-use that existing functionality
|
||||||
useInfo.count = 999
|
useInfo.count = 999
|
||||||
|
Loading…
x
Reference in New Issue
Block a user