Added utility function for playermat moving
This commit is contained in:
parent
e29c8cb198
commit
e2bff833c2
@ -1407,7 +1407,6 @@ function updateDownloadItemList(skipAuthorUpdate)
|
||||
-- if there's a filter, apply it (both for name and author)
|
||||
if (searchFilter == nil or string.contains(string.lower(v.name), searchFilter)) and
|
||||
(authorFilter == nil or v.author == authorFilter) then
|
||||
|
||||
-- start collecting authors unless skipping
|
||||
if not skipAuthorUpdate then
|
||||
table.insert(authorList, v.author)
|
||||
|
@ -345,5 +345,48 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
-- moves + rotates a playermat (and related objects)
|
||||
---@param matColor string Color of the playermat - White, Orange, Green, Red or All
|
||||
---@param position table New position for the playermat
|
||||
---@param rotationY number New y-rotation for the playermat (X and Z will be 0)
|
||||
PlayermatApi.moveAndRotatePlayermat = function(matColor, position, rotationY)
|
||||
-- get mat and related objects
|
||||
local mat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat")
|
||||
local matObjects = guidReferenceApi.getObjectsByOwner(matColor)
|
||||
|
||||
if not mat then return end
|
||||
|
||||
-- use current value if undefined
|
||||
position = position or mat.getPosition()
|
||||
rotationY = rotationY or mat.getRotation().y
|
||||
|
||||
-- store relative positions
|
||||
local storedPositions = {}
|
||||
for _, obj in pairs(matObjects) do
|
||||
if obj ~= mat then
|
||||
storedPositions[obj.getGUID()] = mat.positionToLocal(obj.getPosition())
|
||||
end
|
||||
end
|
||||
|
||||
-- also get objects on the mat
|
||||
local objectsOnMat = searchLib.onObject(mat)
|
||||
for _, obj in ipairs(objectsOnMat) do
|
||||
if obj ~= mat and storedPositions[obj.getGUID()] == nil and obj.interactable ~= false then
|
||||
storedPositions[obj.getGUID()] = mat.positionToLocal(obj.getPosition())
|
||||
end
|
||||
end
|
||||
|
||||
-- move main mat
|
||||
mat.setPosition(position)
|
||||
mat.setRotation({ 0, rotationY, 0 })
|
||||
|
||||
-- set new position + rotation (preserve object X / Z rotation)
|
||||
for guid, pos in pairs(storedPositions) do
|
||||
local obj = getObjectFromGUID(guid)
|
||||
obj.setPosition(mat.positionToWorld(pos))
|
||||
obj.setRotation(obj.getRotation():setAt("y", rotationY))
|
||||
end
|
||||
end
|
||||
|
||||
return PlayermatApi
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user