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\")", "LuaScript": "require(\"core/tour/TourStarter\")",
"LuaScriptState": "", "LuaScriptState": "",
"MeasureMovement": false, "MeasureMovement": false,
"Memo": "{\"matColor\":\"Mythos\",\"type\":\"TourStarter\"}",
"Name": "Custom_Token", "Name": "Custom_Token",
"Nickname": "SCED Tour", "Nickname": "SCED Tour",
"Snap": true, "Snap": true,

View File

@ -1,11 +1,11 @@
local blessCurseApi = require("chaosbag/BlessCurseManagerApi") local blessCurseApi = require("chaosbag/BlessCurseManagerApi")
local chaosBagApi = require("chaosbag/ChaosBagApi") local chaosBagApi = require("chaosbag/ChaosBagApi")
local deckImporterApi = require("arkhamdb/DeckImporterApi") local deckImporterApi = require("arkhamdb/DeckImporterApi")
local optionPanelApi = require("core/OptionPanelApi") local optionPanelApi = require("core/OptionPanelApi")
local playAreaApi = require("core/PlayAreaApi") local playAreaApi = require("core/PlayAreaApi")
local playmatApi = require("playermat/PlaymatApi")
local campaignTokenData = { local campaignTokenData = {
GUID = "51b1c9",
Name = "Custom_Model", Name = "Custom_Model",
Transform = { Transform = {
posX = -21.25, posX = -21.25,
@ -18,9 +18,7 @@ local campaignTokenData = {
scaleY = 2, scaleY = 2,
scaleZ = 2 scaleZ = 2
}, },
Nickname = "Arkham Coin",
Description = "SCED Importer Token", Description = "SCED Importer Token",
GMNotes = "",
Tags = { Tags = {
"ImporterToken" "ImporterToken"
}, },
@ -33,56 +31,47 @@ local campaignTokenData = {
MaterialIndex = 2, MaterialIndex = 2,
TypeIndex = 0, TypeIndex = 0,
CustomShader = { CustomShader = {
SpecularColor = { SpecularColor = {
r = 0.7222887, r = 0.7222887,
g = 0.507659256, g = 0.507659256,
b = 0.339915335 b = 0.339915335
}, },
SpecularIntensity = 0.4, SpecularIntensity = 0.4,
SpecularSharpness = 7.0, SpecularSharpness = 7.0,
FresnelStrength = 0.0 FresnelStrength = 0.0
}, },
CastShadows = true CastShadows = true
} }
} }
-- counter GUIDS (4x damage and 4x horror) function onLoad()
local DAMAGE_HORROR_GUIDS = {
"eb08d6"; "e64eec"; "1f5a0a"; "591a45";
"468e88"; "0257d9"; "7b5729"; "beb964";
}
local TOUR_GUID = "0e5aa8"
local campaignBoxGUID
function onLoad(save_state)
campaignBoxGUID = ""
self.createButton({ self.createButton({
click_function = "findCampaignFromToken", click_function = "findCampaignFromToken",
function_owner = self, function_owner = self,
label = "Import", 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!)", 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}, position = { x = -1, y = 0.2, z = 0 },
font_size = 400, font_size = 400,
width = 1400, width = 1400,
height = 600, height = 600,
scale = {0.5, 1, 0.5}, 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!\n\n(Ensure all chaos tokens have been unsealed!)",
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,
scale = {0.5, 1, 0.5}, scale = { 0.5, 1, 0.5 },
}) })
end 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) -- Identifies import token, determines campaign box and downloads it (if needed)
function findCampaignFromToken(_, _, _) function findCampaignFromToken(_, _, _)
@ -91,11 +80,13 @@ function findCampaignFromToken(_, _, _)
if #coinObjects == 0 then if #coinObjects == 0 then
broadcastToAll("Could not find importer token", Color.Red) broadcastToAll("Could not find importer token", Color.Red)
elseif #coinObjects > 1 then elseif #coinObjects > 1 then
broadcastToAll("More than 1 importer token found. Please delete all but 1 importer token", Color.Yellow) broadcastToAll("More than 1 importer token found. Please delete all but 1 importer token", Color.Yellow)
else else
coin = coinObjects[1] coin = coinObjects[1]
local importData = JSON.decode(coin.getGMNotes()) local importData = JSON.decode(coin.getGMNotes())
campaignBoxGUID = importData["box"] campaignBoxGUID = importData["box"]
local campaignBox = getObjectFromGUID(campaignBoxGUID) local campaignBox = getObjectFromGUID(campaignBoxGUID)
if campaignBox.type == "Generic" then if campaignBox.type == "Generic" then
campaignBox.call("buttonClick_download") campaignBox.call("buttonClick_download")
@ -110,21 +101,21 @@ function findCampaignFromToken(_, _, _)
end, end,
function() function()
local obj = getObjectFromGUID(campaignBoxGUID) local obj = getObjectFromGUID(campaignBoxGUID)
if obj == nil then if obj == nil then
return false return false
else else
return obj.type == "Bag" and obj.getLuaScript() ~= "" return obj.type == "Bag" and obj.getLuaScript() ~= ""
end end
end, end,
2, 2,
function() broadcastToAll("Error loading campaign box") end function() broadcastToAll("Error loading campaign box") end
) )
end end
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(campaignBoxGUID).call("buttonClick_place") getObjectFromGUID(importData["box"]).call("buttonClick_place")
Wait.condition( Wait.condition(
function() createCampaignFromToken(importData) end, function() createCampaignFromToken(importData) end,
function() return findCampaignLog() ~= nil end, function() return findCampaignLog() ~= nil end,
@ -135,30 +126,33 @@ 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)
-- destroy existing campaign log and load saved campaign log
findCampaignLog().destruct() findCampaignLog().destruct()
--create campaign log spawnObjectData({ data = importData["log"] })
spawnObjectData({data = importData["log"]})
--create chaos bag
chaosBagApi.setChaosBagState(importData["bag"]) chaosBagApi.setChaosBagState(importData["bag"])
--populate trauma values
-- populate trauma values
if importData["trauma"] then if importData["trauma"] then
updateCounters(importData["trauma"]) setTrauma(importData["trauma"])
end end
--populate ArkhamDB deck IDs
-- populate ArkhamDB deck IDs
if importData["decks"] then if importData["decks"] then
deckImporterApi.setUiState(importData["decks"]) deckImporterApi.setUiState(importData["decks"])
end end
--set investigator count
playAreaApi.setInvestigatorCount(importData["clueCount"]) playAreaApi.setInvestigatorCount(importData["clueCount"])
--set campaign guide page
-- set campaign guide page
local guide = findCampaignGuide() local guide = findCampaignGuide()
if guide then if guide then
Wait.condition( Wait.condition(
-- Called after the condition function returns true -- Called after the condition function returns true
function() function()
log("Campaign Guide import successful!") log("Campaign Guide import successful!")
end, end,
-- 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() function()
guide.Book.setPage(importData["guide"]) guide.Book.setPage(importData["guide"])
return guide.Book.getPage() == importData["guide"] return guide.Book.getPage() == importData["guide"]
@ -171,16 +165,18 @@ function createCampaignFromToken(importData)
end end
) )
end end
Wait.time(
function() optionPanelApi.loadSettings(importData["options"]) end, Wait.time(function() optionPanelApi.loadSettings(importData["options"]) end, 0.5)
0.5
) -- destroy Tour Starter token
getObjectFromGUID(TOUR_GUID).destruct() Global.call("getObjectFromMemo", { matColor = "Mythos", type = "TourStarter" }).destruct()
-- restore PlayArea image
playAreaApi.updateSurface(importData["playmat"]) playAreaApi.updateSurface(importData["playmat"])
broadcastToAll("Campaign successfully imported!", Color.Green) broadcastToAll("Campaign successfully imported!", Color.Green)
end 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 -- clean up chaos tokens
@ -207,10 +203,12 @@ function createCampaignToken(_, playerColor, _)
broadcastToAll("Campaign log not found!", Color.Red) broadcastToAll("Campaign log not found!", Color.Red)
return return
end end
local traumaValues = nil local traumaValues = {
0, 0, 0, 0,
0, 0, 0, 0
}
local counterData = campaignLog.getVar("ref_buttonData") local counterData = campaignLog.getVar("ref_buttonData")
if counterData ~= nil then if counterData ~= nil then
traumaValues = {}
printToAll("Trauma values found in campaign log!", "Green") printToAll("Trauma values found in campaign log!", "Green")
for i = 1, 10, 3 do for i = 1, 10, 3 do
traumaValues[1 + (i - 1) / 3] = counterData.counter[i].value traumaValues[1 + (i - 1) / 3] = counterData.counter[i].value
@ -225,7 +223,6 @@ function createCampaignToken(_, playerColor, _)
broadcastToAll("Campaign guide not found!", Color.Red) broadcastToAll("Campaign guide not found!", Color.Red)
return return
end end
local campaignGuidePage = campaignGuide.Book.getPage()
local campaignData = { local campaignData = {
box = campaignBoxGUID, box = campaignBoxGUID,
log = campaignLog.getData(), log = campaignLog.getData(),
@ -233,27 +230,25 @@ function createCampaignToken(_, playerColor, _)
trauma = traumaValues, trauma = traumaValues,
decks = deckImporterApi.getUiState(), decks = deckImporterApi.getUiState(),
clueCount = playAreaApi.getInvestigatorCount(), clueCount = playAreaApi.getInvestigatorCount(),
guide = campaignGuidePage, guide = campaignGuide.Book.getPage(),
options = optionPanelApi.getOptions(), options = optionPanelApi.getOptions(),
playmat = playAreaApi.getSurface() playmat = playAreaApi.getSurface()
} }
campaignTokenData.GMNotes = JSON.encode(campaignData) campaignTokenData.GMNotes = JSON.encode(campaignData)
campaignTokenData.Nickname = os.date("%b %d ") .. getObjectFromGUID(campaignBoxGUID).getName() .. " Save" campaignTokenData.Nickname = os.date("%b %d ") .. getObjectFromGUID(campaignBoxGUID).getName() .. " Save"
spawnObjectData({ spawnObjectData({ data = campaignTokenData })
data = campaignTokenData,
position = {-21.25, 1.68, 55.59}
})
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
---------------------------------------------------------
-- helper functions -- helper functions
---------------------------------------------------------
function findCampaignLog() function findCampaignLog()
local campaignLog = getObjectsWithTag("CampaignLog") local campaignLog = getObjectsWithTag("CampaignLog")
if campaignLog then if campaignLog then
if #campaignLog == 1 then if #campaignLog == 1 then
return campaignLog[1] return campaignLog[1]
else else
broadcastToAll("More than 1 campaign log detected; delete all but one.", Color.Red) broadcastToAll("More than 1 campaign log detected; delete all but one.", Color.Red)
return nil return nil
@ -263,35 +258,23 @@ function findCampaignLog()
end end
end end
function findCampaignGuide() function findCampaignGuide()
local campaignGuide = getObjectsWithTag("CampaignGuide") local campaignGuide = getObjectsWithTag("CampaignGuide")
if campaignGuide then if campaignGuide then
if #campaignGuide == 1 then if #campaignGuide == 1 then
return campaignGuide[1] return campaignGuide[1]
else else
broadcastToAll("More than 1 campaign guide detected; delete all but one.", Color.Red) broadcastToAll("More than 1 campaign guide detected; delete all but one.", Color.Red)
return nil return nil
end end
else else
return nil return nil
end end
end end
function updateCounters(tableOfNewValues) function setTrauma(trauma)
if tonumber(tableOfNewValues) then for i = 1, 4 do
local value = tableOfNewValues playmatApi.updateCounter(COLORS[i], "DamageCounter", trauma[i])
tableOfNewValues = {} playmatApi.updateCounter(COLORS[i], "HorrorCounter", trauma[i + 4])
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
end end
end end