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

feat: add Natures #1028

Merged
merged 4 commits into from
Jan 2, 2025
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ and [Bulbapedia].
- Moves
- Learnsets
- Type matchups
- Natures

## JavaScript Companion Library

Expand Down
29 changes: 29 additions & 0 deletions graphql/enums.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3502,3 +3502,32 @@ enum IsNonStandard {
"When set the move can exclusively be used Pokémon Sword and Pokémon Shield as it requires Gigantamaxing your Pokémon."
Gigantamax
}

"The Natures in Pokémon"
enum NaturesEnum {
adamant
bashful
bold
brave
calm
careful
docile
gentle
hardy
hasty
impish
jolly
lax
lonely
mild
modest
naive
naughty
quiet
quirky
rash
relaxed
sassy
serious
timid
}
10 changes: 10 additions & 0 deletions graphql/resolvers.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,14 @@ type Query {

"Gets the type matchup data for the given type or types"
getTypeMatchup("The primary type to check" primaryType: TypesEnum!, "The secondary type to check" secondaryType: TypesEnum): TypeMatchup!

"Gets the details of a specific Nature"
getNature("The nature to look up" nature: NaturesEnum!): Nature!

"""
Returns a list of all the Natures in Pokémon.

For every Nature all the data on each requested field is returned.
"""
getAllNatures: [Nature!]!
}
21 changes: 21 additions & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,24 @@ type TypeEffectiveness {
"The types with 0.5x effectiveness"
resistedTypes: [String!]!
}

"A single Nature entry"
type Nature {
"The key of the nature as stored in the API"
key: NaturesEnum!

"The name of a nature"
name: String!

"The stat the nature increases by 10%"
increasedStat: String

"The stat the nature decreases by 10%"
decreasedStat: String

"The flavor of food the nature prefers"
preferredFlavor: String

"The flavor of food the nature dislikes"
dislikedFlavor: String
}
260 changes: 260 additions & 0 deletions src/lib/assets/natures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
import type { PokemonTypes } from '#assets/pokemon-source';
import { Collection } from '@discordjs/collection';

/** The natures in Pokémon */
export const natures = new Collection<string, PokemonTypes.Natures>([
[
'adamant',
{
name: 'Adamant',
increasedStat: 'Attack',
decreasedStat: 'Special Attack',
preferredFlavor: 'Spicy',
dislikedFlavor: 'Dry'
}
],
[
'bashful',
{
name: 'Bashful',
increasedStat: null,
decreasedStat: null,
preferredFlavor: null,
dislikedFlavor: null
}
],
[
'bold',
{
name: 'Bold',
increasedStat: 'Defense',
decreasedStat: 'Attack',
preferredFlavor: 'Sour',
dislikedFlavor: 'Spicy'
}
],
[
'brave',
{
name: 'Brave',
increasedStat: 'Attack',
decreasedStat: 'Speed',
preferredFlavor: 'Spicy',
dislikedFlavor: 'Sweet'
}
],
[
'calm',
{
name: 'Calm',
increasedStat: 'Special Defense',
decreasedStat: 'Attack',
preferredFlavor: 'Bitter',
dislikedFlavor: 'Spicy'
}
],
[
'careful',
{
name: 'Careful',
increasedStat: 'Special Defense',
decreasedStat: 'Special Attack',
preferredFlavor: 'Bitter',
dislikedFlavor: 'Dry'
}
],
[
'docile',
{
name: 'Docile',
increasedStat: null,
decreasedStat: null,
preferredFlavor: null,
dislikedFlavor: null
}
],
[
'gentle',
{
name: 'Gentle',
increasedStat: 'Special Defense',
decreasedStat: 'Defense',
preferredFlavor: 'Bitter',
dislikedFlavor: 'Sour'
}
],
[
'hardy',
{
name: 'Hardy',
increasedStat: null,
decreasedStat: null,
preferredFlavor: null,
dislikedFlavor: null
}
],
[
'hasty',
{
name: 'Hasty',
increasedStat: 'Hasty',
decreasedStat: 'Defense',
preferredFlavor: 'Sweet',
dislikedFlavor: 'Sour'
}
],
[
'impish',
{
name: 'Impish',
increasedStat: 'Defense',
decreasedStat: 'Sour',
preferredFlavor: 'Special Attack',
dislikedFlavor: 'Dry'
}
],
[
'jolly',
{
name: 'Jolly',
increasedStat: 'Speed',
decreasedStat: 'Special Attack',
preferredFlavor: 'Sweet',
dislikedFlavor: 'Dry'
}
],
[
'lax',
{
name: 'Lax',
increasedStat: 'Defense',
decreasedStat: 'Sour',
preferredFlavor: 'Special Defense',
dislikedFlavor: 'Bitter'
}
],
[
'lonely',
{
name: 'Lonely',
increasedStat: 'Attack',
decreasedStat: 'Defense',
preferredFlavor: 'Spicy',
dislikedFlavor: 'Sour'
}
],
[
'mild',
{
name: 'Mild',
increasedStat: 'Special Attack',
decreasedStat: 'Defense',
preferredFlavor: 'Dry',
dislikedFlavor: 'Sour'
}
],
[
'modest',
{
name: 'Modest',
increasedStat: 'Special Attack',
decreasedStat: 'Attack',
preferredFlavor: 'Dry',
dislikedFlavor: 'Spicy'
}
],
[
'naive',
{
name: 'Naive',
increasedStat: 'Speed',
decreasedStat: 'Special Defense',
preferredFlavor: 'Sweet',
dislikedFlavor: 'Bitter'
}
],
[
'naughty',
{
name: 'Naughty',
increasedStat: 'Attack',
decreasedStat: 'Special Defense',
preferredFlavor: 'Spicy',
dislikedFlavor: 'Bitter'
}
],
[
'quiet',
{
name: 'Quiet',
increasedStat: 'Special Attack',
decreasedStat: 'Speed',
preferredFlavor: 'Dry',
dislikedFlavor: 'Sweet'
}
],
[
'quirky',
{
name: 'Quirky',
increasedStat: null,
decreasedStat: null,
preferredFlavor: null,
dislikedFlavor: null
}
],
[
'rash',
{
name: 'Rash',
increasedStat: 'Special Attack',
decreasedStat: 'Special Defense',
preferredFlavor: 'Dry',
dislikedFlavor: 'Bitter'
}
],
[
'relaxed',
{
name: 'Relaxed',
increasedStat: 'Defense',
decreasedStat: 'Speed',
preferredFlavor: 'Sour',
dislikedFlavor: 'Sweet'
}
],
[
'sassy',
{
name: 'Sassy',
increasedStat: 'Special Defense',
decreasedStat: 'Speed',
preferredFlavor: 'Bitter',
dislikedFlavor: 'Sweet'
}
],
[
'serious',
{
name: 'Serious',
increasedStat: null,
decreasedStat: null,
preferredFlavor: null,
dislikedFlavor: null
}
],
[
'timid',
{
name: 'Timid',
increasedStat: 'Speed',
decreasedStat: 'Attack',
preferredFlavor: 'Sweet',
dislikedFlavor: 'Spicy'
}
]
]);

for (const [key, value] of natures.entries()) {
value.key = key;
}
13 changes: 13 additions & 0 deletions src/lib/assets/pokemon-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,17 @@ export namespace PokemonTypes {
| "Ally's Side"
| 'Normal'
| 'All';

export interface Natures {
key?: string;
name: string;

increasedStat: string | null;

decreasedStat: string | null;

preferredFlavor: string | null;

dislikedFlavor: string | null;
}
}
22 changes: 22 additions & 0 deletions src/lib/mappers/natureMapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { PokemonTypes } from '#assets/pokemon-source';
import type { Nature } from '#types/graphql-mapped-types';
import type { GraphQLSet } from '#utils/GraphQLSet';
import { addPropertyToObjectFieldBased } from '#utils/addPropertyToObject';

export function mapNatureDataToNatureGraphQL({ data, requestedFields }: MapNatureDataToNatureGraphQLParameters): Nature {
const natureObject: Nature = {} as Nature;

addPropertyToObjectFieldBased({ objectTarget: natureObject, propertyKey: 'key', propertyValue: data.key, requestedFields });
addPropertyToObjectFieldBased({ objectTarget: natureObject, propertyKey: 'name', propertyValue: data.name, requestedFields });
addPropertyToObjectFieldBased({ objectTarget: natureObject, propertyKey: 'increasedStat', propertyValue: data.increasedStat, requestedFields });
addPropertyToObjectFieldBased({ objectTarget: natureObject, propertyKey: 'decreasedStat', propertyValue: data.decreasedStat, requestedFields });
addPropertyToObjectFieldBased({ objectTarget: natureObject, propertyKey: 'preferredFlavor', propertyValue: data.preferredFlavor, requestedFields });
addPropertyToObjectFieldBased({ objectTarget: natureObject, propertyKey: 'dislikedFlavor', propertyValue: data.dislikedFlavor, requestedFields });

return natureObject;
}

interface MapNatureDataToNatureGraphQLParameters {
data: PokemonTypes.Natures;
requestedFields: GraphQLSet<keyof Nature>;
}
Loading
Loading