Skip to content

Commit 3bf6657

Browse files
authored
Merge pull request #136 from versx/custom-icons-2
Only Support Custom Pokemon icons in config
2 parents 45b4d90 + 239e6df commit 3bf6657

File tree

6 files changed

+92
-90
lines changed

6 files changed

+92
-90
lines changed

README.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -268,25 +268,22 @@ NodeJS Map clone replacement for [RealDeviceMap](https://github.com/realdevicema
268268
"icons": {
269269
// Default local icon repository
270270
"Default": {
271-
"path": "/img/",
272-
"raidOffsetY": 0.269,
273-
"questOffsetY": 0,
274-
"gymAnchorY": 0.849,
275-
"pokestopAnchorY": 0.896
271+
"path": "/img/pokemon"
272+
},
273+
"POGO": {
274+
"path": "https://mygod.github.io/pokicons/v1"
276275
},
277276
// Remote icon repository
278277
"RemotePokemonExample": {
279278
"path": "https://example.com/pokemon_images",
280-
// Since we can't traverse a remote directory easily, you'll need to provide
281-
// a list of available forms, shiny, or gender icons so the map is aware of
282-
// available icons that way invalid icons are not shown.
283-
"pokemonList": ["001_163", "002_166", "002_166_shiny", "003_169", "003_169_female"],
284-
// Optional raid image vertical offset value
285-
"raidOffsetY": 0.269,
286-
// Optional quest image vertical offset value
287-
"questOffsetY": 0,
288-
"gymAnchorY": 0.849,
289-
"pokestopAnchorY": 0.896
279+
// For repo without index.json support, since we can't traverse a remote directory easily,
280+
// you'll need to provide a list of available forms, shiny, or gender icons so the map is
281+
// aware of available icons that way invalid icons are not shown.
282+
"pokemonList": ["001_00", "002_00", "002_00_shiny", "003_00", "003_00_female", "003_950"]
283+
// expected format is <xxx pokemon id>(_00|_<form id>|_v<temp evolution id>)[_female][_<xx costume id>][_shiny]
284+
// automatic fallback is in place, so the bare minimum you need to provide is "xxx_00" for each pokemon
285+
// and "000" for new pokemon fallback (000 does not need to appear in pokemonList)
286+
// Reference: Asset icon processing tool: https://github.com/Mygod/pokemon-icon-postprocessor
290287
}
291288
},
292289
// Scouting settings

src/config.example.json

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,10 @@
160160
},
161161
"icons": {
162162
"Default": {
163-
"path": "/img",
164-
"raidOffsetY": 0.269,
165-
"questOffsetY": 0,
166-
"gymAnchorY": 0.849,
167-
"pokestopAnchorY": 0.896
163+
"path": "/img/pokemon"
168164
},
169-
"RemotePokemonExample": {
170-
"path": "https://example.com/pokemon_images",
171-
"pokemonList": ["001_163", "002_166", "002_166_shiny", "003_169", "003_169_female"],
172-
"raidOffsetY": 0.269,
173-
"questOffsetY": 0,
174-
"gymAnchorY": 0.849,
175-
"pokestopAnchorY": 0.896
165+
"POGO": {
166+
"path": "https://mygod.github.io/pokicons/v1"
176167
}
177168
},
178169
"scouting": {

src/data/map.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ const getNests = async (minLat, maxLat, minLon, maxLon, nestFilterExclude = null
10581058
return null;
10591059
};
10601060

1061-
const getSearchData = async (lat, lon, id, value) => {
1061+
const getSearchData = async (lat, lon, id, value, iconStyle) => {
10621062
let sql = '';
10631063
let args = [lat, lon, lat];
10641064
let useManualDb = false;
@@ -1187,19 +1187,19 @@ const getSearchData = async (lat, lon, id, value) => {
11871187
let result = results[i];
11881188
// TODO: Check quest types
11891189
if (result.quest_item_id > 0) {
1190-
result.url2 = config.icons['Default'/* TODO: Add icon style */].path + `/item/${result.quest_item_id}.png`;
1190+
result.url2 = `/img/item/${result.quest_item_id}.png`;
11911191
} else if (result.quest_pokemon_id > 0) {
11921192
const formId = result.quest_pokemon_form_id > 0 ? result.quest_pokemon_form_id : '00';
1193-
result.url2 = config.icons['Default'/* TODO: Add icon style */].path + `/pokemon/pokemon_icon_${utils.zeroPad(result.quest_pokemon_id, 3)}_${formId}.png`;
1193+
result.url2 = config.icons[iconStyle].path + `/pokemon_icon_${utils.zeroPad(result.quest_pokemon_id, 3)}_${formId}.png`;
11941194
} else if (result.quest_reward_type === 3) {
1195-
result.url2 = config.icons['Default'/* TODO: Add icon style */].path + '/item/-1.png';
1195+
result.url2 = '/item/-1.png';
11961196
}
11971197
}
11981198
break;
11991199
case 'search-nest':
12001200
for (let i = 0; i < results.length; i++) {
12011201
let result = results[i];
1202-
result.url = config.icons['Default'/* TODO: Add icon style */].path + `/pokemon/pokemon_icon_${utils.zeroPad(result.pokemon_id, 3)}_00.png`;
1202+
result.url = config.icons[iconStyle].path + `/pokemon_icon_${utils.zeroPad(result.pokemon_id, 3)}_00.png`;
12031203
}
12041204
break;
12051205
}

src/routes/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ const getData = async (perms, filter) => {
798798
};
799799

800800
const getSearch = async (filter) => {
801-
const searchData = await map.getSearchData(filter.lat, filter.lon, filter.id, filter.value);
801+
const searchData = await map.getSearchData(filter.lat, filter.lon, filter.id, filter.value, filter.icon_style);
802802
return searchData;
803803
};
804804

src/routes/ui.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const axios = require('axios');
34
const fs = require('fs');
45
const path = require('path');
56
const express = require('express');
@@ -84,7 +85,8 @@ const handlePage = async (req, res) => {
8485
const tileservers = getAvailableTileservers();
8586
data.available_tileservers_json = JSON.stringify(tileservers);
8687

87-
data.available_icon_styles_json = JSON.stringify(config.iconStyles);
88+
await updateAvailableForms(config.icons);
89+
data.available_icon_styles_json = JSON.stringify(config.icons);
8890

8991
// Build available items list
9092
const availableItems = [-3, -2, -1];
@@ -260,7 +262,7 @@ const getAvailableTileservers = () => {
260262
const updateAvailableForms = async (icons) => {
261263
for (const icon of Object.values(icons)) {
262264
if (icon.path.startsWith('/')) {
263-
const pokemonIconsDir = path.resolve(__dirname, `../../static${icon.path}/pokemon`);
265+
const pokemonIconsDir = path.resolve(__dirname, `../../static${icon.path}`);
264266
const files = await fs.promises.readdir(pokemonIconsDir);
265267
if (files) {
266268
const availableForms = [];
@@ -272,6 +274,15 @@ const updateAvailableForms = async (icons) => {
272274
});
273275
icon.pokemonList = availableForms;
274276
}
277+
} else if (!Array.isArray(icon.pokemonList) || Date.now() - icon.lastRetrieved > 60 * 60 * 1000) {
278+
axios({
279+
method: 'GET',
280+
url: icon.path + '/index.json',
281+
responseType: 'json'
282+
}).then((response) => {
283+
icon.pokemonList = response ? response.data : [];
284+
icon.lastRetrieved = Date.now();
285+
});
275286
}
276287
}
277288
};

0 commit comments

Comments
 (0)