From aa574574a6aaa9a67506c225437c78e61c875927 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Fri, 27 Oct 2017 10:00:45 +0200 Subject: [PATCH] clone numbers for components --- src/game-lib-a-component-a.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/game-lib-a-component-a.js b/src/game-lib-a-component-a.js index 4ba69c9..5214825 100644 --- a/src/game-lib-a-component-a.js +++ b/src/game-lib-a-component-a.js @@ -32,6 +32,8 @@ GameLib.Component = function( this.linked = false; + this.cloneNumber = 0; + if (GameLib.Utils.UndefinedOrNull(delayed)) { delayed = false; } @@ -403,20 +405,13 @@ GameLib.Component.prototype.clone = function() { var apiObject = this.toApiObject(); + this.cloneNumber += 1; + apiObject.id = GameLib.Utils.RandomId(); - var matches = apiObject.name.match(/Clone \((\d+)\)/); + apiObject.name = this.name + ' Clone (' + this.cloneNumber + ')'; - if (matches && matches.length > 1) { - if (matches.length === 2) { - var number = Number(matches[1]); - apiObject.name = apiObject.name.replace(/Clone \(\d*\)/, 'Clone (' + (number+1) + ')'); - } - } else { - apiObject.name = apiObject.name + ' Clone (1)' - } - - var runtimeObject = null; + var runtimeObject = null; try { runtimeObject = new this.constructor(this.graphics, apiObject); @@ -436,6 +431,9 @@ GameLib.Component.prototype.clone = function() { } } + /** + * TODO check below event emit + */ GameLib.Event.Emit( GameLib.Event.COMPONENT_CREATED, {