Skip to content

Commit

Permalink
feat: add natures
Browse files Browse the repository at this point in the history
  • Loading branch information
KunoichiZ authored and favna committed Dec 31, 2024
1 parent add19d4 commit 0e3af17
Show file tree
Hide file tree
Showing 15 changed files with 783 additions and 1 deletion.
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
}
21 changes: 21 additions & 0 deletions graphql/resolvers.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,25 @@ 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.
You can provide `take` to limit the amount of Pokémon to return (default: 1), set the offset of where to start with `offset`, and reverse the entire array with `reverse`.
"""
getAllNatures(
"Sets the offset where to start"
offset: Int = 0

"Return only this many results, starting from the offset"
take: Int = 1

"Reverses the dataset before paginating"
reverse: Boolean = false
): [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
}
256 changes: 256 additions & 0 deletions src/lib/assets/natures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
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'
}
]
]);
12 changes: 12 additions & 0 deletions src/lib/assets/pokemon-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,16 @@ export namespace PokemonTypes {
| "Ally's Side"
| 'Normal'
| 'All';

export interface Natures {
name: string;

increasedStat: string | null;

decreasedStat: string | null;

preferredFlavor: string | null;

dislikedFlavor: string | null;
}
}
21 changes: 21 additions & 0 deletions src/lib/mappers/natureMapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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: '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

0 comments on commit 0e3af17

Please sign in to comment.