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

[WIP] Quest Subscriptions UI Rework #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions src/data/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
});
Expand Down
38 changes: 35 additions & 3 deletions src/data/map.js
Original file line number Diff line number Diff line change
@@ -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 = [];
Expand Down Expand Up @@ -55,16 +59,42 @@ 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);
}
}
}
rewards.sort();
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++) {
Expand All @@ -89,6 +119,8 @@ module.exports = {
buildCityList,
buildLocationsList,
getQuestRewards,
getQuestRewardKeywords,
getQuestRewardItems,
getInvasionTypes,
getLureTypes,
};
8 changes: 7 additions & 1 deletion src/routes/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/services/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
172 changes: 172 additions & 0 deletions src/views/quests/new.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,164 @@
</select>
-->
</div>
<div class="card bg-dark">
<div class="card-header bg-dark text-light text-center"><b>Reward Filtering Type</b></div>
<div class="card-body">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="filter_type" id="filter_pokemon" value="filter_pokemon" checked>
<label class="form-check-label" for="filter_pokemon">Pokemon</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="filter_type" id="filter_item" value="filter_item">
<label class="form-check-label" for="filter_item">Item</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="filter_type" id="filter_stardust" value="filter_stardust">
<label class="form-check-label" for="filter_stardust">Stardust</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="filter_type" id="filter_candy" value="filter_candy">
<label class="form-check-label" for="filter_candy">Rare Candy</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="filter_type" id="filter_mega" value="filter_mega">
<label class="form-check-label" for="filter_mega">Mega Pokemon Candy</label>
</div>
</div>
</div>
<div class="card bg-dark filter_pokemon">
<div class="card-header bg-dark text-light text-center"><b>Pokemon</b></div>
<div class="card-body">
<div class="form-group">
Pokemon
<select name="pokemon" class="custom-select">
{{#pokemon}}
<option value="{{id}}">{{name}}</option>
{{/pokemon}}
</select>
</div>
<div class="row">
<div class="col">
<div class="form-group">
Form
<select name="form" class="custom-select">
{{#forms}}
<option value="{{.}}">{{.}}</option>
{{/forms}}
</select>
</div>
</div>
<div class="col">
<div class="form-group">
Costume
<select name="costume" class="custom-select">
{{#costumes}}
<option value="{{.}}">{{.}}</option>
{{/costumes}}
</select>
</div>
</div>
</div>
<div class="form-group">
Gender
<select name="pokemon" class="custom-select">
{{#genders}}
<option value="{{id}}">{{name}}</option>
{{/genders}}
</select>
</div>
<div class="form-group">
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" name="shiny" id="shiny" value="shiny">
<label class="form-check-label" for="shiny">Is Shiny Pokemon</label>
</div>
</div>
</div>
</div>
<div class="card bg-dark filter_item">
<div class="card-header bg-dark text-light text-center"><b>Item</b></div>
<div class="card-body">
<div class="row">
<div class="col">
Item
<select name="item" class="custom-select" disabled>
{{#items}}
<option value="{{id}}">{{name}}</option>
{{/items}}
</select>
</div>
<div class="col">
Amount
<input type="number" class="form-control" name="item_amount" id="item_amount" min=0 max=10 value=0 disabled>
</div>
</div>
</div>
</div>
<div class="card bg-dark filter_stardust" disabled>
<div class="card-header bg-dark text-light text-center"><b>Stardust</b></div>
<div class="card-body">
<div class="form-group">
Amount
<select name="stardust_amount" class="custom-select" disabled>
{{#stardust}}
<option value="{{.}}">{{.}}</option>
{{/stardust}}
</select>
</div>
</div>
</div>
<div class="card bg-dark filter_candy" disabled>
<div class="card-header bg-dark text-light text-center"><b>Candy</b></div>
<div class="card-body">
<div class="form-group">
Amount
<input type="number" class="form-control" name="candy_amount" id="candy_amount" min=0 max=10 value=0 disabled/>
</div>
</div>
</div>
<div class="card bg-dark filter_mega" disabled>
<div class="card-header bg-dark text-light text-center"><b>Mega Pokemon Candy</b></div>
<div class="card-body">
<div class="row">
<div class="col">
Pokemon
<select name="mega_pokemon" class="custom-select" disabled>
{{#pokemon}}
<option value="{{id}}">{{name}}</option>
{{/pokemon}}
</select>
</div>
<div class="col">
Amount
<input type="number" class="form-control" name="mega_candy_amount" id="mega_candy_amount" min=0 max=1000 value=0 disabled />
</div>
</div>
</div>
</div>
<div class="form-group">
<!--
Rewards
- Form Id
- Costume Id
- GenderId
- Ditto
- Shiny
- Raid Levels
- Sticker Id
-->
<!--
Conditions
- Pokemon IDs
- Category Name
- Pokemon Type IDs
- Throw Type Id
- Hit
- Raid Levels
- Alignment IDs
- Character Category IDs
- Raid Pokemon Evolutions
-->
</div>
<div class="form-group">
{{City}}
<br>
Expand Down Expand Up @@ -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);
}
});
</script>