diff --git a/scripts/system/create/entitySelectionTool/entitySelectionTool.js b/scripts/system/create/entitySelectionTool/entitySelectionTool.js index 9bab739060..e224e28fca 100644 --- a/scripts/system/create/entitySelectionTool/entitySelectionTool.js +++ b/scripts/system/create/entitySelectionTool/entitySelectionTool.js @@ -6,6 +6,7 @@ // Modified by Daniela Fontes * @DanielaFifo and Tiago Andrade @TagoWill on 4/7/2017 // Modified by David Back on 1/9/2018 // Copyright 2014 High Fidelity, Inc. +// Copyright 2020 Vircadia contributors // // This script implements a class useful for building tools for editing entities. // @@ -31,6 +32,46 @@ function deepCopy(v) { return JSON.parse(JSON.stringify(v)); } +function getDuplicateAppendedName(name) { + var appendiceChar = "(0123456789)"; + var currentChar = ""; + var rippedName = name; + var existingSequence = 0; + var sequenceReader = ""; + for (var i = name.length - 1; i >= 0; i--) { + currentChar = name.charAt(i); + if (i === (name.length - 1) && currentChar !== ")") { + rippedName = name; + break; + } else { + if (appendiceChar.indexOf(currentChar) === -1) { + rippedName = name; + break; + } else { + if (currentChar == "(" && i === name.length - 2) { + rippedName = name; + break; + } else { + if (currentChar == "(") { + rippedName = name.substr(0, i-1); + existingSequence = parseInt(sequenceReader); + break; + } else { + sequenceReader = currentChar + sequenceReader; + } + } + } + } + } + if (existingSequence === 0) { + rippedName = rippedName.trim() + " (2)"; + } else { + existingSequence++; + rippedName = rippedName.trim() + " (" + existingSequence + ")"; + } + return rippedName.trim(); +} + SelectionManager = (function() { var that = {}; @@ -289,6 +330,8 @@ SelectionManager = (function() { properties.localRotation = properties.rotation; } + properties.name = getDuplicateAppendedName(properties.name); + properties.localVelocity = Vec3.ZERO; properties.localAngularVelocity = Vec3.ZERO;