Merge pull request #682 from argonui/object-owner
Added function to get owner of an object
This commit is contained in:
commit
b027f2495b
@ -5,6 +5,7 @@ do
|
|||||||
return getObjectFromGUID("123456")
|
return getObjectFromGUID("123456")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Returns the matching object
|
||||||
---@param owner string Parent object for this search
|
---@param owner string Parent object for this search
|
||||||
---@param type string Type of object to search for
|
---@param type string Type of object to search for
|
||||||
---@return any: Object reference to the matching object
|
---@return any: Object reference to the matching object
|
||||||
@ -12,21 +13,21 @@ do
|
|||||||
return getGuidHandler().call("getObjectByOwnerAndType", { owner = owner, type = type })
|
return getGuidHandler().call("getObjectByOwnerAndType", { owner = owner, type = type })
|
||||||
end
|
end
|
||||||
|
|
||||||
-- returns all matching objects as a table with references
|
-- Returns all matching objects as a table with references
|
||||||
---@param type string Type of object to search for
|
---@param type string Type of object to search for
|
||||||
---@return table: List of object references to matching objects
|
---@return table: List of object references to matching objects
|
||||||
GUIDReferenceApi.getObjectsByType = function(type)
|
GUIDReferenceApi.getObjectsByType = function(type)
|
||||||
return getGuidHandler().call("getObjectsByType", type)
|
return getGuidHandler().call("getObjectsByType", type)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- returns all matching objects as a table with references
|
-- Returns all matching objects as a table with references
|
||||||
---@param owner string Parent object for this search
|
---@param owner string Parent object for this search
|
||||||
---@return table: List of object references to matching objects
|
---@return table: List of object references to matching objects
|
||||||
GUIDReferenceApi.getObjectsByOwner = function(owner)
|
GUIDReferenceApi.getObjectsByOwner = function(owner)
|
||||||
return getGuidHandler().call("getObjectsByOwner", owner)
|
return getGuidHandler().call("getObjectsByOwner", owner)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- sends new information to the reference handler to edit the main index
|
-- Sends new information to the reference handler to edit the main index
|
||||||
---@param owner string Parent of the object
|
---@param owner string Parent of the object
|
||||||
---@param type string Type of the object
|
---@param type string Type of the object
|
||||||
---@param guid string GUID of the object
|
---@param guid string GUID of the object
|
||||||
@ -38,5 +39,12 @@ do
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Returns the owner of an object or the object it's located on
|
||||||
|
---@param object tts__GameObject Object for this search
|
||||||
|
---@return string: Parent of the object or object it's located on
|
||||||
|
GUIDReferenceApi.getOwnerOfObject = function(object)
|
||||||
|
return getGuidHandler().call("getOwnerOfObject", object)
|
||||||
|
end
|
||||||
|
|
||||||
return GUIDReferenceApi
|
return GUIDReferenceApi
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
local searchLib = require("util/SearchLib")
|
||||||
|
|
||||||
local GuidReferences = {
|
local GuidReferences = {
|
||||||
White = {
|
White = {
|
||||||
ClueCounter = "d86b7c",
|
ClueCounter = "d86b7c",
|
||||||
@ -156,3 +158,37 @@ function editIndex(params)
|
|||||||
editsToIndex[params.owner][params.type] = params.guid
|
editsToIndex[params.owner][params.type] = params.guid
|
||||||
updateMainIndex()
|
updateMainIndex()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Returns the owner of the provided object (either the matColor or "Mythos")
|
||||||
|
---@param object tts__GameObject Object to check
|
||||||
|
function getOwnerOfObject(object)
|
||||||
|
if object == nil then return end
|
||||||
|
|
||||||
|
-- use GUID to check owners instead of obtaining each as reference
|
||||||
|
local objectGuid = object.getGUID()
|
||||||
|
|
||||||
|
-- check if object is directly owned
|
||||||
|
for owner, subtable in pairs(GuidReferences) do
|
||||||
|
for type, guid in pairs(subtable) do
|
||||||
|
if guid == objectGuid then
|
||||||
|
return owner
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- check if it is on an owned object
|
||||||
|
local result = searchLib.belowPosition(object.getPosition())
|
||||||
|
|
||||||
|
for owner, subtable in pairs(GuidReferences) do
|
||||||
|
for type, guid in pairs(subtable) do
|
||||||
|
for _, searchObj in ipairs(result) do
|
||||||
|
if guid == searchObj.getGUID() then
|
||||||
|
return owner
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- default to "Mythos"
|
||||||
|
return "Mythos"
|
||||||
|
end
|
||||||
|
@ -280,7 +280,7 @@ end
|
|||||||
-- This method will broadcast a message to all players if the bag is being searched.
|
-- This method will broadcast a message to all players if the bag is being searched.
|
||||||
---@return boolean: True if the bag is manipulated, false if it should be blocked.
|
---@return boolean: True if the bag is manipulated, false if it should be blocked.
|
||||||
function canTouchChaosTokens()
|
function canTouchChaosTokens()
|
||||||
for color, searching in pairs(bagSearchers) do
|
for _, searching in pairs(bagSearchers) do
|
||||||
if searching then
|
if searching then
|
||||||
broadcastToAll("Someone is searching the chaos bag, can't touch the tokens.", "Red")
|
broadcastToAll("Someone is searching the chaos bag, can't touch the tokens.", "Red")
|
||||||
return false
|
return false
|
||||||
@ -331,7 +331,6 @@ function drawChaosToken(params)
|
|||||||
local takeParameters = {}
|
local takeParameters = {}
|
||||||
|
|
||||||
-- add the token to the list, compute new position based on list length
|
-- add the token to the list, compute new position based on list length
|
||||||
|
|
||||||
if params.returnedToken then
|
if params.returnedToken then
|
||||||
trackChaosToken(params.returnedToken.getName(), matGUID, true)
|
trackChaosToken(params.returnedToken.getName(), matGUID, true)
|
||||||
indexOfReturnedToken = getTokenIndex(params.returnedToken)
|
indexOfReturnedToken = getTokenIndex(params.returnedToken)
|
||||||
@ -349,9 +348,8 @@ function drawChaosToken(params)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local token
|
local token
|
||||||
|
|
||||||
-- resolve a sealed token from a card
|
|
||||||
if params.guidToBeResolved then
|
if params.guidToBeResolved then
|
||||||
|
-- resolve a sealed token from a card
|
||||||
token = getObjectFromGUID(params.guidToBeResolved)
|
token = getObjectFromGUID(params.guidToBeResolved)
|
||||||
token.setPositionSmooth(takeParameters.position)
|
token.setPositionSmooth(takeParameters.position)
|
||||||
local guid = token.getGUID()
|
local guid = token.getGUID()
|
||||||
@ -360,10 +358,8 @@ function drawChaosToken(params)
|
|||||||
blessCurseManagerApi.releasedToken(tokenType, guid)
|
blessCurseManagerApi.releasedToken(tokenType, guid)
|
||||||
end
|
end
|
||||||
tokenArrangerApi.layout()
|
tokenArrangerApi.layout()
|
||||||
|
|
||||||
-- take a token from the bag, either specified or random
|
|
||||||
else
|
else
|
||||||
|
-- take a token from the bag, either specified or random
|
||||||
if params.tokenType then
|
if params.tokenType then
|
||||||
for i, lookedForToken in ipairs(chaosBag.getObjects()) do
|
for i, lookedForToken in ipairs(chaosBag.getObjects()) do
|
||||||
if lookedForToken.nickname == params.tokenType then
|
if lookedForToken.nickname == params.tokenType then
|
||||||
@ -371,19 +367,16 @@ function drawChaosToken(params)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
token = chaosBag.takeObject(takeParameters)
|
token = chaosBag.takeObject(takeParameters)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get data for token description
|
-- get data for token description
|
||||||
local name = token.getName()
|
local name = token.getName()
|
||||||
|
|
||||||
local tokenData = mythosAreaApi.returnTokenData().tokenData or {}
|
local tokenData = mythosAreaApi.returnTokenData().tokenData or {}
|
||||||
local specificData = tokenData[name] or {}
|
local specificData = tokenData[name] or {}
|
||||||
token.setDescription(specificData.description or "")
|
token.setDescription(specificData.description or "")
|
||||||
|
|
||||||
-- track the chaos token (for stat tracker and future returning)
|
|
||||||
trackChaosToken(name, matGUID)
|
trackChaosToken(name, matGUID)
|
||||||
|
|
||||||
if params.returnedToken then
|
if params.returnedToken then
|
||||||
chaosTokens[indexOfReturnedToken] = token
|
chaosTokens[indexOfReturnedToken] = token
|
||||||
else
|
else
|
||||||
@ -750,16 +743,6 @@ function removeChaosToken(id)
|
|||||||
printToAll("Removing " .. name .. " token (in bag: " .. #tokens - 1 .. ")", "White")
|
printToAll("Removing " .. name .. " token (in bag: " .. #tokens - 1 .. ")", "White")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- empty the chaos bag
|
|
||||||
function emptyChaosBag()
|
|
||||||
if not canTouchChaosTokens() then return end
|
|
||||||
|
|
||||||
local chaosBag = findChaosBag()
|
|
||||||
for _, object in ipairs(chaosBag.getObjects()) do
|
|
||||||
chaosBag.takeObject({ callback_function = function(item) item.destruct() end })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- returns all sealed tokens on cards to the chaos bag
|
-- returns all sealed tokens on cards to the chaos bag
|
||||||
function releaseAllSealedTokens(playerColor)
|
function releaseAllSealedTokens(playerColor)
|
||||||
for _, obj in ipairs(getObjectsWithTag("CardThatSeals")) do
|
for _, obj in ipairs(getObjectsWithTag("CardThatSeals")) do
|
||||||
|
Loading…
Reference in New Issue
Block a user