Bug Fixes & Improvements

Added support for Additional Player Cards bag (still needs latency improvements), custom trauma getting, importing on collision, and fixed the tour bug
This commit is contained in:
Entrox-Licher 2024-01-08 17:29:24 -05:00
parent 8dcbce1542
commit f53f7fdba0
2 changed files with 87 additions and 68 deletions

View File

@ -53,5 +53,14 @@
"scaleZ": 3.38 "scaleZ": 3.38
}, },
"Value": 0, "Value": 0,
"XmlUI": "" "XmlUI": "",
"AttachedSnapPoints": [
{
"Position": {
"x": -0.95,
"y": 0.2,
"z": 0.01
}
}
]
} }

View File

@ -47,23 +47,12 @@ local campaignTokenData = {
local COLORS = { "White", "Orange", "Green", "Red" } local COLORS = { "White", "Orange", "Green", "Red" }
function onLoad() function onLoad()
self.createButton({
click_function = "findCampaignFromToken",
function_owner = self,
label = "Import",
tooltip = "Load in a campaign save from a token!\n\n(Token can be anywhere on the table, but ensure there is only 1!)",
position = { x = -1, y = 0.2, z = 0 },
font_size = 400,
width = 1400,
height = 600,
scale = { 0.5, 1, 0.5 },
})
self.createButton({ self.createButton({
click_function = "createCampaignToken", click_function = "createCampaignToken",
function_owner = self, function_owner = self,
label = "Export", label = "Export",
tooltip = "Create a campaign save token!\n\n(Ensure all chaos tokens have been unsealed!)", tooltip = "Create a campaign save token!",
position = { x = 1, y = 0.2, z = 0 }, position = { x = -1, y = 0.2, z = 0 },
font_size = 400, font_size = 400,
width = 1400, width = 1400,
height = 600, height = 600,
@ -75,46 +64,45 @@ end
-- main import functions (split up to allow for Wait conditions) -- main import functions (split up to allow for Wait conditions)
--------------------------------------------------------- ---------------------------------------------------------
-- Identifies import token, determines campaign box and downloads it (if needed) function onCollisionEnter(info)
function findCampaignFromToken(_, _, _) local objectData = info.collision_object.getData()
local coin = nil if info.collision_object.hasTag("ImporterToken") then
local coinObjects = getObjectsWithTag("ImporterToken") findCampaignFromToken(info.collision_object)
if #coinObjects == 0 then
broadcastToAll("Could not find importer token", Color.Red)
elseif #coinObjects > 1 then
broadcastToAll("More than 1 importer token found. Please delete all but 1 importer token", Color.Yellow)
else
coin = coinObjects[1]
local importData = JSON.decode(coin.getGMNotes())
campaignBoxGUID = importData["box"]
local campaignBox = getObjectFromGUID(campaignBoxGUID)
if campaignBox.type == "Generic" then
campaignBox.call("buttonClick_download")
end
Wait.condition(
function()
if #campaignBox.getObjects() > 0 then
placeCampaignFromToken(importData)
else
createCampaignFromToken(importData)
end
end,
function()
local obj = getObjectFromGUID(campaignBoxGUID)
if obj == nil then
return false
else
return obj.type == "Bag" and obj.getLuaScript() ~= ""
end
end,
2,
function() broadcastToAll("Error loading campaign box") end
)
end end
end end
-- Identifies import token, determines campaign box and downloads it (if needed)
function findCampaignFromToken(coin)
broadcastToAll("Campaign Import Initiated")
local importData = JSON.decode(coin.getGMNotes())
coin.destruct()
campaignBoxGUID = importData["box"]
local campaignBox = getObjectFromGUID(campaignBoxGUID)
if campaignBox.type == "Generic" then
campaignBox.call("buttonClick_download")
end
Wait.condition(
function()
if #campaignBox.getObjects() > 0 then
placeCampaignFromToken(importData)
else
createCampaignFromToken(importData)
end
end,
function()
local obj = getObjectFromGUID(campaignBoxGUID)
if obj == nil then
return false
else
return obj.type == "Bag" and obj.getLuaScript() ~= ""
end
end,
2,
function() broadcastToAll("Error loading campaign box") end
)
end
-- After box has been downloaded, places content on table -- After box has been downloaded, places content on table
function placeCampaignFromToken(importData) function placeCampaignFromToken(importData)
getObjectFromGUID(importData["box"]).call("buttonClick_place") getObjectFromGUID(importData["box"]).call("buttonClick_place")
@ -131,6 +119,11 @@ function createCampaignFromToken(importData)
-- destroy existing campaign log and load saved campaign log -- destroy existing campaign log and load saved campaign log
findUniqueObjectWithTag("CampaignLog").destruct() findUniqueObjectWithTag("CampaignLog").destruct()
spawnObjectData({ data = importData["log"] }) spawnObjectData({ data = importData["log"] })
if importData["additionalIndex"] then
findUniqueObjectWithTag("AllCardsHotfix").destruct()
spawnObjectData({data = importData["additionalIndex"]})
end
chaosBagApi.setChaosBagState(importData["bag"]) chaosBagApi.setChaosBagState(importData["bag"])
@ -155,7 +148,7 @@ function createCampaignFromToken(importData)
-- 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() return guide.Book.setPage(importData["guide"]) end, function() return guide.Book.setPage(importData["guide"]) end,
-- Amount of time in seconds until the Wait times out -- Amount of time in seconds until the Wait times out
1, 2,
-- Called if the Wait times out -- Called if the Wait times out
function() log("Campaign Guide import failed!") end function() log("Campaign Guide import failed!") end
) )
@ -165,7 +158,9 @@ function createCampaignFromToken(importData)
-- destroy Tour Starter token -- destroy Tour Starter token
local tourStarter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "TourStarter") local tourStarter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "TourStarter")
tourStarter.destruct() if tourStarter then
tourStarter.destruct()
end
-- restore PlayArea image -- restore PlayArea image
playAreaApi.updateSurface(importData["playmat"]) playAreaApi.updateSurface(importData["playmat"])
@ -175,9 +170,6 @@ end
-- Creates a campaign token with save data encoded into GM Notes based on the current state of the table -- Creates a campaign token with save data encoded into GM Notes based on the current state of the table
function createCampaignToken(_, playerColor, _) function createCampaignToken(_, playerColor, _)
-- clean up chaos tokens
blessCurseApi.removeAll(playerColor)
chaosBagApi.releaseAllSealedTokens(playerColor)
-- find active campaign -- find active campaign
local campaignBox local campaignBox
@ -202,20 +194,20 @@ function createCampaignToken(_, playerColor, _)
return return
end end
local traumaValues = { local additionalIndex = findUniqueObjectWithTag("AllCardsHotfix")
0, 0, 0, 0,
0, 0, 0, 0 local traumaValues = { }
} local trauma = campaignLog.getVar("returnTrauma")
local counterData = campaignLog.getVar("ref_buttonData")
if counterData ~= nil then if trauma ~= nil then
printToAll("Trauma values found in campaign log!", "Green") printToAll("Trauma values found in campaign log!", "Green")
for i = 1, 10, 3 do trauma = campaignLog.call("returnTrauma")
traumaValues[1 + (i - 1) / 3] = counterData.counter[i].value for _, val in ipairs(trauma) do
traumaValues[5 + (i - 1) / 3] = counterData.counter[i + 1].value table.insert(traumaValues, val)
end end
else else
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") return
end end
local campaignGuide = findUniqueObjectWithTag("CampaignGuide") local campaignGuide = findUniqueObjectWithTag("CampaignGuide")
@ -224,6 +216,10 @@ function createCampaignToken(_, playerColor, _)
return return
end end
-- clean up chaos tokens
blessCurseApi.removeAll(playerColor)
chaosBagApi.releaseAllSealedTokens(playerColor)
local campaignData = { local campaignData = {
box = campaignBox.getGUID(), box = campaignBox.getGUID(),
log = campaignLog.getData(), log = campaignLog.getData(),
@ -231,9 +227,10 @@ function createCampaignToken(_, playerColor, _)
trauma = traumaValues, trauma = traumaValues,
decks = deckImporterApi.getUiState(), decks = deckImporterApi.getUiState(),
clueCount = playAreaApi.getInvestigatorCount(), clueCount = playAreaApi.getInvestigatorCount(),
guide = campaignGuide.Book.getPage(), playmat = playAreaApi.getSurface(),
options = optionPanelApi.getOptions(), options = optionPanelApi.getOptions(),
playmat = playAreaApi.getSurface() guide = campaignGuide.Book.getPage(),
additionalIndex = additionalIndex.getData()
} }
campaignTokenData.GMNotes = JSON.encode(campaignData) campaignTokenData.GMNotes = JSON.encode(campaignData)
campaignTokenData.Nickname = os.date("%b %d ") .. campaignBox.getName() .. " Save" campaignTokenData.Nickname = os.date("%b %d ") .. campaignBox.getName() .. " Save"
@ -263,3 +260,16 @@ function setTrauma(trauma)
playmatApi.updateCounter(COLORS[i], "HorrorCounter", trauma[i + 4]) playmatApi.updateCounter(COLORS[i], "HorrorCounter", trauma[i + 4])
end end
end end
-- gets data from campaign log if possible
function loadTrauma(campaignLog)
local trauma = campaignLog.getVar("returnTrauma")
if trauma ~= nil then
printToAll("Trauma values found in campaign log!", "Green")
trauma = campaignLog.call("returnTrauma")
return trauma
else
return nil
end
end