mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Incremental suffix to duplicated entities
This enhancement adds an incremental suffix to the name of the cloned entities resulting from "Duplicate" and "Paste". The goal is to help to figure which entities is the coned one. This addresses issue #575
This commit is contained in:
parent
c1781dc3ce
commit
47e3649298
1 changed files with 56 additions and 0 deletions
|
@ -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.
|
||||
//
|
||||
|
@ -19,6 +20,7 @@
|
|||
const SPACE_LOCAL = "local";
|
||||
const SPACE_WORLD = "world";
|
||||
const HIGHLIGHT_LIST_NAME = "editHandleHighlightList";
|
||||
const ENTIRE_DOMAIN_SCAN_RADIUS = 27713;
|
||||
|
||||
Script.include([
|
||||
"../../libraries/controllers.js",
|
||||
|
@ -31,6 +33,55 @@ function deepCopy(v) {
|
|||
return JSON.parse(JSON.stringify(v));
|
||||
}
|
||||
|
||||
function getDuplicateAppendedName(originalName, forcedIncrement) {
|
||||
var duplicateName, existingNames;
|
||||
var delayCounter = forcedIncrement;
|
||||
var duplicateNumber = 1;
|
||||
var rippedOriginalName = removeNameAppendice(originalName);
|
||||
|
||||
do {
|
||||
duplicateNumber++;
|
||||
if (rippedOriginalName === "") {
|
||||
duplicateName = "(" + duplicateNumber + ")";
|
||||
} else {
|
||||
duplicateName = rippedOriginalName + " (" + duplicateNumber + ")";
|
||||
}
|
||||
existingNames = Entities.findEntitiesByName(duplicateName, Vec3.ZERO, ENTIRE_DOMAIN_SCAN_RADIUS, false);
|
||||
if (existingNames.length === 0) {
|
||||
delayCounter--;
|
||||
}
|
||||
} while (existingNames.length !== 0 || delayCounter >= 0);
|
||||
return duplicateName;
|
||||
}
|
||||
|
||||
function removeNameAppendice(name) {
|
||||
var appendiceChar = "(0123456789)";
|
||||
var rippedName = name;
|
||||
|
||||
for (var i = name.length - 1; i >= 0; i--) {
|
||||
if (i === (name.length - 1) && name.charAt(i) !== ")") {
|
||||
rippedName = name;
|
||||
break;
|
||||
} else {
|
||||
if (appendiceChar.indexOf(name.charAt(i)) === -1) {
|
||||
rippedName = name;
|
||||
break;
|
||||
} else {
|
||||
if (name.charAt(i) == "(" && i === name.length - 2) {
|
||||
rippedName = name;
|
||||
break;
|
||||
} else {
|
||||
if (name.charAt(i) == "(") {
|
||||
rippedName = name.substr(0, i-1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rippedName.trim();
|
||||
}
|
||||
|
||||
SelectionManager = (function() {
|
||||
var that = {};
|
||||
|
||||
|
@ -289,6 +340,8 @@ SelectionManager = (function() {
|
|||
properties.localRotation = properties.rotation;
|
||||
}
|
||||
|
||||
properties.name = getDuplicateAppendedName(properties.name, 0);
|
||||
|
||||
properties.localVelocity = Vec3.ZERO;
|
||||
properties.localAngularVelocity = Vec3.ZERO;
|
||||
|
||||
|
@ -477,6 +530,7 @@ SelectionManager = (function() {
|
|||
|
||||
var copiedProperties = [];
|
||||
var ids = [];
|
||||
var selectionNo = 0;
|
||||
entityClipboard.entities.forEach(function(originalProperties) {
|
||||
var properties = deepCopy(originalProperties);
|
||||
if (properties.root) {
|
||||
|
@ -485,6 +539,8 @@ SelectionManager = (function() {
|
|||
} else {
|
||||
delete properties.position;
|
||||
}
|
||||
properties.name = getDuplicateAppendedName(properties.name, selectionNo);
|
||||
selectionNo++;
|
||||
copiedProperties.push(properties);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue