diff --git a/devTools/types/FC/facilities.d.ts b/devTools/types/FC/facilities.d.ts index 7b929abb66ec91cbb3e7d1e1a5e424c50bec8c29..e31140fcb24828f1ffa064abec3e206e52e19d57 100644 --- a/devTools/types/FC/facilities.d.ts +++ b/devTools/types/FC/facilities.d.ts @@ -1,5 +1,7 @@ declare namespace FC { namespace Facilities { + export type Animal = InstanceType<typeof App.Entity.Animal>; + interface Pit { /** Defaults to "the Pit" if not otherwise set. */ name: string; diff --git a/src/facilities/farmyard/animals/animals.js b/src/facilities/farmyard/animals/animals.js index 4c81cf712de1ce888a18331b9944aa711528f19e..490ce8e4aa99b55723f3e296e1d898ad1db5dc22 100644 --- a/src/facilities/farmyard/animals/animals.js +++ b/src/facilities/farmyard/animals/animals.js @@ -1,4 +1,3 @@ - /** The base animal class. */ App.Entity.Animal = class { /** @@ -12,6 +11,7 @@ App.Entity.Animal = class { this.species = species; this.type = type; this.rarity = rarity; + this.articleAn = 'a'; } /** @returns {boolean} */ @@ -29,16 +29,20 @@ App.Entity.Animal = class { V[this.type].push(this.name); } + /** @type {function():void} */ setActive() { - V.active[this.type].replace(/s$/, '') + V.active[this.type] = this; + } + + /** @param {'a'|'an'} setter */ + set an(setter) { + this.articleAn = setter; } -} +}; App.Facilities.Farmyard.animals = function() { App.Facilities.Farmyard.animals.init(); - class Animal extends App.Entity.Animal {}; - const frag = new DocumentFragment(); const domesticDiv = App.UI.DOM.appendNewElement("div", frag, '', "farmyard-domestic"); @@ -104,7 +108,7 @@ App.Facilities.Farmyard.animals = function() { App.UI.DOM.appendNewElement("span", canineDiv, 'Dogs', "farmyard-animal-type"); - canineDiv.append(hr, animalList("canine", domestic, 5000, canine)); + canineDiv.append(hr, animalList(canine, domestic, 5000, canine)); return canineDiv; } @@ -117,7 +121,7 @@ App.Facilities.Farmyard.animals = function() { App.UI.DOM.appendNewElement("span", hoovedDiv, 'Hooved Animals', "farmyard-animal-type"); - hoovedDiv.append(hr, animalList("hooved", domestic, 20000, hooved)); + hoovedDiv.append(hr, animalList(hooved, domestic, 20000, hooved)); return hoovedDiv; } @@ -130,7 +134,7 @@ App.Facilities.Farmyard.animals = function() { App.UI.DOM.appendNewElement("span", felineDiv, 'Cats', "farmyard-animal-type"); - felineDiv.append(hr, animalList("feline", domestic, 1000, feline)); + felineDiv.append(hr, animalList(feline, domestic, 1000, feline)); return felineDiv; } @@ -147,7 +151,7 @@ App.Facilities.Farmyard.animals = function() { App.UI.DOM.appendNewElement("span", canineDiv, 'Canines', "farmyard-animal-type"); - canineDiv.append(hr, animalList("canine", exotic, 50000, canine)); + canineDiv.append(hr, animalList(canine, exotic, 50000, canine)); return canineDiv; } @@ -173,7 +177,7 @@ App.Facilities.Farmyard.animals = function() { App.UI.DOM.appendNewElement("span", felineDiv, 'Felines', "farmyard-animal-type"); - felineDiv.append(hr, animalList("feline", exotic, 100000, feline)); + felineDiv.append(hr, animalList(feline, exotic, 100000, feline)); return felineDiv; } @@ -185,7 +189,7 @@ App.Facilities.Farmyard.animals = function() { /** * Creates either a link or note text depending on parameters given * @param {object} param - * @param {Animal} param.animal + * @param {App.Entity.Animal} param.animal * @param {string} param.active * @param {string} param.type * @param {number} param.price @@ -194,8 +198,6 @@ App.Facilities.Farmyard.animals = function() { * @returns {string|HTMLElement} */ function animalLink({animal, active, type, price, setActiveHandler, purchaseHandler}) { - type = type.replace(/s$/, ''); // removes the final "s" from "canines" and "felines" - if (animal.purchased) { if (V.active[active] && V.active[active].name === animal.name) { return App.UI.DOM.makeElement("span", `Set as active ${type}`, "note"); @@ -209,7 +211,7 @@ App.Facilities.Farmyard.animals = function() { /** * Creates a list of the specified animal type from the main animal array. - * @param {string} type One of "canine", "hooved", or "feline", also used determine the active animal type. + * @param {"canine"|"hooved"|"feline"} type One of 'canine', 'hooved', or 'feline', also used determine the active animal type. * @param {string} rarity One of domestic or exotic. * @param {number} price * @param {string} active The name of the current active animal of the given type. @@ -229,15 +231,15 @@ App.Facilities.Farmyard.animals = function() { type: type, price: price, setActiveHandler() { - V.active[active] = filteredArray[i]; - App.UI.DOM.replace(mainDiv, animalList(type, rarity, price, active)) + filteredArray[i].setActive(); + App.UI.DOM.replace(mainDiv, animalList(type, rarity, price, active)); }, purchaseHandler() { cashX(forceNeg(price), "farmyard"); filteredArray[i].purchase(); - App.UI.DOM.replace(mainDiv, animalList(type, rarity, price, active)) + App.UI.DOM.replace(mainDiv, animalList(type, rarity, price, active)); } - } + }; optionSpan.append(animalLink(args)); @@ -254,12 +256,12 @@ App.Facilities.Farmyard.animals = function() { App.Facilities.Farmyard.animals.init = function() { if (App.Data.animals.length === 0) { - class Animal extends App.Entity.Animal {}; + class Animal extends App.Entity.Animal {} const dog = 'dog'; const cat = 'cat'; const canine = 'canine'; - const hooved = 'hooved' + const hooved = 'hooved'; const feline = 'feline'; const domestic = 'domestic'; const exotic = 'exotic';