Skip to content

Commit

Permalink
Merge pull request #52 from saertna/formating-booster-board
Browse files Browse the repository at this point in the history
Formating booster board
  • Loading branch information
saertna authored Nov 29, 2023
2 parents 390a03c + 5f2f783 commit 0dc7130
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 165 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Thank you for being a part of this movement to revolutionize our approach to kno

## Manual installation

1. Download the latest release 🔗 **Plugin Download:** [Obsidian Gamification Plugin](https://github.com/saertna/obsidian-gamified-pkm/releases/tag/0.0.83)
1. Download the latest release 🔗 **Plugin Download:** [Obsidian Gamification Plugin](https://github.com/saertna/obsidian-gamified-pkm/releases/tag/0.0.84)
2. Extract the obsidian-gamified-pkm folder from the zip to your vault's plugins folder: `<vault>`/.obsidian/plugins/
- Note: On some machines the .obsidian folder may be hidden. On MacOS you should be able to press Command+Shift+Dot to show the folder in Finder.
- Note: the files `main.js` and `manifest.json` are the files which you need in this folder.
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "gamified-pkm",
"name": "Gamificate your PKM",
"version": "0.0.83",
"version": "0.0.84",
"minAppVersion": "0.15.0",
"description": "Enhance your Personal Knowledge Management with gamification elements. Boost motivation and achieve growth as you engage with your PKM.",
"author": "Andreas Trebing",
Expand Down
Binary file modified obsidian-gamified-pkm/obsidian-gamified-pkm.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-gamified-pkm",
"version": "0.0.83",
"version": "0.0.84",
"description": "Enhance your Personal Knowledge Management with gamification elements. Boost motivation and achieve growth as you engage with your PKM.",
"main": "main.js",
"scripts": {
Expand Down
12 changes: 5 additions & 7 deletions src/ModalBooster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,30 @@ export class ModalBooster extends Modal {
onOpen() {
const { contentEl } = this;
contentEl.setText(this.displayText);


const multiSelectModal = new MultiSelectModal(this.app, [], 'Craft Booster Item', this.gamificationInstance); // Create the modal instance


// Add a button to open the multi-select modal
const button = document.createElement('button');
button.innerText = 'Open Crafting Table';
button.classList.add('modal-button');
button.onclick = () => {
multiSelectModal.setUseBooster(false); // Set the flag for crafting table
multiSelectModal.setUseBooster(false);
multiSelectModal.open();
};


multiSelectModal.readBoostersStock();
multiSelectModal.readIngrementStock();


const button2 = document.createElement('button');
button2.innerText = 'Open Booster Board';
button2.classList.add('modal-button');
button2.onclick = () => {
multiSelectModal.setUseBooster(true);
multiSelectModal.open();
};

contentEl.appendChild(button);
contentEl.appendChild(button2);

}

onClose() {
Expand Down
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 0dc7130

Please sign in to comment.