Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions engine/src/base/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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 [];
}

Expand Down Expand Up @@ -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;
Expand Down