Merge pull request #603 from AleziaKurdis/575_DuplicateNaming

Incremental suffix to cloned entities's name (issue #575)
This commit is contained in:
daleglass 2020-08-20 23:22:37 +02:00 committed by GitHub
commit 012b6b0c84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;