diff --git a/engine/src/base/Base.js b/engine/src/base/Base.js index 124ae6d0d..2381d68e8 100644 --- a/engine/src/base/Base.js +++ b/engine/src/base/Base.js @@ -512,12 +512,16 @@ Wick.Base = class { * @param {Wick.Base} child - the child to add. */ addChild(child) { + if(!(child instanceof Wick.Base)) throw new TypeError("Child isn't a valid wick object."); var classname = child.classname; if (!this._children) { this._children = []; } + // Fix for #142 + child.identifier = this._getUniqueIdentifierQuick(child.identifier); + child._parent = this; child._setProject(this.project); @@ -539,8 +543,11 @@ Wick.Base = class { * @returns {boolean} - true if an item before index was moved */ insertChild(child, index) { + if(!(child instanceof Wick.Base)) throw new TypeError("Child isn't a valid wick object."); var classname = child.classname; + child.identifier = this._getUniqueIdentifierQuick(child.identifier); // fix for the 3 people who have used this. + if (child._parent === this) { let result = 0; let old_index = this._children.indexOf(child); @@ -590,6 +597,7 @@ Wick.Base = class { */ getLinkedAssets () { // Implemented by Wick.Frame and Wick.Clip + console.warn(`getLinkedAssets() is implemented by Wick.Frame and Wick.Clip, but this is object is a Wick.${this.classname}.`) return []; } @@ -647,6 +655,17 @@ Wick.Base = class { } } + _getUniqueIdentifierQuick(identifier) { + var cnames = this.getChildren().map(c => c.identifier); + var matching = cnames.filter(n => n.includes(identifier)) + + if(this._identiferNameIsPartOfWickAPI(identifier) || this._identifierNameExistsInWindowContext(identifier) || matching.length > 0) { + return identifier + '_copy'.repeat(matching.length + 1); + } else { + return identifier; + } + } + _identifierNameExistsInWindowContext(identifier) { if (window[identifier]) { return true;