Created
January 27, 2023 14:49
-
-
Save amalloy/2643748e48763d3a090081a2b7ed813c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function savePiecePositions() | |
savedPieces = {} | |
for _, obj in ipairs(getObjectsWithTag("Resettable")) do | |
savedPieces[obj.getGUID()] = { | |
data=obj.getData(), | |
position=obj.getPosition(), | |
rotation=obj.getRotation(), | |
} | |
end | |
end | |
function restorePiecePositions() | |
for _, obj in ipairs(getObjectsWithTag("Resettable")) do | |
local guid = obj.getGUID() | |
local saved = savedPieces[guid] | |
if saved == nil then | |
-- Piece that wasn't around when we saved; delete it | |
obj.destruct() | |
else | |
-- Put it back where it was, and un-save it | |
obj.setPositionSmooth(saved.position) | |
obj.setRotationSmooth(saved.rotation) | |
savedPieces[guid] = nil | |
end | |
end | |
for _, saved in pairs(savedPieces) do | |
-- Any saved pieces we haven't yet restored were deleted; re-spawn them. | |
spawnObjectData(saved) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment