making rotation relative

This commit is contained in:
Chr1Z93 2023-03-10 00:19:01 +01:00
parent 2343cd8eb0
commit 62b3c29bda
3 changed files with 24 additions and 20 deletions

View File

@ -29,6 +29,7 @@ local chaosTokens = {}
local chaosTokensLastMat = nil local chaosTokensLastMat = nil
local IS_RESHUFFLING = false local IS_RESHUFFLING = false
local bagSearchers = {} local bagSearchers = {}
local MAT_COLORS = {"White", "Orange", "Green", "Red"}
local hideTitleSplashWaitFunctionId = nil local hideTitleSplashWaitFunctionId = nil
local playmatAPI = require("playermat/PlaymatApi") local playmatAPI = require("playermat/PlaymatApi")
local tokenManager = require("core/token/TokenManager") local tokenManager = require("core/token/TokenManager")
@ -850,17 +851,19 @@ function applyOptionPanelChange(id, state)
-- option: Show hand helper for each player -- option: Show hand helper for each player
elseif id == "showHandHelper" then elseif id == "showHandHelper" then
optionPanel[id][1] = spawnOrRemoveHelper(state, "Hand Helper", playmatAPI.transformLocalPosition({0.05, 0, -1.182}, "White") , {0, 270, 0}) for i, color in ipairs(MAT_COLORS) do
optionPanel[id][2] = spawnOrRemoveHelper(state, "Hand Helper", playmatAPI.transformLocalPosition({0.05, 0, -1.182}, "Orange"), {0, 270, 0}) local pos = playmatAPI.transformLocalPosition({0.05, 0, -1.182}, color)
optionPanel[id][3] = spawnOrRemoveHelper(state, "Hand Helper", playmatAPI.transformLocalPosition({0.05, 0, -1.182}, "Green"), {0, 000, 0}) local rot = playmatAPI.returnRotation(color)
optionPanel[id][4] = spawnOrRemoveHelper(state, "Hand Helper", playmatAPI.transformLocalPosition({0.05, 0, -1.182}, "Red"), {0, 180, 0}) optionPanel[id][i] = spawnOrRemoveHelper(state, "Hand Helper", pos, rot)
end
-- option: Show search assistant for each player -- option: Show search assistant for each player
elseif id == "showSearchAssistant" then elseif id == "showSearchAssistant" then
optionPanel[id][1] = spawnOrRemoveHelper(state, "Search Assistant", playmatAPI.transformLocalPosition({-0.3, 0, -1.182}, "White"), {0, 270, 0}) for i, color in ipairs(MAT_COLORS) do
optionPanel[id][2] = spawnOrRemoveHelper(state, "Search Assistant", playmatAPI.transformLocalPosition({-0.3, 0, -1.182}, "Orange"), {0, 270, 0}) local pos = playmatAPI.transformLocalPosition({-0.3, 0, -1.182}, color)
optionPanel[id][3] = spawnOrRemoveHelper(state, "Search Assistant", playmatAPI.transformLocalPosition({-0.3, 0, -1.182}, "Green"), {0, 000, 0}) local rot = playmatAPI.returnRotation(color)
optionPanel[id][4] = spawnOrRemoveHelper(state, "Search Assistant", playmatAPI.transformLocalPosition({-0.3, 0, -1.182}, "Red"), {0, 180, 0}) optionPanel[id][i] = spawnOrRemoveHelper(state, "Search Assistant", pos, rot)
end
-- option: Show chaos bag manager -- option: Show chaos bag manager
elseif id == "showChaosBagManager" then elseif id == "showChaosBagManager" then
@ -907,7 +910,6 @@ 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
function spawnHelperObject(name, position, rotation) function spawnHelperObject(name, position, rotation)
local sourceBag = getObjectFromGUID("830bd0") local sourceBag = getObjectFromGUID("830bd0")
-- error handling for missing sourceBag -- error handling for missing sourceBag

View File

@ -52,7 +52,6 @@ local THREAT_AREA = {
local DRAW_DECK_POSITION = { x = -1.82, y = 1, z = 0 } local DRAW_DECK_POSITION = { x = -1.82, y = 1, z = 0 }
local DISCARD_PILE_POSITION = { x = -1.82, y = 1.5, z = 0.61 } local DISCARD_PILE_POSITION = { x = -1.82, y = 1.5, z = 0.61 }
local PLAY_ZONE_ROTATION = self.getRotation()
local TRASHCAN local TRASHCAN
local STAT_TRACKER local STAT_TRACKER
@ -158,7 +157,7 @@ function searchArea(origin, size)
return Physics.cast({ return Physics.cast({
origin = origin, origin = origin,
direction = {0, 1, 0}, direction = {0, 1, 0},
orientation = PLAY_ZONE_ROTATION, orientation = self.getRotation(),
type = 3, type = 3,
size = size, size = size,
max_distance = 1, max_distance = 1,
@ -181,7 +180,7 @@ function makeDiscardHandlerFor(searchPosition, discardPosition)
if obj.tag == "Deck" or obj.tag == "Card" then if obj.tag == "Deck" or obj.tag == "Card" then
if obj.hasTag("PlayerCard") then if obj.hasTag("PlayerCard") then
obj.setPositionSmooth(self.positionToWorld(DISCARD_PILE_POSITION), false, true) obj.setPositionSmooth(self.positionToWorld(DISCARD_PILE_POSITION), false, true)
obj.setRotation(PLAY_ZONE_ROTATION) obj.setRotation(self.getRotation())
else else
obj.setPositionSmooth(discardPosition, false, true) obj.setPositionSmooth(discardPosition, false, true)
obj.setRotation({0, -90, 0}) obj.setRotation({0, -90, 0})
@ -220,7 +219,7 @@ function findObjectsAtPosition(localPos)
return Physics.cast({ return Physics.cast({
origin = self.positionToWorld(localPos), origin = self.positionToWorld(localPos),
direction = {0, 1, 0}, direction = {0, 1, 0},
orientation = {0, PLAY_ZONE_ROTATION.y + 90, 0}, orientation = {0, self.getRotation().y + 90, 0},
type = 3, type = 3,
size = {3.2, 1, 2}, size = {3.2, 1, 2},
max_distance = 0, max_distance = 0,
@ -252,7 +251,7 @@ function doUpkeep(_, color, alt_click)
elseif obj.tag == "Card" and not obj.is_face_down and not inArea(self.positionToLocal(obj.getPosition()), INVESTIGATOR_AREA) then elseif obj.tag == "Card" and not obj.is_face_down and not inArea(self.positionToLocal(obj.getPosition()), INVESTIGATOR_AREA) then
local cardMetadata = JSON.decode(obj.getGMNotes()) or {} local cardMetadata = JSON.decode(obj.getGMNotes()) or {}
if not doNotReady(obj) then if not doNotReady(obj) then
obj.setRotation(PLAY_ZONE_ROTATION) obj.setRotation(self.getRotation())
end end
if cardMetadata.id == "08031" then if cardMetadata.id == "08031" then
forcedLearning = true forcedLearning = true
@ -700,10 +699,6 @@ function returnGlobalDiscardPosition()
return self.positionToWorld(DISCARD_PILE_POSITION) return self.positionToWorld(DISCARD_PILE_POSITION)
end end
function transformLocalPosition(localPos)
return self.positionToWorld(localPos)
end
-- Sets this playermat's draw 1 button to visible -- Sets this playermat's draw 1 button to visible
---@param visible Boolean. Whether the draw 1 button should be visible ---@param visible Boolean. Whether the draw 1 button should be visible
function showDrawButton(visible) function showDrawButton(visible)
@ -766,7 +761,7 @@ function clickableClues(showCounter)
local pos = self.positionToWorld({x = -1.12, y = 0.05, z = 0.7}) local pos = self.positionToWorld({x = -1.12, y = 0.05, z = 0.7})
for i = 1, clueCount do for i = 1, clueCount do
pos.y = pos.y + 0.045 * i pos.y = pos.y + 0.045 * i
tokenManager.spawnToken(pos, "clue", PLAY_ZONE_ROTATION) tokenManager.spawnToken(pos, "clue", self.getRotation())
end end
end end
end end

View File

@ -75,7 +75,14 @@ do
---@param matColor String Color of the playermat ---@param matColor String Color of the playermat
PlaymatApi.transformLocalPosition = function(localPos, matColor) PlaymatApi.transformLocalPosition = function(localPos, matColor)
local mat = getObjectFromGUID(MAT_IDS[matColor]) local mat = getObjectFromGUID(MAT_IDS[matColor])
return mat.call("transformLocalPosition", localPos) return mat.positionToWorld(localPos)
end
-- Returns the rotation of the requested playmat
---@param matColor String Color of the playermat
PlaymatApi.returnRotation = function(matColor)
local mat = getObjectFromGUID(MAT_IDS[matColor])
return mat.getRotation()
end end
-- Sets the requested playermat's snap points to limit snapping to matching card types or not. If -- Sets the requested playermat's snap points to limit snapping to matching card types or not. If