diff --git a/src/components/BarnView.vue b/src/components/BarnView.vue index 252f6af..8ce4e1f 100644 --- a/src/components/BarnView.vue +++ b/src/components/BarnView.vue @@ -44,7 +44,7 @@ export default { let productFromAnimal = AnimalService.getProductFromAnimalID(animal.id); iziToast.info({ - title: productFromAnimal.name+' can be collected '+ moment(animal.production.ready).fromNow(), + title: productFromAnimal.name+' can be collected '+ moment(animal.production.ready).fromNow() + ' ('+animal.production.percent+'%)', image: productFromAnimal.icon, }); @@ -70,6 +70,7 @@ export default { }); animal.production = { + started: moment(), ready: moment().add(animalData.production.time, 'minutes'), percent: 0, canBeCollected: false diff --git a/src/store/index.js b/src/store/index.js index 65f2feb..a0cf327 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -281,10 +281,9 @@ export default createStore({ if (field.data.percentDone <= 100) { let minutesSincePlanting = moment.duration(moment().diff(field.data.planted)).asMinutes(); - field.data.percentDone = - Number( - Number(minutesSincePlanting) / Number(seed.cropData.timeToGrow) * 100 - ).toFixed(2); + field.data.percentDone = Number( + Number(minutesSincePlanting) / Number(seed.cropData.timeToGrow) * 100 + ).toFixed(2); if (field.data.percentDone >= 100) { field.data.percentDone = 100; @@ -333,6 +332,7 @@ export default createStore({ let animalData = AnimalService.getAnimalByID(animal.id); if (!animal.production) { animal.production = { + started: moment(), ready: moment().add(animalData.production.time, 'minutes'), percent: 0, canBeCollected: false @@ -344,8 +344,11 @@ export default createStore({ } if (animal.production.percent <= 100) { - let minutesLeft = moment.duration(moment(animal.production.ready).diff(moment())).asMinutes(); - animal.production.percent = Number((Number(animalData.production.time) * 100) / Number(minutesLeft) - 100).toFixed(2); + let minutesSinceLastCollection = moment.duration(moment().diff(animal.production.started)).asMinutes(); + animal.production.percent = Number( + Number(minutesSinceLastCollection) / Number(animalData.production.time) * 100 + ).toFixed(2); + if (animal.production.percent >= 100) { animal.production.percent = 100; animal.production.canBeCollected = true;