made campaign importer export dynamic

This commit is contained in:
Chr1Z93 2023-09-30 01:05:30 +02:00
parent 9a1898ca4d
commit 0fedc74ded
2 changed files with 70 additions and 86 deletions

View File

@ -36,6 +36,7 @@
"LuaScript": "require(\"core/tour/TourStarter\")",
"LuaScriptState": "",
"MeasureMovement": false,
"Memo": "{\"matColor\":\"Mythos\",\"type\":\"TourStarter\"}",
"Name": "Custom_Token",
"Nickname": "SCED Tour",
"Snap": true,

View File

@ -3,9 +3,9 @@ local chaosBagApi = require("chaosbag/ChaosBagApi")
local deckImporterApi = require("arkhamdb/DeckImporterApi")
local optionPanelApi = require("core/OptionPanelApi")
local playAreaApi = require("core/PlayAreaApi")
local playmatApi = require("playermat/PlaymatApi")
local campaignTokenData = {
GUID = "51b1c9",
Name = "Custom_Model",
Transform = {
posX = -21.25,
@ -18,9 +18,7 @@ local campaignTokenData = {
scaleY = 2,
scaleZ = 2
},
Nickname = "Arkham Coin",
Description = "SCED Importer Token",
GMNotes = "",
Tags = {
"ImporterToken"
},
@ -46,18 +44,7 @@ local campaignTokenData = {
}
}
-- counter GUIDS (4x damage and 4x horror)
local DAMAGE_HORROR_GUIDS = {
"eb08d6"; "e64eec"; "1f5a0a"; "591a45";
"468e88"; "0257d9"; "7b5729"; "beb964";
}
local TOUR_GUID = "0e5aa8"
local campaignBoxGUID
function onLoad(save_state)
campaignBoxGUID = ""
function onLoad()
self.createButton({
click_function = "findCampaignFromToken",
function_owner = self,
@ -82,7 +69,9 @@ function onLoad(save_state)
})
end
-- The main import functions. Due to timing concerns, has to be split up into several separate methods 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 findCampaignFromToken(_, _, _)
@ -94,8 +83,10 @@ function findCampaignFromToken(_, _, _)
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")
@ -124,7 +115,7 @@ end
-- After box has been downloaded, places content on table
function placeCampaignFromToken(importData)
getObjectFromGUID(campaignBoxGUID).call("buttonClick_place")
getObjectFromGUID(importData["box"]).call("buttonClick_place")
Wait.condition(
function() createCampaignFromToken(importData) end,
function() return findCampaignLog() ~= nil end,
@ -135,21 +126,24 @@ 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
findCampaignLog().destruct()
--create campaign log
spawnObjectData({ data = importData["log"] })
--create chaos bag
chaosBagApi.setChaosBagState(importData["bag"])
-- populate trauma values
if importData["trauma"] then
updateCounters(importData["trauma"])
setTrauma(importData["trauma"])
end
-- populate ArkhamDB deck IDs
if importData["decks"] then
deckImporterApi.setUiState(importData["decks"])
end
--set investigator count
playAreaApi.setInvestigatorCount(importData["clueCount"])
-- set campaign guide page
local guide = findCampaignGuide()
if guide then
@ -171,16 +165,18 @@ function createCampaignFromToken(importData)
end
)
end
Wait.time(
function() optionPanelApi.loadSettings(importData["options"]) end,
0.5
)
getObjectFromGUID(TOUR_GUID).destruct()
Wait.time(function() optionPanelApi.loadSettings(importData["options"]) end, 0.5)
-- destroy Tour Starter token
Global.call("getObjectFromMemo", { matColor = "Mythos", type = "TourStarter" }).destruct()
-- restore PlayArea image
playAreaApi.updateSurface(importData["playmat"])
broadcastToAll("Campaign successfully imported!", Color.Green)
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
@ -207,10 +203,12 @@ function createCampaignToken(_, playerColor, _)
broadcastToAll("Campaign log not found!", Color.Red)
return
end
local traumaValues = nil
local traumaValues = {
0, 0, 0, 0,
0, 0, 0, 0
}
local counterData = campaignLog.getVar("ref_buttonData")
if counterData ~= nil then
traumaValues = {}
printToAll("Trauma values found in campaign log!", "Green")
for i = 1, 10, 3 do
traumaValues[1 + (i - 1) / 3] = counterData.counter[i].value
@ -225,7 +223,6 @@ function createCampaignToken(_, playerColor, _)
broadcastToAll("Campaign guide not found!", Color.Red)
return
end
local campaignGuidePage = campaignGuide.Book.getPage()
local campaignData = {
box = campaignBoxGUID,
log = campaignLog.getData(),
@ -233,21 +230,19 @@ function createCampaignToken(_, playerColor, _)
trauma = traumaValues,
decks = deckImporterApi.getUiState(),
clueCount = playAreaApi.getInvestigatorCount(),
guide = campaignGuidePage,
guide = campaignGuide.Book.getPage(),
options = optionPanelApi.getOptions(),
playmat = playAreaApi.getSurface()
}
campaignTokenData.GMNotes = JSON.encode(campaignData)
campaignTokenData.Nickname = os.date("%b %d ") .. getObjectFromGUID(campaignBoxGUID).getName() .. " Save"
spawnObjectData({
data = campaignTokenData,
position = {-21.25, 1.68, 55.59}
})
spawnObjectData({ data = campaignTokenData })
broadcastToAll("Campaign successfully exported! Save coin object to import on a fresh save", Color.Green)
end
---------------------------------------------------------
-- helper functions
---------------------------------------------------------
function findCampaignLog()
local campaignLog = getObjectsWithTag("CampaignLog")
@ -277,21 +272,9 @@ function findCampaignGuide()
end
end
function updateCounters(tableOfNewValues)
if tonumber(tableOfNewValues) then
local value = tableOfNewValues
tableOfNewValues = {}
for i = 1, #DAMAGE_HORROR_GUIDS do
table.insert(tableOfNewValues, value)
end
end
for i, guid in ipairs(DAMAGE_HORROR_GUIDS) do
local TOKEN = getObjectFromGUID(guid)
if TOKEN ~= nil then
TOKEN.call("updateVal", tableOfNewValues[i])
else
printToAll(": No. " .. i .. " could not be found.", "Yellow")
end
function setTrauma(trauma)
for i = 1, 4 do
playmatApi.updateCounter(COLORS[i], "DamageCounter", trauma[i])
playmatApi.updateCounter(COLORS[i], "HorrorCounter", trauma[i + 4])
end
end