Skip to content

Commit

Permalink
#85 - fixed deprecation messages
Browse files Browse the repository at this point in the history
  • Loading branch information
geoidesic committed Aug 9, 2024
1 parent 79fb260 commit 769055b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 49 deletions.
1 change: 0 additions & 1 deletion src/components/molecules/Footer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
// Sample helper function to process abilityGenerationMethod
function isAbilityGenerationMethodReady(method) {
log.d("method", method);
if (!method) {
return false;
}
Expand Down
129 changes: 82 additions & 47 deletions src/components/organisms/dnd5e/Tabs/Class.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
characterSubClass,
level,
tabs,
subClassesForClass
subClassesForClass,
} from "~/src/helpers/store";
import { localize } from "#runtime/svelte/helper";
import { TJSSelect } from "@typhonjs-fvtt/svelte-standard/component";
import DonationTracker from "~/src/plugins/donation-tracker"
import DonationTracker from "~/src/plugins/donation-tracker";
let richHTML = "",
html = "",
Expand All @@ -31,8 +31,10 @@
classesPlaceholder = "Classes",
subclassesPlaceholder = "Subclasses",
packs = getPacksFromSettings("classes"),
subClassesPack = game.packs.get('dnd5e.subclasses'),
subClassesPack = game.packs.get("dnd5e.subclasses"),
subClassesPacks = getPacksFromSettings("subclasses"),
classAdvancementArrayFiltered = [],
subClassAdvancementArrayFiltered = [],
mappedClassIndex = extractItemsFromPacks(packs, [
"name->label",
"img",
Expand All @@ -43,12 +45,9 @@
]),
filteredClassIndex = mappedClassIndex
.filter((i) => {
return i.type == 'class' && DonationTracker.canViewItem(i)
return i.type == "class" && DonationTracker.canViewItem(i);
})
.sort((a, b) => a.label.localeCompare(b.label))
;
.sort((a, b) => a.label.localeCompare(b.label));
const levelOptions = [];
for (let i = 1; i <= 20; i++) {
levelOptions.push({ label: "Level " + i, value: i });
Expand All @@ -67,49 +66,58 @@
await tick();
importClassAdvancements();
importSubClassAdvancements();
};
const getFilteredSubclassIndex = async () => {
const filteredSubClassIndex = [];
for(let subClassesPack of subClassesPacks) {
for (let subClassesPack of subClassesPacks) {
let index = await subClassesPack.getIndex({
fields: ["system.classIdentifier"],
});
if(!subClassesPack) continue
let mappedSubClassIndex = extractMapIteratorObjectProperties(index.entries(), [
if (!subClassesPack) continue;
let mappedSubClassIndex = extractMapIteratorObjectProperties(
index.entries(),
[
"name->label",
"img",
"type",
"folder",
"uuid->value",
"system",
"_id",
])
],
);
filteredSubClassIndex.push(mappedSubClassIndex?.filter(
(x) => x.system.classIdentifier == $characterClass.system.identifier,
))
filteredSubClassIndex.push(
mappedSubClassIndex?.filter(
(x) => x.system.classIdentifier == $characterClass.system.identifier,
),
);
}
const output = filteredSubClassIndex.flat().sort((a, b) => a.label.localeCompare(b.label));
return output
const output = filteredSubClassIndex
.flat()
.sort((a, b) => a.label.localeCompare(b.label));
return output;
};
const selectClassHandler = async (option) => {
activeSubClass = null;
$characterSubClass = null;
subclassValue = null;
subClassAdvancementArrayFiltered = [];
richSubClassHTML = "";
$characterClass = await fromUuid(option);
log.d($characterClass.system.advancement);
log.d(Array.isArray($characterClass.system.advancement));
log.d($characterClass?.system?.advancement.filter);
log.d($characterClass?.system?.advancement.map);
activeClass = option;
await tick();
subClassesIndex = await getFilteredSubclassIndex();
$subClassesForClass = subClassesIndex;
await tick();
importClassAdvancements();
richHTML = await TextEditor.enrichHTML(html);
Expand All @@ -118,7 +126,9 @@
const importClassAdvancements = async () => {
for (const classAdvancement of classAdvancementArrayFiltered) {
try {
const module = await import(`~/src/components/molecules/dnd5e/Advancements/${classAdvancement.type}.svelte`);
const module = await import(
`~/src/components/molecules/dnd5e/Advancements/${classAdvancement.type}.svelte`
);
classAdvancementComponents[classAdvancement.type] = module.default;
} catch (error) {
log.e(`Failed to load component for ${classAdvancement.type}:`, error);
Expand All @@ -130,8 +140,8 @@
$characterSubClass = await fromUuid(option);
activeSubClass = option;
await tick();
importClassAdvancements()
importSubClassAdvancements()
importClassAdvancements();
importSubClassAdvancements();
richSubClassHTML = await TextEditor.enrichHTML(
$characterSubClass.system.description.value,
);
Expand All @@ -140,44 +150,70 @@
const importSubClassAdvancements = async () => {
for (const subClassAdvancement of subClassAdvancementArrayFiltered) {
try {
const module = await import(`~/src/components/molecules/dnd5e/Advancements/${subClassAdvancement.type}.svelte`);
const module = await import(
`~/src/components/molecules/dnd5e/Advancements/${subClassAdvancement.type}.svelte`
);
await tick();
subClassAdvancementComponents[subClassAdvancement.type] = module.default;
subClassAdvancementComponents[subClassAdvancement.type] =
module.default;
} catch (error) {
log.e(`Failed to load component for ${subClassAdvancement.type}:`, error);
log.e(
`Failed to load component for ${subClassAdvancement.type}:`,
error,
);
}
}
};
function getHint(advancement) {
if(game.version > 12) {
return advancement.hint || null;
} else {
return advancement.configuration?.hint || null
}
}
$: html = $characterClass?.system?.description.value || "";
$: subClassProp = activeSubClass;
$: classProp = activeClass;
$: combinedHtml = richHTML + (richSubClassHTML ? `<h1>${localize('GAS.SubClass')}</h1>` + richSubClassHTML : '');
$: combinedHtml =
richHTML +
(richSubClassHTML
? `<h1>${localize("GAS.SubClass")}</h1>` + richSubClassHTML
: "");
$: classAdvancementComponents = {};
$: subClassAdvancementComponents = {};
$: if(subClassesIndex?.length) {
subclasses = subClassesIndex.flat().sort((a, b) => a.label.localeCompare(b.label));
$: if (subClassesIndex?.length) {
subclasses = subClassesIndex
.flat()
.sort((a, b) => a.label.localeCompare(b.label));
} else {
subclasses = [];
}
$: subClassAdvancementArrayFiltered = $characterSubClass?.advancement?.byId
? Object.entries($characterSubClass.advancement.byId)
.filter(([id, value]) => value.level === $level)
.map(([id, value]) => ({ ...value, id }))
: [];
$: classAdvancementArrayFiltered = $characterClass?.advancement?.byId
? Object.entries($characterClass.advancement.byId)
.filter(([id, value]) => value.level === $level)
$: if ($characterSubClass?.system?.advancement.length) {
subClassAdvancementArrayFiltered =
$characterSubClass.system.advancement.filter(
(value) => value.level === $level,
);
} else {
subClassAdvancementArrayFiltered = [];
}
.map(([id, value]) => ({ ...value, id }))
: [];
$: if ($characterClass?.system?.advancement.length) {
classAdvancementArrayFiltered = $characterClass.system.advancement.filter(
(value) => value.level === $level,
);
} else {
classAdvancementArrayFiltered = [];
}
onMount(async () => {
if ($characterClass) {
log.d($characterClass);
classValue = $characterClass.uuid;
await tick();
importClassAdvancements();
Expand All @@ -193,7 +229,6 @@
);
}
});
</script>
<template lang="pug">
Expand Down Expand Up @@ -226,7 +261,7 @@
+each("classAdvancementArrayFiltered as advancement")
//- @todo: this should be broken out into components for each advancement.type
li.left(data-type="{advancement.type}")
.flexrow(data-tooltip="{advancement.configuration?.hint || null}" data-tooltip-class="gas-tooltip dnd5e2 dnd5e-tooltip item-tooltip")
.flexrow(data-tooltip="{getHint(advancement)}" data-tooltip-class="gas-tooltip dnd5e2 dnd5e-tooltip item-tooltip")
.flex0.relative.image
img.icon(src="{advancement.icon}" alt="{advancement.title}")
.flex2 {advancement.title}
Expand All @@ -248,7 +283,7 @@
+each("subClassAdvancementArrayFiltered as advancement")
//- @todo: this should be broken out into components for each advancement.type
li.left(data-type="{advancement.type}")
.flexrow(data-tooltip="{advancement.configuration?.hint || null}" data-tooltip-locked="true" data-tooltip-class="gas-tooltip dnd5e2 dnd5e-tooltip item-tooltip" )
.flexrow(data-tooltip="{getHint(advancement)}" data-tooltip-locked="true" data-tooltip-class="gas-tooltip dnd5e2 dnd5e-tooltip item-tooltip" )
.flex0.relative.image
img.icon(src="{advancement.icon}" alt="{advancement.title}")
.flex2 {advancement.title}
Expand All @@ -257,8 +292,8 @@
.flex0.border-right.right-border-gradient-mask
.flex3.left.pl-md.scroll.col-b {@html combinedHtml}
</template>
</template>
<style lang="sass">
@import "../../../../../styles/Mixins.scss"
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ export function resetStores() {
isActorCreated.set(false);
actorInGame.set(false);
abilityGenerationMethod.set(null);
subClassesForClass = set([]);
subClassesForClass.set([]);

}
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { registerSettings } from '~/src/settings';
import DonationTrackerGameSettings from '~/src/settings/DonationTrackerGameSettings.js';



window.log = log;
log.level = log.DEBUG;

Expand All @@ -25,6 +26,8 @@ Hooks.once("init", (app, html, data) => {
initLevelup();
registerSettings(app);



Hooks.call("gas.initIsComplete");

});
Expand Down

0 comments on commit 769055b

Please sign in to comment.