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 user interface option to Notify by Pokemon Level #2399

Merged
merged 7 commits into from
Jan 27, 2018

Conversation

tomballgithub
Copy link
Contributor

Description

This adds a user interface option to notify by pokemon level. This is virtually the same coding as the notify by pokemon perfection.

If the user enters a pokemon level between 1 and 40, the map will notify them if a pokemon meeting that level is found. If both a level and perfection notification are configured, a pokemon will only be notified if it meets both criteria.

Motivation and Context

This was request in the PR channel and I have had multiple users request this feature. It is especially interesting now with weather-boosting causing pokemon with level 35 to be found in the wild

How Has This Been Tested?

I tested the code on my Rocketmap server user interface under Ubuntu 16.04.
I tweaked it until it worked as desired.

Screenshots (if appropriate):

image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

static/js/map.js Outdated
hasHighIV = notifiedMinPerfection > 0 && perfection >= notifiedMinPerfection
hasHighLevel = notifiedMinLevel > 0 && level >= notifiedMinLevel

hasHighAttributes = (hasHighIV && notifiedMinLevel === 0) || (hasHighLevel && notifiedMinPerfection === 0) || hasHighLevel && hasHighIV
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to

hasHighAttributes = (hasHighIV && !(notifiedMinLevel > 0)) || (hasHighLevel && !(notifiedMinPerfection > 0)) || hasHighLevel && hasHighIV

...to make it always work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed...

@tomballgithub
Copy link
Contributor Author

tomballgithub commented Dec 19, 2017

FYI sloppydrive's users found the needed code improvement earlier but otherwise this is working well.

Copy link
Contributor

@sirlindqvist sirlindqvist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problems, also works good in combination with minimum IV level.

@darkelement1987
Copy link
Contributor

Is it also possible for you to build in 'Exclude/hide pokemon by iv/level'? I would love that.

@tomballgithub
Copy link
Contributor Author

@darkelement1987 Yes there is another PR that allows you to hide pokemon that are not being notified. So you could set the minimum level and IV to what you want and then 'hide unnotified pokemon' and it will only show the high level ones (excluding the others) #2377

@darkelement1987
Copy link
Contributor

darkelement1987 commented Jan 15, 2018 via email

@tomballgithub
Copy link
Contributor Author

Rebased...

static/js/map.js Outdated
if (isNaN(notifiedMinLevel) || notifiedMinLevel <= 0) {
notifiedMinLevel = ''
}
if (notifiedMinLevel > 40) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wild pokemon can be max lvl 30 and 35 with weather boost, just a tiny notice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using level 40 allows this code to be future proof.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this check and set the upper limit to 35 in the input in the HTML template. If anyone tampers with it to allow values above 35, the code is right to assume that they only want to be notified of levels at or above whichever level they've set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't seem to be a simple way to do this in the template. Min/Max values are only applicable if input type is number not text. Changing to number causes a behavior change in that there are now scroll bars up/down and the input box gets resized. I'll leave it as-is but change to 35 maximum even though I'd prefer 40 to be future proof.

@@ -869,6 +869,9 @@ var StoreOptions = {
'excludedRarity': {
default: 0, // 0: none, 1: <=Common, 2: <=Uncommon, 3: <=Rare, 4: <=Very Rare, 5: <=Ultra Rare
type: StoreTypes.Number
'remember_text_level_notify': {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

js object literal syntax error, npm run build will fail

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, fixed. Was introduced during rebase.

static/js/map.js Outdated
hasHighIV = notifiedMinPerfection > 0 && perfection >= notifiedMinPerfection
hasHighLevel = notifiedMinLevel > 0 && level >= notifiedMinLevel

hasHighAttributes = (hasHighIV && !(notifiedMinLevel > 0)) || (hasHighLevel && !(notifiedMinPerfection > 0)) || hasHighLevel && hasHighIV
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify

hasHighAttributes = (hasHighIV && !(notifiedMinLevel > 0)) || (hasHighLevel && !(notifiedMinPerfection > 0)) || hasHighLevel && hasHighIV

to

const shouldNotifyForIV = (hasHighIV && notifiedMinLevel <= 0)
const shouldNotifyForLevel = (hasHighLevel && (hasHighIV || notifiedMinPerfection <= 0))

hasHighAttributes = shouldNotifyForIV || shouldNotifyForLevel

Note that I used <= 0 because it's the reverse of >. If < is unnecessary, change it to ==.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was due to a bug caused by the '' assignment as default

$textLevelNotify.on('change', function (e) {
notifiedMinLevel = parseInt($textLevelNotify.val(), 10)
if (isNaN(notifiedMinLevel) || notifiedMinLevel <= 0) {
notifiedMinLevel = ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default should be 0 rather than an empty string and the <= 0 should be changed with < 0. 0 can be a valid option, to disable it. Make sure to keep the behavior consistent with "Notify by IV".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree but note that I copied the exact '' assignment also used for remember_text_perfection_notify

static/js/map.js Outdated
if (isNaN(notifiedMinLevel) || notifiedMinLevel <= 0) {
notifiedMinLevel = ''
}
if (notifiedMinLevel > 40) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this check and set the upper limit to 35 in the input in the HTML template. If anyone tampers with it to allow values above 35, the code is right to assume that they only want to be notified of levels at or above whichever level they've set.

Fixed travis

Change code to handled undefined notification parameters
@tomballgithub
Copy link
Contributor Author

Should be all rebased and fixed

Copy link
Contributor

@jaake77 jaake77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with some IV accounts and it works.
Thanks for the feature!

static/js/map.js Outdated
}

return hasHighIV
return hasHighAttributes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current code will cause a problem when "Notify by IV" is enabled and "Notify by level" is disabled, and the Pokémon has IV data but no cp_multiplier (technically not possible since they're both inserted during scan, but logically they're unrelated so they should be separated).

The problem lies in your condition:

var hasHighAttributes = false

if (poke['individual_attack'] != null && poke['cp_multiplier'] !== null) {
    ...
}

return hasHighAttributes

@tomballgithub
Copy link
Contributor Author

Approved via code review only, not testing of latest changes

Copy link
Contributor

@jaake77 jaake77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it! ty.

@sebastienvercammen sebastienvercammen merged commit 57d4902 into RocketMap:develop Jan 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants