Files
5etools-mirror-2.github.io/js/bestiary/bestiary-encounterbuilder-cache.js
TheGiddyLimit 8117ebddc5 v1.198.1
2024-01-01 19:34:49 +00:00

40 lines
898 B
JavaScript

import {EncounterBuilderCacheBase} from "../encounterbuilder/encounterbuilder-cache.js";
export class EncounterBuilderCacheBestiaryPage extends EncounterBuilderCacheBase {
_cache = null;
constructor ({bestiaryPage}) {
super();
this._bestiaryPage = bestiaryPage;
}
_build () {
if (this._cache != null) return;
// create a map of {XP: [monster list]}
this._cache = this._getBuiltCache();
}
_getBuiltCache () {
const out = {};
this._bestiaryPage.list_.visibleItems
.map(li => this._bestiaryPage.dataList_[li.ix])
.filter(mon => !this._isUnwantedCreature(mon))
.forEach(mon => {
(out[Parser.crToXpNumber(mon.cr)] ||= []).push(mon);
});
return out;
}
reset () { this._cache = null; }
getCreaturesByXp (xp) {
this._build();
return this._cache[xp] || [];
}
getXpKeys () {
this._build();
return Object.keys(this._cache).map(it => Number(it));
}
}