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:
39
js/bestiary/bestiary-encounterbuilder-cache.js
Normal file
39
js/bestiary/bestiary-encounterbuilder-cache.js
Normal 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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user