Skip to content

Commit

Permalink
fix: bestiary property is now readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Jan 22, 2022
1 parent f6ba2dc commit 303596c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ const DEFAULT_DATA: StatblockData = {
export default class StatBlockPlugin extends Plugin {
settings: StatblockData;
data: Map<string, Monster>;
bestiary: Map<string, Monster>;
_bestiary: Map<string, Monster>;
get bestiary() {
return this._bestiary;
}
watcher = new Watcher(this);
private _sorted: Monster[] = [];
get canUseDiceRoller() {
Expand Down Expand Up @@ -140,7 +143,7 @@ export default class StatBlockPlugin extends Plugin {
addIcon(SAVE_SYMBOL, SAVE_ICON);
addIcon(EXPORT_SYMBOL, EXPORT_ICON);

this.bestiary = new Map([...BESTIARY_BY_NAME, ...this.data]);
this._bestiary = new Map([...BESTIARY_BY_NAME, ...this.data]);

this.registerMarkdownCodeBlockProcessor(
"statblock",
Expand Down Expand Up @@ -203,7 +206,7 @@ export default class StatBlockPlugin extends Plugin {
) {
if (!monster.name) return;
this.data.set(monster.name, monster);
this.bestiary.set(monster.name, monster);
this._bestiary.set(monster.name, monster);

if (save) {
await this.saveSettings();
Expand Down Expand Up @@ -233,7 +236,7 @@ export default class StatBlockPlugin extends Plugin {
for (const monster of monsters) {
if (!this.data.has(monster)) continue;
this.data.delete(monster);
this.bestiary.delete(monster);
this._bestiary.delete(monster);
}
await this.saveSettings();

Expand All @@ -245,10 +248,10 @@ export default class StatBlockPlugin extends Plugin {
async deleteMonster(monster: string, sortFields = true, save = true) {
if (!this.data.has(monster)) return;
this.data.delete(monster);
this.bestiary.delete(monster);
this._bestiary.delete(monster);

if (BESTIARY_BY_NAME.has(monster)) {
this.bestiary.set(monster, BESTIARY_BY_NAME.get(monster));
this._bestiary.set(monster, BESTIARY_BY_NAME.get(monster));
}

if (save) await this.saveSettings();
Expand Down Expand Up @@ -391,8 +394,8 @@ export default class StatBlockPlugin extends Plugin {
}
const monster: Monster = Object.assign(
{},
this.bestiary.get(params.monster) ??
this.bestiary.get(params.creature)
this._bestiary.get(params.monster) ??
this._bestiary.get(params.creature)
);
//TODO: The traits are breaking because it expects { name, desc }, not array.
if (monster) {
Expand Down Expand Up @@ -469,7 +472,7 @@ ${e.stack
const monster: Monster = Object.assign<
Partial<Monster>,
HomebrewCreature
>(this.bestiary.get(creature.name) ?? {}, { ...creature }) as Monster;
>(this._bestiary.get(creature.name) ?? {}, { ...creature }) as Monster;
if (!monster) return null;
return new StatBlockRenderer(
el,
Expand Down

0 comments on commit 303596c

Please sign in to comment.