Addressed various PR suggestions. Additionally, implemented ChaosBagApi to follow API design pattern suggested for the codebase.
This commit is contained in:
parent
b537b13ae6
commit
838c0be0fc
@ -2,46 +2,22 @@ local campaignTokenData = {
|
|||||||
GUID = "51b1c9",
|
GUID = "51b1c9",
|
||||||
Name = "Custom_Model",
|
Name = "Custom_Model",
|
||||||
Transform = {
|
Transform = {
|
||||||
posX = 2.80123329,
|
posX = -21.25,
|
||||||
posY = 1.681688,
|
posY = 1.68,
|
||||||
posZ = -23.6498032,
|
posZ = 55.59,
|
||||||
rotX = -2.22745348E-06,
|
rotX = 0,
|
||||||
rotY = 269.999664,
|
rotY = 270,
|
||||||
rotZ = -1.6614282E-06,
|
rotZ = 0,
|
||||||
scaleX = 2.00499868,
|
scaleX = 2,
|
||||||
scaleY = 2.00499868,
|
scaleY = 2,
|
||||||
scaleZ = 2.00499868
|
scaleZ = 2
|
||||||
},
|
},
|
||||||
Nickname = "Arkham Coin",
|
Nickname = "Arkham Coin",
|
||||||
Description = "SCED Importer Token",
|
Description = "SCED Importer Token",
|
||||||
GMNotes = "",
|
GMNotes = "",
|
||||||
AltLookAngle = {
|
|
||||||
x = 0.0,
|
|
||||||
y = 0.0,
|
|
||||||
z = 0.0
|
|
||||||
},
|
|
||||||
ColorDiffuse = {
|
|
||||||
r = 1.0,
|
|
||||||
g = 1.0,
|
|
||||||
b = 1.0
|
|
||||||
},
|
|
||||||
Tags = {
|
Tags = {
|
||||||
"ImporterToken"
|
"ImporterToken"
|
||||||
},
|
},
|
||||||
LayoutGroupSortIndex = 0,
|
|
||||||
Value = 0,
|
|
||||||
Locked = false,
|
|
||||||
Grid = true,
|
|
||||||
Snap = true,
|
|
||||||
IgnoreFoW = false,
|
|
||||||
MeasureMovement = false,
|
|
||||||
DragSelectable = true,
|
|
||||||
Autoraise = true,
|
|
||||||
Sticky = true,
|
|
||||||
Tooltip = true,
|
|
||||||
GridProjection = false,
|
|
||||||
HideWhenFaceDown = false,
|
|
||||||
Hands = false,
|
|
||||||
CustomMesh = {
|
CustomMesh = {
|
||||||
MeshURL = "http://cloud-3.steamusercontent.com/ugc/943949966265929204/A38BB5D72419E6298385556D931877C0A1A55C17/",
|
MeshURL = "http://cloud-3.steamusercontent.com/ugc/943949966265929204/A38BB5D72419E6298385556D931877C0A1A55C17/",
|
||||||
DiffuseURL = "http://cloud-3.steamusercontent.com/ugc/254843371583188147/920981125E37B5CEB6C400E3FD353A2C428DA969/",
|
DiffuseURL = "http://cloud-3.steamusercontent.com/ugc/254843371583188147/920981125E37B5CEB6C400E3FD353A2C428DA969/",
|
||||||
@ -61,50 +37,49 @@ local campaignTokenData = {
|
|||||||
FresnelStrength = 0.0
|
FresnelStrength = 0.0
|
||||||
},
|
},
|
||||||
CastShadows = true
|
CastShadows = true
|
||||||
},
|
}
|
||||||
LuaScript = "",
|
|
||||||
LuaScriptState = "",
|
|
||||||
XmlUI = ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- colors and order for following tables
|
|
||||||
local COLORS = { "White"; "Orange"; "Green"; "Red"; "Agenda" }
|
|
||||||
|
|
||||||
-- counter GUIDS (4x damage and 4x horror)
|
-- counter GUIDS (4x damage and 4x horror)
|
||||||
local DAMAGE_HORROR_GUIDS = {
|
local DAMAGE_HORROR_GUIDS = {
|
||||||
"eb08d6"; "e64eec"; "1f5a0a"; "591a45";
|
"eb08d6"; "e64eec"; "1f5a0a"; "591a45";
|
||||||
"468e88"; "0257d9"; "7b5729"; "beb964";
|
"468e88"; "0257d9"; "7b5729"; "beb964";
|
||||||
}
|
}
|
||||||
|
|
||||||
local campaignData = {}
|
local tokenZone
|
||||||
|
local deckImporter
|
||||||
|
local investigatorCounter
|
||||||
|
|
||||||
local tokenZone = getObjectFromGUID("ef3b5f")
|
local chaosBagApi
|
||||||
local deckImporter = getObjectFromGUID("a28140")
|
|
||||||
local investigatorCounter = getObjectFromGUID("f182ee")
|
|
||||||
|
|
||||||
local campaignBoxGUID = ""
|
local campaignBoxGUID
|
||||||
local traumaValues = false
|
|
||||||
local deckIds = false
|
|
||||||
local campaignGuidePage = false
|
|
||||||
|
|
||||||
function onLoad(save_state)
|
function onLoad(save_state)
|
||||||
|
chaosBagApi = require("chaosbag/ChaosBagApi")
|
||||||
|
campaignBoxGUID = ""
|
||||||
|
|
||||||
|
tokenZone = getObjectFromGUID("ef3b5f")
|
||||||
|
deckImporter = getObjectFromGUID("a28140")
|
||||||
|
investigatorCounter = getObjectFromGUID("f182ee")
|
||||||
self.createButton({
|
self.createButton({
|
||||||
click_function = "findCampaignFromToken",
|
click_function = "findCampaignFromToken",
|
||||||
function_owner = self,
|
function_owner = self,
|
||||||
label = "Import",
|
label = "Import",
|
||||||
position = {x=-1, y=0.2, z=0},
|
position = {x=-1, y=0.2, z=0},
|
||||||
width = 350,
|
font_size = 400,
|
||||||
height = 150,
|
width = 1400,
|
||||||
scale = {2, 1, 2},
|
height = 600,
|
||||||
|
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",
|
||||||
position = {x=1, y=0.2, z=0},
|
position = {x=1, y=0.2, z=0},
|
||||||
width = 350,
|
font_size = 400,
|
||||||
height = 150,
|
width = 1400,
|
||||||
scale = {2, 1, 2},
|
height = 600,
|
||||||
|
scale = {0.5, 1, 0.5},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -158,11 +133,10 @@ end
|
|||||||
|
|
||||||
function createCampaignFromToken(importData)
|
function createCampaignFromToken(importData)
|
||||||
findCampaignLog().destruct()
|
findCampaignLog().destruct()
|
||||||
findChaosBag().destruct()
|
|
||||||
--create campaign log
|
--create campaign log
|
||||||
spawnObjectData({data = importData[2]})
|
spawnObjectData({data = importData[2]})
|
||||||
--create chaos bag
|
--create chaos bag
|
||||||
spawnObjectData({data = importData[3]})
|
chaosBagApi.setChaosBagState(importData[3])
|
||||||
--populate trauma values
|
--populate trauma values
|
||||||
if importData[4] then
|
if importData[4] then
|
||||||
updateCounters(importData[4])
|
updateCounters(importData[4])
|
||||||
@ -210,14 +184,9 @@ function createCampaignToken(_, _, _)
|
|||||||
broadcastToAll("Campaign log not found!", Color.Red)
|
broadcastToAll("Campaign log not found!", Color.Red)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local chaosBag = findChaosBag()
|
|
||||||
if chaosBag == nil then
|
|
||||||
broadcastToAll("Chaos bag not found in standard position!", Color.Red)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local counterData = campaignLog.getVar("ref_buttonData")
|
local counterData = campaignLog.getVar("ref_buttonData")
|
||||||
if counterData ~= nil then
|
if counterData ~= nil then
|
||||||
traumaValues = {}
|
local 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
|
||||||
@ -227,26 +196,26 @@ function createCampaignToken(_, _, _)
|
|||||||
printToAll("Trauma values could not be found in campaign log!", "Yellow")
|
printToAll("Trauma values could not be found in campaign log!", "Yellow")
|
||||||
printToAll("Default values for health and sanity loaded.", "Yellow")
|
printToAll("Default values for health and sanity loaded.", "Yellow")
|
||||||
end
|
end
|
||||||
deckIds = {deckImporter.getInputs()[1].value, deckImporter.getInputs()[2].value, deckImporter.getInputs()[3].value, deckImporter.getInputs()[4].value}
|
local deckIds = {deckImporter.getInputs()[1].value, deckImporter.getInputs()[2].value, deckImporter.getInputs()[3].value, deckImporter.getInputs()[4].value}
|
||||||
local campaignGuide = findCampaignGuide()
|
local campaignGuide = findCampaignGuide()
|
||||||
if campaignGuide == nil then
|
if campaignGuide == nil then
|
||||||
broadcastToAll("Campaign loguideg not found!", Color.Red)
|
broadcastToAll("Campaign guide not found!", Color.Red)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local campaignGuidePage = campaignGuide.Book.getPage()
|
local campaignGuidePage = campaignGuide.Book.getPage()
|
||||||
|
|
||||||
campaignData = {
|
local campaignData = {
|
||||||
campaignBoxGUID,
|
campaignBoxGUID,
|
||||||
campaignLog.getData(),
|
campaignLog.getData(),
|
||||||
chaosBag.getData(),
|
chaosBagApi.getChaosBagState(),
|
||||||
traumaValues,
|
traumaValues,
|
||||||
deckIds,
|
deckIds,
|
||||||
investigatorCounter.getVar("val"),
|
require("core/PlayAreaApi").getInvestigatorCount(),
|
||||||
campaignGuidePage,
|
campaignGuidePage,
|
||||||
Global.getTable("optionPanel")
|
Global.getTable("optionPanel")
|
||||||
}
|
}
|
||||||
campaignTokenData.GMNotes = JSON.encode(campaignData)
|
campaignTokenData.GMNotes = JSON.encode(campaignData)
|
||||||
campaignTokenData.Nickname = getObjectFromGUID(campaignBoxGUID).getName() .. os.date(" Save: %b %d")
|
campaignTokenData.Nickname = os.date(" Save: %b %d") .. getObjectFromGUID(campaignBoxGUID).getName()
|
||||||
spawnObjectData({
|
spawnObjectData({
|
||||||
data = campaignTokenData,
|
data = campaignTokenData,
|
||||||
position = {-21.25, 1.68, 55.59}
|
position = {-21.25, 1.68, 55.59}
|
||||||
@ -272,14 +241,6 @@ function findCampaignGuide()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- checks scripting zone for chaos bag
|
|
||||||
function findChaosBag()
|
|
||||||
for _, item in ipairs(getObjectFromGUID("83ef06").getObjects()) do
|
|
||||||
if item.getDescription() == "Chaos Bag" then
|
|
||||||
return item
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function updateCounters(tableOfNewValues)
|
function updateCounters(tableOfNewValues)
|
||||||
if tonumber(tableOfNewValues) then
|
if tonumber(tableOfNewValues) then
|
||||||
|
27
src/chaosbag/ChaosBagApi.ttslua
Normal file
27
src/chaosbag/ChaosBagApi.ttslua
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
do
|
||||||
|
local ChaosBagApi = {}
|
||||||
|
|
||||||
|
-- respawns the chaos bag with a new state of tokens
|
||||||
|
---@param tokenList Table List of chaos token ids
|
||||||
|
ChaosBagApi.setChaosBagState = function(tokenList)
|
||||||
|
return Global.call("setChaosBagState", tokenList)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- returns a Table List of chaos token ids in the current chaos bag
|
||||||
|
-- requires copying the data into a new table because TTS is weird about handling table return values in Global
|
||||||
|
ChaosBagApi.getChaosBagState = function()
|
||||||
|
local chaosBagContentsCatcher = Global.call("getChaosBagState")
|
||||||
|
local chaosBagContents = {}
|
||||||
|
for _, v in ipairs(chaosBagContentsCatcher) do
|
||||||
|
table.insert(chaosBagContents, v)
|
||||||
|
end
|
||||||
|
return chaosBagContents
|
||||||
|
end
|
||||||
|
|
||||||
|
-- checks scripting zone for chaos bag (also called by a lot of objects!)
|
||||||
|
ChaosBagApi.findChaosBag = function()
|
||||||
|
return Global.call("findChaosBag")
|
||||||
|
end
|
||||||
|
|
||||||
|
return ChaosBagApi
|
||||||
|
end
|
@ -537,8 +537,38 @@ function getDataValue(storage, key)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function createChaosTokenNameLookupTable()
|
||||||
|
local namesToIds = {}
|
||||||
|
for k, v in pairs(ID_URL_MAP) do
|
||||||
|
namesToIds[v.name] = k
|
||||||
|
end
|
||||||
|
return namesToIds
|
||||||
|
end
|
||||||
|
|
||||||
|
-- returns a Table List of chaos token ids in the current chaos bag
|
||||||
|
---@api chaosbag/ChaosBagApi
|
||||||
|
function getChaosBagState()
|
||||||
|
local tokens = {}
|
||||||
|
local invertedTable = createChaosTokenNameLookupTable()
|
||||||
|
log(invertedTable)
|
||||||
|
local chaosbag = findChaosBag()
|
||||||
|
|
||||||
|
for _, v in ipairs(chaosbag.getObjects()) do
|
||||||
|
local id = invertedTable[v.name]
|
||||||
|
if id then
|
||||||
|
table.insert(tokens, id)
|
||||||
|
else
|
||||||
|
printToAll(v.name .. " token not recognized. Will not be recorded.", "Yellow")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return tokens
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
-- respawns the chaos bag with a new state of tokens
|
-- respawns the chaos bag with a new state of tokens
|
||||||
---@param tokenList Table List of chaos token ids
|
---@param tokenList Table List of chaos token ids
|
||||||
|
---@api chaosbag/ChaosBagApi
|
||||||
function setChaosBagState(tokenList)
|
function setChaosBagState(tokenList)
|
||||||
if not canTouchChaosTokens() then return end
|
if not canTouchChaosTokens() then return end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user