Skip to content

Commit

Permalink
fix: #94
Browse files Browse the repository at this point in the history
  • Loading branch information
geoidesic committed Sep 10, 2024
1 parent 07e5fed commit 489d2b0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/components/molecules/Footer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
});
}
game.system.log.d('dropItemRegistry', $dropItemRegistry)
// game.system.log.d('dropItemRegistry', $dropItemRegistry)
dropItemRegistry.advanceQueue(true);
};
Expand Down Expand Up @@ -251,7 +251,7 @@ div
//- .flex2
//- input.left(type="text" value="{tokenValue}" on:input="{handleTokenNameInput}")
+if("!$isLevelUp")
//- button.mt-xs(type="button" role="button" on:mousedown="{clickCreateHandler}") Create Character
button.mt-xs(type="button" role="button" on:mousedown="{clickCreateHandler}") Create Character
.flex1
ProgressBar(progress="{progress}")
+if("$progress != '100'")
Expand Down
13 changes: 13 additions & 0 deletions src/helpers/Utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,23 @@ export const prepareItemForDrop = async ({ itemData, isLevelUp, isMultiClass })
//- used by dropItemRegistry
export const dropItemOnCharacter = async (actor, item) => {
game.system.log.d('dropItemOnCharacter');
game.system.log.d('dropItemOnCharacter item', item);
game.system.log.d('actor.sheet._onDropItemCreate fn', actor.sheet._onDropItemCreate);
return await actor.sheet._onDropItemCreate(item);
}

export const itemHasAdvancementChoices = (item) => {
let hasAdvancementChoices = false;
if (!item?.system?.advancement.length) return false;
for (const adv of item.system.advancement) {
if (adv.configuration.choices) {
hasAdvancementChoices = true;
break;
}
}
return hasAdvancementChoices;
}

export const isAdvancementsForLevelInItem = (level, item) => {
// where structure is like system.advancement = [{level: 1, ...}]
const adv = item?.system?.advancement.find(adv => adv.level === level)
Expand Down
43 changes: 28 additions & 15 deletions src/helpers/store.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { writable, get, derived } from 'svelte/store';;
import { dropItemOnCharacter, prepareItemForDrop, log } from "~/src/helpers/Utility";
import { dropItemOnCharacter, prepareItemForDrop, itemHasAdvancementChoices } from "~/src/helpers/Utility";
const initialTabs = [
{ label: "Abilities", id: "abilities", component: "Abilities" },
{ label: "Race", id: "race", component: "Race" },
Expand All @@ -25,41 +25,54 @@ const arrayOfObjectsStore = () => {
return {
subscribe,
add: (app) => {
update(apps => [...apps, app]);
update(apps => {
const filteredApps = apps.filter(existingApp => existingApp.id !== app.id); // Remove any app with the same id
return [...filteredApps, app]; // Add the new app
});
game.system.log.d('currentStore.length', get(store).length);
},


remove,
removeAll: () => set([]),
advanceQueue: async (initial) => {
game.system.log.d('advanceQueue')
game.system.log.d('advanceQueue initial', initial || false)

// game.system.log.d('advanceQueue')
// game.system.log.d('advanceQueue initial', initial || false)
const currentStore = get(store);

game.system.log.d('advanceQueue currentStore.length', currentStore.length)
// game.system.log.d('currentStore.length', currentStore.length)
// game.system.log.d('advanceQueue currentStore.length', currentStore.length)

const next = currentStore[0] || false;
game.system.log.d("advanceQueue next", next);
game.system.log.d('current item to advance: ', next.id)
// game.system.log.d("advanceQueue next", next);
// game.system.log.d('current item to advance: ', next.id)
if (!next) {
inProcess.set(false);
game.system.log.d('end of queue')
return false;
}
inProcess.set(next);
remove(next.id);
game.system.log.d('advanceQueue currentStore.length', currentStore.length)
game.system.log.d('dropping item to character', next)
game.system.log.d(next.itemData);
// game.system.log.d('advanceQueue currentStore.length', currentStore.length)
// game.system.log.d('dropping item to character', next)
// game.system.log.d(next.itemData);
const item = await prepareItemForDrop(next)

try {
const result = await dropItemOnCharacter(next.actor, item);
game.system.log.d('dropItemOnCharacter result', result)
// game.system.log.d('dropItemOnCharacter result', result)
} catch (error) {
game.system.log.e('dropItemOnCharacter error', error)
// game.system.log.e('dropItemOnCharacter error', error)
}

return currentStore.length > 0
if(currentStore.length == 1) {
if(!itemHasAdvancementChoices(next.itemData)) {
return false
}
}
if(currentStore.length == 0) return false
return true;

},
currentProcess: derived(inProcess, $inProcess => $inProcess),
updateCurrentProcess: (obj) => inProcess.update(p => ({...p, ...obj})),
Expand Down

0 comments on commit 489d2b0

Please sign in to comment.