added playermat slot symbol saving to campaign exporter

This commit is contained in:
Chr1Z93 2024-05-21 13:26:01 +02:00
parent dedd50aedd
commit 8d8662209b
3 changed files with 38 additions and 5 deletions

View File

@ -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"

View File

@ -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",

View File

@ -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)