Merge pull request #818 from argonui/playarea-upkeep

Added "Ready Cards" button to Play Area
This commit is contained in:
dscarpac 2024-08-15 10:19:51 -05:00 committed by GitHub
commit 683b689536
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 119 additions and 19 deletions

View File

@ -12,6 +12,10 @@
"displayed": "LinkedPhaseTracker",
"normalized": "linkedphasetracker"
},
{
"displayed": "DoNotReady",
"normalized": "donotready"
},
{
"displayed": "displacement_excluded",
"normalized": "displacement_excluded"

View File

@ -959,6 +959,13 @@
"ImageURL": "https://steamusercontent-a.akamaihd.net/ugc/998015670465071049/FFAE162920D67CF38045EFBD3B85AD0F916147B2/",
"WidthScale": 0
},
"CustomUIAssets": [
{
"Name": "font_teutonic-arkham",
"Type": 1,
"URL": "https://steamusercontent-a.akamaihd.net/ugc/2027213118467703445/89328E273B4C5180BF491516CE998DE3C604E162/"
}
],
"Description": "",
"DragSelectable": true,
"GMNotes": "",
@ -995,5 +1002,5 @@
"scaleZ": 10
},
"Value": 0,
"XmlUI": ""
"XmlUI": "\u003cInclude src=\"PlayArea.xml\"/\u003e"
}

View File

@ -61,7 +61,7 @@ function updateVal(number)
if number then
broadcastDoom(val)
else
broadcastToAll("0 doom on the agenda", "White")
broadcastToAll("0 doom on the agenda")
end
end
@ -72,9 +72,9 @@ function broadcastDoom(val)
local doomThreshold = getDoomThreshold()
if doomThreshold then
broadcastToAll(val .. " doom on the agenda (" .. doomInPlay .. "/" .. doomThreshold .. " in play)", "White")
broadcastToAll(val .. " doom on the agenda (" .. doomInPlay .. "/" .. doomThreshold .. " in play)")
else
broadcastToAll(val .. " doom on the agenda (" .. doomInPlay .. " in play)", "White")
broadcastToAll(val .. " doom on the agenda (" .. doomInPlay .. " in play)")
end
end

View File

@ -54,6 +54,9 @@ function triggerUpkeepMultihanded(playerColor)
playermatApi.doUpkeepFromHotkey(matColor, playerColor)
end
end
-- also trigger the PlayArea's "Ready Cards" function
playAreaApi.readyCards()
end
-- adds 1 doom to the agenda

View File

@ -69,7 +69,7 @@ function onLoad(savedData)
end
-- this needs to be here since the playarea will be reloaded when the image changes
self.interactable = false
self.interactable = false
Wait.time(function() collisionEnabled = true end, 0.1)
end
@ -308,7 +308,7 @@ function buildConnection(cardId, iconCardList, locData)
-- If the reciprocal exists, convert it to BiDi, otherwise add as a one-way
if locationConnections[connectedGuid] ~= nil
and (locationConnections[connectedGuid][cardId] == ONE_WAY
or locationConnections[connectedGuid][cardId] == BIDIRECTIONAL) then
or locationConnections[connectedGuid][cardId] == BIDIRECTIONAL) then
locationConnections[connectedGuid][cardId] = BIDIRECTIONAL
locationConnections[cardId][connectedGuid] = nil
else
@ -512,6 +512,62 @@ function highlightMissingData(state)
end
end
-- Readies all cards in the main playarea (both player cards, treacheries and enemies)
function readyCards(player, clickType)
local playerColor = player.color
-- when right-clicked
if clickType == "-2" then
printToColor("This will ready (rotate 90° closer to 0°) all cards in the main play area." ..
" Make sure to handle enemy engagement manually. To exclude a card from this (e.g. Handcuffs)," ..
" right-click it, select 'Tags' and add the tag 'DoNotReady' to it.", playerColor)
return
end
local zone = guidReferenceApi.getObjectByOwnerAndType("Mythos", "PlayAreaZone")
if not zone then
broadcastToColor("Scripting zone couldn't be found.", playerColor, "Red")
return
end
local count = 0
local rot = self.getRotation()
for _, obj in ipairs(zone.getObjects()) do
if obj.type == "Card" and obj.locked == false and not (obj.getVar("do_not_ready") or obj.hasTag("DoNotReady")) then
local cardRotation = obj.getRotation()
local roundedRotY = round(cardRotation.y, 0)
local yRotDiff = roundedRotY - rot.y
if yRotDiff < 0 then
yRotDiff = yRotDiff + 360
end
-- rotate cards to the next multiple of 90° towards 0°
local cardRotY = rot.y
if yRotDiff > 90 and yRotDiff <= 180 then
cardRotY = rot.y + 90
elseif yRotDiff > 180 and yRotDiff < 270 then
cardRotY = rot.y + 270
end
-- highlighting for readied cards
if cardRotY == rot.y and roundedRotY ~= rot.y then
obj.highlightOn({ r = 0.8, g = 1, b = 0.05 }, 2)
count = count + 1
end
obj.setRotation(cardRotation:setAt("y", cardRotY))
end
end
local cardString = " cards "
if count == 1 then
cardString = " card "
end
broadcastToAll("Readied " .. count .. cardString .. " in Play Area")
end
---------------------------------------------------------
-- functions for outside calls
---------------------------------------------------------

View File

@ -105,7 +105,12 @@ do
-- Updates the surface of the play area
PlayAreaApi.updateSurface = function(url)
return getPlayArea().call("updateSurface", url)
getPlayArea().call("updateSurface", url)
end
-- Readies cards in the PlayArea
PlayAreaApi.readyCards = function()
getPlayArea().call("readyCards")
end
-- Returns a deep copy of the currently tracked locations

View File

@ -350,23 +350,22 @@ function doUpkeep(_, clickedByColor, isRightClick)
elseif obj.type == "Card" and not inArea(self.positionToLocal(obj.getPosition()), INVESTIGATOR_AREA) then
local cardMetadata = JSON.decode(obj.getGMNotes()) or {}
if not (obj.getVar("do_not_ready") or obj.hasTag("DoNotReady")) then
local cardRotation = round(obj.getRotation().y, 0) - rot.y
local yRotDiff = 0
local cardRotation = obj.getRotation()
local yRotDiff = round(cardRotation.y, 0) - rot.y
if cardRotation < 0 then
cardRotation = cardRotation + 360
if yRotDiff < 0 then
yRotDiff = yRotDiff + 360
end
-- rotate cards to the next multiple of 90° towards 0°
if cardRotation > 90 and cardRotation <= 180 then
yRotDiff = 90
elseif cardRotation < 270 and cardRotation > 180 then
yRotDiff = 270
local cardRotY = rot.y
if yRotDiff > 90 and yRotDiff <= 180 then
cardRotY = rot.y + 90
elseif yRotDiff > 180 and yRotDiff < 270 then
cardRotY = rot.y + 270
end
-- set correct rotation for face-down cards
rot.z = obj.is_face_down and 180 or 0
obj.setRotation({ rot.x, rot.y + yRotDiff, rot.z })
obj.setRotation(cardRotation:setAt("y", cardRotY))
end
-- detect Forced Learning to handle card drawing accordingly

View File

@ -1,4 +1,4 @@
<Panel position="160 70 -13"
<Panel position="160 70 -11"
rotation="0 0 180"
height="74"
width="315">
@ -7,5 +7,6 @@
textColors="#ffffff|#88e3cf|#4f8478"
font="font_teutonic-arkham"
fontSize="62"
textAlignment="MiddleCenter"
onClick="reshuffleEncounterDeck">Reshuffle ➡</Button>
</Panel>

25
xml/PlayArea.xml Normal file
View File

@ -0,0 +1,25 @@
<Panel position="169 182 -11"
rotation="0 0 180"
height="280"
width="660">
<Button scale="0.045 0.045 1"
color="#ffffff05"
textColors="#ffffff|#88e3cf|#4f8478"
font="font_teutonic-arkham"
fontSize="125"
textAlignment="MiddleCenter"
onClick="readyCards">Ready Cards in Play Area ↺</Button>
</Panel>
<Panel position="-169 182 -11"
rotation="0 0 180"
height="280"
width="660">
<Button scale="0.045 0.045 1"
color="#ffffff05"
textColors="#ffffff|#88e3cf|#4f8478"
font="font_teutonic-arkham"
fontSize="125"
textAlignment="MiddleCenter"
onClick="readyCards">Ready Cards in Play Area ↺</Button>
</Panel>