This commit is contained in:
Chr1Z93 2023-10-02 14:08:26 +02:00
parent 47004e773a
commit 8de5fc6b56
2 changed files with 31 additions and 53 deletions

View File

@ -8,8 +8,6 @@ local tokenArrangerApi = require("accessories/TokenArrangerApi")
local tokenChecker = require("core/token/TokenChecker") local tokenChecker = require("core/token/TokenChecker")
local tokenManager = require("core/token/TokenManager") local tokenManager = require("core/token/TokenManager")
local guidHandler = getObjectsWithTag("GUIDs")[1]
--------------------------------------------------------- ---------------------------------------------------------
-- general setup -- general setup
--------------------------------------------------------- ---------------------------------------------------------
@ -31,7 +29,7 @@ local NOT_INTERACTABLE = {
"975c39", -- vertical border right "975c39", -- vertical border right
} }
local DATA_HELPER local guidHandler, DATA_HELPER
local chaosTokens = {} local chaosTokens = {}
local chaosTokensLastMat = nil local chaosTokensLastMat = nil
local bagSearchers = {} local bagSearchers = {}
@ -129,7 +127,8 @@ function onLoad(savedData)
if obj ~= nil then obj.interactable = false end if obj ~= nil then obj.interactable = false end
end end
--DATA_HELPER = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "DataHelper" }) guidHandler = getObjectsWithTag("GUIDs")[1]
DATA_HELPER = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "DataHelper" })
resetChaosTokenStatTracker() resetChaosTokenStatTracker()
getModVersion() getModVersion()
math.randomseed(os.time()) math.randomseed(os.time())
@ -907,7 +906,7 @@ function applyOptionPanelChange(id, state)
for i, color in ipairs(MAT_COLORS) do for i, color in ipairs(MAT_COLORS) do
local pos = playmatApi.transformLocalPosition({0.05, 0, -1.182}, color) local pos = playmatApi.transformLocalPosition({0.05, 0, -1.182}, color)
local rot = playmatApi.returnRotation(color) local rot = playmatApi.returnRotation(color)
optionPanel[id][i] = spawnOrRemoveHelper(state, "Hand Helper", pos, rot, color) optionPanel[id][i] = spawnOrRemoveHelper(state, "Hand Helper", pos, rot)
end end
-- option: Show search assistant for each player -- option: Show search assistant for each player
@ -915,7 +914,7 @@ function applyOptionPanelChange(id, state)
for i, color in ipairs(MAT_COLORS) do for i, color in ipairs(MAT_COLORS) do
local pos = playmatApi.transformLocalPosition({-0.3, 0, -1.182}, color) local pos = playmatApi.transformLocalPosition({-0.3, 0, -1.182}, color)
local rot = playmatApi.returnRotation(color) local rot = playmatApi.returnRotation(color)
optionPanel[id][i] = spawnOrRemoveHelper(state, "Search Assistant", pos, rot, color) optionPanel[id][i] = spawnOrRemoveHelper(state, "Search Assistant", pos, rot)
end end
-- option: Show attachment helper -- option: Show attachment helper
@ -942,12 +941,12 @@ end
---@param position Vector Position of the object (where it will spawn) ---@param position Vector Position of the object (where it will spawn)
---@param rotation Vector Rotation of the object for spawning (default: {0, 270, 0}) ---@param rotation Vector Rotation of the object for spawning (default: {0, 270, 0})
---@return. GUID of the spawnedObj (or nil if object was removed) ---@return. GUID of the spawnedObj (or nil if object was removed)
function spawnOrRemoveHelper(state, name, position, rotation, color) function spawnOrRemoveHelper(state, name, position, rotation)
if (type(state) == "table" and #state == 0) then if (type(state) == "table" and #state == 0) then
return removeHelperObject(name) return removeHelperObject(name)
elseif state then elseif state then
Player.getPlayers()[1].pingTable(position) Player.getPlayers()[1].pingTable(position)
return spawnHelperObject(name, position, rotation, color).getGUID() return spawnHelperObject(name, position, rotation).getGUID()
else else
return removeHelperObject(name) return removeHelperObject(name)
end end
@ -957,8 +956,7 @@ end
---@param name String Name of the object that should be copied ---@param name String Name of the object that should be copied
---@param position Table Desired position of the object ---@param position Table Desired position of the object
---@param rotation Table Desired rotation of the object (defaults to object's rotation) ---@param rotation Table Desired rotation of the object (defaults to object's rotation)
---@param color String Matcolor this object is spawned for to set memo function spawnHelperObject(name, position, rotation)
function spawnHelperObject(name, position, rotation, color)
local sourceBag = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "OptionPanelSource" }) local sourceBag = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "OptionPanelSource" })
-- error handling for missing sourceBag -- error handling for missing sourceBag
@ -977,12 +975,6 @@ function spawnHelperObject(name, position, rotation, color)
for _, obj in ipairs(sourceBag.getData().ContainedObjects) do for _, obj in ipairs(sourceBag.getData().ContainedObjects) do
if obj["Nickname"] == name then if obj["Nickname"] == name then
spawnTable.data = obj spawnTable.data = obj
-- this set the memo to identify the object at a later point (type = name without spaces)
if color then
spawnTable.data["Memo"] = "{\"matColor\":\"" .. color .. "\",\"type\":\"" .. name:gsub("%s+", "") .. "\"}"
end
spawnTable.callback_function = function(spawnedObj) spawnTable.callback_function = function(spawnedObj)
Wait.time(function() spawnedObj.setLock(true) end, 2) Wait.time(function() spawnedObj.setLock(true) end, 2)
end end

View File

@ -6,18 +6,11 @@ do
---@param startPos Table Starting position to get the closest mat from ---@param startPos Table Starting position to get the closest mat from
PlaymatApi.getMatColorByPosition = function(startPos) PlaymatApi.getMatColorByPosition = function(startPos)
local result, smallestDistance local result, smallestDistance
for _, mat in ipairs(internal.getMatForColor("All")) do for matColor, mat in pairs(internal.getMatForColor("All")) do
local distance = Vector.between(startPos, mat.getPosition()):magnitude() local distance = Vector.between(startPos, mat.getPosition()):magnitude()
if smallestDistance == nil or distance < smallestDistance then if smallestDistance == nil or distance < smallestDistance then
smallestDistance = distance smallestDistance = distance
for _, tag in ipairs(mat.getTags) do result = matColor
if tag == "White"
or tag == "Orange"
or tag == "Green"
or tag == "Red" then
result = tag
end
end
end end
end end
return result return result
@ -26,7 +19,7 @@ do
-- Returns the color of the player's hand that is seated next to the playmat -- Returns the color of the player's hand that is seated next to the playmat
---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All") ---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All")
PlaymatApi.getPlayerColor = function(matColor) PlaymatApi.getPlayerColor = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
return mat.getVar("playerColor") return mat.getVar("playerColor")
end end
end end
@ -34,17 +27,10 @@ do
-- Returns the color of the playmat that owns the playercolor's hand -- Returns the color of the playmat that owns the playercolor's hand
---@param handColor String Color of the playmat ---@param handColor String Color of the playmat
PlaymatApi.getMatColor = function(handColor) PlaymatApi.getMatColor = function(handColor)
for _, mat in ipairs(internal.getMatForColor("All")) do for matColor, mat in pairs(internal.getMatForColor("All")) do
local playerColor = mat.getVar("playerColor") local playerColor = mat.getVar("playerColor")
if playerColor == handColor then if playerColor == handColor then
for _, tag in ipairs(mat.getTags) do return matColor
if tag == "White"
or tag == "Orange"
or tag == "Green"
or tag == "Red" then
return tag
end
end
end end
end end
end end
@ -52,7 +38,7 @@ do
-- Returns if there is the card "Dream-Enhancing Serum" on the requested playmat -- Returns if there is the card "Dream-Enhancing Serum" on the requested playmat
---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All") ---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All")
PlaymatApi.isDES = function(matColor) PlaymatApi.isDES = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
return mat.getVar("isDES") return mat.getVar("isDES")
end end
end end
@ -60,7 +46,7 @@ do
-- Returns the draw deck of the requested playmat -- Returns the draw deck of the requested playmat
---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All") ---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All")
PlaymatApi.getDrawDeck = function(matColor) PlaymatApi.getDrawDeck = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
mat.call("getDrawDiscardDecks") mat.call("getDrawDiscardDecks")
return mat.getVar("drawDeck") return mat.getVar("drawDeck")
end end
@ -69,7 +55,7 @@ do
-- Returns the position of the discard pile of the requested playmat -- Returns the position of the discard pile of the requested playmat
---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All") ---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All")
PlaymatApi.getDiscardPosition = function(matColor) PlaymatApi.getDiscardPosition = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
return mat.call("returnGlobalDiscardPosition") return mat.call("returnGlobalDiscardPosition")
end end
end end
@ -78,7 +64,7 @@ do
---@param localPos Table Local position to be transformed ---@param localPos Table Local position to be transformed
---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All") ---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All")
PlaymatApi.transformLocalPosition = function(localPos, matColor) PlaymatApi.transformLocalPosition = function(localPos, matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
return mat.positionToWorld(localPos) return mat.positionToWorld(localPos)
end end
end end
@ -86,7 +72,7 @@ do
-- Returns the rotation of the requested playmat -- Returns the rotation of the requested playmat
---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All") ---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All")
PlaymatApi.returnRotation = function(matColor) PlaymatApi.returnRotation = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
return mat.getRotation() return mat.getRotation()
end end
end end
@ -95,7 +81,7 @@ do
---@param matColor String Color of the playmat - White, Orange, Green, Red or All ---@param matColor String Color of the playmat - White, Orange, Green, Red or All
---@param playerColor String Color of the calling player (for messages) ---@param playerColor String Color of the calling player (for messages)
PlaymatApi.doUpkeepFromHotkey = function(matColor, playerColor) PlaymatApi.doUpkeepFromHotkey = function(matColor, playerColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
mat.call("doUpkeepFromHotkey", playerColor) mat.call("doUpkeepFromHotkey", playerColor)
end end
end end
@ -103,7 +89,7 @@ do
-- Returns the active investigator id -- Returns the active investigator id
---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All") ---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All")
PlaymatApi.returnInvestigatorId = function(matColor) PlaymatApi.returnInvestigatorId = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
return mat.getVar("activeInvestigatorId") return mat.getVar("activeInvestigatorId")
end end
end end
@ -115,7 +101,7 @@ do
---@param matchCardTypes Boolean Whether snap points should only snap for the matching card types ---@param matchCardTypes Boolean Whether snap points should only snap for the matching card types
---@param matColor String Color of the playmat - White, Orange, Green, Red or All ---@param matColor String Color of the playmat - White, Orange, Green, Red or All
PlaymatApi.setLimitSnapsByType = function(matchCardTypes, matColor) PlaymatApi.setLimitSnapsByType = function(matchCardTypes, matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
mat.call("setLimitSnapsByType", matchCardTypes) mat.call("setLimitSnapsByType", matchCardTypes)
end end
end end
@ -124,7 +110,7 @@ do
---@param isDrawButtonVisible Boolean Whether the draw 1 button should be visible or not ---@param isDrawButtonVisible Boolean Whether the draw 1 button should be visible or not
---@param matColor String Color of the playmat - White, Orange, Green, Red or All ---@param matColor String Color of the playmat - White, Orange, Green, Red or All
PlaymatApi.showDrawButton = function(isDrawButtonVisible, matColor) PlaymatApi.showDrawButton = function(isDrawButtonVisible, matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
mat.call("showDrawButton", isDrawButtonVisible) mat.call("showDrawButton", isDrawButtonVisible)
end end
end end
@ -133,7 +119,7 @@ do
---@param showCounter Boolean Whether the clickable counter should be present or not ---@param showCounter Boolean Whether the clickable counter should be present or not
---@param matColor String Color of the playmat - White, Orange, Green, Red or All ---@param matColor String Color of the playmat - White, Orange, Green, Red or All
PlaymatApi.clickableClues = function(showCounter, matColor) PlaymatApi.clickableClues = function(showCounter, matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
mat.call("clickableClues", showCounter) mat.call("clickableClues", showCounter)
end end
end end
@ -141,7 +127,7 @@ do
-- Removes all clues (to the trash for tokens and counters set to 0) for the requested playmat -- Removes all clues (to the trash for tokens and counters set to 0) for the requested playmat
---@param matColor String Color of the playmat - White, Orange, Green, Red or All ---@param matColor String Color of the playmat - White, Orange, Green, Red or All
PlaymatApi.removeClues = function(matColor) PlaymatApi.removeClues = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
mat.call("removeClues") mat.call("removeClues")
end end
end end
@ -150,7 +136,7 @@ do
---@param useClickableCounters Boolean Controls which type of counter is getting checked ---@param useClickableCounters Boolean Controls which type of counter is getting checked
PlaymatApi.getClueCount = function(useClickableCounters, matColor) PlaymatApi.getClueCount = function(useClickableCounters, matColor)
local count = 0 local count = 0
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
count = count + mat.call("getClueCount", useClickableCounters) count = count + mat.call("getClueCount", useClickableCounters)
end end
return count return count
@ -162,7 +148,7 @@ do
---@param newValue Number Value to set the counter to ---@param newValue Number Value to set the counter to
---@param modifier Number If newValue is not provided, the existing value will be adjusted by this modifier ---@param modifier Number If newValue is not provided, the existing value will be adjusted by this modifier
PlaymatApi.updateCounter = function(matColor, type, newValue, modifier) PlaymatApi.updateCounter = function(matColor, type, newValue, modifier)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
mat.call("updateCounter", { type = type, newValue = newValue, modifier = modifier }) mat.call("updateCounter", { type = type, newValue = newValue, modifier = modifier })
end end
end end
@ -171,7 +157,7 @@ do
---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All") ---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All")
---@param type String Counter to target ---@param type String Counter to target
PlaymatApi.getCounterValue = function(matColor, type) PlaymatApi.getCounterValue = function(matColor, type)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
return mat.call("getCounterValue", type) return mat.call("getCounterValue", type)
end end
end end
@ -179,7 +165,7 @@ do
-- resets the specified skill tracker to "1, 1, 1, 1" -- resets the specified skill tracker to "1, 1, 1, 1"
---@param matColor String Color of the playmat - White, Orange, Green, Red or All ---@param matColor String Color of the playmat - White, Orange, Green, Red or All
PlaymatApi.resetSkillTracker = function(matColor) PlaymatApi.resetSkillTracker = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
mat.call("resetSkillTracker") mat.call("resetSkillTracker")
end end
end end
@ -189,7 +175,7 @@ do
---@param filter Function Optional filter function (return true for desired objects) ---@param filter Function Optional filter function (return true for desired objects)
PlaymatApi.searchAroundPlaymat = function(matColor, filter) PlaymatApi.searchAroundPlaymat = function(matColor, filter)
local objList = {} local objList = {}
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
for _, obj in ipairs(mat.call("searchAroundSelf", filter)) do for _, obj in ipairs(mat.call("searchAroundSelf", filter)) do
table.insert(objList, obj) table.insert(objList, obj)
end end
@ -200,14 +186,14 @@ do
-- Discard a non-hidden card from the corresponding player's hand -- Discard a non-hidden card from the corresponding player's hand
---@param matColor String Color of the playmat - White, Orange, Green, Red or All ---@param matColor String Color of the playmat - White, Orange, Green, Red or All
PlaymatApi.doDiscardOne = function(matColor) PlaymatApi.doDiscardOne = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in pairs(internal.getMatForColor(matColor)) do
mat.call("doDiscardOne") mat.call("doDiscardOne")
end end
end end
-- Triggers the metadata sync for all playmats -- Triggers the metadata sync for all playmats
PlaymatApi.syncAllCustomizableCards = function() PlaymatApi.syncAllCustomizableCards = function()
for _, mat in ipairs(internal.getMatForColor("All")) do for _, mat in pairs(internal.getMatForColor("All")) do
mat.call("syncAllCustomizableCards") mat.call("syncAllCustomizableCards")
end end
end end