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
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
4 changes: 4 additions & 0 deletions static/js/map.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,10 @@ var StoreOptions = {
default: '',
type: StoreTypes.Number
},
'remember_text_level_notify': {
default: 0,
type: StoreTypes.Number
},
'excludedRarity': {
default: 0, // 0: none, 1: <=Common, 2: <=Uncommon, 3: <=Rare, 4: <=Very Rare, 5: <=Ultra Rare
type: StoreTypes.Number
Expand Down
31 changes: 30 additions & 1 deletion static/js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var $selectExclude
var $selectPokemonNotify
var $selectRarityNotify
var $textPerfectionNotify
var $textLevelNotify
var $selectStyle
var $selectIconSize
var $switchOpenGymsOnly
Expand Down Expand Up @@ -37,6 +38,7 @@ var excludedRarity
var notifiedPokemon = []
var notifiedRarity = []
var notifiedMinPerfection = null
var notifiedMinLevel = null

var buffer = []
var reincludedPokemon = []
Expand Down Expand Up @@ -1045,14 +1047,28 @@ function playPokemonSound(pokemonID, cryFileTypes) {
}

function isNotifyPerfectionPoke(poke) {
var hasHighAttributes = false
var hasHighIV = false

// Notify for IV.
if (poke['individual_attack'] != null) {
const perfection = getIv(poke['individual_attack'], poke['individual_defense'], poke['individual_stamina'])
hasHighIV = notifiedMinPerfection > 0 && perfection >= notifiedMinPerfection
const shouldNotifyForIV = (hasHighIV && notifiedMinLevel <= 0)

hasHighAttributes = shouldNotifyForIV
}

// Or notify for level. If IV filter is enabled, this is an AND relation.
if (poke['cp_multiplier'] !== null) {
const level = getPokemonLevel(poke['cp_multiplier'])
const hasHighLevel = notifiedMinLevel > 0 && level >= notifiedMinLevel
const shouldNotifyForLevel = (hasHighLevel && (hasHighIV || notifiedMinPerfection <= 0))

hasHighAttributes = hasHighAttributes || shouldNotifyForLevel
}

return hasHighIV
return hasHighAttributes
}

function isNotifyPoke(poke) {
Expand Down Expand Up @@ -2687,6 +2703,7 @@ $(function () {
$selectPokemonNotify = $('#notify-pokemon')
$selectRarityNotify = $('#notify-rarity')
$textPerfectionNotify = $('#notify-perfection')
$textLevelNotify = $('#notify-level')
var numberOfPokemon = 493

// Load pokemon names and populate lists
Expand Down Expand Up @@ -2768,13 +2785,25 @@ $(function () {
$textPerfectionNotify.val(notifiedMinPerfection)
Store.set('remember_text_perfection_notify', notifiedMinPerfection)
})
$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

}
if (notifiedMinLevel > 35) {
notifiedMinLevel = 35
}
$textLevelNotify.val(notifiedMinLevel)
Store.set('remember_text_level_notify', notifiedMinLevel)
})

// recall saved lists
$selectExclude.val(Store.get('remember_select_exclude')).trigger('change')
$selectExcludeRarity.val(Store.get('excludedRarity')).trigger('change')
$selectPokemonNotify.val(Store.get('remember_select_notify')).trigger('change')
$selectRarityNotify.val(Store.get('remember_select_rarity_notify')).trigger('change')
$textPerfectionNotify.val(Store.get('remember_text_perfection_notify')).trigger('change')
$textLevelNotify.val(Store.get('remember_text_level_notify')).trigger('change')

if (isTouchDevice() && isMobileDevice()) {
$('.select2-search input').prop('readonly', true)
Expand Down
6 changes: 6 additions & 0 deletions templates/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ <h3>Notify of Perfection</h3>
<input id="notify-perfection" type="text" name="notify-perfection" placeholder="Minimum perfection %"/>
</label>
</div>
</div>
<div class="form-control">
<label for="notify-level">
<h3>Notify of Level</h3>
<input id="notify-level" type="text" name="notify-level" placeholder="Minimum level"/>
</label>
</div>
{% endif %}
<div class="form-control switch-container">
Expand Down