Skip to content

Commit

Permalink
Fixed missing stock information for boosters
Browse files Browse the repository at this point in the history
added debug messages on variable
  • Loading branch information
saertna committed Nov 28, 2023
1 parent dcb9e7c commit f1e7e9a
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 119 deletions.
40 changes: 21 additions & 19 deletions src/MultiSelectModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
elements,
boosterRecipes,
listOfUseableBoostersToBeShown,
listOfUseableIngredientsToBeShown
listOfUseableIngredientsToBeShown,
debugLogs
} from './constants';
import { ModalInformationbox } from 'ModalInformationbox';
import gamification, { isMinutesPassed, hoursUntilMinutesPassed} from 'main';
Expand Down Expand Up @@ -33,7 +34,7 @@ export class MultiSelectModal extends Modal {
const { contentEl } = this;
contentEl.empty();

//this.readBoostersStock();
this.readBoostersStock();
// take care only to run several times through when boosters are used
if (this.useBooster) {
boosterRecipes.forEach(item => {
Expand All @@ -59,10 +60,9 @@ export class MultiSelectModal extends Modal {
}

private boosterAvailableForUse(item: string) {
//console.debug(`boosterAvailableForUse: ${item}`)
if(debugLogs) console.debug(`boosterAvailableForUse: ${item}`)
let found = false;
listOfUseableBoostersToBeShown.forEach(element => {
//console.debug(`${item} == ${element} ??`)
if (item == element) {
if (!found) {
found = true;
Expand Down Expand Up @@ -90,7 +90,7 @@ export class MultiSelectModal extends Modal {
}

updateIncrementStock(increment: string, stock: number) {
console.debug(`increment "${increment}" new value ${stock}`);
if(debugLogs) console.debug(`increment "${increment}" new value ${stock}`);
this.remainingStock[increment] = stock;
this.gamificationInstance.setSettingNumber(this.getIngerementVarNameFromName(increment) || '', stock);
}
Expand All @@ -116,15 +116,15 @@ export class MultiSelectModal extends Modal {
this.gamificationInstance.setSettingNumber('boosterUseCount',boosterOverallUse + 1)
} else {
// Handle the case where boosterLastUsedDate is not a valid string.
console.debug(`decrementBooster: "boosterUseCount" could not got read.`)
if(debugLogs) console.debug(`decrementBooster: "boosterUseCount" could not got read.`)
}
const boosterUse = this.gamificationInstance.getSettingNumber(this.getBoosterUseFromName(booster))
if (typeof boosterUse === 'number' && boosterUse !== null) {
// Now you can safely assign boosterLastUsedDate to boosterLastUsedDate.
this.gamificationInstance.setSettingNumber(this.getBoosterUseFromName(booster),boosterUse + 1)
} else {
// Handle the case where boosterLastUsedDate is not a valid string.
console.debug(`decrementBooster: "${this.getBoosterUseFromName(booster)}" could not got read.`)
if(debugLogs) console.debug(`decrementBooster: "${this.getBoosterUseFromName(booster)}" could not got read.`)
}
this.updateQuantityDisplay(booster);
}
Expand Down Expand Up @@ -235,6 +235,7 @@ export class MultiSelectModal extends Modal {
container.className = 'modal-checkbox-container';

//const stock = this.remainingStock[labelText] || 0;
if(debugLogs) console.log(`createBoosterList: labelText: ${labelText}`)
const stock = this.boosters[labelText];

const label = container.createEl('div', { cls: `${labelText.replace(' ', '-')}` });
Expand All @@ -243,7 +244,8 @@ export class MultiSelectModal extends Modal {
const momentDate = this.gamificationInstance.getSettingString(this.getBoosterDateFromName(labelText));

if (isMinutesPassed(window.moment(momentDate as string, 'YYYY-MM-DD HH:mm:ss'), this.getBoosterCooldownFromName(labelText)) == false) {
console.debug(`Booster ${labelText} is still in cooldown for ${window.moment(momentDate as string, 'YYYY-MM-DD HH:mm:ss'), this.getBoosterCooldownFromName(labelText) / 60} hours`);
if(debugLogs) console.debug(`Booster ${labelText} is still in cooldown for ${window.moment(momentDate as string, 'YYYY-MM-DD HH:mm:ss'), this.getBoosterCooldownFromName(labelText) / 60} hours`);
if(debugLogs) console.log(`createBoosterList: Stock amount ${stock}`)
label.createEl('div', { text: `${labelText} : (${stock})` });

useButton.innerText = `cooldown ${hoursUntilMinutesPassed(window.moment(momentDate as string, 'YYYY-MM-DD HH:mm:ss'), this.getBoosterCooldownFromName(labelText))} hours`;
Expand Down Expand Up @@ -279,7 +281,7 @@ export class MultiSelectModal extends Modal {

incrementItem(item: string) {
const stock = this.remainingStock[item];
//console.debug(`incrementItem: stock = ${stock}`);
if(debugLogs) console.debug(`incrementItem: stock = ${stock}`);
if (stock > 0) {
this.selectedItems.push(item);
this.remainingStock[item]--;
Expand Down Expand Up @@ -308,9 +310,9 @@ export class MultiSelectModal extends Modal {


private useBoosterItem(labelText: string) {
console.debug(`use Booster ${labelText}`);
if(debugLogs) console.debug(`use Booster ${labelText}`);
if(labelText=='Fortune Infusion'){
//console.debug(`acquireIngredients();`)
if(debugLogs) console.debug(`acquireIngredients();`)
this.gamificationInstance.acquireIngredients(1,1,10)
} else if (labelText=='Temporal Tweaker'){

Expand Down Expand Up @@ -383,10 +385,10 @@ export class MultiSelectModal extends Modal {
private checkIngredientsAvailability(incredients: { name: string; incredients: string[]; }) {
for (const ingredient of incredients.incredients) {
const [quantity, shortName] = ingredient.split('x');
//console.debug(`quantity: ${quantity}\tshortName: ${shortName}`)
if(debugLogs) console.debug(`quantity: ${quantity}\tshortName: ${shortName}`)
const requiredQuantity = parseInt(quantity);
const availableStock = this.remainingStock[this.getIngerementNameFromShortName(shortName) || 0];
//console.debug(`requiredQuantity: ${requiredQuantity}\tavailableStock: ́${availableStock}`)
if(debugLogs) console.debug(`requiredQuantity: ${requiredQuantity}\tavailableStock: ́${availableStock}`)
if (requiredQuantity > availableStock) {
return false; // Not enough stock for this ingredient
}
Expand All @@ -405,7 +407,7 @@ export class MultiSelectModal extends Modal {
totalAvailableIngredients += this.remainingStock[this.getIngerementFromName(increment).name] || 0;
});

console.debug(`total amount of ingrediments: ${totalAvailableIngredients}`)
if(debugLogs) console.debug(`total amount of ingrediments: ${totalAvailableIngredients}`)
// If at least 1000 ingredients are available
if (totalAvailableIngredients >= 1000) {
// Burn ingredients proportionally
Expand All @@ -414,7 +416,7 @@ export class MultiSelectModal extends Modal {
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.debug(`${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}`)
//if(debugLogs) console.debug(`${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;
//this.updateIncrementStock(this.getIngerementFromName(increment).varName, this.remainingStock[this.getIngerementFromName(increment).name])
this.updateIncrementStock(this.getIngerementFromName(increment).name, this.remainingStock[this.getIngerementFromName(increment).name] - proportionalAmount)
Expand Down Expand Up @@ -476,23 +478,23 @@ export class MultiSelectModal extends Modal {
if(this.check1000IngredientsAvailableAndBurn()){
this.updateBoosterStock(selectedItems.name, 1);
this.gamificationInstance.setSettingNumber(this.getBoosterVarNameFromName(selectedItems.name), this.boosters[selectedItems.name]);
console.debug(`craft booster ${selectedItems.name}`);
if(debugLogs) console.debug(`craft booster ${selectedItems.name}`);
} else {
console.debug(`not enough ingredients for booster ${selectedItems.name} in stock`);
if(debugLogs) console.debug(`not enough ingredients for booster ${selectedItems.name} in stock`);
new ModalInformationbox(this.app, `Not enough ingrediments available for '${selectedItems.name}'. Craft more Notes to collect new ingrediments.`).open();
}
} else if(selectedItems.name == 'Fortune Infusion'){

} else {
if (this.checkIngredientsAvailability(selectedItems)) {
console.debug(`craft booster ${selectedItems.name}`);
if(debugLogs) console.debug(`craft booster ${selectedItems.name}`);
this.updateBoosterStock(selectedItems.name, 1);
this.gamificationInstance.setSettingNumber(this.getBoosterVarNameFromName(selectedItems.name), this.boosters[selectedItems.name]);
this.useIngrediments(selectedItems);
//this.updateQuantityDisplay(selectedItems.name)
this.updateStockInformation();
} else {
console.debug(`not enough ingredients for booster ${selectedItems.name} in stock`);
if(debugLogs) console.debug(`not enough ingredients for booster ${selectedItems.name} in stock`);
new ModalInformationbox(this.app, `Not enough ingrediments available for '${selectedItems.name}'. Craft more Notes to collect new ingrediments.`).open();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/badges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function getBadgeForLevel(level: number, inform: boolean): Badge {
// Example usage:
// const currentLevel = 42; // Replace this with the actual player's level
// const badge = getBadgeForLevel(currentLevel);
// console.debug(`Congratulations! You've reached Level ${currentLevel}. You've earned the "${badge.name}" badge. ${badge.description}`);
// if(debugLogs) console.debug(`Congratulations! You've reached Level ${currentLevel}. You've earned the "${badge.name}" badge. ${badge.description}`);



Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const streakboosterIncreaseDaily: number = 0.1;
export const streakboosterIncreaseWeekly: number = 1;
export const CryptoJS = require("crypto-js");
export const secretKey = "2ZU^12y#QmNB5$yEin5^";
export const debugLogs = false;
export const avatarInitContent = `# Avatar
| | |
Expand Down
3 changes: 2 additions & 1 deletion src/creatmodchartcalculation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {TFile} from 'obsidian';
import { debugLogs } from './constants';

export function findEarliestCreatedFile(files: TFile[]): TFile {
let earliestCreatedFile: TFile = files[0];
Expand Down Expand Up @@ -82,7 +83,7 @@ export function createChartFormat(y_axis: string, countsStringMod: string, chart
export async function replaceChartContent (avatarPageName: string, newContent: string) {
const existingFile = this.app.vault.getAbstractFileByPath(`${avatarPageName}.md`);
if (existingFile == null) {
console.debug(`File ${avatarPageName}.md does not exist`);
if(debugLogs) console.debug(`File ${avatarPageName}.md does not exist`);
return;
}
const file = existingFile as TFile;
Expand Down
Loading

0 comments on commit f1e7e9a

Please sign in to comment.