From e2bff833c2e72df174ecf13d574525f4a98e549b Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sun, 13 Oct 2024 14:26:45 +0200 Subject: [PATCH 1/2] Added utility function for playermat moving --- src/core/Global.ttslua | 1 - src/playermat/PlayermatApi.ttslua | 47 +++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 65b3f8e5..4b226094 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -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) diff --git a/src/playermat/PlayermatApi.ttslua b/src/playermat/PlayermatApi.ttslua index 313f0778..ab616337 100644 --- a/src/playermat/PlayermatApi.ttslua +++ b/src/playermat/PlayermatApi.ttslua @@ -122,8 +122,8 @@ do PlayermatApi.getHelperSpawnData = function(matColor, helperName) local resultTable = {} local localPositionTable = { - ["Hand Helper"] = Vector( -0.055, 0, -1.132 ), - ["Search Assistant"] = Vector( -0.34, 0, -1.132 ) + ["Hand Helper"] = Vector(-0.055, 0, -1.132), + ["Search Assistant"] = Vector(-0.34, 0, -1.132) } for color, mat in pairs(getMatForColor(matColor)) do @@ -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 From 4509005b12d5f3c55e844eea9942e6bf4613ca8d Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sun, 13 Oct 2024 18:06:31 +0200 Subject: [PATCH 2/2] updated script --- src/core/Global.ttslua | 6 ++++++ src/playermat/PlayermatApi.ttslua | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 4b226094..77d1fe3a 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -2754,3 +2754,9 @@ function removeDuplicatesAndSort(t) return result end + +-- wrapper for 'easier' access to this function +-- Note: There's intentionally no proper UI or button etc. for this, since we don't fully support rotated mats +function moveAndRotatePlayermat(params) + playermatApi.moveAndRotate(params.matColor, params.position, params.rotationY) +end diff --git a/src/playermat/PlayermatApi.ttslua b/src/playermat/PlayermatApi.ttslua index ab616337..2307aa12 100644 --- a/src/playermat/PlayermatApi.ttslua +++ b/src/playermat/PlayermatApi.ttslua @@ -349,7 +349,7 @@ do ---@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) + PlayermatApi.moveAndRotate = function(matColor, position, rotationY) -- get mat and related objects local mat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat") local matObjects = guidReferenceApi.getObjectsByOwner(matColor)