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 tokenManager = require("core/token/TokenManager")
local guidHandler = getObjectsWithTag("GUIDs")[1]
---------------------------------------------------------
-- general setup
---------------------------------------------------------
@ -31,7 +29,7 @@ local NOT_INTERACTABLE = {
"975c39", -- vertical border right
}
local DATA_HELPER
local guidHandler, DATA_HELPER
local chaosTokens = {}
local chaosTokensLastMat = nil
local bagSearchers = {}
@ -129,7 +127,8 @@ function onLoad(savedData)
if obj ~= nil then obj.interactable = false 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()
getModVersion()
math.randomseed(os.time())
@ -907,7 +906,7 @@ function applyOptionPanelChange(id, state)
for i, color in ipairs(MAT_COLORS) do
local pos = playmatApi.transformLocalPosition({0.05, 0, -1.182}, 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
-- option: Show search assistant for each player
@ -915,7 +914,7 @@ function applyOptionPanelChange(id, state)
for i, color in ipairs(MAT_COLORS) do
local pos = playmatApi.transformLocalPosition({-0.3, 0, -1.182}, 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
-- option: Show attachment helper
@ -942,12 +941,12 @@ end
---@param position Vector Position of the object (where it will spawn)
---@param rotation Vector Rotation of the object for spawning (default: {0, 270, 0})
---@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
return removeHelperObject(name)
elseif state then
Player.getPlayers()[1].pingTable(position)
return spawnHelperObject(name, position, rotation, color).getGUID()
return spawnHelperObject(name, position, rotation).getGUID()
else
return removeHelperObject(name)
end
@ -957,8 +956,7 @@ end
---@param name String Name of the object that should be copied
---@param position Table Desired position of the object
---@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, color)
function spawnHelperObject(name, position, rotation)
local sourceBag = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "OptionPanelSource" })
-- error handling for missing sourceBag
@ -977,12 +975,6 @@ function spawnHelperObject(name, position, rotation, color)
for _, obj in ipairs(sourceBag.getData().ContainedObjects) do
if obj["Nickname"] == name then
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)
Wait.time(function() spawnedObj.setLock(true) end, 2)
end

View File

@ -6,18 +6,11 @@ do
---@param startPos Table Starting position to get the closest mat from
PlaymatApi.getMatColorByPosition = function(startPos)
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()
if smallestDistance == nil or distance < smallestDistance then
smallestDistance = distance
for _, tag in ipairs(mat.getTags) do
if tag == "White"
or tag == "Orange"
or tag == "Green"
or tag == "Red" then
result = tag
end
end
result = matColor
end
end
return result
@ -26,7 +19,7 @@ do
-- 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")
PlaymatApi.getPlayerColor = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
for _, mat in pairs(internal.getMatForColor(matColor)) do
return mat.getVar("playerColor")
end
end
@ -34,17 +27,10 @@ do
-- Returns the color of the playmat that owns the playercolor's hand
---@param handColor String Color of the playmat
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")
if playerColor == handColor then
for _, tag in ipairs(mat.getTags) do
if tag == "White"
or tag == "Orange"
or tag == "Green"
or tag == "Red" then
return tag
end
end
return matColor
end
end
end
@ -52,7 +38,7 @@ do
-- 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")
PlaymatApi.isDES = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
for _, mat in pairs(internal.getMatForColor(matColor)) do
return mat.getVar("isDES")
end
end
@ -60,7 +46,7 @@ do
-- Returns the draw deck of the requested playmat
---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All")
PlaymatApi.getDrawDeck = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
for _, mat in pairs(internal.getMatForColor(matColor)) do
mat.call("getDrawDiscardDecks")
return mat.getVar("drawDeck")
end
@ -69,7 +55,7 @@ do
-- 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")
PlaymatApi.getDiscardPosition = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
for _, mat in pairs(internal.getMatForColor(matColor)) do
return mat.call("returnGlobalDiscardPosition")
end
end
@ -78,7 +64,7 @@ do
---@param localPos Table Local position to be transformed
---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All")
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)
end
end
@ -86,7 +72,7 @@ do
-- Returns the rotation of the requested playmat
---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All")
PlaymatApi.returnRotation = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
for _, mat in pairs(internal.getMatForColor(matColor)) do
return mat.getRotation()
end
end
@ -95,7 +81,7 @@ do
---@param matColor String Color of the playmat - White, Orange, Green, Red or All
---@param playerColor String Color of the calling player (for messages)
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)
end
end
@ -103,7 +89,7 @@ do
-- Returns the active investigator id
---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All")
PlaymatApi.returnInvestigatorId = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
for _, mat in pairs(internal.getMatForColor(matColor)) do
return mat.getVar("activeInvestigatorId")
end
end
@ -115,7 +101,7 @@ do
---@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
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)
end
end
@ -124,7 +110,7 @@ do
---@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
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)
end
end
@ -133,7 +119,7 @@ do
---@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
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)
end
end
@ -141,7 +127,7 @@ do
-- 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
PlaymatApi.removeClues = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
for _, mat in pairs(internal.getMatForColor(matColor)) do
mat.call("removeClues")
end
end
@ -150,7 +136,7 @@ do
---@param useClickableCounters Boolean Controls which type of counter is getting checked
PlaymatApi.getClueCount = function(useClickableCounters, matColor)
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)
end
return count
@ -162,7 +148,7 @@ do
---@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
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 })
end
end
@ -171,7 +157,7 @@ do
---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All")
---@param type String Counter to target
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)
end
end
@ -179,7 +165,7 @@ do
-- resets the specified skill tracker to "1, 1, 1, 1"
---@param matColor String Color of the playmat - White, Orange, Green, Red or All
PlaymatApi.resetSkillTracker = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
for _, mat in pairs(internal.getMatForColor(matColor)) do
mat.call("resetSkillTracker")
end
end
@ -189,7 +175,7 @@ do
---@param filter Function Optional filter function (return true for desired objects)
PlaymatApi.searchAroundPlaymat = function(matColor, filter)
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
table.insert(objList, obj)
end
@ -200,14 +186,14 @@ do
-- Discard a non-hidden card from the corresponding player's hand
---@param matColor String Color of the playmat - White, Orange, Green, Red or All
PlaymatApi.doDiscardOne = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
for _, mat in pairs(internal.getMatForColor(matColor)) do
mat.call("doDiscardOne")
end
end
-- Triggers the metadata sync for all playmats
PlaymatApi.syncAllCustomizableCards = function()
for _, mat in ipairs(internal.getMatForColor("All")) do
for _, mat in pairs(internal.getMatForColor("All")) do
mat.call("syncAllCustomizableCards")
end
end