Addressed more PR suggestions, adding named tables, more APIs, improving deck importer functions, and fixing a minor error in an unrelated API

This commit is contained in:
Entrox-Licher 2023-06-18 14:07:24 -04:00
parent 7a79bc8fac
commit 609c54738e
6 changed files with 117 additions and 36 deletions

View File

@ -46,21 +46,19 @@ local DAMAGE_HORROR_GUIDS = {
"468e88"; "0257d9"; "7b5729"; "beb964";
}
local tokenZone
local deckImporter
local investigatorCounter
local deckImporterApi
local chaosBagApi
local playAreaAPI
local campaignBoxGUID
function onLoad(save_state)
chaosBagApi = require("chaosbag/ChaosBagApi")
playAreaAPI = require("core/PlayAreaApi")
deckImporterApi = require("arkhamdb/DeckImporterApi")
campaignBoxGUID = ""
tokenZone = getObjectFromGUID("ef3b5f")
deckImporter = getObjectFromGUID("a28140")
investigatorCounter = getObjectFromGUID("f182ee")
self.createButton({
click_function = "findCampaignFromToken",
function_owner = self,
@ -98,7 +96,7 @@ function findCampaignFromToken(_, _, _)
else
coin = coinObjects[1]
local importData = JSON.decode(coin.getGMNotes())
campaignBoxGUID = importData[1]
campaignBoxGUID = importData["box"]
local campaignBox = getObjectFromGUID(campaignBoxGUID)
if campaignBox.type == "Generic" then
campaignBox.call("buttonClick_download")
@ -140,19 +138,19 @@ end
function createCampaignFromToken(importData)
findCampaignLog().destruct()
--create campaign log
spawnObjectData({data = importData[2]})
spawnObjectData({data = importData["log"]})
--create chaos bag
chaosBagApi.setChaosBagState(importData[3])
chaosBagApi.setChaosBagState(importData["bag"])
--populate trauma values
if importData[4] then
updateCounters(importData[4])
updateCounters(importData["trauma"])
end
--populate ArkhamDB deck IDs
if importData[5] then
deckImporter.call("updateDeckIds", importData[5])
deckImporterApi.setUiState(importData["decks"])
end
--set investigator count
investigatorCounter.call("updateVal", importData[6])
playAreaAPI.setInvestigatorCount(importData["clueCount"])
--set campaign guide page
if findCampaignGuide() then
Wait.condition(
@ -160,8 +158,8 @@ function createCampaignFromToken(importData)
--log("Campaign Guide import successful!")
end,
function()
findCampaignGuide().Book.setPage(importData[7])
return findCampaignGuide().Book.getPage() == importData[7]
findCampaignGuide().Book.setPage(importData["guide"])
return findCampaignGuide().Book.getPage() == importData["guide"]
end,
1,
function()
@ -169,7 +167,7 @@ function createCampaignFromToken(importData)
end
)
end
Global.call("loadSettings", importData[8])
Global.call("loadSettings", importData["options"])
broadcastToAll("Campaign successfully imported!", Color.Green)
end
@ -204,7 +202,6 @@ function createCampaignToken(_, _, _)
printToAll("Trauma values could not be found in campaign log!", "Yellow")
printToAll("Default values for health and sanity loaded.", "Yellow")
end
local deckIds = {deckImporter.getInputs()[1].value, deckImporter.getInputs()[2].value, deckImporter.getInputs()[3].value, deckImporter.getInputs()[4].value}
local campaignGuide = findCampaignGuide()
if campaignGuide == nil then
broadcastToAll("Campaign guide not found!", Color.Red)
@ -213,14 +210,14 @@ function createCampaignToken(_, _, _)
local campaignGuidePage = campaignGuide.Book.getPage()
local campaignData = {
campaignBoxGUID,
campaignLog.getData(),
chaosBagApi.getChaosBagState(),
traumaValues,
deckIds,
require("core/PlayAreaApi").getInvestigatorCount(),
campaignGuidePage,
Global.getTable("optionPanel")
box = campaignBoxGUID,
log = campaignLog.getData(),
bag = chaosBagApi.getChaosBagState(),
trauma = traumaValues,
decks = deckImporterApi.getUiState(),
clueCount = playAreaAPI.getInvestigatorCount(),
guide = campaignGuidePage,
options = Global.getTable("optionPanel")
}
campaignTokenData.GMNotes = JSON.encode(campaignData)
campaignTokenData.Nickname = os.date("%b %d ") .. getObjectFromGUID(campaignBoxGUID).getName() .. " Save"

View File

@ -0,0 +1,39 @@
do
local DeckImporterApi = {}
local DECK_IMPORTER_GUID = "a28140"
-- Returns a table with the full state of the UI, including options and deck IDs.
-- This can be used to persist via onSave(), or provide values for a load operation
-- Table values:
-- redDeck: Deck ID to load for the red player
-- orangeDeck: Deck ID to load for the orange player
-- whiteDeck: Deck ID to load for the white player
-- greenDeck: Deck ID to load for the green player
-- private: True to load a private deck, false to load a public deck
-- loadNewest: True if the most upgraded version of the deck should be loaded
-- investigators: True if investigator cards should be spawned
DeckImporterApi.getUiState = function()
local passthroughTable = {}
for k,v in pairs(getObjectFromGUID(DECK_IMPORTER_GUID).call("getUiState")) do
passthroughTable[k] = v
end
return passthroughTable
end
-- Updates the state of the UI based on the provided table. Any values not provided will be left the same.
-- @param uiStateTable Table of values to update on importer
-- Table values:
-- redDeck: Deck ID to load for the red player
-- orangeDeck: Deck ID to load for the orange player
-- whiteDeck: Deck ID to load for the white player
-- greenDeck: Deck ID to load for the green player
-- private: True to load a private deck, false to load a public deck
-- loadNewest: True if the most upgraded version of the deck should be loaded
-- investigators: True if investigator cards should be spawned
DeckImporterApi.setUiState = function(uiStateTable)
return getObjectFromGUID(DECK_IMPORTER_GUID).call("setUiState", uiStateTable)
end
return DeckImporterApi
end

View File

@ -45,6 +45,49 @@ function getUiState()
}
end
-- Updates the state of the UI based on the provided table. Any values not provided will be left the same.
-- @param uiStateTable Table of values to update on importer
-- Table values:
-- redDeck: Deck ID to load for the red player
-- orangeDeck: Deck ID to load for the orange player
-- whiteDeck: Deck ID to load for the white player
-- greenDeck: Deck ID to load for the green player
-- private: True to load a private deck, false to load a public deck
-- loadNewest: True if the most upgraded version of the deck should be loaded
-- investigators: True if investigator cards should be spawned
function setUiState(uiStateTable)
-- Callback functions aren't triggered when editing buttons/inputs so values must be set manually
if uiStateTable["greenDeck"] then
greenDeckId = uiStateTable["greenDeck"]
self.editInput({index=0, value=greenDeckId})
end
if uiStateTable["redDeck"] then
redDeckId = uiStateTable["redDeck"]
self.editInput({index=1, value=redDeckId})
end
if uiStateTable["whiteDeck"] then
whiteDeckId = uiStateTable["whiteDeck"]
self.editInput({index=2, value=whiteDeckId})
end
if uiStateTable["orangeDeck"]then
orangeDeckId = uiStateTable["orangeDeck"]
self.editInput({index=3, value=orangeDeckId})
end
if uiStateTable["private"] then
privateDeck = uiStateTable["private"]
self.editButton { index = 0, label = PRIVATE_TOGGLE_LABELS[privateDeck] }
end
if uiStateTable["loadNewest"] then
loadNewestDeck = uiStateTable["loadNewest"]
self.editButton { index = 1, label = UPGRADED_TOGGLE_LABELS[loadNewestDeck] }
end
if uiStateTable["investigators"] then
loadInvestigators = uiStateTable["investigators"]
self.editButton { index = 2, label = LOAD_INVESTIGATOR_TOGGLE_LABELS[loadInvestigators] }
end
end
-- Sets up the UI for the deck loader, populating fields from the given save state table decoded from onLoad()
function initializeUi(savedUiState)
if savedUiState ~= nil then
@ -154,17 +197,6 @@ function whiteDeckChanged(_, _, inputValue) whiteDeckId = inputValue end
function greenDeckChanged(_, _, inputValue) greenDeckId = inputValue end
function updateDeckIds(idList)
greenDeckId = idList[1]
redDeckId = idList[2]
whiteDeckId = idList[3]
orangeDeckId = idList[4]
self.editInput({index=0, value=greenDeckId})
self.editInput({index=1, value=redDeckId})
self.editInput({index=2, value=whiteDeckId})
self.editInput({index=3, value=orangeDeckId})
end
-- Event handlers for toggle buttons
function publicPrivateChanged()
privateDeck = not privateDeck

View File

@ -4,7 +4,7 @@ do
-- returns the chaos token metadata (if provided through scenario reference card)
MythosAreaApi.returnTokenData = function()
return getObjectFromGUID("9f334f").call("returnTokenData")
return getObjectFromGUID(MYTHOS_AREA_GUID).call("returnTokenData")
end
return MythosAreaApi

View File

@ -511,6 +511,13 @@ function getInvestigatorCount()
return investigatorCounter.getVar("val")
end
-- Updates the current value of the investigator counter from the playmat
---@param count Number of investigators to set on the counter
function setInvestigatorCount(count)
local investigatorCounter = getObjectFromGUID("f182ee")
return investigatorCounter.call("updateVal", count)
end
-- Check to see if the given object is within the bounds of the play area, based solely on the X and
-- Z coordinates, ignoring height
---@param object Object Object to check

View File

@ -9,6 +9,12 @@ do
return getObjectFromGUID(PLAY_AREA_GUID).call("getInvestigatorCount")
end
-- Updates the current value of the investigator counter from the playmat
---@param count Number of investigators to set on the counter
PlayAreaApi.setInvestigatorCount = function(count)
return getObjectFromGUID(PLAY_AREA_GUID).call("setInvestigatorCount", count)
end
-- Move all contents on the play area (cards, tokens, etc) one slot in the given direction. Certain
-- fixed objects will be ignored, as will anything the player has tagged with
-- 'displacement_excluded'