//createClass.js
(function () {
/* global adventurejs A */
var p = adventurejs.Game.prototype;
/**
* <pre class="display"><code class="language-javascript">MyGame.createClass(
* class Foo extends adventurejs.Bar {
* constructor(name, game_name) {
* super(name, game_name);
* this.class = "Foo";
* }
* }
* )</code></pre>
* <p>
* <strong>createClass()</strong> is a constructor function
* available to authors for creating whole new classes of Assets.
* The function takes one parameter: a class declaration function.
* For example, to create a special class of Yggdrasil tree:
* </p>
* <pre class="display"><code class="language-javascript">MyGame.createClass(
* class Yggdrasil extends adventurejs.Tree {
* constructor(name, game_name) {
* super(name, game_name);
* this.class = "Yggdrasil";
* }
* }
* )</code></pre>
* <p>
* At runtime, <strong>createClass()</strong> plugs the new
* class constructor directly into AdventureJS, where it can
* be used to construct instances with the usual
* Game.createAsset({}) method. As of this writing, createClass
* is basically a passthrough without any internal error
* checking, so consider yourself going off road. It's
* recommended that you browse through the
* <a href="/doc/AssetReference__Overview.html">Asset Reference</a>
* to see how classes are laid out.
* </p>
* <p>
* You can also find more info under
* <a href="/doc/Advanced_CustomClasses.html">Custom Classes</a>.
* </p>
* @memberOf adventurejs.Game
* @method adventurejs.Game#createClass
* @kind function
* @param {Object} asset A generic object with properties to copy into a new class definition.
* @returns {Boolean}
*/
p.createClass = function Game_createClass(cls) {
if (typeof cls !== "function" || !cls.name) {
throw new Error("Must provide a named class");
}
adventurejs[cls.name] = cls;
return true;
};
})();