Merge branch 'main' into card-panel
This commit is contained in:
commit
e9b25d5f88
@ -1 +1 @@
|
||||
{"includeDrawnTokens":true,"percentage":false,"tokenPrecedence":{"":[0,11],"Auto-fail":[-100,7],"Bless":[101,8],"Cultist":[-2,4],"Curse":[-101,9],"Elder Sign":[100,2],"Elder Thing":[-4,6],"Frost":[-99,10],"Skull":[-1,3],"Tablet":[-3,5]}}
|
||||
{"includeDrawnTokens":true,"percentage":false,"tokenPrecedence":{"":[0,11],"Auto-fail":[-100,7],"Bless":[110,8],"Cultist":[-2,4],"Curse":[-110,9],"Elder Sign":[100,2],"Elder Thing":[-4,6],"Frost":[-105,10],"Skull":[-1,3],"Tablet":[-3,5]}}
|
||||
|
@ -161,12 +161,12 @@ function restoreCampaignData(importData, coin)
|
||||
deckImporterApi.setUiState(importData["decks"])
|
||||
end
|
||||
|
||||
-- maybe set campaign guide page
|
||||
if importData["guide"] then
|
||||
-- maybe set campaign guide page (unless it was on the first page)
|
||||
if importData["guide"] and importData["guide"] ~= 0 then
|
||||
local campaignGuide = findUniqueObjectWithTag("CampaignGuide")
|
||||
if campaignGuide then
|
||||
Wait.condition(
|
||||
-- Called after the condition function returns true
|
||||
-- Called after the condition function returns true
|
||||
function() printToAll("Campaign Guide import successful!") end,
|
||||
-- Condition function that is called continuously until it returns true or timeout is reached
|
||||
function() return campaignGuide.Book.setPage(importData["guide"]) end,
|
||||
@ -190,6 +190,13 @@ function restoreCampaignData(importData, coin)
|
||||
playAreaApi.updateSurface(importData["playarea"])
|
||||
playAreaApi.setInvestigatorCount(importData["clueCount"])
|
||||
|
||||
-- restore Playmat slots
|
||||
if importData["slotData"] then
|
||||
for matColor, slotData in pairs(importData["slotData"]) do
|
||||
playmatApi.loadSlotData(matColor, slotData)
|
||||
end
|
||||
end
|
||||
|
||||
coin.destruct()
|
||||
broadcastToAll("Campaign successfully imported!", "Green")
|
||||
end
|
||||
@ -265,6 +272,13 @@ function createCampaignToken(_, playerColor, _)
|
||||
table.insert(campaignTokenData.ContainedObjects, indexData)
|
||||
end
|
||||
|
||||
-- get the slot symbol data for each playmat (use GUIDReferenceApi to only get this for existing playmats)
|
||||
campaignData.slotData = {}
|
||||
for matColor, _ in pairs(guidReferenceApi.getObjectsByType("Playermat")) do
|
||||
local slotData = playmatApi.getSlotData(matColor)
|
||||
campaignData.slotData[matColor] = slotData
|
||||
end
|
||||
|
||||
-- finish the data for the campaign token
|
||||
campaignTokenData.GMNotes = JSON.encode(campaignData)
|
||||
campaignTokenData.Nickname = campaignBox.getName() .. os.date(" %b %d") .. " Save"
|
||||
|
@ -11,7 +11,8 @@ local phaseImages = {
|
||||
"http://cloud-3.steamusercontent.com/ugc/982233321870237261/C287CAED2423970F33E72D6C7415CBEC6794C533/"
|
||||
}
|
||||
|
||||
local phaseId, broadcastChange
|
||||
-- these are intentionally global for remote updating
|
||||
-- phaseId, broadcastChange
|
||||
|
||||
function onSave()
|
||||
return JSON.encode({
|
||||
|
@ -12,16 +12,18 @@ buttonParameters.height = 325
|
||||
|
||||
local inputParameters = {}
|
||||
inputParameters.function_owner = self
|
||||
inputParameters.font_size = 100
|
||||
inputParameters.width = 250
|
||||
inputParameters.height = inputParameters.font_size + 23
|
||||
inputParameters.font_size = 200
|
||||
inputParameters.width = 500
|
||||
inputParameters.height = inputParameters.font_size + 46
|
||||
inputParameters.alignment = 3
|
||||
inputParameters.validation = 2
|
||||
inputParameters.tab = 2
|
||||
inputParameters.scale = { 0.5, 0.5, 0.5 }
|
||||
|
||||
local percentageLabel = {}
|
||||
percentageLabel.function_owner = self
|
||||
percentageLabel.click_function = "none"
|
||||
percentageLabel.font_size = 200
|
||||
percentageLabel.width = 0
|
||||
percentageLabel.height = 0
|
||||
|
||||
@ -69,13 +71,13 @@ function onLoad(savedData)
|
||||
end
|
||||
|
||||
createButtonsAndInputs()
|
||||
|
||||
|
||||
-- maybe trigger layout() to draw percentage buttons
|
||||
local objList = getObjectsWithTag("tempToken")
|
||||
if #objList > 0 then
|
||||
Wait.time(layout, 0.5)
|
||||
end
|
||||
|
||||
|
||||
-- context menu items
|
||||
self.addContextMenuItem("Load default values", function()
|
||||
loadDefaultValues()
|
||||
@ -153,10 +155,10 @@ function loadDefaultValues()
|
||||
["Tablet"] = { -3, 5},
|
||||
["Elder Thing"] = { -4, 6},
|
||||
["Auto-fail"] = { -100, 7},
|
||||
["Bless"] = { 101, 8},
|
||||
["Curse"] = { -101, 9},
|
||||
["Frost"] = { -99, 10},
|
||||
[""] = { 0, 11}
|
||||
["Bless"] = { 110, 8},
|
||||
["Curse"] = { -110, 9},
|
||||
["Frost"] = { -105, 10},
|
||||
[""] = { 0, 11}
|
||||
}
|
||||
end
|
||||
|
||||
@ -195,9 +197,11 @@ function createButtonsAndInputs()
|
||||
click_function = "layout",
|
||||
tooltip = "Left-Click: Update!\nRight-Click: Hide Tokens!",
|
||||
position = { 0.725, 0.1, 2.025 },
|
||||
scale = { 0.5, 0.5, 0.5 },
|
||||
color = { 1, 1, 1 },
|
||||
width = 675,
|
||||
height = 175
|
||||
font_size = 200,
|
||||
width = 1350,
|
||||
height = 325
|
||||
})
|
||||
end
|
||||
|
||||
@ -238,14 +242,14 @@ function deleteCopiedTokens()
|
||||
end
|
||||
|
||||
-- creates buttons as labels as display for percentage values
|
||||
function createPercentageButton(tokenCount, valueCount, tokenName)
|
||||
local startPos = Vector(2.3, -0.04, 0.875 * valueCount)
|
||||
function createPercentageButton(tokenCount, rowCount, tokenName)
|
||||
local startPos = Vector(2.3, -0.04, 0.875 * rowCount)
|
||||
|
||||
if percentage == "cumulative" then
|
||||
percentageLabel.scale = { 1.5, 1.5, 1.5 }
|
||||
percentageLabel.scale = { 0.75, 0.75, 0.75 }
|
||||
percentageLabel.position = startPos - Vector(0, 0, 2.85)
|
||||
else
|
||||
percentageLabel.scale = { 2, 2, 2 }
|
||||
percentageLabel.scale = { 1, 1, 1 }
|
||||
percentageLabel.position = startPos - Vector(0, 0, 2.675)
|
||||
end
|
||||
|
||||
@ -254,8 +258,8 @@ function createPercentageButton(tokenCount, valueCount, tokenName)
|
||||
percentageLabel.font_color = { 0.35, 0.71, 0.85 }
|
||||
elseif tokenName == "Auto-fail" then
|
||||
percentageLabel.font_color = { 0.86, 0.1, 0.1 }
|
||||
-- check if the tokenName contains letters (e.g. symbol token)
|
||||
elseif string.match(tokenName, "%a") ~= nil then
|
||||
-- tokenName contains letters (e.g. symbol token)
|
||||
percentageLabel.font_color = { 0.68, 0.53, 0.86 }
|
||||
else
|
||||
percentageLabel.font_color = { 0.85, 0.67, 0.33 }
|
||||
@ -302,12 +306,14 @@ function layout(_, _, isRightClick)
|
||||
end
|
||||
|
||||
-- clone tokens from chaos bag (default position above trash can)
|
||||
local rawData = chaosBag.getData().ContainedObjects
|
||||
local rawData = chaosBag.getData().ContainedObjects or {}
|
||||
|
||||
-- optionally get the data for tokens in play
|
||||
if includeDrawnTokens then
|
||||
for _, token in pairs(chaosBagApi.getTokensInPlay()) do
|
||||
if token ~= nil then table.insert(rawData, token.getData()) end
|
||||
if token ~= nil then
|
||||
table.insert(rawData, token.getData())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -335,8 +341,15 @@ function layout(_, _, isRightClick)
|
||||
end
|
||||
end
|
||||
|
||||
-- sort table by value (symbols last if same value)
|
||||
table.sort(data, tokenValueComparator)
|
||||
-- handling for near empty chaos bag
|
||||
if #data == 0 then
|
||||
-- small delay to limit update calls
|
||||
Wait.time(function() updating = false end, 0.1)
|
||||
return
|
||||
elseif #data > 1 then
|
||||
-- sort table by value (symbols last if same value)
|
||||
table.sort(data, tokenValueComparator)
|
||||
end
|
||||
|
||||
-- laying out the tokens
|
||||
local pos = self.getPosition() + Vector(3.55, -0.05, -3.95)
|
||||
@ -346,21 +359,21 @@ function layout(_, _, isRightClick)
|
||||
local rotation = self.getRotation()
|
||||
local currentValue = data[1].value
|
||||
local tokenCount = { row = 0, sum = 0, total = #data }
|
||||
local valueCount = 1
|
||||
local tokenName = false
|
||||
local rowCount = 1
|
||||
local tokenName
|
||||
|
||||
for i, item in ipairs(data) do
|
||||
for _, item in ipairs(data) do
|
||||
-- this is true for the first token in a new row
|
||||
if item.value ~= currentValue then
|
||||
if percentage then
|
||||
tokenCount.sum = tokenCount.sum + tokenCount.row
|
||||
createPercentageButton(tokenCount, valueCount, tokenName)
|
||||
createPercentageButton(tokenCount, rowCount, tokenName)
|
||||
end
|
||||
|
||||
location.x = location.x - 1.75
|
||||
location.z = pos.z
|
||||
currentValue = item.value
|
||||
valueCount = valueCount + 1
|
||||
rowCount = rowCount + 1
|
||||
tokenCount.row = 0
|
||||
end
|
||||
|
||||
@ -377,21 +390,17 @@ function layout(_, _, isRightClick)
|
||||
-- this is repeated to create the button for the last token
|
||||
if percentage then
|
||||
tokenCount.sum = tokenCount.sum + tokenCount.row
|
||||
createPercentageButton(tokenCount, valueCount, tokenName)
|
||||
createPercentageButton(tokenCount, rowCount, tokenName)
|
||||
end
|
||||
|
||||
-- introducing a small delay to limit update calls
|
||||
-- small delay to limit update calls
|
||||
Wait.time(function() updating = false end, 0.1)
|
||||
end
|
||||
|
||||
-- called from outside to set default values for tokens
|
||||
function onTokenDataChanged(parameters)
|
||||
local tokenData = parameters.tokenData or {}
|
||||
local currentScenario = parameters.currentScenario or ""
|
||||
local useFrontData = parameters.useFrontData
|
||||
|
||||
-- update token precedence
|
||||
for key, table in pairs(tokenData) do
|
||||
for key, table in pairs(parameters.tokenData or {}) do
|
||||
local modifier = table.modifier
|
||||
if modifier == -999 then modifier = 0 end
|
||||
tokenPrecedence[key][1] = modifier
|
||||
|
@ -135,11 +135,17 @@ function discardObject(playerColor, hoveredObject)
|
||||
return
|
||||
end
|
||||
|
||||
-- warning for locations since these are usually not meant to be discarded
|
||||
if hoveredObject.hasTag("Location") then
|
||||
broadcastToAll("Watch out: A location was discarded.", "Yellow")
|
||||
-- These should probably not be discarded normally. Ask player for confirmation.
|
||||
if (hoveredObject.type == "Deck") or hoveredObject.hasTag("Location") then
|
||||
local suspect = (hoveredObject.type == "Deck") and "Deck" or "Location"
|
||||
Player[playerColor].showConfirmDialog("Discard " .. suspect .. "?", function () performDiscard(playerColor, hoveredObject) end)
|
||||
return
|
||||
end
|
||||
|
||||
performDiscard(playerColor, hoveredObject)
|
||||
end
|
||||
|
||||
function performDiscard(playerColor, hoveredObject)
|
||||
-- initialize list of objects to discard
|
||||
local discardTheseObjects = { hoveredObject }
|
||||
|
||||
@ -168,7 +174,7 @@ function discardTopDeck(playerColor, hoveredObject)
|
||||
else
|
||||
takenCard = hoveredObject
|
||||
end
|
||||
Wait.frames(function() discardObject(playerColor, takenCard) end, 1)
|
||||
Wait.frames(function() performDiscard(playerColor, takenCard) end, 1)
|
||||
end
|
||||
|
||||
-- helper function to get the player to trigger the discard function for
|
||||
|
@ -222,6 +222,11 @@ function onObjectNumberTyped(hoveredObject, playerColor, number)
|
||||
end
|
||||
end
|
||||
|
||||
-- TTS event, used to redraw the playmat slot symbols after a small delay to account for the custom font loading
|
||||
function onPlayerConnect()
|
||||
Wait.time(function() playmatApi.redrawSlotSymbols("All") end, 0.2)
|
||||
end
|
||||
|
||||
---------------------------------------------------------
|
||||
-- chaos token drawing
|
||||
---------------------------------------------------------
|
||||
|
@ -121,7 +121,14 @@ end
|
||||
---@param cardData table TTS object data for the card
|
||||
function addCardToIndex(cardData)
|
||||
-- using the more efficient 'json.parse()' to speed this process up
|
||||
local cardMetadata = json.parse(cardData.GMNotes)
|
||||
local status, cardMetadata = pcall(function() json.parse(cardData.GMNotes) end)
|
||||
|
||||
-- if an error happens, fallback to the regular parser
|
||||
if status ~= true then
|
||||
cardMetadata = JSON.decode(cardData.GMNotes)
|
||||
end
|
||||
|
||||
-- if metadata was not valid JSON or empty, don't add the card
|
||||
if not cardMetadata then return end
|
||||
|
||||
-- use the ZoopGuid as fallback if no id present
|
||||
|
@ -72,8 +72,8 @@ local slotNameToChar = {
|
||||
["Tarot"] = "A"
|
||||
}
|
||||
|
||||
-- slot symbol for the respective slot (from top left to bottom right)
|
||||
local slotData = {}
|
||||
-- slot symbol for the respective slot (from top left to bottom right) - intentionally global!
|
||||
slotData = {}
|
||||
local defaultSlotData = {
|
||||
-- 1st row
|
||||
"any", "any", "any", "Tarot", "Hand (left)", "Hand (right)", "Ally",
|
||||
|
@ -55,6 +55,25 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
-- gets the slot data for the playmat
|
||||
---@param matColor string Color of the playmat - White, Orange, Green or Red (does not support "All")
|
||||
PlaymatApi.getSlotData = function(matColor)
|
||||
for _, mat in pairs(getMatForColor(matColor)) do
|
||||
return mat.getTable("slotData")
|
||||
end
|
||||
end
|
||||
|
||||
-- sets the slot data for the playmat
|
||||
---@param matColor string Color of the playmat - White, Orange, Green or Red (does not support "All")
|
||||
---@param newSlotData table New slot data for the playmat
|
||||
PlaymatApi.loadSlotData = function(matColor, newSlotData)
|
||||
for _, mat in pairs(getMatForColor(matColor)) do
|
||||
mat.setTable("slotData", newSlotData)
|
||||
mat.call("redrawSlotSymbols")
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- Performs a search of the deck area of the requested playmat and returns the result as table
|
||||
---@param matColor string Color of the playmat - White, Orange, Green or Red (does not support "All")
|
||||
PlaymatApi.getDeckAreaObjects = function(matColor)
|
||||
@ -258,6 +277,14 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
-- Redraws the XML for the slot symbols based on the slotData table
|
||||
---@param matColor string Color of the playmat - White, Orange, Green, Red or All
|
||||
PlaymatApi.redrawSlotSymbols = function(matColor)
|
||||
for _, mat in pairs(getMatForColor(matColor)) do
|
||||
mat.call("redrawSlotSymbols")
|
||||
end
|
||||
end
|
||||
|
||||
-- Finds all objects on the playmat and associated set aside zone and returns a table
|
||||
---@param matColor string Color of the playmat - White, Orange, Green, Red or All
|
||||
---@param filter string Name of the filte function (see util/SearchLib)
|
||||
|
Loading…
Reference in New Issue
Block a user