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 playmatApi = require("playermat/PlaymatApi")
local additionalIndex
local campaignLog
local checkWarning = true
local campaignTokenData = {
Name = "Custom_Model",
Name = "Custom_Model_Bag",
Transform = {
posX = -21.25,
posY = 1.68,
@ -30,7 +34,7 @@ local campaignTokenData = {
ColliderURL = "http://cloud-3.steamusercontent.com/ugc/943949966265929204/A38BB5D72419E6298385556D931877C0A1A55C17/",
Convex = true,
MaterialIndex = 2,
TypeIndex = 0,
TypeIndex = 6,
CustomShader = {
SpecularColor = {
r = 0.7222887,
@ -47,6 +51,7 @@ local campaignTokenData = {
local COLORS = { "White", "Orange", "Green", "Red" }
function onLoad()
log(getObjectFromGUID("1f5a0a").getData())
self.createButton({
click_function = "createCampaignToken",
function_owner = self,
@ -60,6 +65,24 @@ function onLoad()
})
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)
---------------------------------------------------------
@ -75,19 +98,22 @@ end
function importFromToken(coin)
broadcastToAll("Campaign Import Initiated")
local importData = JSON.decode(coin.getGMNotes())
coin.destruct()
local campaignBoxGUID = importData["box"]
local campaignBox = getObjectFromGUID(campaignBoxGUID)
if not campaignBox then
broadcastToAll("Campaign Box not present on table!", Color.Red)
return
end
if campaignBox.type == "Generic" then
campaignBox.call("buttonClick_download")
end
Wait.condition(
function()
if #campaignBox.getObjects() > 0 then
placeCampaignFromToken(importData)
placeCampaignFromToken(importData, coin)
else
createCampaignFromToken(importData)
createCampaignFromToken(importData, coin)
end
end,
function()
@ -104,10 +130,10 @@ function importFromToken(coin)
end
-- After box has been downloaded, places content on table
function placeCampaignFromToken(importData)
function placeCampaignFromToken(importData, coin)
getObjectFromGUID(importData["box"]).call("buttonClick_place")
Wait.condition(
function() createCampaignFromToken(importData) end,
function() createCampaignFromToken(importData, coin) end,
function() return findUniqueObjectWithTag("CampaignLog") ~= nil end,
2,
function() broadcastToAll("Error placing campaign box") end
@ -115,15 +141,29 @@ function placeCampaignFromToken(importData)
end
-- After content is placed on table, conducts all the other import operations
function createCampaignFromToken(importData)
-- destroy existing campaign log and load saved campaign log
findUniqueObjectWithTag("CampaignLog").destruct()
spawnObjectData({ data = importData["log"] })
function createCampaignFromToken(importData, coin)
checkWarning = false
if importData["additionalIndex"] then
findUniqueObjectWithTag("AllCardsHotfix").destruct()
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
-- 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"])
@ -188,13 +228,13 @@ function createCampaignToken(_, playerColor, _)
return
end
local campaignLog = findUniqueObjectWithTag("CampaignLog")
campaignLog = findUniqueObjectWithTag("CampaignLog")
if campaignLog == nil then
broadcastToAll("Campaign log not found!", Color.Red)
return
end
local additionalIndex = findUniqueObjectWithTag("AllCardsHotfix")
additionalIndex = findUniqueObjectWithTag("AllCardsHotfix")
local traumaValues = { }
local trauma = campaignLog.getVar("returnTrauma")
@ -221,7 +261,7 @@ function createCampaignToken(_, playerColor, _)
local campaignData = {
box = campaignBox.getGUID(),
log = campaignLog.getData(),
log = campaignLog.getPosition(),
bag = chaosBagApi.getChaosBagState(),
trauma = traumaValues,
decks = deckImporterApi.getUiState(),
@ -229,11 +269,23 @@ function createCampaignToken(_, playerColor, _)
playarea = playAreaApi.getSurface(),
options = optionPanelApi.getOptions(),
guide = campaignGuide.Book.getPage(),
additionalIndex = additionalIndex.getJSON()
additionalIndex = additionalIndex.getPosition()
}
campaignTokenData.GMNotes = JSON.encode(campaignData)
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)
end
@ -261,12 +313,12 @@ function setTrauma(trauma)
end
-- gets data from campaign log if possible
function loadTrauma(campaignLog)
local trauma = campaignLog.getVar("returnTrauma")
function loadTrauma(log)
local trauma = log.getVar("returnTrauma")
if trauma ~= nil then
printToAll("Trauma values found in campaign log!", "Green")
trauma = campaignLog.call("returnTrauma")
trauma = log.call("returnTrauma")
return trauma
else
return nil

View File

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