Pre-release
AdventureJS Docs Downloads Bundler Devlog Score: 0 Moves: 0
// getName.js
(function () {
  /* global AdventureJS A */
  var p = AdventureJS.Assets.Asset.prototype;

  /**
   * <strong>getName</strong> is called to get an asset's name.
   * @memberOf AdventureJS.Assets.Asset
   * @method AdventureJS.Assets.Asset#getName
   * @param {String} type The type of name to get. Valid options
   * are: article, definite|the, indefinite|a, stack?
   * (with question mark). Provide values in lowercase,
   * Sentencecase or UPPERCASE to get results in that format.
   * @param {String} kace Optionally provide an explicit case,
   * which takes precedence over cases found in type param.
   * Valid options are: lower, upper, capitalize, proper.
   */
  p.getName = function Asset_getName(type = "article", kace = "") {
    if (kace === "lower") type = type.toLowerCase();
    if (kace === "upper") type = type.toUpperCase();
    if (kace === "capitalize") type = A.FX.capitalize(type);
    if (kace === "proper") type = A.FX.propercase(type);
    let name = "";

    switch (type) {
      case "article":
        name = this.article_name;
        break;
      case "Article":
        name = this.Article_name;
        break;
      case "ARTICLE":
        name = this.ARTICLE_NAME;
        break;

      case "proper":
        name = this.proper_case || this.name;
        break;

      case "definite":
      case "the":
        name = this.definite_name;
        break;
      case "Definite":
      case "The":
        name = this.Definite_name;
        break;
      case "DEFINITE":
      case "THE":
        name = this.DEFINITE_NAME;
        break;

      case "indefinite":
      case "a":
        name = this.indefinite_name;
        break;
      case "Indefinite":
      case "A":
        name = this.Indefinite_name;
        break;
      case "INDEFINITE":
        name = this.INDEFINITE_NAME;
        break;
    }

    if (!name) name = this.name;
    let char = this.hasClass("Character") ? "ajs-character-name" : "";
    name = this.applyNameStyles(name);
    name = `<span class="ajs-asset-name ${char} ajs-${this.class.toLowerCase()}-name">${name}</span>`;

    return name;
  };
})();