/* Copyright 2015 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

'use strict';

var EventEmitter = require('events');
var assert = require('assert');

var ModuleDef = require('server/modules/module_def');

class ModuleLibrary extends EventEmitter {
  constructor() {
    super();
    
    // Map of name -> ModuleDef
    this.modules = {};
  }
  register(def) {
    assert(!(def.name in this.modules), 'Def ' + def.name + ' already exists!');
    this.modules[def.name] = def;
    // We can safely use 'on' rather than 'once' here, because neither the 
    // moduledefs nor this library are ever destroyed.
    def.on('reloaded', () => {
      this.emit('reloaded', def);
    });
  }
}

let library = new ModuleLibrary;

// Engine modules.
library.register(new ModuleDef('_faded_out', 'demo_modules/solid/solid.js', '', '', {
  color: 'black'
}));

module.exports = library;

/* Copyright 2015 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

'use strict';

var EventEmitter = require('events');
var assert = require('assert');

class ModuleLibrary extends EventEmitter {
  constructor() {
    super();
    
    // Map of name -> ModuleDef
    this.modules = {};
  }
  register(def) {
    assert(!(def.name in this.modules), 'Def ' + def.name + ' already exists!');
    this.modules[def.name] = def;
    // We can safely use 'on' rather than 'once' here, because neither the 
    // moduledefs nor this library are ever destroyed.
    def.on('reloaded', () => {
      this.emit('reloaded', def);
    });
	
    if (def.name == 'solid') {
      this.register(def.extend('_faded_out', '', '', {
        color: 'black'
      }));
    }
  }
}

module.exports = new ModuleLibrary;

Change way we init fading.
Change way we init fading.

The current strategy fails when chicago-brick is used as an npm dep. Instead, do something that works, but is also hacky.
