Merge branch 'main' into clean-up-helper

This commit is contained in:
Chr1Z93 2024-10-27 21:35:11 +01:00
commit 7052f312f5
5 changed files with 65 additions and 85 deletions

View File

@ -2299,7 +2299,7 @@ function TokenManager.spawnToken(params)
end end
TokenManager.initTokenTemplates() TokenManager.initTokenTemplates()
local tokenTemplate = tokenTemplates[loadTokenType] local tokenTemplate = deepCopy(tokenTemplates[loadTokenType])
if tokenTemplate == nil then if tokenTemplate == nil then
error("Unknown token type '" .. loadTokenType .. "'") error("Unknown token type '" .. loadTokenType .. "'")
return return

View File

@ -41,7 +41,7 @@ end
function onLoad(savedData) function onLoad(savedData)
if savedData and savedData ~= "" then if savedData and savedData ~= "" then
local loadedState = JSON.decode(savedData) or {} local loadedState = JSON.decode(savedData) or {}
scenarioCard = getObjectFromGUID(loadedState.scenarioCardGUID) or nil scenarioCard = getObjectFromGUID(loadedState.scenarioCardGuid) or nil
currentScenario = loadedState.currentScenario or "" currentScenario = loadedState.currentScenario or ""
useFrontData = loadedState.useFrontData or true useFrontData = loadedState.useFrontData or true
tokenData = loadedState.tokenData or {} tokenData = loadedState.tokenData or {}
@ -105,9 +105,9 @@ function onCollisionEnter(collisionInfo)
local cardName = object.getName() local cardName = object.getName()
if cardName == "Scenario" or md.type == "ScenarioReference" then if cardName == "Scenario" or md.type == "ScenarioReference" then
getDataFromReferenceCard(object, cardName, md)
scenarioCard = object scenarioCard = object
scenarioCard.setPosition({ -3.85, 1.60, -10.39 }) scenarioCard.setPosition({ -3.85, 1.60, -10.39 })
getDataFromReferenceCard(scenarioCard, cardName, md)
end end
end end
end end

View File

@ -50,7 +50,8 @@ do
-- x and z will use the default rotation from the source bag -- x and z will use the default rotation from the source bag
---@param callbackName? string Name of the callback function (in Global) ---@param callbackName? string Name of the callback function (in Global)
---@param callbackParams? any Parameters for the callback function ---@param callbackParams? any Parameters for the callback function
function TokenManagerApi.spawnToken(position, tokenType, rotation, callbackName, callbackParams) ---@param scriptstate? any Scriptstate for the token
function TokenManagerApi.spawnToken(position, tokenType, rotation, callbackName, callbackParams, scriptstate)
Global.call("callTable", { Global.call("callTable", {
{ "TokenManager", "spawnToken" }, { "TokenManager", "spawnToken" },
{ {
@ -58,7 +59,8 @@ do
rotation = rotation, rotation = rotation,
tokenType = tokenType, tokenType = tokenType,
callbackName = callbackName, callbackName = callbackName,
callbackParams = callbackParams callbackParams = callbackParams,
scriptstate = scriptstate
} }
}) })
end end

View File

@ -403,8 +403,8 @@ function doUpkeep(_, clickedByColor, isRightClick)
-- flip investigator mini-card and summoned servitor mini-card -- flip investigator mini-card and summoned servitor mini-card
for _, obj in ipairs(getObjects()) do for _, obj in ipairs(getObjects()) do
if obj.type == "Card" and obj.is_face_down then if obj.type == "Card" and obj.is_face_down then
local notes = JSON.decode(obj.getGMNotes()) local md = JSON.decode(obj.getGMNotes()) or {}
if notes ~= nil and notes.type == "Minicard" and (notes.id == activeInvestigatorData.miniId or notes.id == "09080-m") then if md.type == "Minicard" and (md.id == activeInvestigatorData.miniId or md.id == "09080-m") then
obj.flip() obj.flip()
end end
end end
@ -1141,12 +1141,11 @@ end
-- number of customizable cards in play. -- number of customizable cards in play.
function syncAllCustomizableCards() function syncAllCustomizableCards()
for _, card in ipairs(searchAroundSelf("isCard")) do for _, card in ipairs(searchAroundSelf("isCard")) do
syncCustomizableMetadata(card) syncCustomizableMetadata(card, JSON.decode(card.getGMNotes()))
end end
end end
function syncCustomizableMetadata(card) function syncCustomizableMetadata(card, cardMetadata)
local cardMetadata = JSON.decode(card.getGMNotes()) or {}
if cardMetadata == nil or cardMetadata.customizations == nil then return end if cardMetadata == nil or cardMetadata.customizations == nil then return end
for _, upgradeSheet in ipairs(searchAroundSelf("isCard")) do for _, upgradeSheet in ipairs(searchAroundSelf("isCard")) do
@ -1189,62 +1188,45 @@ function onCollisionEnter(collisionInfo)
-- only continue for cards -- only continue for cards
if object.type ~= "Card" then return end if object.type ~= "Card" then return end
maybeUpdateActiveInvestigator(object) local md = JSON.decode(object.getGMNotes()) or {}
syncCustomizableMetadata(object) syncCustomizableMetadata(object, md)
local localCardPos = self.positionToLocal(object.getPosition()) local localCardPos = self.positionToLocal(object.getPosition())
if inArea(localCardPos, DECK_DISCARD_AREA) then if inArea(localCardPos, INVESTIGATOR_AREA) then
if md.type == "Investigator" and md.id ~= nil then
maybeUpdateActiveInvestigator(object, md)
-- this is mostly for helpers like Stella and Kohaku
spawnTokensOrShowHelper(object)
end
elseif inArea(localCardPos, DECK_DISCARD_AREA) then
tokenSpawnTrackerApi.resetTokensSpawned(object) tokenSpawnTrackerApi.resetTokensSpawned(object)
removeTokensFromObject(object) removeTokensFromObject(object)
else
if shouldSpawnTokensOrShowHelper(object) then elseif object.is_face_down == false then
if object.hasTag("CardWithHelper") then -- main uses spawning
-- get state of the option panel if inArea(localCardPos, MAIN_PLAY_AREA) and (md.type == "Asset" or md.type == "Event") then
local options = GlobalApi.getOptionPanelState() spawnTokensOrShowHelper(object)
if options.enableCardHelpers then end
object.call("setHelperState", true)
end -- encounter types / committed skill cards in the threat area
else if inArea(localCardPos, THREAT_AREA) and (md.type == "Treachery" or md.type == "Enemy" or md.type == "Skill" or md.weakness) then
spawnTokensFor(object) spawnTokensOrShowHelper(object)
end
end end
end end
end end
-- checks if tokens should be spawned for the provided card function spawnTokensOrShowHelper(card)
function shouldSpawnTokensOrShowHelper(card) spawnTokensFor(card)
if card.is_face_down then return false end
local localCardPos = self.positionToLocal(card.getPosition()) if card.hasTag("CardWithHelper") then
local metadata = JSON.decode(card.getGMNotes()) -- get state of the option panel
local options = GlobalApi.getOptionPanelState()
-- If no metadata we don't know the type, so only spawn in the main area if options.enableCardHelpers then
if metadata == nil then card.call("setHelperState", true)
return inArea(localCardPos, MAIN_PLAY_AREA) end
end end
-- Spawn tokens for assets and events on the main area
if inArea(localCardPos, MAIN_PLAY_AREA)
and (metadata.type == "Asset"
or metadata.type == "Event") then
return true
end
if inArea(localCardPos, INVESTIGATOR_AREA)
and (metadata.type == "Investigator") then -- this is mostly for helpers like Stella and Kohaku
return true
end
-- Spawn tokens for all encounter types in the threat area
if inArea(localCardPos, THREAT_AREA)
and (metadata.type == "Treachery"
or metadata.type == "Enemy"
or metadata.type == "Skill"
or metadata.weakness) then
return true
end
return false
end end
function onObjectEnterContainer(container, object) function onObjectEnterContainer(container, object)
@ -1286,32 +1268,24 @@ end
-- updates the internal investigator data and performs additional operations if an investigator card is detected -- updates the internal investigator data and performs additional operations if an investigator card is detected
---@param card tts__Object Card that might be an investigator ---@param card tts__Object Card that might be an investigator
function maybeUpdateActiveInvestigator(card) ---@param md table Metadata for the card
-- don't continue if this card is not in the investigator area function maybeUpdateActiveInvestigator(card, md)
if not inArea(self.positionToLocal(card.getPosition()), INVESTIGATOR_AREA) then return end
-- get metadata
local notes = JSON.decode(card.getGMNotes()) or {}
-- don't continue for cards without proper metadata
if notes.type ~= "Investigator" or notes.id == nil then return end
-- don't continue if this is already the active investigator -- don't continue if this is already the active investigator
if notes.id == activeInvestigatorData.id then return end if md.id == activeInvestigatorData.id then return end
-- extract relevant data from the metadata -- extract relevant data from the metadata
activeInvestigatorData.class = notes.class activeInvestigatorData.class = md.class
activeInvestigatorData.id = notes.id activeInvestigatorData.id = md.id
activeInvestigatorData.miniId = getMiniId(notes.id) activeInvestigatorData.miniId = getMiniId(md.id)
ownedObjects.InvestigatorSkillTracker.call("updateStats", { ownedObjects.InvestigatorSkillTracker.call("updateStats", {
notes.willpowerIcons, md.willpowerIcons,
notes.intellectIcons, md.intellectIcons,
notes.combatIcons, md.combatIcons,
notes.agilityIcons md.agilityIcons
}) })
updateTexture() updateTexture()
newInvestigatorCallback(notes.id) newInvestigatorCallback(md.id)
-- set proper scale for investigators -- set proper scale for investigators
local cardData = card.getData() local cardData = card.getData()
@ -1332,7 +1306,7 @@ function maybeUpdateActiveInvestigator(card)
spawnActionTokens() spawnActionTokens()
-- spawn additional token (maybe specific for investigator) -- spawn additional token (maybe specific for investigator)
if notes.extraToken and notes.extraToken ~= "None" then if md.extraToken and md.extraToken ~= "None" then
local tokenType = "universalActionAbility" local tokenType = "universalActionAbility"
local rotation = self.getRotation() local rotation = self.getRotation()
local callbackName = "updateUniversalActionAbilityToken" local callbackName = "updateUniversalActionAbilityToken"
@ -1340,7 +1314,7 @@ function maybeUpdateActiveInvestigator(card)
-- spawn tokens (split string by "|") -- spawn tokens (split string by "|")
local count = { action = 0, ability = 0 } local count = { action = 0, ability = 0 }
for str in string.gmatch(notes.extraToken, "([^|]+)") do for str in string.gmatch(md.extraToken, "([^|]+)") do
local type = "action" local type = "action"
if str == "FreeTrigger" or str == "Reaction" then if str == "FreeTrigger" or str == "Reaction" then
type = "ability" type = "ability"
@ -1452,12 +1426,12 @@ function updateTexture(overrideName)
-- apply texture -- apply texture
local customInfo = self.getCustomObject() local customInfo = self.getCustomObject()
if customInfo.image ~= newUrl then if customInfo.image ~= newUrl then
-- temporarily lock objects so they don't fall through the mat -- make sure objects are resting and store position
local objectsToUnlock = {} local objectsToUnlock = {}
for _, obj in ipairs(searchAroundSelf()) do for _, obj in ipairs(searchAroundSelf()) do
if not obj.getLock() then if not obj.getLock() then
obj.setLock(true) obj.resting = true
table.insert(objectsToUnlock, obj) table.insert(objectsToUnlock, { obj = obj, pos = obj.getPosition() })
end end
end end
@ -1466,12 +1440,14 @@ function updateTexture(overrideName)
self.setCustomObject(customInfo) self.setCustomObject(customInfo)
local reloadedMat = self.reload() local reloadedMat = self.reload()
-- unlock objects when mat is reloaded -- restore object positions
Wait.condition(function() Wait.condition(function()
Wait.frames(function() Wait.frames(function()
for _, obj in ipairs(objectsToUnlock) do for _, objTable in ipairs(objectsToUnlock) do
obj.setLock(false) if objTable.obj ~= nil then
obj.resting = true objTable.obj.resting = true
objTable.obj.setPosition(objTable.pos)
end
end end
end, 5) end, 5)
end, function() return reloadedMat.loading_custom == false end) end, function() return reloadedMat.loading_custom == false end)

View File

@ -23,6 +23,7 @@ function onScriptingButtonDown(index, playerColor)
local rotation = Vector(0, Player[playerColor].getPointerRotation(), 0) local rotation = Vector(0, Player[playerColor].getPointerRotation(), 0)
callbackName = nil callbackName = nil
callbackParams = nil callbackParams = nil
scriptstate = nil
-- check for subtype of resource based on card below -- check for subtype of resource based on card below
if tokenType == "resource" then if tokenType == "resource" then
@ -59,6 +60,7 @@ function onScriptingButtonDown(index, playerColor)
hoverObj.call("modifyValue", 1) hoverObj.call("modifyValue", 1)
return return
end end
scriptstate = 1
-- check for nearest investigator card and change action token state to its class -- check for nearest investigator card and change action token state to its class
elseif tokenType == "universalActionAbility" then elseif tokenType == "universalActionAbility" then