Skip to content

Commit

Permalink
Fixed calculation for remaining ingrediments
Browse files Browse the repository at this point in the history
  • Loading branch information
saertna committed Oct 21, 2023
1 parent 2394d99 commit 8e00d40
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
17 changes: 9 additions & 8 deletions main.js

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions src/MultiSelectModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,22 +322,27 @@ export class MultiSelectModal extends Modal {
return true;
}


private check1000IngredientsAvailableAndBurn() {
let totalAvailableIngredients = 0;

// Calculate the total number of available ingredients
elements.forEach(increment => {
totalAvailableIngredients += this.remainingStock[increment.name] || 0;
//elements.forEach(increment => {
listOfUseableIngredientsToBeShown.forEach(increment => {
totalAvailableIngredients += this.remainingStock[this.getIngerementFromName(increment).name] || 0;
});

console.log(`total amount of ingrediments: ${totalAvailableIngredients}`)
// If at least 1000 ingredients are available
if (totalAvailableIngredients >= 1000) {
// Burn ingredients proportionally
elements.forEach(increment => {
if (this.remainingStock[increment.name]) {
const proportionalAmount = Math.ceil((this.remainingStock[increment.name] / totalAvailableIngredients) * 1000);
const difference = this.remainingStock[increment.name] - proportionalAmount;
this.remainingStock[increment.name] -= difference;
//elements.forEach(increment => {
listOfUseableIngredientsToBeShown.forEach(increment => {
if (this.remainingStock[this.getIngerementFromName(increment).name]) {
const proportionalAmount = Math.ceil((this.remainingStock[this.getIngerementFromName(increment).name] / totalAvailableIngredients) * 1000);
//const rest = this.remainingStock[this.getIngerementFromName(increment).name] - proportionalAmount;
//console.log(`${this.getIngerementFromName(increment).shortName} ${this.remainingStock[this.getIngerementFromName(increment).name]} shall be ${this.remainingStock[this.getIngerementFromName(increment).name] - rest} = ${this.remainingStock[this.getIngerementFromName(increment).name]} - ${rest}`)
this.remainingStock[this.getIngerementFromName(increment).name] = this.remainingStock[this.getIngerementFromName(increment).name] - proportionalAmount;;
}
});

Expand Down

0 comments on commit 8e00d40

Please sign in to comment.