Skip to content

Commit

Permalink
Add option to Notify by Pokemon Level (#2399)
Browse files Browse the repository at this point in the history
* Add user interface option to Notify By Pokemon Level

Fixed travis

Change code to handled undefined notification parameters

* Fix typo

* Fix rebase issue

* Make changes based on review input

* Cleanup

* Remove errant const

* Fix conflict in logic.
  • Loading branch information
tomballgithub authored and sebastienvercammen committed Jan 27, 2018
1 parent 5225b59 commit 57d4902
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
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 @@ -1059,14 +1061,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 @@ -2706,6 +2722,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 @@ -2787,13 +2804,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 = ''
}
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

0 comments on commit 57d4902

Please sign in to comment.