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

Add cell_coords #716

Merged
merged 3 commits into from
May 9, 2022
Merged
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
15 changes: 13 additions & 2 deletions src/controllers/monster.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const geoTz = require('geo-tz')
const moment = require('moment-timezone')
require('moment-precise-range-plugin')

const { S2 } = require('s2-geometry')
const S2ts = require('nodes2ts')
const Controller = require('./controller')

class Monster extends Controller {
Expand Down Expand Up @@ -501,12 +502,22 @@ class Monster extends Controller {
else if (data.pokestop_id === 'None') data.seenType = encountered ? 'encounter' : 'wild'
else data.seenType = 'pokestop'

if (data.seenType === 'cell' && !data.cell_coords) {
const areaCellKey = S2.latLngToKey(data.latitude, data.longitude, 15)
const s2cell = new S2ts.S2Cell(new S2ts.S2CellId(areaCellKey))
data.cell_coords = []
for (let i = 0; i <= 3; i++) {
const vertex = S2ts.S2LatLng.fromPoint(s2cell.getVertex(i))
data.cell_coords.push([parseFloat(vertex.latDegrees), parseFloat(vertex.lngDegrees)])
}
}

await this.getStaticMapUrl(
logReference,
data,
'monster',
['pokemon_id', 'latitude', 'longitude', 'form', 'costume', 'imgUrl', 'imgUrlAlt'],
['pokemon_id', 'display_pokemon_id', 'latitude', 'longitude', 'verified', 'costume', 'form', 'pokemonId', 'generation', 'weather', 'confirmedTime', 'shinyPossible', 'seen_type', 'cell_coords', 'imgUrl', 'imgUrlAlt', 'nightTime', 'duskTime', 'dawnTime'],
['pokemon_id', 'display_pokemon_id', 'latitude', 'longitude', 'verified', 'costume', 'form', 'pokemonId', 'generation', 'weather', 'confirmedTime', 'shinyPossible', 'seenType', 'seen_type', 'cell_coords', 'imgUrl', 'imgUrlAlt', 'nightTime', 'duskTime', 'dawnTime'],
)
data.staticmap = data.staticMap // deprecated

Expand Down
9 changes: 6 additions & 3 deletions src/lib/discord/poracleDiscordMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,12 @@ class PoracleDiscordMessage {

async reply(message) {
// Don't actually reply, but send to channel to avoid Discord reply text
if (message.embed) {
message.embeds = [message.embed]
delete message.embed
if (message.embed || message.embeds) {
if (message.embed) {
message.embeds = [message.embed]
delete message.embed
}

this.msg.channel.send(message)
} else {
// This is a channel, do not reply but rather send to avoid @ reply
Expand Down
2 changes: 1 addition & 1 deletion src/lib/poracleMessage/commands/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ exports.run = async (client, msg, args, options) => {

if (client.config.discord.uploadEmbedImages) {
message.embeds[0].image.url = 'attachment://image.png'
message.files = [{ attachment: maplink, name: 'image.png' }]
message.files = [{ attachment: staticMap, name: 'image.png' }]
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions tileservercache_templates/poracle-monster.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,19 @@
"height": 50
}
]
#if(seenType == "cell"): ,
"polygons": [
{
"fill_color": "rgba(255,255,255,0.6)",
"stroke_color": "\#C7C7C7",
"stroke_width": 1,
"path":
[
#for(coord in cell_coords):
#if(index != 0):,#endif[#index(coord, 0), #index(coord, 1)]
#endfor
]
}
]
#endif
}
16 changes: 16 additions & 0 deletions tileservercache_templates/poracle-multi-monster.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@
"height": 20
}
],
#if(seenType == "cell"):
"polygons": [
{
"fill_color": "rgba(255,255,255,0.6)",
"stroke_color": "\#C7C7C7",
"stroke_width": 1,
"path":
[
#for(coord in cell_coords):
#if(index != 0):,#endif[#index(coord, 0), #index(coord, 1)]
#endfor
]
}
]
#else:
"circles": [
{
"fill_color": "rgba(255,255,255,0.6)",
Expand All @@ -46,6 +61,7 @@
"radius": 40
}
]
#endif
}
},
{
Expand Down