This commit is contained in:
TheGiddyLimit
2024-01-01 19:34:49 +00:00
parent 332769043f
commit 8117ebddc5
1748 changed files with 2544409 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
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));
}
}