Skip to content

Commit

Permalink
Fix the willItemsFit bank method
Browse files Browse the repository at this point in the history
  • Loading branch information
beardeddragon5 committed Feb 6, 2024
1 parent 401fb1f commit 0f6c280
Show file tree
Hide file tree
Showing 4 changed files with 339 additions and 51 deletions.
5 changes: 3 additions & 2 deletions src/empty.mts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ export async function getNextEmpty(ctx: ItemPlaceholderContext) {
for (let i = 0; i < countEmpties; i++) {
const emptyId = `item_placeholder:empty_i_${i}`;
const item = game.items.getObjectByID(emptyId);

if (!game.bank.items.has(item)) {
if (!item) {
break;
} else if (!game.bank.items.has(item)) {
return emptyId;
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/setup.mts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,23 @@ export async function setup(ctx: ItemPlaceholderContext) {
}
});

ctx.patch(Bank, 'willItemsFit').replace(function (original, items) {
const useSlots = ctx.settings.section('General').get('use-slots');
if (useSlots) {
const newItems = new Set();
return items.every(({ item }) => {
if (this.items.has(item)) {
return true;
} else {
newItems.add(item);
return this.occupiedSlots + newItems.size <= this.maximumSlots;
}
});
} else {
return original(items);
}
});

const runIfValidItem = (onPlaceholderFound: (item: Item) => void) =>
function <P extends unknown[], T extends (item: Item, ...args: P) => void>(
this: Bank,
Expand Down
3 changes: 3 additions & 0 deletions src/ui.mts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ export async function setupUI(ctx: ItemPlaceholderContext) {
async createEmpty() {
const itemID = await getNextEmpty(ctx);
const item = game.items.getObjectByID(itemID);
if (!item) {
return;
}
game.bank.addItem(item, 1, false, false, true, false);
const bankItem = game.bank.items.get(item);
if (bankItem) {
Expand Down
Loading

0 comments on commit 0f6c280

Please sign in to comment.