refactor animal methods / vue methods

This commit is contained in:
negue
2018-10-29 20:46:16 +01:00
parent 3c5025a78e
commit c73f565f65
4 changed files with 56 additions and 43 deletions

View File

@@ -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);
},
};
}