mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
refactor animal methods / vue methods
This commit is contained in:
@@ -7,8 +7,21 @@ function getText (textOrFunction) {
|
||||
}
|
||||
}
|
||||
|
||||
export function isOwned (type, animal, userItems) {
|
||||
return userItems[`${type}s`][animal.key] > 0;
|
||||
}
|
||||
|
||||
export default function createAnimal (egg, potion, type, content, userItems) {
|
||||
export function isHatchable (animal, userItems) {
|
||||
return !isOwned('pet', animal, userItems) &&
|
||||
userItems.eggs[animal.eggKey] &&
|
||||
userItems.hatchingPotions[animal.potionKey];
|
||||
}
|
||||
|
||||
export function isAllowedToFeed (animal, userItems) {
|
||||
return isOwned('pet', animal, userItems) && !isOwned('mount', animal, userItems);
|
||||
}
|
||||
|
||||
export function createAnimal (egg, potion, type, content, userItems) {
|
||||
let animalKey = `${egg.key}-${potion.key}`;
|
||||
|
||||
return {
|
||||
@@ -20,16 +33,16 @@ export default function createAnimal (egg, potion, type, content, userItems) {
|
||||
potionName: getText(potion.text),
|
||||
name: content[`${type}Info`][animalKey].text(),
|
||||
isOwned () {
|
||||
return userItems[`${type}s`][animalKey] > 0;
|
||||
return isOwned(type, this, userItems);
|
||||
},
|
||||
mountOwned () {
|
||||
return userItems.mounts[this.key] > 0;
|
||||
return isOwned('mount', this, userItems);
|
||||
},
|
||||
isAllowedToFeed () {
|
||||
return type === 'pet' && this.isOwned() && !this.mountOwned();
|
||||
return isAllowedToFeed(this, userItems);
|
||||
},
|
||||
isHatchable () {
|
||||
return !this.isOwned() & userItems.eggs[egg.key] > 0 && userItems.hatchingPotions[potion.key] > 0;
|
||||
return isHatchable(this, userItems);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user