Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to hide/unhide tame #5772

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ model Tame {
max_total_loot Json @default("{}") @db.Json
fed_items Json @default("{}") @db.Json
species_variant Int @default(1)
hidden Boolean @default(false)

equipped_primary Int?
equipped_armor Int?
Expand Down
57 changes: 52 additions & 5 deletions src/mahoji/commands/tames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
value: t.id.toString()
};
})
.filter(t => (!value ? true : t.name.toLowerCase().includes(value.toLowerCase())));

Check warning on line 100 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

Unexpected string value in conditional. An explicit empty string check is required

Check warning on line 100 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

Unexpected string value in conditional. An explicit empty string check is required
}

export const tameEquipSlots = ['equipped_primary', 'equipped_armor'] as const;
Expand Down Expand Up @@ -257,7 +257,7 @@
t.species_id === TameSpeciesID.Eagle,
image: readFileSync('./src/lib/resources/images/tames/3_replace_1.png')
},
...tameImageReplacementChoices.map(tameImage => ({

Check warning on line 260 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

'tameImage' is already declared in the upper scope on line 364 column 23

Check warning on line 260 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

'tameImage' is already declared in the upper scope on line 364 column 23
shouldActivate: (t: Tame, user: MUser) =>
t.custom_icon_id === tameImage.name && user.perkTier() >= PerkTier.Four,
image: tameImage.image
Expand Down Expand Up @@ -292,11 +292,11 @@
},
tames: await Promise.all(
tameSpecies.map(async value => {
const tameImage = await loadImage(

Check warning on line 295 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

'tameImage' is already declared in the upper scope on line 364 column 23

Check warning on line 295 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

'tameImage' is already declared in the upper scope on line 364 column 23
await readFile(`./src/lib/resources/images/tames/${value.id}_sprite.png`)
);
const vars = [...value.variants];
if (value.shinyVariant) vars.push(value.shinyVariant);

Check warning on line 299 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

Unexpected number value in conditional. An explicit zero/NaN check is required

Check warning on line 299 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

Unexpected number value in conditional. An explicit zero/NaN check is required
return {
id: value.id,
name: value.name,
Expand Down Expand Up @@ -336,7 +336,7 @@
)
};
}
initSprites();

Check warning on line 339 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 339 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

function drawText(ctx: SKRSContext2D, text: string, x: number, y: number) {
const baseFill = ctx.fillStyle;
Expand All @@ -361,10 +361,11 @@
// Fallback to sorting by max_combat_level if no last_activity_date for both
return getMainTameLevel(tameB) - getMainTameLevel(tameA);
}
export async function tameImage(user: MUser): CommandResponse {
export async function tameImage(user: MUser, show_hidden?: boolean): CommandResponse {
const userTames = await prisma.tame.findMany({
where: {
user_id: user.id
user_id: user.id,
hidden: show_hidden ? undefined : false
},
orderBy: {
last_activity_date: 'desc'
Expand Down Expand Up @@ -429,7 +430,7 @@
ctx.translate(16, 16);
let i = 0;
for (const t of userTames) {
const species = tameSpecies.find(i => i.id === t.species_id)!;

Check warning on line 433 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

'i' is already declared in the upper scope on line 431 column 6

Check warning on line 433 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

'i' is already declared in the upper scope on line 431 column 6
let isTameActive: boolean = false;
let selectedTame = tame && t.id === tame.id;
if (selectedTame) isTameActive = activity !== null;
Expand All @@ -447,16 +448,16 @@
const tameX = (10 + 256) * x + (isTameActive ? tameImageSize : 256 - tameImageSize) / 2;
const tameY = (10 + 128) * y + 10;

const imageReplacement = tameImageReplacementEasterEggs.find(i => i.shouldActivate(t, user));

Check warning on line 451 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

'i' is already declared in the upper scope on line 431 column 6

Check warning on line 451 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

'i' is already declared in the upper scope on line 431 column 6

const tameImage = imageReplacement

Check warning on line 453 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

'tameImage' is already declared in the upper scope on line 364 column 23

Check warning on line 453 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

'tameImage' is already declared in the upper scope on line 364 column 23
? await loadImage(imageReplacement.image)
: sprites.tames!.find(t => t.id === species.id)!.sprites.find(f => f.type === t.species_variant)!

Check warning on line 455 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

't' is already declared in the upper scope on line 432 column 13

Check warning on line 455 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

't' is already declared in the upper scope on line 432 column 13
.growthStage[t.growth_stage];

// Draw tame
ctx.drawImage(tameImage, tameX, tameY, tameImageSize, tameImageSize);
const foreground = tameForegrounds.find(i => i.shouldActivate(t));

Check warning on line 460 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

'i' is already declared in the upper scope on line 431 column 6

Check warning on line 460 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

'i' is already declared in the upper scope on line 431 column 6
if (foreground) {
ctx.drawImage(await loadImage(foreground.image), tameX, tameY, tameImageSize, tameImageSize);
}
Expand Down Expand Up @@ -1410,6 +1411,22 @@
return `You selected your ${tameName(toSelect)}.`;
}

async function hideTameCommand(user: MUser, tameID: number, hidden?: boolean) {
const tame = await prisma.tame.findFirst({ where: { user_id: user.id, id: tameID } });
if (!tame) {
return "Couldn't find that tame.";
}
const newStatus = hidden === undefined ? !tame.hidden : hidden;
await prisma.tame.update({
where: { id: tame.id },
data: {
hidden: newStatus
}
});
const context = newStatus ? 'hidden' : 'unhidden';
return `We have now **${context}** your tame, ${tame.nickname}.`;
}

async function viewCommand(user: MUser, tameID: number): CommandResponse {
const tames = await prisma.tame.findMany({ where: { user_id: user.id } });
const tame = tames.find(t => t.id === tameID);
Expand Down Expand Up @@ -1705,7 +1722,7 @@
export type TamesCommandOptions = CommandRunOptions<{
set_name?: { name: string };
cancel?: {};
list?: {};
list?: { hidden?: boolean };
merge?: { tame: string };
feed?: { items: string };
kill?: { name: string };
Expand All @@ -1730,6 +1747,7 @@
set_custom_image?: {
image: string;
};
hide?: { tame: string; hidden?: boolean };
}>;
export const tamesCommand: OSBMahojiCommand = {
name: 'tames',
Expand All @@ -1747,7 +1765,15 @@
{
type: ApplicationCommandOptionType.Subcommand,
name: 'list',
description: 'List your tames.'
description: 'List your tames.',
options: [
{
type: ApplicationCommandOptionType.Boolean,
name: 'hidden',
description: 'Include hidden tames?',
required: false
}
]
},
{
type: ApplicationCommandOptionType.Subcommand,
Expand Down Expand Up @@ -2002,19 +2028,40 @@
}
}
]
},
{
type: ApplicationCommandOptionType.Subcommand,
name: 'hide',
description: 'Hide a tame.',
options: [
{
type: ApplicationCommandOptionType.String,
name: 'tame',
description: 'The tame you want to hide.',
required: true,
autocomplete: tameAutocomplete
},
{
type: ApplicationCommandOptionType.Boolean,
name: 'hidden',
description: 'Set hidden value.',
required: false
}
]
}
],
run: async ({ options, userID, channelID, interaction }: TamesCommandOptions) => {
const user = await mUserFetch(userID);
if (options.set_name) return setNameCommand(user, options.set_name.name);
if (options.cancel) return cancelCommand(user);
if (options.list) return tameImage(user);
if (options.list) return tameImage(user, options.list.hidden);
if (options.merge) return mergeCommand(user, interaction, Number(options.merge.tame));
if (options.feed) return feedCommand(interaction, user, options.feed.items);
if (options.kill) return killCommand(user, channelID, options.kill.name);
if (options.collect) return collectCommand(user, channelID, options.collect.name);
if (options.select) return selectCommand(user, Number(options.select.tame));
if (options.view) return viewCommand(user, Number(options.view.tame));
if (options.hide) return hideTameCommand(user, Number(options.hide.tame), options.hide.hidden);
if (options.status) return statusCommand(user);
if (options.equip) return tameEquipCommand(user, options.equip.item);
if (options.unequip) return tameUnequipCommand(user, options.unequip.item);
Expand Down
Loading