Skip to content

Commit

Permalink
Show warning when there are monsters that match the search term, but …
Browse files Browse the repository at this point in the history
…are filtered or in unselected sources
  • Loading branch information
elsoybean committed Sep 1, 2018
1 parent cf9b1ce commit 36a04ad
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 12 deletions.
7 changes: 7 additions & 0 deletions app/encounter-builder/monster-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
</th>
</tr>
</thead>
<tbody>
<tr class="monster-table--warning-row" ng-if="vm.filters.search && (vm.monsters | countHiddenMonstersFilter:vm.filters) > 0">
<td colspan="7" class="monster-table--filter-warning-cell">
{{ vm.monsters | countHiddenMonstersFilter:vm.filters }} monsters hidden by filters or in unselected sources
</td>
</tr>
</tbody>
<tbody>
<tr
dir-paginate="monster in vm.monsters | monstersFilter:vm.filters | itemsPerPage: vm.filters.pageSize"
Expand Down
19 changes: 19 additions & 0 deletions app/encounter-builder/monster-table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
}
}
}

&--filter-warning-cell {
background-color: darken($state-warning-bg, 5%);
text-align: center;
font-style: italic;
}
}

@media (max-width: 768px) {
Expand Down Expand Up @@ -78,7 +84,16 @@
}
}

.monster-table--warning-row {
display: block;
position: relative;
&:not(:last-child) {
border-bottom: 1px solid #ddd;
}
}

// Cells; double-classed to override precedence of libraries so borders are actually removed.
.monster-table--filter-warning-cell.monster-table--filter-warning-cell,
.monster-table--button-cell.monster-table--button-cell,
.monster-table--name-cell.monster-table--name-cell,
.monster-table--cr-cell.monster-table--cr-cell,
Expand All @@ -92,6 +107,10 @@
margin: 0 $spacing;
}

.monster-table--filter-warning-cell.monster-table--filter-warning-cell {
width: 100%;
}

.monster-table--name-cell.monster-table--name-cell {
display: block;
font-size: 1.25em;
Expand Down
23 changes: 23 additions & 0 deletions app/filters/count-hidden-monsters.filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(function() {
"use strict";

angular.module("app")
.filter("countHiddenMonstersFilter", CountHiddenMonsters);

CountHiddenMonsters.$inject = ["monsterFactory"];

function CountHiddenMonsters(monsterLib) {
return function ( input, filters ) {
if (!input) return 0;
var output = 0, i;

for ( i = 0; i < input.length; i++ ) {
if ( monsterLib.checkIsMonsterFoundAndFiltered(input[i], filters) ) {
output++;
}
}

return output;
};
}
})();
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<script src="app/encounter-manager/encounter-manager.controller.js"></script>
<script src="app/encounter-manager/manager-row.component.js"></script>
<script src="app/encounter-manager/manager-row.controller.js"></script>
<script src="app/filters/count-hidden-monsters.filter.js"></script>
<script src="app/filters/filter-and-sort-monsters.filter.js"></script>
<script src="app/filters/positive-and-negative-numbers.filter.js"></script>
<script src="app/filters/sort-encounter.filter.js"></script>
Expand Down
36 changes: 24 additions & 12 deletions scripts/monsterfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
function MonsterFactory(alignments, crInfo) {
var factory = {
checkMonster: checkMonster,
checkIsMonsterFoundAndFiltered: checkIsMonsterFoundAndFiltered,
Monster: Monster,
};

Expand Down Expand Up @@ -159,6 +160,14 @@
};
var lastRegex = regexCache[""];
function checkMonster(monster, filters, args) {
return !isFiltered(monster, filters, args) && isNameMatched(monster, filters);
}

function checkIsMonsterFoundAndFiltered(monster, filters, args) {
return isNameMatched(monster, filters) && isFiltered(monster, filters, args);
}

function isFiltered(monster, filters, args) {
args = args || {};

var legendaryMap = {
Expand All @@ -171,52 +180,56 @@
var legendaryFilter = legendaryMap[filters.legendary];

if (legendaryFilter) {
if (!monster[legendaryFilter]) return false;
if (!monster[legendaryFilter]) return true;
} else {
if (monster.legendary || monster.lair) return false;
if (monster.legendary || monster.lair) return true;
}
}

if ( filters.type && monster.type !== filters.type ) {
return false;
return true;
}

if ( filters.size && monster.size !== filters.size ) {
return false;
return true;
}

if ( args.nonUnique && monster.unique ) {
return false;
return true;
}

if ( filters.alignment ) {
if ( !monster.alignment ) {
return false;
return true;
}

if ( ! (filters.alignment.flags & monster.alignment.flags) ) {
return false;
return true;
}
}

if ( !args.skipCrCheck ) {
if ( filters.minCr && monster.cr.numeric < filters.minCr ) {
return false;
return true;
}

if ( filters.maxCr && monster.cr.numeric > filters.maxCr ) {
return false;
return true;
}
}

if ( filters.environment && monster.environments.indexOf(filters.environment) === -1 ) {
return false;
return true;
}

if ( !isInSource(monster, filters.source) ) {
return false;
return true;
}

return false;
}

function isNameMatched(monster, filters) {
if ( filters.search ) {
let checkRegex = filters.search.match(/^\/(.*?)\/?$/);
if ( checkRegex ) {
Expand Down Expand Up @@ -254,7 +267,6 @@
} else if ( monster.searchable.indexOf(filters.search.toLowerCase()) === -1 ) {
return false;
}

}

return true;
Expand Down
12 changes: 12 additions & 0 deletions styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -7557,6 +7557,10 @@ button.close {
display: none; }
.monster-table--source-name__long {
display: inline; } }
.monster-table--filter-warning-cell {
background-color: #faf2cc;
text-align: center;
font-style: italic; }

@media (max-width: 768px) {
.monster-table--table {
Expand All @@ -7572,6 +7576,12 @@ button.close {
min-height: 100px; }
.monster-table--row:not(:last-child) {
border-bottom: 1px solid #ddd; }
.monster-table--warning-row {
display: block;
position: relative; }
.monster-table--warning-row:not(:last-child) {
border-bottom: 1px solid #ddd; }
.monster-table--filter-warning-cell.monster-table--filter-warning-cell,
.monster-table--button-cell.monster-table--button-cell,
.monster-table--name-cell.monster-table--name-cell,
.monster-table--cr-cell.monster-table--cr-cell,
Expand All @@ -7583,6 +7593,8 @@ button.close {
border: 0;
padding: 0;
margin: 0 3px; }
.monster-table--filter-warning-cell.monster-table--filter-warning-cell {
width: 100%; }
.monster-table--name-cell.monster-table--name-cell {
display: block;
font-size: 1.25em; }
Expand Down

0 comments on commit 36a04ad

Please sign in to comment.