mirror of
https://github.com/Kornstalx/5etools-mirror-2.github.io.git
synced 2025-10-28 20:45:35 -05:00
40 lines
898 B
JavaScript
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));
|
|
}
|
|
}
|