Skip to content

Commit

Permalink
[foundryvtt#1401] Remove items selected earlier from options list
Browse files Browse the repository at this point in the history
  • Loading branch information
arbron committed Aug 22, 2022
1 parent 28b7222 commit d4bcc4e
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions module/advancement/types/item-choice.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,6 @@ export class ItemChoiceFlow extends AdvancementFlow {
const max = this.advancement.data.configuration.choices[this.level];
const choices = { max, current: this.selected.size, full: this.selected.size >= max };

// TODO: Make any choices made at previous levels unavailable
// TODO: Make any items already on actor unavailable?

const previousLevels = {};
const previouslySelected = new Set();
for ( const [level, data] of Object.entries(this.advancement.data.value) ) {
Expand All @@ -260,11 +257,12 @@ export class ItemChoiceFlow extends AdvancementFlow {
Object.values(data).forEach(uuid => previouslySelected.add(uuid));
}

const items = [...this.pool, ...this.dropped];
items.forEach(i => {
const items = [...this.pool, ...this.dropped].reduce((items, i) => {
i.checked = this.selected.has(i.uuid);
i.disabled = (!i.checked && choices.full) || previouslySelected.has(i.uuid);
});
i.disabled = !i.checked && choices.full;
if ( !previouslySelected.has(i.uuid) ) items.push(i);
return items;
}, []);

return foundry.utils.mergeObject(super.getData(), { choices, items, previousLevels });
}
Expand Down Expand Up @@ -344,7 +342,7 @@ export class ItemChoiceFlow extends AdvancementFlow {
// If the item is already been marked as selected, no need to go further
if ( this.selected.has(item.uuid) ) return false;

// TODO: Check to ensure the dropped item doesn't already exist on the actor
// TODO: Check to ensure the dropped item hasn't been selected at a lower level

// Mark the item as selected
this.selected.add(item.uuid);
Expand Down

0 comments on commit d4bcc4e

Please sign in to comment.