Skip to content

Commit

Permalink
Merge pull request #45 from PwQt/44-multiple-spells-in-magic-items-br…
Browse files Browse the repository at this point in the history
…eaking-magic-items-page

#44 fix to sortByLevel helper
  • Loading branch information
PwQt authored Jan 20, 2024
2 parents 20996e9 + ca2d1c1 commit db081e0
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/scripts/magic-item-entry/AbstractMagicItemEntry.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { warn } from "../lib/lib";
import { MagiItemHelpers } from "../magic-item-helpers";
import { MagicItemHelpers } from "../magic-item-helpers";

export class AbstractMagicItemEntry {
constructor(data) {
mergeObject(this, data);
}

get displayName() {
return MagiItemHelpers.getEntityNameCompendiumWithBabele(this.pack, this.name);
return MagicItemHelpers.getEntityNameCompendiumWithBabele(this.pack, this.name);
}

async renderSheet() {
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/magic-item-entry/MagicItemFeat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MAGICITEMS } from "../config";
import { MagiItemHelpers } from "../magic-item-helpers";
import { MagicItemHelpers } from "../magic-item-helpers";
import { AbstractMagicItemEntry } from "./AbstractMagicItemEntry";

export class MagicItemFeat extends AbstractMagicItemEntry {
Expand Down Expand Up @@ -28,6 +28,6 @@ export class MagicItemFeat extends AbstractMagicItemEntry {
}

get effects() {
return MagiItemHelpers.localized(MAGICITEMS.effects);
return MagicItemHelpers.localized(MAGICITEMS.effects);
}
}
4 changes: 2 additions & 2 deletions src/scripts/magic-item-entry/MagicItemTable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MAGICITEMS } from "../config";
import { MagiItemHelpers } from "../magic-item-helpers";
import { MagicItemHelpers } from "../magic-item-helpers";
import { AbstractMagicItemEntry } from "./AbstractMagicItemEntry";

export class MagicItemTable extends AbstractMagicItemEntry {
Expand All @@ -8,7 +8,7 @@ export class MagicItemTable extends AbstractMagicItemEntry {
}

get usages() {
return MagiItemHelpers.localized(MAGICITEMS.tableUsages);
return MagicItemHelpers.localized(MAGICITEMS.tableUsages);
}

async roll(actor) {
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/magic-item-helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isRealNumber } from "./lib/lib";

export class MagiItemHelpers {
export class MagicItemHelpers {
static numeric = function (value, fallback) {
// if ($.isNumeric(value)) {
// return parseInt(value);
Expand Down Expand Up @@ -61,7 +61,7 @@ export class MagiItemHelpers {
}

static sortByLevel(a, b) {
return a.level === b.level ? MagicItem.sortByName(a, b) : a.level - b.level;
return a.level === b.level ? MagicItemHelpers.sortByName(a, b) : a.level - b.level;
}

/**
Expand Down
18 changes: 9 additions & 9 deletions src/scripts/magic-item/MagicItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MAGICITEMS } from "../config.js";
import { MagicItemFeat } from "../magic-item-entry/MagicItemFeat.js";
import { MagicItemSpell } from "../magic-item-entry/MagicItemSpell.js";
import { MagicItemTable } from "../magic-item-entry/MagicItemTable.js";
import { MagiItemHelpers } from "../magic-item-helpers.js";
import { MagicItemHelpers } from "../magic-item-helpers.js";

export class MagicItem {
constructor(flags) {
Expand Down Expand Up @@ -48,10 +48,10 @@ export class MagicItem {

sort() {
if (this.sorting === "a") {
this.spells = this.spells.sort(MagiItemHelpers.sortByName);
this.spells = this.spells.sort(MagicItemHelpers.sortByName);
}
if (this.sorting === "l") {
this.spells = this.spells.sort(MagiItemHelpers.sortByLevel);
this.spells = this.spells.sort(MagicItemHelpers.sortByLevel);
}
}

Expand Down Expand Up @@ -113,23 +113,23 @@ export class MagicItem {
}

get chargeTypes() {
return MagiItemHelpers.localized(MAGICITEMS.chargeTypes);
return MagicItemHelpers.localized(MAGICITEMS.chargeTypes);
}

get destroyChecks() {
return MagiItemHelpers.localized(MAGICITEMS.destroyChecks);
return MagicItemHelpers.localized(MAGICITEMS.destroyChecks);
}

get destroyTypes() {
return MagiItemHelpers.localized(MAGICITEMS.destroyTypes);
return MagicItemHelpers.localized(MAGICITEMS.destroyTypes);
}

get rechargeUnits() {
return MagiItemHelpers.localized(MAGICITEMS.rechargeUnits);
return MagicItemHelpers.localized(MAGICITEMS.rechargeUnits);
}

get rechargeTypes() {
return MagiItemHelpers.localized(MAGICITEMS.rechargeTypes);
return MagicItemHelpers.localized(MAGICITEMS.rechargeTypes);
}

get rechargeText() {
Expand Down Expand Up @@ -259,7 +259,7 @@ export class MagicItem {
}

addEntity(entity, pack) {
let name = MagiItemHelpers.getEntityNameWithBabele(entity);
let name = MagicItemHelpers.getEntityNameWithBabele(entity);
if (entity.type === "spell") {
this.addSpell({
uuid: entity.uuid,
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/magic-item/OwnedMagicItem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MAGICITEMS } from "../config";
import CONSTANTS from "../constants/constants";
import { warn } from "../lib/lib";
import { MagiItemHelpers } from "../magic-item-helpers";
import { MagicItemHelpers } from "../magic-item-helpers";
import { OwnedMagicItemFeat } from "../magic-item-owned-entry/OwnedMagicItemFeat";
import { OwnedMagicItemSpell } from "../magic-item-owned-entry/OwnedMagicItemSpell";
import { OwnedMagicItemTable } from "../magic-item-owned-entry/OwnedMagicItemTable";
Expand All @@ -21,7 +21,7 @@ export class OwnedMagicItem extends MagicItem {

this.rechargeableLabel = this.rechargeable
? `(${game.i18n.localize("MAGICITEMS.SheetRecharge")}: ${this.rechargeText} ${
MagiItemHelpers.localized(MAGICITEMS.rechargeUnits)[this.rechargeUnit]
MagicItemHelpers.localized(MAGICITEMS.rechargeUnits)[this.rechargeUnit]
} )`
: game.i18n.localize("MAGICITEMS.SheetNoRecharge");

Expand Down
12 changes: 6 additions & 6 deletions src/scripts/magicItemtab.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MAGICITEMS } from "./config.js";
import CONSTANTS from "./constants/constants.js";
import { MagiItemHelpers } from "./magic-item-helpers.js";
import { MagicItemHelpers } from "./magic-item-helpers.js";
import { MagicItem } from "./magic-item/MagicItem.js";

const magicItemTabs = [];
Expand Down Expand Up @@ -173,7 +173,7 @@ export class MagicItemTab {
this.render();
});
this.html.find('input[name="flags.magicitems.charges"]').change((evt) => {
this.magicItem.charges = MagiItemHelpers.numeric(evt.target.value, this.magicItem.charges);
this.magicItem.charges = MagicItemHelpers.numeric(evt.target.value, this.magicItem.charges);
this.render();
});
this.html.find('select[name="flags.magicitems.chargeType"]').change((evt) => {
Expand Down Expand Up @@ -236,15 +236,15 @@ export class MagicItemTab {
this.render();
});
this.html.find(`input[name="flags.magicitems.spells.${idx}.consumption"]`).change((evt) => {
spell.consumption = MagiItemHelpers.numeric(evt.target.value, spell.consumption);
spell.consumption = MagicItemHelpers.numeric(evt.target.value, spell.consumption);
this.render();
});
this.html.find(`select[name="flags.magicitems.spells.${idx}.upcast"]`).change((evt) => {
spell.upcast = parseInt(evt.target.value);
this.render();
});
this.html.find(`input[name="flags.magicitems.spells.${idx}.upcastCost"]`).change((evt) => {
spell.upcastCost = MagiItemHelpers.numeric(evt.target.value, spell.cost);
spell.upcastCost = MagicItemHelpers.numeric(evt.target.value, spell.cost);
this.render();
});
this.html.find(`input[name="flags.magicitems.spells.${idx}.flatDc"]`).click((evt) => {
Expand All @@ -265,7 +265,7 @@ export class MagicItemTab {
this.render();
});
this.html.find(`input[name="flags.magicitems.feats.${idx}.consumption"]`).change((evt) => {
feat.consumption = MagiItemHelpers.numeric(evt.target.value, feat.consumption);
feat.consumption = MagicItemHelpers.numeric(evt.target.value, feat.consumption);
this.render();
});
this.html.find(`a[data-feat-idx="${idx}"]`).click((evt) => {
Expand All @@ -274,7 +274,7 @@ export class MagicItemTab {
});
this.magicItem.tables.forEach((table, idx) => {
this.html.find(`input[name="flags.magicitems.tables.${idx}.consumption"]`).change((evt) => {
table.consumption = MagiItemHelpers.numeric(evt.target.value, table.consumption);
table.consumption = MagicItemHelpers.numeric(evt.target.value, table.consumption);
});
this.html.find(`a[data-table-idx="${idx}"]`).click((evt) => {
table.renderSheet();
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/magicitemactor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MAGICITEMS } from "./config.js";
import { warn } from "./lib/lib.js";
import { MagiItemHelpers } from "./magic-item-helpers.js";
import { MagicItemHelpers } from "./magic-item-helpers.js";
import { OwnedMagicItem } from "./magic-item/OwnedMagicItem.js";

/**
Expand Down
8 changes: 4 additions & 4 deletions src/scripts/magicitemsheet.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MAGICITEMS } from "./config.js";
import CONSTANTS from "./constants/constants.js";
import { MagiItemHelpers } from "./magic-item-helpers.js";
import { MagicItemHelpers } from "./magic-item-helpers.js";
import { MagicItemActor } from "./magicitemactor.js";

const magicItemSheets = [];
Expand Down Expand Up @@ -101,12 +101,12 @@ export class MagicItemSheet {
this.html.find(".item h4.spell-name").click((evt) => this.onItemShow(evt));
this.actor.items.forEach((item) => {
this.html.find(`input[data-item-id="magicitems.${item.id}.uses"]`).change((evt) => {
item.setUses(MagiItemHelpers.numeric(evt.currentTarget.value, item.uses));
item.setUses(MagicItemHelpers.numeric(evt.currentTarget.value, item.uses));
item.update();
});
item.ownedEntries.forEach((entry) => {
this.html.find(`input[data-item-id="magicitems.${item.id}.${entry.id}.uses"]`).change((evt) => {
entry.uses = MagiItemHelpers.numeric(evt.currentTarget.value, entry.uses);
entry.uses = MagicItemHelpers.numeric(evt.currentTarget.value, entry.uses);
item.update();
});
});
Expand Down Expand Up @@ -146,7 +146,7 @@ export class MagicItemSheet {
if (itemUuid) {
uuid = itemUuid;
} else {
uuid = MagiItemHelpers.retrieveUuid({
uuid = MagicItemHelpers.retrieveUuid({
documentName: null,
documentId: itemId,
documentCollectionType: "Item",
Expand Down

0 comments on commit db081e0

Please sign in to comment.