Addressed final lingering PR suggestions

Fixed indentation, moved things out of onLoad, and made a minor refactor to helper methods to avoid repeated funciton calls.
This commit is contained in:
Entrox-Licher 2023-08-07 13:14:35 -04:00
parent b4b9e49baf
commit e69b9042a9

View File

@ -46,19 +46,15 @@ local DAMAGE_HORROR_GUIDS = {
"468e88"; "0257d9"; "7b5729"; "beb964";
}
local chaosBagApi
local playAreaAPI
local optionPanelApi
local deckImporterApi
local chaosBagApi = require("chaosbag/ChaosBagApi")
local playAreaAPI = require("core/PlayAreaApi")
local deckImporterApi = require("arkhamdb/DeckImporterApi")
local optionPanelApi = require("core/OptionPanelApi")
local blessCurseApi = require("chaosbag/BlessCurseManagerApi")
local campaignBoxGUID
function onLoad(save_state)
chaosBagApi = require("chaosbag/ChaosBagApi")
playAreaAPI = require("core/PlayAreaApi")
deckImporterApi = require("arkhamdb/DeckImporterApi")
optionPanelApi = require("core/OptionPanelApi")
blessCurseApi = require("chaosbag/BlessCurseManagerApi")
campaignBoxGUID = ""
self.createButton({
@ -113,7 +109,7 @@ function findCampaignFromToken(_, _, _)
end,
function()
local obj = getObjectFromGUID(campaignBoxGUID)
if obj == nil then
if obj == nil then
return false
else
return obj.type == "Bag" and obj.getLuaScript() ~= ""
@ -245,9 +241,10 @@ end
-- helper functions
function findCampaignLog()
if getObjectsWithTag("CampaignLog") then
if #getObjectsWithTag("CampaignLog") == 1 then
return getObjectsWithTag("CampaignLog")[1]
local campaignLog = getObjectsWithTag("CampaignLog")
if campaignLog then
if #campaignLog == 1 then
return campaignLog[1]
else
broadcastToAll("More than 1 campaign log detected; delete all but one.", Color.Red)
return nil
@ -258,9 +255,10 @@ function findCampaignLog()
end
function findCampaignGuide()
if getObjectsWithTag("CampaignGuide") then
if #getObjectsWithTag("CampaignGuide") == 1 then
return getObjectsWithTag("CampaignGuide")[1]
local campaignGuide = getObjectsWithTag("CampaignGuide")
if campaignGuide then
if #campaignGuide == 1 then
return campaignGuide[1]
else
broadcastToAll("More than 1 campaign guide detected; delete all but one.", Color.Red)
return nil
@ -275,17 +273,16 @@ function updateCounters(tableOfNewValues)
local value = tableOfNewValues
tableOfNewValues = {}
for i = 1, #DAMAGE_HORROR_GUIDS do
table.insert(tableOfNewValues, value)
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])
TOKEN.call("updateVal", tableOfNewValues[i])
else
printToAll(": No. " .. i .. " could not be found.", "Yellow")
printToAll(": No. " .. i .. " could not be found.", "Yellow")
end
end
end
end