implemented call function
This commit is contained in:
parent
96f251183f
commit
6be0b197a4
@ -2383,6 +2383,22 @@ end
|
|||||||
-- Utility functions
|
-- 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
|
-- removes a value from a table
|
||||||
function removeValueFromTable(t, val)
|
function removeValueFromTable(t, val)
|
||||||
for i, v in ipairs(t) do
|
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.
|
-- Pushes new location data into the local copy of the Data Helper location data.
|
||||||
---@param dataTable table Key/Value pairs following the DataHelper style
|
---@param dataTable table Key/Value pairs following the DataHelper style
|
||||||
function TokenManagerApi.addLocationData(dataTable)
|
function TokenManagerApi.addLocationData(dataTable)
|
||||||
Global.call("TokenManager.addLocationData", dataTable)
|
Global.call("callTable", {
|
||||||
|
{ "TokenManager", "addLocationData" },
|
||||||
|
dataTable
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Pushes new player card data into the local copy of the Data Helper player data.
|
-- 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
|
---@param dataTable table Key/Value pairs following the DataHelper style
|
||||||
function TokenManagerApi.addPlayerCardData(dataTable)
|
function TokenManagerApi.addPlayerCardData(dataTable)
|
||||||
Global.call("TokenManager.addPlayerCardData", dataTable)
|
Global.call("callTable", {
|
||||||
|
{ "TokenManager", "addPlayerCardData" },
|
||||||
|
dataTable
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Spawns tokens for the card. This function is built to just throw a card at it and let it do
|
-- 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
|
---@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
|
--- spawned for that type. e.g. Akachi's playermat should pass "Charge"=1
|
||||||
function TokenManagerApi.spawnForCard(card, extraUses)
|
function TokenManagerApi.spawnForCard(card, extraUses)
|
||||||
Global.call("TokenManager.spawnForCard", { card = card, extraUses = extraUses })
|
Global.call("callTable", {
|
||||||
|
{ "TokenManager", "spawnForCard" },
|
||||||
|
{ card = card, extraUses = extraUses }
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Spawns a single token at the given global position by copying it from the template bag.
|
-- 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
|
-- 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
|
---@param callback? function A callback function triggered after the new token is spawned
|
||||||
function TokenManagerApi.spawnToken(position, tokenType, rotation, callback)
|
function TokenManagerApi.spawnToken(position, tokenType, rotation, callback)
|
||||||
Global.call("TokenManager.spawnToken", {
|
Global.call("callTable", {
|
||||||
position = position,
|
{ "TokenManager", "spawnToken" },
|
||||||
tokenType = tokenType,
|
{
|
||||||
rotation = rotation,
|
position = position,
|
||||||
callback = callback
|
tokenType = tokenType,
|
||||||
|
rotation = rotation,
|
||||||
|
callback = callback
|
||||||
|
}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -47,12 +59,15 @@ do
|
|||||||
---@param shiftDown? number An offset for the z-value of this group of tokens
|
---@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
|
---@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)
|
function TokenManagerApi.spawnTokenGroup(card, tokenType, tokenCount, shiftDown, subType)
|
||||||
Global.call("TokenManager.spawnTokenGroup", {
|
Global.call("callTable", {
|
||||||
card = card,
|
{ "TokenManager", "spawnTokenGroup" },
|
||||||
tokenType = tokenType,
|
{
|
||||||
tokenCount = tokenCount,
|
card = card,
|
||||||
shiftDown = shiftDown,
|
tokenType = tokenType,
|
||||||
subType = subType
|
tokenCount = tokenCount,
|
||||||
|
shiftDown = shiftDown,
|
||||||
|
subType = subType
|
||||||
|
}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -60,7 +75,10 @@ do
|
|||||||
---@param card tts__Object Card object to be replenished
|
---@param card tts__Object Card object to be replenished
|
||||||
---@param uses table The already decoded metadata.uses (to avoid decoding again)
|
---@param uses table The already decoded metadata.uses (to avoid decoding again)
|
||||||
function TokenManagerApi.maybeReplenishCard(card, uses)
|
function TokenManagerApi.maybeReplenishCard(card, uses)
|
||||||
Global.call("TokenManager.maybeReplenishCard", { card = card, uses = uses })
|
Global.call("callTable", {
|
||||||
|
{ "TokenManager", "maybeReplenishCard" },
|
||||||
|
{ card = card, uses = uses }
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
return TokenManagerApi
|
return TokenManagerApi
|
||||||
|
@ -1129,9 +1129,7 @@ end
|
|||||||
|
|
||||||
-- checks if tokens should be spawned for the provided card
|
-- checks if tokens should be spawned for the provided card
|
||||||
function shouldSpawnTokens(card)
|
function shouldSpawnTokens(card)
|
||||||
if card.is_face_down then
|
if card.is_face_down then return false end
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local localCardPos = self.positionToLocal(card.getPosition())
|
local localCardPos = self.positionToLocal(card.getPosition())
|
||||||
local metadata = JSON.decode(card.getGMNotes())
|
local metadata = JSON.decode(card.getGMNotes())
|
||||||
|
Loading…
Reference in New Issue
Block a user