| 331 | } |
| 332 | |
| 333 | sortSystems (levelSystems, systemModels) { |
| 334 | const [sorted, originalsSeen] = Array.from([[], {}]) |
| 335 | const visit = function (system) { |
| 336 | if (system.original in originalsSeen) { return } |
| 337 | const systemModel = _.find(systemModels, { original: system.original }) |
| 338 | if (!systemModel) { return console.error('Couldn\'t find model for original', system.original, 'from', systemModels) } |
| 339 | for (const d of Array.from(systemModel.dependencies || [])) { |
| 340 | const system2 = _.find(levelSystems, { original: d.original }) |
| 341 | visit(system2) |
| 342 | } |
| 343 | // console.log 'sorted systems adding', systemModel.name |
| 344 | sorted.push({ model: systemModel, config: $.extend(true, {}, system.config) }) |
| 345 | originalsSeen[system.original] = true |
| 346 | } |
| 347 | for (const system of Array.from(levelSystems != null ? levelSystems : [])) { visit(system) } |
| 348 | return sorted |
| 349 | } |
| 350 | |
| 351 | sortThangComponents (thangs, levelComponents, parentType) { |
| 352 | // Here we have to sort the Components by their dependencies. |