From 38ccb7a533061b94b60a04a45cd1a2c101a1796c Mon Sep 17 00:00:00 2001 From: versx Date: Wed, 31 Aug 2022 22:57:40 -0700 Subject: [PATCH] Start quest subscriptions rework, push before I forget I did this a few months back :grimacing: --- src/data/default.js | 28 ++++++ src/data/map.js | 38 +++++++- src/routes/ui.js | 8 +- src/services/locale.js | 12 +++ src/views/quests/new.mustache | 172 ++++++++++++++++++++++++++++++++++ 5 files changed, 254 insertions(+), 4 deletions(-) diff --git a/src/data/default.js b/src/data/default.js index 8a6c1e8..7fc64e3 100644 --- a/src/data/default.js +++ b/src/data/default.js @@ -14,6 +14,34 @@ data.genders = [ { 'id': 'm', 'name': 'Male' }, { 'id': 'f', 'name': 'Female', } ]; +data.stardust = [ + 0, + 100, + 150, + 200, + 250, + 300, + 350, + 400, + 450, + 500, + 600, + 700, + 750, + 800, + 900, + 1000, + 1100, + 1200, + 1250, + 1300, + 1400, + 1500, + 2000, + 2500, + 3000, + 3500, +]; data.leagues = config.pvp.leagues.map(league => { return { 'name': league }; }); diff --git a/src/data/map.js b/src/data/map.js index f6e385b..76bb310 100644 --- a/src/data/map.js +++ b/src/data/map.js @@ -1,9 +1,13 @@ 'use strict'; +//const fs = require('fs'); +//const path = require('path'); + const Localizer = require('../services/locale.js'); const Location = require('../models/location.js'); const MapPokestop = require('../models/map/pokestop.js'); const config = require('../config.json'); +const masterfile = require('../../static/data/masterfile.json'); const getPokemonNameIdsList = async () => { const pokemon = []; @@ -55,9 +59,9 @@ const getQuestRewards = async () => { for (const quest of quests) { const questRewards = JSON.parse(quest.questRewards); if (questRewards.length > 0) { - const reward = Localizer.getQuestReward(questRewards[0]); - if (reward && !rewards.includes(reward)) { - rewards.push(reward); + const questReward = questRewards[0]; + if (questReward && !rewards.includes(questReward)) { + rewards.push(questReward); } } } @@ -65,6 +69,32 @@ const getQuestRewards = async () => { return rewards; }; +const getQuestRewardKeywords = async () => { + const rewards = await getQuestRewards(); + const keywords = []; + for (const reward of rewards) { + const keyword = Localizer.getQuestReward(reward); + if (keyword && !rewards.includes(keyword)) { + rewards.push(keyword); + } + } + return keywords; +}; + +const getQuestRewardItems = async () => { + const items = masterfile.items; + const list = []; + const keys = Object.keys(items); + for (const itemId of keys) { + const item = items[itemId]; + list.push({ + ...item, + id: itemId, + }); + } + return list; +}; + const getInvasionTypes = () => { const types = []; for (let i = 0; i <= 50; i++) { @@ -89,6 +119,8 @@ module.exports = { buildCityList, buildLocationsList, getQuestRewards, + getQuestRewardKeywords, + getQuestRewardItems, getInvasionTypes, getLureTypes, }; \ No newline at end of file diff --git a/src/routes/ui.js b/src/routes/ui.js index 8631b71..31ef51b 100644 --- a/src/routes/ui.js +++ b/src/routes/ui.js @@ -309,7 +309,11 @@ router.get('/quest/new', async (req, res) => { data.servers = validateRoles(req, res); const pokestopNames = await PokestopQuest.getPokestopNames(); data.pokestops = [...new Set(pokestopNames)]; - data.rewards = await map.getQuestRewards(); + data.pokemon = await map.getPokemonNameIdsList(); + data.forms = Localizer.getFormNames(); + data.costumes = Localizer.getCostumeNames(); + data.rewards = await map.getQuestRewardKeywords(); + data.items = await map.getQuestRewardItems(); data.cities = map.buildCityList(req.session.guilds); data.locations = await map.buildLocationsList(req.session.guilds, req.session.user_id); res.render('quests/new', data); @@ -328,6 +332,8 @@ router.get('/quest/edit/:id', async (req, res) => { const pokestopNames = await PokestopQuest.getPokestopNames(); data.pokestops = [...new Set(pokestopNames)]; data.pokestop_name = quest.pokestopName; + data.pokemon = await map.getPokemonNameIdsList(); + data.forms = Localizer.getFormNames(); data.reward = quest.reward; const cities = getSelectedAreas( // Currently subscribed areas list diff --git a/src/services/locale.js b/src/services/locale.js index e95dc47..33365b8 100644 --- a/src/services/locale.js +++ b/src/services/locale.js @@ -82,6 +82,18 @@ class Localizer { return forms; } + getCostumeNames() { + const locales = i18n.getCatalog(config.locale); + const costumes = []; + for (const locale in locales) { + const costumeName = locales[locale]; + if (costumeName && locale.includes('costume_') && !costumes.includes(costumeName)) { + costumes.push(costumeName); + } + } + return costumes; + } + getQuestReward(reward) { // TODO: Use format method switch (reward.type) { diff --git a/src/views/quests/new.mustache b/src/views/quests/new.mustache index d5a36e3..618e05a 100644 --- a/src/views/quests/new.mustache +++ b/src/views/quests/new.mustache @@ -39,6 +39,164 @@ --> +
+
Reward Filtering Type
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
Pokemon
+
+
+ Pokemon + +
+
+
+
+ Form + +
+
+
+
+ Costume + +
+
+
+
+ Gender + +
+
+
+ + +
+
+
+
+
+
Item
+
+
+
+ Item + +
+
+ Amount + +
+
+
+
+
+
Stardust
+
+
+ Amount + +
+
+
+
+
Candy
+
+
+ Amount + +
+
+
+
+
Mega Pokemon Candy
+
+
+
+ Pokemon + +
+
+ Amount + +
+
+
+
+
+ + +
{{City}}
@@ -107,4 +265,18 @@ $('#location').append(new Option(location.name, location.name)); } }); + + $('#filter_pokemon, #filter_item, #filter_stardust, #filter_candy, #filter_mega').on('change', function() { + const keys = [ + 'filter_pokemon', + 'filter_item', + 'filter_stardust', + 'filter_candy', + 'filter_mega', + ]; + for (const key of keys) { + const isSelected = this.value === key; + $('.' + key).find('*').attr('disabled', !isSelected); + } + });