Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/components/chests/chests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ describe('Chests', () => {
expect(errorTrackerMock.Object.track).not.toHaveBeenCalled();
});

it('patches doItOrigin without replacing an existing toolkit wrapper', () => {
setup('function toolkitWrapper() {}');
const wrapper = itemUse.doIt;
itemUse.doItOrigin = doItWithSource(
"function (itemId, itemCount) { EventHandler.signal('item_used', [itemId]); }",
);

chests.init();

expect(itemUse.doIt).toBe(wrapper);
expect(itemUse.doItOrigin.toString()).toContain('TW_Calc.trackChest(itemId,res);');
expect(errorTrackerMock.Object.track).not.toHaveBeenCalled();
});

it('tracks an error and leaves the handler untouched when the anchor is missing', () => {
setup("function (itemId, itemCount) { EventHandler.signal('something_else', [itemId]); }");
const original = itemUse.doIt;
Expand Down
2 changes: 1 addition & 1 deletion src/components/chests/chests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Chests implements Component {
const pos = match.index;
const body = str.substr(0, pos) + 'TW_Calc.trackChest(itemId,res);' + str.substr(pos);
this.logger.log('patching the chest handler...', body);
newStr = 'ItemUse.doIt = ' + body;
newStr = `ItemUse.${toolkit} = ${body}`;
eval(newStr);
} catch (e: unknown) {
const error = e as Error;
Expand Down