Fixed Latency Issues

Resolved issues around latency concerning the Additional PLayer Cards bag, and converted the save tokens to be a bag now.
This commit is contained in:
Entrox-Licher 2024-01-10 20:54:17 -05:00
parent 9a4cd9ec1c
commit eafb62ba30
2 changed files with 89 additions and 21 deletions

View File

@ -6,8 +6,12 @@ local optionPanelApi = require("core/OptionPanelApi")
local playAreaApi = require("core/PlayAreaApi") local playAreaApi = require("core/PlayAreaApi")
local playmatApi = require("playermat/PlaymatApi") local playmatApi = require("playermat/PlaymatApi")
local additionalIndex
local campaignLog
local checkWarning = true
local campaignTokenData = { local campaignTokenData = {
Name = "Custom_Model", Name = "Custom_Model_Bag",
Transform = { Transform = {
posX = -21.25, posX = -21.25,
posY = 1.68, posY = 1.68,
@ -30,7 +34,7 @@ local campaignTokenData = {
ColliderURL = "http://cloud-3.steamusercontent.com/ugc/943949966265929204/A38BB5D72419E6298385556D931877C0A1A55C17/", ColliderURL = "http://cloud-3.steamusercontent.com/ugc/943949966265929204/A38BB5D72419E6298385556D931877C0A1A55C17/",
Convex = true, Convex = true,
MaterialIndex = 2, MaterialIndex = 2,
TypeIndex = 0, TypeIndex = 6,
CustomShader = { CustomShader = {
SpecularColor = { SpecularColor = {
r = 0.7222887, r = 0.7222887,
@ -47,6 +51,7 @@ local campaignTokenData = {
local COLORS = { "White", "Orange", "Green", "Red" } local COLORS = { "White", "Orange", "Green", "Red" }
function onLoad() function onLoad()
log(getObjectFromGUID("1f5a0a").getData())
self.createButton({ self.createButton({
click_function = "createCampaignToken", click_function = "createCampaignToken",
function_owner = self, function_owner = self,
@ -60,6 +65,24 @@ function onLoad()
}) })
end end
function onObjectLeaveContainer(container, object)
if container.hasTag("ImporterToken") and checkWarning then
broadcastToAll(
"Removing objects from the Save Coin bag will break functionality. Please replace the objects in the same order they were removed.",
Color.Yellow
)
end
end
function onObjectEnterContainer(container, object)
if container.hasTag("ImporterToken") and checkWarning then
broadcastToAll(
"Adding objects to the Save Coin bag will break functionality. Please remove the objects.",
Color.Yellow
)
end
end
--------------------------------------------------------- ---------------------------------------------------------
-- main import functions (split up to allow for Wait conditions) -- main import functions (split up to allow for Wait conditions)
--------------------------------------------------------- ---------------------------------------------------------
@ -75,19 +98,22 @@ end
function importFromToken(coin) function importFromToken(coin)
broadcastToAll("Campaign Import Initiated") broadcastToAll("Campaign Import Initiated")
local importData = JSON.decode(coin.getGMNotes()) local importData = JSON.decode(coin.getGMNotes())
coin.destruct()
local campaignBoxGUID = importData["box"] local campaignBoxGUID = importData["box"]
local campaignBox = getObjectFromGUID(campaignBoxGUID) local campaignBox = getObjectFromGUID(campaignBoxGUID)
if not campaignBox then
broadcastToAll("Campaign Box not present on table!", Color.Red)
return
end
if campaignBox.type == "Generic" then if campaignBox.type == "Generic" then
campaignBox.call("buttonClick_download") campaignBox.call("buttonClick_download")
end end
Wait.condition( Wait.condition(
function() function()
if #campaignBox.getObjects() > 0 then if #campaignBox.getObjects() > 0 then
placeCampaignFromToken(importData) placeCampaignFromToken(importData, coin)
else else
createCampaignFromToken(importData) createCampaignFromToken(importData, coin)
end end
end, end,
function() function()
@ -104,10 +130,10 @@ function importFromToken(coin)
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, coin)
getObjectFromGUID(importData["box"]).call("buttonClick_place") getObjectFromGUID(importData["box"]).call("buttonClick_place")
Wait.condition( Wait.condition(
function() createCampaignFromToken(importData) end, function() createCampaignFromToken(importData, coin) end,
function() return findUniqueObjectWithTag("CampaignLog") ~= nil end, function() return findUniqueObjectWithTag("CampaignLog") ~= nil end,
2, 2,
function() broadcastToAll("Error placing campaign box") end function() broadcastToAll("Error placing campaign box") end
@ -115,16 +141,30 @@ function placeCampaignFromToken(importData)
end 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, coin)
-- destroy existing campaign log and load saved campaign log
findUniqueObjectWithTag("CampaignLog").destruct()
spawnObjectData({ data = importData["log"] })
checkWarning = false
if importData["additionalIndex"] then if importData["additionalIndex"] then
findUniqueObjectWithTag("AllCardsHotfix").destruct() findUniqueObjectWithTag("AllCardsHotfix").destruct()
spawnObjectJSON({json = importData["additionalIndex"]}) if coin.getObjects() then
local newBag = coin.takeObject({index = 0, position = importData["additionalIndex"]})
Wait.time(function() newBag.setLock(true) end, 1)
else
spawnObjectJSON({json = importData["additionalIndex"]})
end
end end
-- destroy existing campaign log and load saved campaign log
findUniqueObjectWithTag("CampaignLog").destruct()
if coin.getObjects() then
coin.takeObject({index = 0, position = importData["log"]})
else
spawnObjectData({ data = importData["log"] })
end
coin.destruct()
checkWarning = true
chaosBagApi.setChaosBagState(importData["bag"]) chaosBagApi.setChaosBagState(importData["bag"])
-- populate trauma values -- populate trauma values
@ -188,13 +228,13 @@ function createCampaignToken(_, playerColor, _)
return return
end end
local campaignLog = findUniqueObjectWithTag("CampaignLog") 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 additionalIndex = findUniqueObjectWithTag("AllCardsHotfix") additionalIndex = findUniqueObjectWithTag("AllCardsHotfix")
local traumaValues = { } local traumaValues = { }
local trauma = campaignLog.getVar("returnTrauma") local trauma = campaignLog.getVar("returnTrauma")
@ -221,7 +261,7 @@ function createCampaignToken(_, playerColor, _)
local campaignData = { local campaignData = {
box = campaignBox.getGUID(), box = campaignBox.getGUID(),
log = campaignLog.getData(), log = campaignLog.getPosition(),
bag = chaosBagApi.getChaosBagState(), bag = chaosBagApi.getChaosBagState(),
trauma = traumaValues, trauma = traumaValues,
decks = deckImporterApi.getUiState(), decks = deckImporterApi.getUiState(),
@ -229,11 +269,23 @@ function createCampaignToken(_, playerColor, _)
playarea = playAreaApi.getSurface(), playarea = playAreaApi.getSurface(),
options = optionPanelApi.getOptions(), options = optionPanelApi.getOptions(),
guide = campaignGuide.Book.getPage(), guide = campaignGuide.Book.getPage(),
additionalIndex = additionalIndex.getJSON() additionalIndex = additionalIndex.getPosition()
} }
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"
spawnObjectData({ data = campaignTokenData }) spawnObjectData({ data = campaignTokenData, callback_function = finishTokenSpawning })
end
function finishTokenSpawning(obj)
local logData = campaignLog.getData()
local indexData = additionalIndex.getData()
additionalIndex.setLock(false)
checkWarning = false
obj.putObject(additionalIndex)
obj.putObject(campaignLog)
checkWarning = true
spawnObjectData({data = indexData})
spawnObjectData({data = logData})
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
@ -261,12 +313,12 @@ function setTrauma(trauma)
end end
-- gets data from campaign log if possible -- gets data from campaign log if possible
function loadTrauma(campaignLog) function loadTrauma(log)
local trauma = campaignLog.getVar("returnTrauma") local trauma = log.getVar("returnTrauma")
if trauma ~= nil then if trauma ~= nil then
printToAll("Trauma values found in campaign log!", "Green") printToAll("Trauma values found in campaign log!", "Green")
trauma = campaignLog.call("returnTrauma") trauma = log.call("returnTrauma")
return trauma return trauma
else else
return nil return nil

View File

@ -72,6 +72,7 @@ end
-- yielding. Based on the current count of cards this will require -- yielding. Based on the current count of cards this will require
-- approximately 60 frames to complete. -- approximately 60 frames to complete.
function buildIndex() function buildIndex()
local cardCount = 0
indexingDone = false indexingDone = false
if (self.getData().ContainedObjects == nil) then if (self.getData().ContainedObjects == nil) then
return 1 return 1
@ -80,6 +81,11 @@ function buildIndex()
local cardMetadata = JSON.decode(cardData.GMNotes) local cardMetadata = JSON.decode(cardData.GMNotes)
if (cardMetadata ~= nil) then if (cardMetadata ~= nil) then
addCardToIndex(cardData, cardMetadata) addCardToIndex(cardData, cardMetadata)
cardCount = cardCount + 1
if cardCount > 9 then
cardCount = 0
coroutine.yield(0)
end
end end
end end
local hotfixBags = getObjectsWithTag("AllCardsHotfix") local hotfixBags = getObjectsWithTag("AllCardsHotfix")
@ -91,12 +97,22 @@ function buildIndex()
local deepCardMetadata = JSON.decode(deepCardData.GMNotes) local deepCardMetadata = JSON.decode(deepCardData.GMNotes)
if deepCardMetadata ~= nil then if deepCardMetadata ~= nil then
addCardToIndex(deepCardData, deepCardMetadata) addCardToIndex(deepCardData, deepCardMetadata)
cardCount = cardCount + 1
if cardCount > 9 then
cardCount = 0
coroutine.yield(0)
end
end end
end end
else else
local cardMetadata = JSON.decode(cardData.GMNotes) local cardMetadata = JSON.decode(cardData.GMNotes)
if cardMetadata ~= nil then if cardMetadata ~= nil then
addCardToIndex(cardData, cardMetadata) addCardToIndex(cardData, cardMetadata)
cardCount = cardCount + 1
if cardCount > 9 then
cardCount = 0
coroutine.yield(0)
end
end end
end end
end end