Skip to content

Commit

Permalink
changes to json creating and pokemon preview start
Browse files Browse the repository at this point in the history
  • Loading branch information
Killermaschine88 committed Jun 25, 2022
1 parent 275ab59 commit 2bc326c
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 23 deletions.
13 changes: 7 additions & 6 deletions commands/interaction/pokemon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { GameMap } = require("../../constants/pokemon/map");
const { newProfileModal } = require("../../constants/pokemon/constants");
const { updateEmbed, generateProfileSelection, getStarterPokemon, generateStarterSelection } = require("../../constants/pokemon/functions");
const { generateProfileSelection, getStarterPokemon, generateStarterSelection } = require("../../constants/pokemon/functions");
const { InteractionCollector } = require("discord.js");
const { createProfile, saveProfile } = require("../../constants/pokemon/mongoFunctions");
const { menuHandler } = require("../../constants/pokemon/handlers");
Expand Down Expand Up @@ -57,17 +57,18 @@ module.exports = {
await createProfile(interaction, name, Game, starterPokemon);
profiles = (await interaction.client.mongo.findOne({ _id: interaction.user.id })).profiles;
await interaction.editReply(generateProfileSelection(profiles));
} else if (id === "movement") {
// Returning components back to walking row
Game.updateMessage();
}

//Defering
if (!["newProfile"].includes(id)) {
await i.deferUpdate().catch((err) => err);
}
await i.deferUpdate().catch((err) => err);

collector.resetTimer(); //Reset timer on input

//Menu Handler
if (["menu", "pokedex", "pokemon", "bag", "save", "movement", "exitAndSave"].includes(id)) {
if (["menu", "pokedex", "pokemonTeam", "bag", "save", "exitAndSave", "backToMenu"].includes(id)) {
await menuHandler(i, Game);
}

Expand All @@ -79,7 +80,7 @@ module.exports = {
});

collector.on("end", async (__, reason) => {
await reply.edit({ content: reason ? `Command stopped because: **${reason}**` : null, components: [] }).catch((err) => err);
await reply.edit({ content: reason !== "time" ? `Command stopped because: **${reason}**` : null, components: [] }).catch((err) => err);

if (Game?.isStarted()) {
await saveProfile(interaction, Game);
Expand Down
24 changes: 19 additions & 5 deletions constants/pokemon/functions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
let emojis = require("../JSON/emojiList");
const pokemonList = require("../JSON/pokemonList");
const { getRandomNumber } = require("../util/functions");
const { getRandomNumber, emojiStringToId } = require("../util/functions");
const { MessageActionRow, MessageButton, MessageEmbed, MessageSelectMenu } = require("discord.js");
const { uploadEmoji } = require("../../events/messageCreate");
const { uploadEmoji } = require("../../constants/util/emoji");
const { client } = require("../../index");
const fs = require("fs");

Expand All @@ -12,6 +12,8 @@ function getEmoji(name, shiny = false, way = "down") {
else return emojis[name];
}

emojis = JSON.parse(fs.readFileSync(__dirname + "/../JSON/emojiList.json"));

name = name.toUpperCase();

if (!emojis[name]) {
Expand Down Expand Up @@ -168,11 +170,11 @@ function generateStarterSelection() {
}

function generateMenu() {
const rows = [new MessageActionRow().addComponents(new MessageSelectMenu().setPlaceholder("Empty").setMinValues(1).setMaxValues(1).setCustomId("menuSelect"))];
const rows = [new MessageActionRow().addComponents(new MessageSelectMenu().setPlaceholder("Select an option").setMinValues(1).setMaxValues(1).setCustomId("menuSelect"))];
const options = [
{ label: "Back to Game", emoji: "977989090714714183", value: "movement" },
{ label: "Pokedex", emoji: "989794527952908328", value: "pokedex" },
{ label: "Pokemon Team", emoji: "989792754169167903", value: "pokemon" },
{ label: "Pokemon Team", emoji: "989792754169167903", value: "pokemonTeam" },
{ label: "Bag", emoji: "989794285002047518", value: "bag" },
{ label: "Save", emoji: "989807222051721216", value: "save" },
{ label: "Exit and Save", emoji: "863398571302060032", value: "exitAndSave" },
Expand All @@ -185,4 +187,16 @@ function generateMenu() {
return { components: rows };
}

module.exports = { generateMenu, getEmoji, getOffset, handleMovement, generateMap, pokemonFound, generateRandomPokemon, generateProfileSelection, getStarterPokemon, generateStarterSelection };
function getPokemonTeamRow(team) {
const rows = [new MessageActionRow().addComponents(new MessageSelectMenu().setPlaceholder("Select a Pokemon to View").setMinValues(1).setMaxValues(1).setCustomId("pokemonTeamSelect"))];

rows[0].components[0].options.push({ label: "Back to Menu", value: "backToMenu", emoji: { id: "977989090714714183" }})

for(let i = 0; i < team.length; i++) {
rows[0].components[0].options.push({ label: team[i].name, value: `pokemon_${i}`, emoji: { id: emojiStringToId(getEmoji(team[i].id )) }})
}

return { components: rows };
}

module.exports = { getPokemonTeamRow, generateMenu, getEmoji, getOffset, handleMovement, generateMap, pokemonFound, generateRandomPokemon, generateProfileSelection, getStarterPokemon, generateStarterSelection };
12 changes: 5 additions & 7 deletions constants/pokemon/handlers.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
const { generateMenu, updateEmbed } = require("./functions");
const { generateMenu, getPokemonTeamRow } = require("./functions");
const { saveProfile } = require("./mongoFunctions");

async function menuHandler(interaction, Game) {
const id = interaction?.values?.[0] || interaction.customId;

//Missing: pokedex, pokemon, bag
//Missing: pokedex, bag

if (id === "menu") {
if (["menu", "backToMenu"].includes(id)) {
await Game.getMessage().edit(generateMenu());
} else if (id === "save") {
// Saving profile
await saveProfile(interaction, Game);
return interaction.followUp({ content: "Saved successfully.", ephemeral: true });
} else if (id === "movement") {
// Returning components back to walking row
Game.updateMessage();
} else if (id === "exitAndSave") {
// Saving and closing game
await saveProfile(interaction, Game);
Game.getData("collector")?.stop("Saved game and exited");
} else if (id === "pokemon") {
} else if (id === "pokemonTeam") {
// Showing current Pokemon in the Team
Game.getMessage().edit(getPokemonTeamRow(Game.getProfile().team));
}
}

Expand Down
4 changes: 3 additions & 1 deletion constants/pokemon/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ class GameMap {
setVariables(interaction, collector) {
this.client = interaction.client;
this.user = interaction.user;
this.profile = getCurrentProfile(this.client, this.user, this.profileIndex);
getCurrentProfile(this.client, this.user, this.profileIndex).then((data) => {
this.profile = data;
});
this.collector = collector;
return this;
}
Expand Down
7 changes: 5 additions & 2 deletions constants/util/apiFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ async function returnMoves(moveList) {
let pokemonMoves = [];

const filteredList = moveList.filter((move) => move.version_group_details[0].version_group.name === "diamond-pearl");
let firstAttack = true;

for (const move of filteredList) {
// Ignoring moves that arent from level up
Expand All @@ -34,9 +35,11 @@ async function returnMoves(moveList) {

//Pushing to array
if (moveData.damage_class.name === "status" && moveData.meta.healing > 0) {
pokemonMoves.push({ name: titleCase(move.move.name.replaceAll("-", " ")), id: move.move.name, levelLearnedAt: move.version_group_details[0].level_learned_at, data: { type: moveData.damage_class.name, healing: moveData.meta.healing, effect: moveData.effect_entries[0].short_effect.replaceAll("$effect_chance% ", "") } });
pokemonMoves.push({ selected: firstAttack ? true : false, name: titleCase(move.move.name.replaceAll("-", " ")), id: move.move.name, levelLearnedAt: move.version_group_details[0].level_learned_at, data: { type: moveData.damage_class.name, healing: moveData.meta.healing, effect: moveData.effect_entries[0].short_effect.replaceAll("$effect_chance% ", "") } });
firstAttack = false;
} else if (["physical", "special"].includes(moveData.damage_class.name)) {
pokemonMoves.push({ name: titleCase(move.move.name.replaceAll("-", " ")), id: move.move.name, levelLearnedAt: move.version_group_details[0].level_learned_at, data: { accuracy: moveData.accuracy, type: moveData.damage_class.name, power: moveData.power, effect: moveData.effect_entries[0].short_effect.replaceAll("$effect_chance% ", "") } });
pokemonMoves.push({ selected: firstAttack ? true : false, name: titleCase(move.move.name.replaceAll("-", " ")), id: move.move.name, levelLearnedAt: move.version_group_details[0].level_learned_at, data: { accuracy: moveData.accuracy, type: moveData.damage_class.name, power: moveData.power, effect: moveData.effect_entries[0].short_effect.replaceAll("$effect_chance% ", "") } });
firstAttack = false;
}
}
return pokemonMoves.sort((a, b) => a.levelLearnedAt - b.levelLearnedAt);
Expand Down
1 change: 1 addition & 0 deletions constants/util/emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async function uploadEmoji(input, client) {

fs.writeFileSync(__dirname + "/../JSON/emojiList.json", JSON.stringify(emojiList, null, 2));

await generatePokemonEntry(name.toLowerCase());
client.channels.cache.get("989085658486292480").send(`Created <:${normalEmoji.name}:${normalEmoji.id}> <:${shinyEmoji.name}:${shinyEmoji.id}>, \`<:${normalEmoji.name}:${normalEmoji.id}>\` \`<:${shinyEmoji.name}:${shinyEmoji.id}>\``);
return true;
}
Expand Down
6 changes: 5 additions & 1 deletion constants/util/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ function titleCase(str) {
});
}

module.exports = { getRandomNumber, sleep, badName, titleCase };
function emojiStringToId(emoji) {
return emoji.split(":")[2].replace(">", "")
}

module.exports = { getRandomNumber, sleep, badName, titleCase, emojiStringToId };;
2 changes: 1 addition & 1 deletion events/messageCreate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { generatePokemonEntry, uploadEmoji } = require("../constants/util/emoji")
const { generatePokemonEntry, uploadEmoji } = require("../constants/util/emoji");

module.exports = {
name: "messageCreate",
Expand Down

0 comments on commit 2bc326c

Please sign in to comment.