From a4483e63676f8caa64f546f8cdce53ac173fc9b2 Mon Sep 17 00:00:00 2001 From: Alezia Kurdis <60075796+AleziaKurdis@users.noreply.github.com> Date: Thu, 13 May 2021 21:45:49 -0400 Subject: [PATCH] Safeguard code for Copy/Paste Position/Rotation Safeguard code for Copy/Paste Position/Rotation The 4 actions has now validations to avoid to only have those validation on the UI. Making sure there is a single selection to execute these actions: Copy Position Copy Rotation Making sure there is a selection that doesn't contain locked entity and that we have a copied value in order to execute these actions: Paste Location Paste Rotation --- scripts/system/create/edit.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/system/create/edit.js b/scripts/system/create/edit.js index c29eb32903..614bd5fd59 100644 --- a/scripts/system/create/edit.js +++ b/scripts/system/create/edit.js @@ -2617,19 +2617,21 @@ var PropertiesTool = function (opts) { } } } else if (data.action === "copyPosition") { - selectionManager.saveProperties(); - properties = selectionManager.savedProperties[selectionManager.selections[0]]; - copiedPosition = properties.position; - Window.copyToClipboard(JSON.stringify(copiedPosition)); - print("COPIED: " + JSON.stringify(copiedPosition)); + if (selectionManager.selections.length === 1) { + selectionManager.saveProperties(); + properties = selectionManager.savedProperties[selectionManager.selections[0]]; + copiedPosition = properties.position; + Window.copyToClipboard(JSON.stringify(copiedPosition)); + } } else if (data.action === "copyRotation") { - selectionManager.saveProperties(); - properties = selectionManager.savedProperties[selectionManager.selections[0]]; - copiedRotation = properties.rotation; - Window.copyToClipboard(JSON.stringify(copiedRotation)); - print("COPIED: " + JSON.stringify(copiedRotation)); + if (selectionManager.selections.length === 1) { + selectionManager.saveProperties(); + properties = selectionManager.savedProperties[selectionManager.selections[0]]; + copiedRotation = properties.rotation; + Window.copyToClipboard(JSON.stringify(copiedRotation)); + } } else if (data.action === "pastePosition") { - if (copiedPosition !== undefined) { + if (copiedPosition !== undefined && selectionManager.selections.length > 0 && SelectionManager.hasUnlockedSelection()) { selectionManager.saveProperties(); for (i = 0; i < selectionManager.selections.length; i++) { Entities.editEntity(selectionManager.selections[i], { @@ -2638,12 +2640,11 @@ var PropertiesTool = function (opts) { } pushCommandForSelections(); selectionManager._update(false, this); - print("PASTE POSITION"); } else { audioFeedback.rejection(); } } else if (data.action === "pasteRotation") { - if (copiedRotation !== undefined) { + if (copiedRotation !== undefined && selectionManager.selections.length > 0 && SelectionManager.hasUnlockedSelection()) { selectionManager.saveProperties(); for (i = 0; i < selectionManager.selections.length; i++) { Entities.editEntity(selectionManager.selections[i], { @@ -2651,8 +2652,7 @@ var PropertiesTool = function (opts) { }); } pushCommandForSelections(); - selectionManager._update(false, this); - print("PASTE ROTATION"); + selectionManager._update(false, this); } else { audioFeedback.rejection(); }