Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
//addAsset.js
(function () {
  /*global adventurejs A*/

  var p = adventurejs.Game.prototype;

  /**
   * <pre class="display"><code class="language-javascript">MyGame.addAsset({ "class":"foo", "name":"bar", [...] })</code></pre>
   * <p>
   * <strong>addAsset()</strong> is a constructor function
   * that can be used to dynamically create new
   * {@link adventurejs.Asset|Assets} at runtime,
   * which is to say, after the game has been initialized.
   * This method encapsulates
   * <a href="/doc/adventurejs.Game.html#createAsset">game.createAsset()</a>,
   * <a href="/doc/adventurejs.Asset.html#validate">asset.validate()</a>
   * and
   * <a href="/doc/adventurejs.Asset.html#initialize">asset.initialize()</a>.
   * The end result is equivalent to using createAsset()
   * in your game file.
   * </p>
   * @memberOf adventurejs.Game
   * @method adventurejs.Game#addAsset
   * @kind function
   * @param {Object} asset A generic object with properties to copy into a new classed object.
   * @returns {Object} A new Asset of the class specified in asset.class.
   */
  p.addAsset = function Game_addAsset(asset) {
    let classed = this.createAsset(asset);
    if (!classed) return false;
    if (!classed.validate()) return false;
    if (!classed.initialize()) return false;
    return classed;
  };
})();