mirror of
https://github.com/Kornstalx/5etools-mirror-2.github.io.git
synced 2025-10-28 20:45:35 -05:00
v1.198.1
This commit is contained in:
105
js/filter-recipes.js
Normal file
105
js/filter-recipes.js
Normal file
@@ -0,0 +1,105 @@
|
||||
"use strict";
|
||||
|
||||
class PageFilterRecipes extends PageFilter {
|
||||
static _DIET_TO_FULL = {
|
||||
"V": "Vegan",
|
||||
"C": "Vegetarian",
|
||||
"X": "Omni",
|
||||
};
|
||||
static _MISC_TAG_TO_FULL = {
|
||||
"alcohol": "Contains Alcohol",
|
||||
"feast": "Feast Dish",
|
||||
};
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
|
||||
this._typeFilter = new Filter({
|
||||
header: "Category",
|
||||
displayFn: StrUtil.toTitleCase,
|
||||
itemSortFn: SortUtil.ascSortLower,
|
||||
});
|
||||
this._dishTypeFilter = new Filter({
|
||||
header: "Dish Type",
|
||||
displayFn: StrUtil.toTitleCase,
|
||||
itemSortFn: SortUtil.ascSortLower,
|
||||
});
|
||||
this._servesFilter = new RangeFilter({header: "Serves", min: 1, max: 1});
|
||||
this._dietFilter = new Filter({
|
||||
header: "Diet",
|
||||
displayFn: PageFilterRecipes._dietToFull,
|
||||
itemSortFn: SortUtil.ascSortLower,
|
||||
});
|
||||
this._allergensFilter = new Filter({
|
||||
header: "Allergens",
|
||||
displayFn: StrUtil.toTitleCase,
|
||||
itemSortFn: SortUtil.ascSortLower,
|
||||
});
|
||||
this._miscFilter = new Filter({
|
||||
header: "Miscellaneous",
|
||||
items: ["SRD"],
|
||||
isMiscFilter: true,
|
||||
displayFn: PageFilterRecipes._miscTagToFull,
|
||||
});
|
||||
}
|
||||
|
||||
static mutateForFilters (it) {
|
||||
it._fMisc = it.srd ? ["SRD"] : [];
|
||||
if (it.miscTags) it._fMisc.push(...it.miscTags);
|
||||
it._fServes = (it.serves?.min != null && it.serves?.max != null) ? [it.serves.min, it.serves.max] : (it.serves?.exact ?? null);
|
||||
it._fDiet = it.diet ? PageFilterRecipes._DIET_TO_FULL[it.diet] || it.diet : null;
|
||||
if (it.hasFluff || it.fluff?.entries) it._fMisc.push("Has Info");
|
||||
if (it.hasFluffImages || it.fluff?.images) it._fMisc.push("Has Images");
|
||||
}
|
||||
|
||||
addToFilters (it, isExcluded) {
|
||||
if (isExcluded) return;
|
||||
|
||||
this._sourceFilter.addItem(it.source);
|
||||
this._typeFilter.addItem(it.type);
|
||||
this._dishTypeFilter.addItem(it.dishTypes);
|
||||
this._servesFilter.addItem(it._fServes);
|
||||
this._dietFilter.addItem(it._fDiet);
|
||||
this._allergensFilter.addItem(it.allergenGroups);
|
||||
this._miscFilter.addItem(it._fMisc);
|
||||
}
|
||||
|
||||
async _pPopulateBoxOptions (opts) {
|
||||
opts.filters = [
|
||||
this._sourceFilter,
|
||||
this._typeFilter,
|
||||
this._dishTypeFilter,
|
||||
this._servesFilter,
|
||||
this._dietFilter,
|
||||
this._allergensFilter,
|
||||
this._miscFilter,
|
||||
];
|
||||
}
|
||||
|
||||
toDisplay (values, it) {
|
||||
return this._filterBox.toDisplay(
|
||||
values,
|
||||
it.source,
|
||||
it.type,
|
||||
it.dishTypes,
|
||||
it._fServes,
|
||||
it._fDiet,
|
||||
it.allergenGroups,
|
||||
it._fMisc,
|
||||
);
|
||||
}
|
||||
|
||||
static _dietToFull (diet) { return PageFilterRecipes._DIET_TO_FULL[diet] || diet; }
|
||||
static _miscTagToFull (tag) { return PageFilterRecipes._MISC_TAG_TO_FULL[tag] || tag; }
|
||||
}
|
||||
|
||||
globalThis.PageFilterRecipes = PageFilterRecipes;
|
||||
|
||||
class ListSyntaxRecipes extends ListUiUtil.ListSyntax {
|
||||
static _INDEXABLE_PROPS_ENTRIES = [
|
||||
"ingredients",
|
||||
"instructions",
|
||||
];
|
||||
}
|
||||
|
||||
globalThis.ListSyntaxRecipes = ListSyntaxRecipes;
|
||||
Reference in New Issue
Block a user