mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:41:20 +02:00
Clone suffix without uniqueness check
Simpler solution without any hazardous uniqueness check. Cloned entities will systematically get the suffix " (2)", unless their name has already a suffix. In that case, we simply increment the suffix.
This commit is contained in:
parent
47e3649298
commit
91ebd378f5
1 changed files with 20 additions and 32 deletions
|
@ -20,7 +20,6 @@
|
||||||
const SPACE_LOCAL = "local";
|
const SPACE_LOCAL = "local";
|
||||||
const SPACE_WORLD = "world";
|
const SPACE_WORLD = "world";
|
||||||
const HIGHLIGHT_LIST_NAME = "editHandleHighlightList";
|
const HIGHLIGHT_LIST_NAME = "editHandleHighlightList";
|
||||||
const ENTIRE_DOMAIN_SCAN_RADIUS = 27713;
|
|
||||||
|
|
||||||
Script.include([
|
Script.include([
|
||||||
"../../libraries/controllers.js",
|
"../../libraries/controllers.js",
|
||||||
|
@ -33,52 +32,43 @@ function deepCopy(v) {
|
||||||
return JSON.parse(JSON.stringify(v));
|
return JSON.parse(JSON.stringify(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDuplicateAppendedName(originalName, forcedIncrement) {
|
function getDuplicateAppendedName(name) {
|
||||||
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 appendiceChar = "(0123456789)";
|
||||||
|
var currentChar = "";
|
||||||
var rippedName = name;
|
var rippedName = name;
|
||||||
|
var existingSequence = 0;
|
||||||
|
var sequenceReader = "";
|
||||||
for (var i = name.length - 1; i >= 0; i--) {
|
for (var i = name.length - 1; i >= 0; i--) {
|
||||||
if (i === (name.length - 1) && name.charAt(i) !== ")") {
|
currentChar = name.charAt(i);
|
||||||
|
if (i === (name.length - 1) && currentChar !== ")") {
|
||||||
rippedName = name;
|
rippedName = name;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if (appendiceChar.indexOf(name.charAt(i)) === -1) {
|
if (appendiceChar.indexOf(currentChar) === -1) {
|
||||||
rippedName = name;
|
rippedName = name;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if (name.charAt(i) == "(" && i === name.length - 2) {
|
if (currentChar == "(" && i === name.length - 2) {
|
||||||
rippedName = name;
|
rippedName = name;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if (name.charAt(i) == "(") {
|
if (currentChar == "(") {
|
||||||
rippedName = name.substr(0, i-1);
|
rippedName = name.substr(0, i-1);
|
||||||
|
existingSequence = parseInt(sequenceReader);
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
sequenceReader = currentChar + sequenceReader;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (existingSequence === 0) {
|
||||||
|
rippedName = rippedName.trim() + " (2)";
|
||||||
|
} else {
|
||||||
|
existingSequence++;
|
||||||
|
rippedName = rippedName.trim() + " (" + existingSequence + ")";
|
||||||
|
}
|
||||||
return rippedName.trim();
|
return rippedName.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,7 +330,7 @@ SelectionManager = (function() {
|
||||||
properties.localRotation = properties.rotation;
|
properties.localRotation = properties.rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
properties.name = getDuplicateAppendedName(properties.name, 0);
|
properties.name = getDuplicateAppendedName(properties.name);
|
||||||
|
|
||||||
properties.localVelocity = Vec3.ZERO;
|
properties.localVelocity = Vec3.ZERO;
|
||||||
properties.localAngularVelocity = Vec3.ZERO;
|
properties.localAngularVelocity = Vec3.ZERO;
|
||||||
|
@ -530,7 +520,6 @@ SelectionManager = (function() {
|
||||||
|
|
||||||
var copiedProperties = [];
|
var copiedProperties = [];
|
||||||
var ids = [];
|
var ids = [];
|
||||||
var selectionNo = 0;
|
|
||||||
entityClipboard.entities.forEach(function(originalProperties) {
|
entityClipboard.entities.forEach(function(originalProperties) {
|
||||||
var properties = deepCopy(originalProperties);
|
var properties = deepCopy(originalProperties);
|
||||||
if (properties.root) {
|
if (properties.root) {
|
||||||
|
@ -539,8 +528,7 @@ SelectionManager = (function() {
|
||||||
} else {
|
} else {
|
||||||
delete properties.position;
|
delete properties.position;
|
||||||
}
|
}
|
||||||
properties.name = getDuplicateAppendedName(properties.name, selectionNo);
|
properties.name = getDuplicateAppendedName(properties.name);
|
||||||
selectionNo++;
|
|
||||||
copiedProperties.push(properties);
|
copiedProperties.push(properties);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue