From c8881a7a28a06651a36822136600dbe9f25723e7 Mon Sep 17 00:00:00 2001 From: Filippo Ledda Date: Fri, 8 Nov 2019 15:30:12 +0100 Subject: [PATCH] #119 Fixed retro compatibility issue --- js/geppettoModel/ModelFactory.js | 41 +++++++++++++++++++------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/js/geppettoModel/ModelFactory.js b/js/geppettoModel/ModelFactory.js index a76b853c3..efd5dbc4d 100644 --- a/js/geppettoModel/ModelFactory.js +++ b/js/geppettoModel/ModelFactory.js @@ -100,21 +100,8 @@ define(function (require) { } if (jsonModel.worlds) { geppettoModel.worlds = jsonModel.worlds.map(world => this.createWorld(world)); - geppettoModel.variables = geppettoModel.getCurrentWorld().getVariables(); - if (geppettoModel.getCurrentWorld().getInstances()) { - // Add instances from the default world to allPaths - this.allPaths = geppettoModel.getCurrentWorld().getInstances().map( - instance => ({ - path: instance.getPath(), - type: instance.getValue().eClass, - metaType: instance._metaType, - static: true - }) - ); - - this.allPathsIndexing = [...this.allPaths]; - } - + geppettoModel.variables = geppettoModel.getCurrentWorld().getVariables() + .concat(geppettoModel.variables); } // create libraries @@ -145,7 +132,23 @@ define(function (require) { } } } + + if (geppettoModel.getCurrentWorld()) { + + // Add instances from the default world to allPaths + let staticInstancesPaths = geppettoModel.getCurrentWorld().getInstances().map( + instance => ({ + path: instance.getPath(), + metaType: instance.getType().getMetaType(), + type: instance.getType().getPath(), + static: true + }) + ); + this.allPaths = this.allPaths.concat(staticInstancesPaths); + this.allPathsIndexing = this.allPathsIndexing.concat(staticInstancesPaths); + } + return geppettoModel; }, @@ -170,8 +173,12 @@ define(function (require) { default: throw instance.eClass + " instance type is not supported" } - - instance.value = this.createValue(rawInstance, { wrappedObj: rawInstance.value }); + if (instance.value) { + instance.value = this.createValue(rawInstance, { wrappedObj: rawInstance.value }); + } else { + console.error("Instance", instance, "has no value defined"); + } + return instance; },