From f53f7fdba0b9be1b8e9c3e8f50e556fed7edfcd9 Mon Sep 17 00:00:00 2001 From: Entrox-Licher Date: Mon, 8 Jan 2024 17:29:24 -0500 Subject: [PATCH 01/11] 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 --- objects/CampaignImporterExporter.334ee3.json | 11 +- .../CampaignImporterExporter.ttslua | 144 ++++++++++-------- 2 files changed, 87 insertions(+), 68 deletions(-) diff --git a/objects/CampaignImporterExporter.334ee3.json b/objects/CampaignImporterExporter.334ee3.json index 094530cc..4bfc53e9 100644 --- a/objects/CampaignImporterExporter.334ee3.json +++ b/objects/CampaignImporterExporter.334ee3.json @@ -53,5 +53,14 @@ "scaleZ": 3.38 }, "Value": 0, - "XmlUI": "" + "XmlUI": "", + "AttachedSnapPoints": [ + { + "Position": { + "x": -0.95, + "y": 0.2, + "z": 0.01 + } + } + ] } diff --git a/src/accessories/CampaignImporterExporter.ttslua b/src/accessories/CampaignImporterExporter.ttslua index 80facb5f..c219a17a 100644 --- a/src/accessories/CampaignImporterExporter.ttslua +++ b/src/accessories/CampaignImporterExporter.ttslua @@ -47,23 +47,12 @@ local campaignTokenData = { local COLORS = { "White", "Orange", "Green", "Red" } 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({ click_function = "createCampaignToken", function_owner = self, label = "Export", - tooltip = "Create a campaign save token!\n\n(Ensure all chaos tokens have been unsealed!)", - position = { x = 1, y = 0.2, z = 0 }, + tooltip = "Create a campaign save token!", + position = { x = -1, y = 0.2, z = 0 }, font_size = 400, width = 1400, height = 600, @@ -75,46 +64,45 @@ end -- main import functions (split up to allow for Wait conditions) --------------------------------------------------------- --- Identifies import token, determines campaign box and downloads it (if needed) -function findCampaignFromToken(_, _, _) - local coin = nil - local coinObjects = getObjectsWithTag("ImporterToken") - 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 - ) +function onCollisionEnter(info) + local objectData = info.collision_object.getData() + if info.collision_object.hasTag("ImporterToken") then + findCampaignFromToken(info.collision_object) 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 function placeCampaignFromToken(importData) getObjectFromGUID(importData["box"]).call("buttonClick_place") @@ -131,6 +119,11 @@ function createCampaignFromToken(importData) -- destroy existing campaign log and load saved campaign log findUniqueObjectWithTag("CampaignLog").destruct() spawnObjectData({ data = importData["log"] }) + + if importData["additionalIndex"] then + findUniqueObjectWithTag("AllCardsHotfix").destruct() + spawnObjectData({data = importData["additionalIndex"]}) + end chaosBagApi.setChaosBagState(importData["bag"]) @@ -155,7 +148,7 @@ function createCampaignFromToken(importData) -- Condition function that is called continiously until returs true or timeout is reached function() return guide.Book.setPage(importData["guide"]) end, -- Amount of time in seconds until the Wait times out - 1, + 2, -- Called if the Wait times out function() log("Campaign Guide import failed!") end ) @@ -165,7 +158,9 @@ function createCampaignFromToken(importData) -- destroy Tour Starter token local tourStarter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "TourStarter") - tourStarter.destruct() + if tourStarter then + tourStarter.destruct() + end -- restore PlayArea image 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 function createCampaignToken(_, playerColor, _) - -- clean up chaos tokens - blessCurseApi.removeAll(playerColor) - chaosBagApi.releaseAllSealedTokens(playerColor) -- find active campaign local campaignBox @@ -202,20 +194,20 @@ function createCampaignToken(_, playerColor, _) return end - local traumaValues = { - 0, 0, 0, 0, - 0, 0, 0, 0 - } - local counterData = campaignLog.getVar("ref_buttonData") - if counterData ~= nil then + local additionalIndex = findUniqueObjectWithTag("AllCardsHotfix") + + local traumaValues = { } + local trauma = campaignLog.getVar("returnTrauma") + + if trauma ~= nil then printToAll("Trauma values found in campaign log!", "Green") - for i = 1, 10, 3 do - traumaValues[1 + (i - 1) / 3] = counterData.counter[i].value - traumaValues[5 + (i - 1) / 3] = counterData.counter[i + 1].value + trauma = campaignLog.call("returnTrauma") + for _, val in ipairs(trauma) do + table.insert(traumaValues, val) end else printToAll("Trauma values could not be found in campaign log!", "Yellow") - printToAll("Default values for health and sanity loaded.", "Yellow") + return end local campaignGuide = findUniqueObjectWithTag("CampaignGuide") @@ -224,6 +216,10 @@ function createCampaignToken(_, playerColor, _) return end + -- clean up chaos tokens + blessCurseApi.removeAll(playerColor) + chaosBagApi.releaseAllSealedTokens(playerColor) + local campaignData = { box = campaignBox.getGUID(), log = campaignLog.getData(), @@ -231,9 +227,10 @@ function createCampaignToken(_, playerColor, _) trauma = traumaValues, decks = deckImporterApi.getUiState(), clueCount = playAreaApi.getInvestigatorCount(), - guide = campaignGuide.Book.getPage(), + playmat = playAreaApi.getSurface(), options = optionPanelApi.getOptions(), - playmat = playAreaApi.getSurface() + guide = campaignGuide.Book.getPage(), + additionalIndex = additionalIndex.getData() } campaignTokenData.GMNotes = JSON.encode(campaignData) campaignTokenData.Nickname = os.date("%b %d ") .. campaignBox.getName() .. " Save" @@ -263,3 +260,16 @@ function setTrauma(trauma) playmatApi.updateCounter(COLORS[i], "HorrorCounter", trauma[i + 4]) 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 From 1bc78bd2a155e2d198dfed7f73f4b8e33a508287 Mon Sep 17 00:00:00 2001 From: Entrox-Licher Date: Mon, 8 Jan 2024 17:37:47 -0500 Subject: [PATCH 02/11] Performance Improvement --- src/accessories/CampaignImporterExporter.ttslua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/accessories/CampaignImporterExporter.ttslua b/src/accessories/CampaignImporterExporter.ttslua index c219a17a..ed3a889e 100644 --- a/src/accessories/CampaignImporterExporter.ttslua +++ b/src/accessories/CampaignImporterExporter.ttslua @@ -122,7 +122,7 @@ function createCampaignFromToken(importData) if importData["additionalIndex"] then findUniqueObjectWithTag("AllCardsHotfix").destruct() - spawnObjectData({data = importData["additionalIndex"]}) + spawnObjectJSON({json = importData["additionalIndex"]}) end chaosBagApi.setChaosBagState(importData["bag"]) @@ -230,7 +230,7 @@ function createCampaignToken(_, playerColor, _) playmat = playAreaApi.getSurface(), options = optionPanelApi.getOptions(), guide = campaignGuide.Book.getPage(), - additionalIndex = additionalIndex.getData() + additionalIndex = additionalIndex.getJSON() } campaignTokenData.GMNotes = JSON.encode(campaignData) campaignTokenData.Nickname = os.date("%b %d ") .. campaignBox.getName() .. " Save" From 01a292f10a6987f8896300465e430888880f2d76 Mon Sep 17 00:00:00 2001 From: Entrox-Licher Date: Tue, 9 Jan 2024 13:42:00 -0500 Subject: [PATCH 03/11] Addressing PR fixes --- src/accessories/CampaignImporterExporter.ttslua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/accessories/CampaignImporterExporter.ttslua b/src/accessories/CampaignImporterExporter.ttslua index ed3a889e..f8a9da01 100644 --- a/src/accessories/CampaignImporterExporter.ttslua +++ b/src/accessories/CampaignImporterExporter.ttslua @@ -52,7 +52,7 @@ function onLoad() function_owner = self, label = "Export", tooltip = "Create a campaign save token!", - position = { x = -1, y = 0.2, z = 0 }, + position = { x = -1, y = 0.21, z = 0 }, font_size = 400, width = 1400, height = 600, @@ -67,17 +67,17 @@ end function onCollisionEnter(info) local objectData = info.collision_object.getData() if info.collision_object.hasTag("ImporterToken") then - findCampaignFromToken(info.collision_object) + importFromToken(info.collision_object) end end -- Identifies import token, determines campaign box and downloads it (if needed) -function findCampaignFromToken(coin) +function importFromToken(coin) broadcastToAll("Campaign Import Initiated") local importData = JSON.decode(coin.getGMNotes()) coin.destruct() - campaignBoxGUID = importData["box"] + local campaignBoxGUID = importData["box"] local campaignBox = getObjectFromGUID(campaignBoxGUID) if campaignBox.type == "Generic" then campaignBox.call("buttonClick_download") @@ -163,7 +163,7 @@ function createCampaignFromToken(importData) end -- restore PlayArea image - playAreaApi.updateSurface(importData["playmat"]) + playAreaApi.updateSurface(importData["playarea"]) broadcastToAll("Campaign successfully imported!", Color.Green) end @@ -206,8 +206,7 @@ function createCampaignToken(_, playerColor, _) table.insert(traumaValues, val) end else - printToAll("Trauma values could not be found in campaign log!", "Yellow") - return + printToAll("Trauma values could not be found in campaign log!", "Yellow") end local campaignGuide = findUniqueObjectWithTag("CampaignGuide") @@ -227,7 +226,7 @@ function createCampaignToken(_, playerColor, _) trauma = traumaValues, decks = deckImporterApi.getUiState(), clueCount = playAreaApi.getInvestigatorCount(), - playmat = playAreaApi.getSurface(), + playarea = playAreaApi.getSurface(), options = optionPanelApi.getOptions(), guide = campaignGuide.Book.getPage(), additionalIndex = additionalIndex.getJSON() From c3b6c672636247dbac3b9d2a0158b70462a52e9c Mon Sep 17 00:00:00 2001 From: Entrox-Licher Date: Tue, 9 Jan 2024 13:45:08 -0500 Subject: [PATCH 04/11] Updated description --- objects/CampaignImporterExporter.334ee3.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/objects/CampaignImporterExporter.334ee3.json b/objects/CampaignImporterExporter.334ee3.json index 4bfc53e9..87c2e914 100644 --- a/objects/CampaignImporterExporter.334ee3.json +++ b/objects/CampaignImporterExporter.334ee3.json @@ -22,7 +22,7 @@ "ImageURL": "http://cloud-3.steamusercontent.com/ugc/254843371583173230/BECDC34EB4D2C8C5F9F9933C97085F82A2F21AE3/", "WidthScale": 0 }, - "Description": "Saves the state of the table to enable loading the campaign into a new save and keep all current progress.\n\nThis tool will track which campaign you're playing, the entire contents of your campaign log, the contents of your chaos bag, update your health/sanity according to trauma, your ArkhamDB deck IDs, the number of investigators, the page of your campaign guide, and any options you have selected in the options panel.\n\nFor saving trauma values to correct seats, ensure investigators in the campaign log are in the following order: White, Orange, Green, Red\n\n(For custom campaigns, ensure: 1) Campaign Box, Campaign Log, and Campaign Guide each have the corresponding tag, 2)The Campaign Box is on the table when you import or export.", + "Description": "Saves the state of the table to enable loading the campaign into a new save and keep all current progress.\n\nThis tool will track which campaign you're playing, the entire contents of your campaign log, the contents of your chaos bag, update your health/sanity according to trauma, your ArkhamDB deck IDs, the number of investigators, the page of your campaign guide, cards in the Additional Player Cards bag and any options you have selected in the options panel.\n\nFor saving trauma values to correct seats, ensure investigators in the campaign log are in the following order: White, Orange, Green, Red\n\nFor custom campaigns, ensure: 1) Campaign Box, Campaign Log, and Campaign Guide each have the corresponding tag, 2)The Campaign Box is on the table when you import or export.", "DragSelectable": true, "GMNotes": "", "GUID": "334ee3", From eafb62ba30330aa1439032ef527b9bb5e0d1ef9d Mon Sep 17 00:00:00 2001 From: Entrox-Licher Date: Wed, 10 Jan 2024 20:54:17 -0500 Subject: [PATCH 05/11] Fixed Latency Issues Resolved issues around latency concerning the Additional PLayer Cards bag, and converted the save tokens to be a bag now. --- .../CampaignImporterExporter.ttslua | 94 ++++++++++++++----- src/playercards/AllCardsBag.ttslua | 16 ++++ 2 files changed, 89 insertions(+), 21 deletions(-) diff --git a/src/accessories/CampaignImporterExporter.ttslua b/src/accessories/CampaignImporterExporter.ttslua index f8a9da01..f2b83fe9 100644 --- a/src/accessories/CampaignImporterExporter.ttslua +++ b/src/accessories/CampaignImporterExporter.ttslua @@ -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,16 +141,30 @@ 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() - 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 - + + -- 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"]) -- populate trauma values @@ -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 diff --git a/src/playercards/AllCardsBag.ttslua b/src/playercards/AllCardsBag.ttslua index a6a7bb9a..7b70b556 100644 --- a/src/playercards/AllCardsBag.ttslua +++ b/src/playercards/AllCardsBag.ttslua @@ -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 From 8c722fc8dc4b98a06901b725a5d84de562c8dfc8 Mon Sep 17 00:00:00 2001 From: Entrox-Licher Date: Thu, 11 Jan 2024 11:44:20 -0500 Subject: [PATCH 06/11] If statement fix --- src/accessories/CampaignImporterExporter.ttslua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/accessories/CampaignImporterExporter.ttslua b/src/accessories/CampaignImporterExporter.ttslua index f2b83fe9..1335d4ef 100644 --- a/src/accessories/CampaignImporterExporter.ttslua +++ b/src/accessories/CampaignImporterExporter.ttslua @@ -146,7 +146,7 @@ function createCampaignFromToken(importData, coin) checkWarning = false if importData["additionalIndex"] then findUniqueObjectWithTag("AllCardsHotfix").destruct() - if coin.getObjects() then + if coin.type == "Bag" then local newBag = coin.takeObject({index = 0, position = importData["additionalIndex"]}) Wait.time(function() newBag.setLock(true) end, 1) else @@ -156,7 +156,7 @@ function createCampaignFromToken(importData, coin) -- destroy existing campaign log and load saved campaign log findUniqueObjectWithTag("CampaignLog").destruct() - if coin.getObjects() then + if coin.type == "Bag" then coin.takeObject({index = 0, position = importData["log"]}) else spawnObjectData({ data = importData["log"] }) From 1f71fe03466997a39f799184d9778aefa6691e7b Mon Sep 17 00:00:00 2001 From: Entrox-Licher Date: Thu, 11 Jan 2024 11:46:11 -0500 Subject: [PATCH 07/11] Name improvement --- src/accessories/CampaignImporterExporter.ttslua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/accessories/CampaignImporterExporter.ttslua b/src/accessories/CampaignImporterExporter.ttslua index 1335d4ef..ddccbb91 100644 --- a/src/accessories/CampaignImporterExporter.ttslua +++ b/src/accessories/CampaignImporterExporter.ttslua @@ -272,7 +272,7 @@ function createCampaignToken(_, playerColor, _) additionalIndex = additionalIndex.getPosition() } campaignTokenData.GMNotes = JSON.encode(campaignData) - campaignTokenData.Nickname = os.date("%b %d ") .. campaignBox.getName() .. " Save" + campaignTokenData.Nickname = campaignBox.getName() .. os.date(" %b %d") .. " Save" spawnObjectData({ data = campaignTokenData, callback_function = finishTokenSpawning }) end From c4e8f86d311d3aa593b39c6a6565728202867f4a Mon Sep 17 00:00:00 2001 From: Entrox-Licher Date: Thu, 11 Jan 2024 12:44:40 -0500 Subject: [PATCH 08/11] Removed Log --- src/accessories/CampaignImporterExporter.ttslua | 1 - 1 file changed, 1 deletion(-) diff --git a/src/accessories/CampaignImporterExporter.ttslua b/src/accessories/CampaignImporterExporter.ttslua index ddccbb91..9a4b88f1 100644 --- a/src/accessories/CampaignImporterExporter.ttslua +++ b/src/accessories/CampaignImporterExporter.ttslua @@ -51,7 +51,6 @@ local campaignTokenData = { local COLORS = { "White", "Orange", "Green", "Red" } function onLoad() - log(getObjectFromGUID("1f5a0a").getData()) self.createButton({ click_function = "createCampaignToken", function_owner = self, From 2c0f7612b2a4a55cbd2b4dd7f3e262b0b0494d9c Mon Sep 17 00:00:00 2001 From: Entrox-Licher Date: Thu, 11 Jan 2024 12:47:50 -0500 Subject: [PATCH 09/11] Added lock functionality --- src/accessories/CampaignImporterExporter.ttslua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/accessories/CampaignImporterExporter.ttslua b/src/accessories/CampaignImporterExporter.ttslua index 9a4b88f1..74cc8c93 100644 --- a/src/accessories/CampaignImporterExporter.ttslua +++ b/src/accessories/CampaignImporterExporter.ttslua @@ -156,7 +156,8 @@ function createCampaignFromToken(importData, coin) -- destroy existing campaign log and load saved campaign log findUniqueObjectWithTag("CampaignLog").destruct() if coin.type == "Bag" then - coin.takeObject({index = 0, position = importData["log"]}) + local newLog = coin.takeObject({index = 0, position = importData["log"]}) + Wait.time(function() newLog.setLock(true) end, 1) else spawnObjectData({ data = importData["log"] }) end @@ -278,6 +279,7 @@ end function finishTokenSpawning(obj) local logData = campaignLog.getData() local indexData = additionalIndex.getData() + campaignLog.setLock(false) additionalIndex.setLock(false) checkWarning = false obj.putObject(additionalIndex) From e285f8e1514928735e1dd9c6c16d1b8c0e4a1e3c Mon Sep 17 00:00:00 2001 From: Entrox-Licher Date: Mon, 15 Jan 2024 16:43:33 -0500 Subject: [PATCH 10/11] PR Comments Addressed --- objects/CampaignImporterExporter.334ee3.json | 2 +- .../CampaignImporterExporter.ttslua | 38 ++++++++----------- src/core/GUIDReferenceHandler.ttslua | 1 + 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/objects/CampaignImporterExporter.334ee3.json b/objects/CampaignImporterExporter.334ee3.json index 87c2e914..958210ec 100644 --- a/objects/CampaignImporterExporter.334ee3.json +++ b/objects/CampaignImporterExporter.334ee3.json @@ -59,7 +59,7 @@ "Position": { "x": -0.95, "y": 0.2, - "z": 0.01 + "z": 0 } } ] diff --git a/src/accessories/CampaignImporterExporter.ttslua b/src/accessories/CampaignImporterExporter.ttslua index 74cc8c93..13afae3e 100644 --- a/src/accessories/CampaignImporterExporter.ttslua +++ b/src/accessories/CampaignImporterExporter.ttslua @@ -6,8 +6,6 @@ local optionPanelApi = require("core/OptionPanelApi") local playAreaApi = require("core/PlayAreaApi") local playmatApi = require("playermat/PlaymatApi") -local additionalIndex -local campaignLog local checkWarning = true local campaignTokenData = { @@ -87,7 +85,6 @@ end --------------------------------------------------------- function onCollisionEnter(info) - local objectData = info.collision_object.getData() if info.collision_object.hasTag("ImporterToken") then importFromToken(info.collision_object) end @@ -112,7 +109,7 @@ function importFromToken(coin) if #campaignBox.getObjects() > 0 then placeCampaignFromToken(importData, coin) else - createCampaignFromToken(importData, coin) + restoreCampaignData(importData, coin) end end, function() @@ -132,7 +129,7 @@ end function placeCampaignFromToken(importData, coin) getObjectFromGUID(importData["box"]).call("buttonClick_place") Wait.condition( - function() createCampaignFromToken(importData, coin) end, + function() restoreCampaignData(importData, coin) end, function() return findUniqueObjectWithTag("CampaignLog") ~= nil end, 2, function() broadcastToAll("Error placing campaign box") end @@ -140,14 +137,13 @@ function placeCampaignFromToken(importData, coin) end -- After content is placed on table, conducts all the other import operations -function createCampaignFromToken(importData, coin) +function restoreCampaignData(importData, coin) checkWarning = false if importData["additionalIndex"] then - findUniqueObjectWithTag("AllCardsHotfix").destruct() + guidReferenceApi.getObjectByOwnerAndType("Mythos", "AdditionalPlayerCardsBag").destruct() if coin.type == "Bag" then - local newBag = coin.takeObject({index = 0, position = importData["additionalIndex"]}) - Wait.time(function() newBag.setLock(true) end, 1) + coin.takeObject({index = 0, position = importData["additionalIndex"], callback_function = function(obj) obj.setLock(true) end}) else spawnObjectJSON({json = importData["additionalIndex"]}) end @@ -156,8 +152,7 @@ function createCampaignFromToken(importData, coin) -- destroy existing campaign log and load saved campaign log findUniqueObjectWithTag("CampaignLog").destruct() if coin.type == "Bag" then - local newLog = coin.takeObject({index = 0, position = importData["log"]}) - Wait.time(function() newLog.setLock(true) end, 1) + local newLog = coin.takeObject({index = 0, position = importData["log"], callback_function = function(obj) obj.setLock(true) end}) else spawnObjectData({ data = importData["log"] }) end @@ -228,13 +223,13 @@ function createCampaignToken(_, playerColor, _) return end - campaignLog = findUniqueObjectWithTag("CampaignLog") + local campaignLog = findUniqueObjectWithTag("CampaignLog") if campaignLog == nil then broadcastToAll("Campaign log not found!", Color.Red) return end - additionalIndex = findUniqueObjectWithTag("AllCardsHotfix") + local additionalIndex = guidReferenceApi.getObjectByOwnerAndType("Mythos", "AdditionalPlayerCardsBag") local traumaValues = { } local trauma = campaignLog.getVar("returnTrauma") @@ -273,20 +268,17 @@ function createCampaignToken(_, playerColor, _) } campaignTokenData.GMNotes = JSON.encode(campaignData) campaignTokenData.Nickname = campaignBox.getName() .. os.date(" %b %d") .. " Save" + campaignTokenData.ContainedObjects = { } + local indexData = additionalIndex.getData() + indexData.Locked = false + table.insert(campaignTokenData.ContainedObjects, indexData) + local logData = campaignLog.getData() + logData.Locked = false + table.insert(campaignTokenData.ContainedObjects, logData) spawnObjectData({ data = campaignTokenData, callback_function = finishTokenSpawning }) end function finishTokenSpawning(obj) - local logData = campaignLog.getData() - local indexData = additionalIndex.getData() - campaignLog.setLock(false) - 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 diff --git a/src/core/GUIDReferenceHandler.ttslua b/src/core/GUIDReferenceHandler.ttslua index 5fbd6547..a9ab8503 100644 --- a/src/core/GUIDReferenceHandler.ttslua +++ b/src/core/GUIDReferenceHandler.ttslua @@ -60,6 +60,7 @@ local GuidReferences = { Trash = "4b8594" }, Mythos = { + AdditionalPlayerCardsBag = "2cba6b", AllCardsBag = "15bb07", BlessCurseManager = "5933fb", CampaignThePathToCarcosa = "aca04c", From 2a766522fc25d0337124f403d5eba1fb53e00bfe Mon Sep 17 00:00:00 2001 From: Entrox-Licher Date: Mon, 15 Jan 2024 16:45:09 -0500 Subject: [PATCH 11/11] Removed redundant function --- src/accessories/CampaignImporterExporter.ttslua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/accessories/CampaignImporterExporter.ttslua b/src/accessories/CampaignImporterExporter.ttslua index 13afae3e..16eb2dbb 100644 --- a/src/accessories/CampaignImporterExporter.ttslua +++ b/src/accessories/CampaignImporterExporter.ttslua @@ -275,10 +275,7 @@ function createCampaignToken(_, playerColor, _) local logData = campaignLog.getData() logData.Locked = false table.insert(campaignTokenData.ContainedObjects, logData) - spawnObjectData({ data = campaignTokenData, callback_function = finishTokenSpawning }) -end - -function finishTokenSpawning(obj) + spawnObjectData({ data = campaignTokenData }) broadcastToAll("Campaign successfully exported! Save coin object to import on a fresh save", Color.Green) end