Browse Source

fix them stupid chickens

master
Nero Ignis 3 years ago
parent
commit
8397423619
  1. 3
      src/components/BarnView.vue
  2. 15
      src/store/index.js

3
src/components/BarnView.vue

@ -44,7 +44,7 @@ export default {
let productFromAnimal = AnimalService.getProductFromAnimalID(animal.id); let productFromAnimal = AnimalService.getProductFromAnimalID(animal.id);
iziToast.info({ 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, image: productFromAnimal.icon,
}); });
@ -70,6 +70,7 @@ export default {
}); });
animal.production = { animal.production = {
started: moment(),
ready: moment().add(animalData.production.time, 'minutes'), ready: moment().add(animalData.production.time, 'minutes'),
percent: 0, percent: 0,
canBeCollected: false canBeCollected: false

15
src/store/index.js

@ -281,10 +281,9 @@ export default createStore({
if (field.data.percentDone <= 100) { if (field.data.percentDone <= 100) {
let minutesSincePlanting = moment.duration(moment().diff(field.data.planted)).asMinutes(); let minutesSincePlanting = moment.duration(moment().diff(field.data.planted)).asMinutes();
field.data.percentDone = field.data.percentDone = Number(
Number( Number(minutesSincePlanting) / Number(seed.cropData.timeToGrow) * 100
Number(minutesSincePlanting) / Number(seed.cropData.timeToGrow) * 100 ).toFixed(2);
).toFixed(2);
if (field.data.percentDone >= 100) { if (field.data.percentDone >= 100) {
field.data.percentDone = 100; field.data.percentDone = 100;
@ -333,6 +332,7 @@ export default createStore({
let animalData = AnimalService.getAnimalByID(animal.id); let animalData = AnimalService.getAnimalByID(animal.id);
if (!animal.production) { if (!animal.production) {
animal.production = { animal.production = {
started: moment(),
ready: moment().add(animalData.production.time, 'minutes'), ready: moment().add(animalData.production.time, 'minutes'),
percent: 0, percent: 0,
canBeCollected: false canBeCollected: false
@ -344,8 +344,11 @@ export default createStore({
} }
if (animal.production.percent <= 100) { if (animal.production.percent <= 100) {
let minutesLeft = moment.duration(moment(animal.production.ready).diff(moment())).asMinutes(); let minutesSinceLastCollection = moment.duration(moment().diff(animal.production.started)).asMinutes();
animal.production.percent = Number((Number(animalData.production.time) * 100) / Number(minutesLeft) - 100).toFixed(2); animal.production.percent = Number(
Number(minutesSinceLastCollection) / Number(animalData.production.time) * 100
).toFixed(2);
if (animal.production.percent >= 100) { if (animal.production.percent >= 100) {
animal.production.percent = 100; animal.production.percent = 100;
animal.production.canBeCollected = true; animal.production.canBeCollected = true;

Loading…
Cancel
Save