campaign exporter update

This commit is contained in:
Chr1Z93 2023-09-30 20:09:00 +02:00
parent 93bf6a8b61
commit 282a411ec2
2 changed files with 30 additions and 74 deletions

View File

@ -43,6 +43,7 @@ local campaignTokenData = {
CastShadows = true CastShadows = true
} }
} }
local COLORS = { "White", "Orange", "Green", "Red" }
function onLoad() function onLoad()
self.createButton({ self.createButton({
@ -118,7 +119,7 @@ function placeCampaignFromToken(importData)
getObjectFromGUID(importData["box"]).call("buttonClick_place") getObjectFromGUID(importData["box"]).call("buttonClick_place")
Wait.condition( Wait.condition(
function() createCampaignFromToken(importData) end, function() createCampaignFromToken(importData) end,
function() return findCampaignLog() ~= nil end, function() return findUniqueObjectWithTag("CampaignLog") ~= nil end,
2, 2,
function() broadcastToAll("Error placing campaign box") end function() broadcastToAll("Error placing campaign box") end
) )
@ -127,7 +128,7 @@ end
-- After content is placed on table, conducts all the other import operations -- After content is placed on table, conducts all the other import operations
function createCampaignFromToken(importData) function createCampaignFromToken(importData)
-- destroy existing campaign log and load saved campaign log -- destroy existing campaign log and load saved campaign log
findCampaignLog().destruct() findUniqueObjectWithTag("CampaignLog").destruct()
spawnObjectData({ data = importData["log"] }) spawnObjectData({ data = importData["log"] })
chaosBagApi.setChaosBagState(importData["bag"]) chaosBagApi.setChaosBagState(importData["bag"])
@ -145,24 +146,17 @@ function createCampaignFromToken(importData)
playAreaApi.setInvestigatorCount(importData["clueCount"]) playAreaApi.setInvestigatorCount(importData["clueCount"])
-- set campaign guide page -- set campaign guide page
local guide = findCampaignGuide() local guide = findUniqueObjectWithTag("CampaignGuide")
if guide then if guide then
Wait.condition( Wait.condition(
-- Called after the condition function returns true -- Called after the condition function returns true
function() function() log("Campaign Guide import successful!") end,
log("Campaign Guide import successful!")
end,
-- Condition function that is called continiously until returs true or timeout is reached -- Condition function that is called continiously until returs true or timeout is reached
function() function() return guide.Book.setPage(importData["guide"]) end,
guide.Book.setPage(importData["guide"])
return guide.Book.getPage() == importData["guide"]
end,
-- Amount of time in seconds until the Wait times out -- Amount of time in seconds until the Wait times out
1, 1,
-- Called if the Wait times out -- Called if the Wait times out
function() function() log("Campaign Guide import failed!") end
log("Campaign Guide import failed!")
end
) )
end end
@ -183,26 +177,29 @@ function createCampaignToken(_, playerColor, _)
blessCurseApi.removeAll(playerColor) blessCurseApi.removeAll(playerColor)
chaosBagApi.releaseAllSealedTokens(playerColor) chaosBagApi.releaseAllSealedTokens(playerColor)
local campaignBoxGUID = ""
-- find active campaign -- find active campaign
local campaignBox
for _, obj in ipairs(getObjectsWithTag("CampaignBox")) do for _, obj in ipairs(getObjectsWithTag("CampaignBox")) do
if obj.type == "Bag" and #obj.getObjects() == 0 then if obj.type == "Bag" and #obj.getObjects() == 0 then
if campaignBoxGUID ~= "" then if not campaignBox then
campaignBox = obj
else
broadcastToAll("Multiple empty campaign box detected; delete all but one.", Color.Red) broadcastToAll("Multiple empty campaign box detected; delete all but one.", Color.Red)
return return
end end
campaignBoxGUID = obj.getGUID()
end end
end end
if campaignBoxGUID == "" then if not campaignBox then
broadcastToAll("Campaign box with all placed objects not found!", Color.Red) broadcastToAll("Campaign box with all placed objects not found!", Color.Red)
return return
end end
local campaignLog = findCampaignLog()
local campaignLog = findUniqueObjectWithTag("CampaignLog")
if campaignLog == nil then if campaignLog == nil then
broadcastToAll("Campaign log not found!", Color.Red) broadcastToAll("Campaign log not found!", Color.Red)
return return
end end
local traumaValues = { local traumaValues = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0 0, 0, 0, 0
@ -218,13 +215,15 @@ function createCampaignToken(_, playerColor, _)
printToAll("Trauma values could not be found in campaign log!", "Yellow") printToAll("Trauma values could not be found in campaign log!", "Yellow")
printToAll("Default values for health and sanity loaded.", "Yellow") printToAll("Default values for health and sanity loaded.", "Yellow")
end end
local campaignGuide = findCampaignGuide()
local campaignGuide = findUniqueObjectWithTag("CampaignGuide")
if campaignGuide == nil then if campaignGuide == nil then
broadcastToAll("Campaign guide not found!", Color.Red) broadcastToAll("Campaign guide not found!", Color.Red)
return return
end end
local campaignData = { local campaignData = {
box = campaignBoxGUID, box = campaignBox.getGUID(),
log = campaignLog.getData(), log = campaignLog.getData(),
bag = chaosBagApi.getChaosBagState(), bag = chaosBagApi.getChaosBagState(),
trauma = traumaValues, trauma = traumaValues,
@ -235,7 +234,7 @@ function createCampaignToken(_, playerColor, _)
playmat = playAreaApi.getSurface() playmat = playAreaApi.getSurface()
} }
campaignTokenData.GMNotes = JSON.encode(campaignData) campaignTokenData.GMNotes = JSON.encode(campaignData)
campaignTokenData.Nickname = os.date("%b %d ") .. getObjectFromGUID(campaignBoxGUID).getName() .. " Save" campaignTokenData.Nickname = os.date("%b %d ") .. campaignBox.getName() .. " Save"
spawnObjectData({ data = campaignTokenData }) spawnObjectData({ data = campaignTokenData })
broadcastToAll("Campaign successfully exported! Save coin object to import on a fresh save", Color.Green) broadcastToAll("Campaign successfully exported! Save coin object to import on a fresh save", Color.Green)
end end
@ -244,30 +243,14 @@ end
-- helper functions -- helper functions
--------------------------------------------------------- ---------------------------------------------------------
function findCampaignLog() function findUniqueObjectWithTag(tag)
local campaignLog = getObjectsWithTag("CampaignLog") local objects = getObjectsWithTag(tag)
if campaignLog then if not objects then return end
if #campaignLog == 1 then
return campaignLog[1]
else
broadcastToAll("More than 1 campaign log detected; delete all but one.", Color.Red)
return nil
end
else
return nil
end
end
function findCampaignGuide() if #objects == 1 then
local campaignGuide = getObjectsWithTag("CampaignGuide") return objects[1]
if campaignGuide then
if #campaignGuide == 1 then
return campaignGuide[1]
else
broadcastToAll("More than 1 campaign guide detected; delete all but one.", Color.Red)
return nil
end
else else
broadcastToAll("More than 1 " .. tag .. " detected; delete all but one.", Color.Red)
return nil return nil
end end
end end

View File

@ -58,36 +58,9 @@ end
-- loadNewest: True if the most upgraded version of the deck should be loaded -- loadNewest: True if the most upgraded version of the deck should be loaded
-- investigators: True if investigator cards should be spawned -- investigators: True if investigator cards should be spawned
function setUiState(uiStateTable) function setUiState(uiStateTable)
-- Callback functions aren't triggered when editing buttons/inputs so values must be set manually self.clearButtons()
self.clearInputs()
if uiStateTable["greenDeck"] then initializeUi(uiStateTable)
greenDeckId = uiStateTable["greenDeck"]
self.editInput({index=0, value=greenDeckId})
end
if uiStateTable["redDeck"] then
redDeckId = uiStateTable["redDeck"]
self.editInput({index=1, value=redDeckId})
end
if uiStateTable["whiteDeck"] then
whiteDeckId = uiStateTable["whiteDeck"]
self.editInput({index=2, value=whiteDeckId})
end
if uiStateTable["orangeDeck"]then
orangeDeckId = uiStateTable["orangeDeck"]
self.editInput({index=3, value=orangeDeckId})
end
if uiStateTable["private"] then
privateDeck = uiStateTable["private"]
self.editButton { index = 0, label = PRIVATE_TOGGLE_LABELS[privateDeck] }
end
if uiStateTable["loadNewest"] then
loadNewestDeck = uiStateTable["loadNewest"]
self.editButton { index = 1, label = UPGRADED_TOGGLE_LABELS[loadNewestDeck] }
end
if uiStateTable["investigators"] then
loadInvestigators = uiStateTable["investigators"]
self.editButton { index = 2, label = LOAD_INVESTIGATOR_TOGGLE_LABELS[loadInvestigators] }
end
end end
-- Sets up the UI for the deck loader, populating fields from the given save state table decoded from onLoad() -- Sets up the UI for the deck loader, populating fields from the given save state table decoded from onLoad()