made campaign importer export dynamic
This commit is contained in:
parent
9a1898ca4d
commit
0fedc74ded
@ -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,
|
||||||
|
@ -3,9 +3,9 @@ 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"
|
||||||
},
|
},
|
||||||
@ -46,43 +44,34 @@ local campaignTokenData = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- 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(_, _, _)
|
||||||
@ -94,8 +83,10 @@ function findCampaignFromToken(_, _, _)
|
|||||||
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")
|
||||||
@ -124,7 +115,7 @@ 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,22 +126,25 @@ 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(
|
||||||
@ -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,21 +230,19 @@ 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")
|
||||||
@ -277,21 +272,9 @@ function findCampaignGuide()
|
|||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user