Skip to content

Commit

Permalink
BIS gear command improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Feb 21, 2024
1 parent f194d23 commit de7239d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/lib/gear/functions/generateGearImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ export async function generateGearImage(
user: MUser,
gearSetup: Gear | GearSetup,
gearType: GearSetupType | null,
petID: number | null
petID: number | null,
titleOverride?: string
) {
debugLog('Generating gear image', { user_id: user.id });
const transmogItem = (gearType && transmogItems.find(t => user.gear[gearType].hasEquipped(t.item.name))) ?? null;

Check warning on line 250 in src/lib/gear/functions/generateGearImage.ts

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected value in conditional. A boolean expression is required
Expand Down Expand Up @@ -301,8 +302,13 @@ export async function generateGearImage(

ctx.font = '16px OSRSFontCompact';
// Draw preset title
if (gearType) {
drawTitleText(ctx, toTitleCase(gearType), Math.floor(176 / 2) + (transMogImage ? 200 : 0), 25);
if (titleOverride || gearType) {

Check warning on line 305 in src/lib/gear/functions/generateGearImage.ts

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected value in conditional. A boolean expression is required
drawTitleText(
ctx,
toTitleCase(titleOverride ?? gearType ?? ''),
Math.floor(176 / 2) + (transMogImage ? 200 : 0),
25
);
}

// Draw items
Expand Down
3 changes: 2 additions & 1 deletion src/lib/util/findBISGear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export function findBestGearSetups(stat: GearStat): Gear[] {
EquipmentSlot.Hands,
EquipmentSlot.Legs,
EquipmentSlot.Neck,
EquipmentSlot.Ring
EquipmentSlot.Ring,
EquipmentSlot.Body
]) {
const item = findItem([slot]);
if (item) {

Check warning on line 49 in src/lib/util/findBISGear.ts

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected object value in conditional. The condition is always true
Expand Down
15 changes: 13 additions & 2 deletions src/mahoji/commands/gear.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Canvas, loadImage } from '@napi-rs/canvas';
import { toTitleCase } from '@oldschoolgg/toolkit';
import { ApplicationCommandOptionType, CommandRunOptions } from 'mahoji';

import { gearValidationChecks } from '../../lib/constants';
import { allPetIDs } from '../../lib/data/CollectionsExport';
import { generateGearImage } from '../../lib/gear/functions/generateGearImage';
import { GearSetupType, GearSetupTypes, GearStat } from '../../lib/gear/types';
import { equipPet } from '../../lib/minions/functions/equipPet';
import { unequipPet } from '../../lib/minions/functions/unequipPet';
Expand Down Expand Up @@ -209,7 +211,14 @@ export const gearCommand: OSBMahojiCommand = {

if (options.best_in_slot?.stat) {

Check warning on line 212 in src/mahoji/commands/gear.ts

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected value in conditional. A boolean expression is required
const res = findBestGearSetups(options.best_in_slot.stat);
return `These are the best in slot items for ${options.best_in_slot.stat}.
const totalCanvas = new Canvas(5 * 175, 240);
const ctx = totalCanvas.getContext('2d');
for (let i = 0; i < 5; i++) {
const gearImage = await generateGearImage(user, res[i], 'melee', null, `${i + 1}`);
ctx.drawImage(await loadImage(gearImage), i * 175, 0);
}
return {
content: `These are the best in slot items for ${options.best_in_slot.stat}.
${res
.slice(0, 10)
Expand All @@ -219,7 +228,9 @@ ${res
options.best_in_slot!.stat
}`
)
.join('\n')}`;
.join('\n')}`,
files: [await totalCanvas.encode('png')]
};
}
if ((options.equip || options.unequip) && !gearValidationChecks.has(userID)) {
const { itemsUnequippedAndRefunded } = await user.validateEquippedGear();
Expand Down

0 comments on commit de7239d

Please sign in to comment.