Skip to content

Commit 6efc130

Browse files
authored
Merge pull request #30 from TeamLumi/PokemonMoves
Pokemon moves
2 parents 89c2d6f + 42512eb commit 6efc130

File tree

6 files changed

+318
-105
lines changed

6 files changed

+318
-105
lines changed

plugins/move-data-plugin/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { Joi } = require('@docusaurus/utils-validation');
44
const { GAMEDATA2, GAMEDATA3, GAMEDATAV, MovesTable } = require('../../__gamedata');
55
const { getMoveProperties } = require('../pokedex-data-plugin/dex/moves');
66
const { normalizePokemonName } = require('../pokedex-data-plugin/dex/name');
7+
const { getTypeName } = require('../pokedex-data-plugin/dex/types');
78

89
/**
910
* @param {{path: string, routeBasePath: string, moveComponent: string, moveListComponent: string, wrapperComponent: string}} options
@@ -30,6 +31,7 @@ function moveDexDataPlugin(context, options) {
3031
id: m.moveId,
3132
name: m.name,
3233
type: m.type,
34+
typeName: getTypeName(m.type),
3335
}));
3436

3537
return {

plugins/pokedex-data-plugin/dex/moves.js

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const {
1010
TutorMoves,
1111
GAMEDATA2
1212
} = require('../../../__gamedata');
13-
const { getPokemonFormId, getPokemonName } = require('./name');
13+
const { FORM_MAP, isValidPokemon } = require('./functions');
14+
const { getPokemonFormId, getPokemonName, getPokemonMonsNoAndFormNoFromPokemonId } = require('./name');
1415

1516
const IS_MOVE_INDEX = false;
1617
const MAX_TM_COUNT = 104;
@@ -321,6 +322,56 @@ function getTutorMoves(monsno = 0, formno = 0, mode = GAMEDATA2) {
321322
return tutorSet;
322323
}
323324

325+
function searchForMovesOnPokemon(moveId = 0, mode = GAMEDATA2) {
326+
// This is a wild function.
327+
// I may want to make a json specifically for loading this in the movedex
328+
// Just depends on the load times for it
329+
// This maps over every pokemon in a mode,
330+
// then maps over their entire learnset to see if it can learn a move
331+
return Object.values(FORM_MAP[mode])
332+
.flat()
333+
.slice(1)
334+
.map((id) => {
335+
// This is a map and not a filter because
336+
// we want to return which method(s) a pokemon can learn a move
337+
const isValid = isValidPokemon(id, mode);
338+
if (!isValid) {
339+
return null; // Skip invalid Pokémon
340+
}
341+
let monsNo = 0, formNo = 0;
342+
try {
343+
[monsNo, formNo] = getPokemonMonsNoAndFormNoFromPokemonId(id, mode);
344+
} catch (error) {
345+
console.log("This pokemonID didn't work", id, mode);
346+
}
347+
const learnsets = {
348+
level: getLevelLearnset(id, mode),
349+
tm: getTechMachineLearnset(id, mode),
350+
egg: getEggMoves(id, mode),
351+
tutor: getTutorMoves(monsNo, formNo, mode)
352+
};
353+
354+
// Find which learnsets contain the move
355+
const setsContainingMove = Object.entries(learnsets)
356+
.filter(([key, moves]) =>
357+
Array.isArray(moves) &&
358+
moves.some(move => move.move?.moveId === moveId) // Check moveId
359+
)
360+
.map(([key]) => key); // Only keep the keys (e.g., "level", "tm")
361+
362+
if (setsContainingMove.length > 0) {
363+
return {
364+
id:`${monsNo}-${formNo}`,
365+
mode,
366+
learnsets: setsContainingMove // Include only the relevant learnset names
367+
};
368+
}
369+
370+
return null; // Skip if no learnsets contain the move
371+
})
372+
.filter(Boolean); // Remove null values}
373+
}
374+
324375
module.exports = {
325376
generateMovesViaLearnset,
326377
getMoveId,
@@ -332,5 +383,6 @@ module.exports = {
332383
getPokemonLearnset,
333384
getMoveLevelLearned,
334385
getLevelLearnset,
335-
getTutorMoves
386+
getTutorMoves,
387+
searchForMovesOnPokemon,
336388
};

src/components/MoveDex/MoveListPageContent.jsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState } from 'react'
2-
import { Box, Container, ListItem, ListItemButton, ListItemIcon, Typography } from '@mui/material';
2+
import { Box, Container, ListItem, ListItemButton, ListItemIcon, MenuItem, Select, Typography } from '@mui/material';
33
import AutoSizer from 'react-virtualized-auto-sizer';
44
import { FixedSizeList } from 'react-window';
55
import { MoveIcon, PokemonMove, PokemonMoveType, TYPE_COLOR_MAP } from '../Pokedex2/PokemonMovesetList';
@@ -10,6 +10,11 @@ import { normalizePokemonName } from '../../utils/dex/name';
1010

1111
const MoveListPageContent = ({ movesList }) => {
1212
const [moves, setMoves] = useState(movesList);
13+
const [searchKey, setSearchKey] = useState("name");
14+
15+
const handleChange = (event) => {
16+
setSearchKey(event.target.value);
17+
};
1318

1419
return (
1520
<Container sx={{ flex: '1 1 auto', display: 'flex', flexDirection: 'column' }}>
@@ -31,7 +36,16 @@ const MoveListPageContent = ({ movesList }) => {
3136
marginTop: "16px",
3237
}}
3338
>
34-
<MoveSearchInput movesList={movesList} setMoves={setMoves} />
39+
<MoveSearchInput movesList={movesList} setMoves={setMoves} searchKey={searchKey} />
40+
<Select
41+
labelId='search-key-label'
42+
id="search-key-select"
43+
value={searchKey}
44+
onChange={handleChange}
45+
>
46+
<MenuItem value={"name"}>Move Name</MenuItem>
47+
<MenuItem value={"type"}>Move Type</MenuItem>
48+
</Select>
3549
</Box>
3650

3751
<Box flex="1 1 auto" paddingY="12px" minHeight={{ xs: '60vh', sm: '60vh' }}>

0 commit comments

Comments
 (0)