implemented call function
This commit is contained in:
parent
96f251183f
commit
6be0b197a4
@ -2383,6 +2383,22 @@ end
|
||||
-- Utility functions
|
||||
---------------------------------------------------------
|
||||
|
||||
-- allows calling a function inside of a table (like the TokenManager)
|
||||
function callTable(params)
|
||||
local keys = params[1] or {}
|
||||
local arg = params[2] or nil
|
||||
local var = _G
|
||||
for _, key in ipairs(keys) do
|
||||
var = var[key]
|
||||
if type(var) ~= "table" then break end
|
||||
end
|
||||
if type(var) ~= "function" then
|
||||
log("resulting var was not a function " .. table.concat(keys, "->"))
|
||||
return
|
||||
end
|
||||
return var(arg)
|
||||
end
|
||||
|
||||
-- removes a value from a table
|
||||
function removeValueFromTable(t, val)
|
||||
for i, v in ipairs(t) do
|
||||
|
@ -4,13 +4,19 @@ do
|
||||
-- Pushes new location data into the local copy of the Data Helper location data.
|
||||
---@param dataTable table Key/Value pairs following the DataHelper style
|
||||
function TokenManagerApi.addLocationData(dataTable)
|
||||
Global.call("TokenManager.addLocationData", dataTable)
|
||||
Global.call("callTable", {
|
||||
{ "TokenManager", "addLocationData" },
|
||||
dataTable
|
||||
})
|
||||
end
|
||||
|
||||
-- Pushes new player card data into the local copy of the Data Helper player data.
|
||||
---@param dataTable table Key/Value pairs following the DataHelper style
|
||||
function TokenManagerApi.addPlayerCardData(dataTable)
|
||||
Global.call("TokenManager.addPlayerCardData", dataTable)
|
||||
Global.call("callTable", {
|
||||
{ "TokenManager", "addPlayerCardData" },
|
||||
dataTable
|
||||
})
|
||||
end
|
||||
|
||||
-- Spawns tokens for the card. This function is built to just throw a card at it and let it do
|
||||
@ -21,7 +27,10 @@ do
|
||||
---@param extraUses table A table of <use type>=<count> which will modify the number of tokens
|
||||
--- spawned for that type. e.g. Akachi's playermat should pass "Charge"=1
|
||||
function TokenManagerApi.spawnForCard(card, extraUses)
|
||||
Global.call("TokenManager.spawnForCard", { card = card, extraUses = extraUses })
|
||||
Global.call("callTable", {
|
||||
{ "TokenManager", "spawnForCard" },
|
||||
{ card = card, extraUses = extraUses }
|
||||
})
|
||||
end
|
||||
|
||||
-- Spawns a single token at the given global position by copying it from the template bag.
|
||||
@ -31,11 +40,14 @@ do
|
||||
-- x and z will use the default rotation from the source bag
|
||||
---@param callback? function A callback function triggered after the new token is spawned
|
||||
function TokenManagerApi.spawnToken(position, tokenType, rotation, callback)
|
||||
Global.call("TokenManager.spawnToken", {
|
||||
position = position,
|
||||
tokenType = tokenType,
|
||||
rotation = rotation,
|
||||
callback = callback
|
||||
Global.call("callTable", {
|
||||
{ "TokenManager", "spawnToken" },
|
||||
{
|
||||
position = position,
|
||||
tokenType = tokenType,
|
||||
rotation = rotation,
|
||||
callback = callback
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
@ -47,12 +59,15 @@ do
|
||||
---@param shiftDown? number An offset for the z-value of this group of tokens
|
||||
---@param subType? string Subtype of token to spawn. This will only differ from the tokenName for resource tokens
|
||||
function TokenManagerApi.spawnTokenGroup(card, tokenType, tokenCount, shiftDown, subType)
|
||||
Global.call("TokenManager.spawnTokenGroup", {
|
||||
card = card,
|
||||
tokenType = tokenType,
|
||||
tokenCount = tokenCount,
|
||||
shiftDown = shiftDown,
|
||||
subType = subType
|
||||
Global.call("callTable", {
|
||||
{ "TokenManager", "spawnTokenGroup" },
|
||||
{
|
||||
card = card,
|
||||
tokenType = tokenType,
|
||||
tokenCount = tokenCount,
|
||||
shiftDown = shiftDown,
|
||||
subType = subType
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
@ -60,7 +75,10 @@ do
|
||||
---@param card tts__Object Card object to be replenished
|
||||
---@param uses table The already decoded metadata.uses (to avoid decoding again)
|
||||
function TokenManagerApi.maybeReplenishCard(card, uses)
|
||||
Global.call("TokenManager.maybeReplenishCard", { card = card, uses = uses })
|
||||
Global.call("callTable", {
|
||||
{ "TokenManager", "maybeReplenishCard" },
|
||||
{ card = card, uses = uses }
|
||||
})
|
||||
end
|
||||
|
||||
return TokenManagerApi
|
||||
|
@ -1129,9 +1129,7 @@ end
|
||||
|
||||
-- checks if tokens should be spawned for the provided card
|
||||
function shouldSpawnTokens(card)
|
||||
if card.is_face_down then
|
||||
return false
|
||||
end
|
||||
if card.is_face_down then return false end
|
||||
|
||||
local localCardPos = self.positionToLocal(card.getPosition())
|
||||
local metadata = JSON.decode(card.getGMNotes())
|
||||
|
Loading…
Reference in New Issue
Block a user