From 169cc7d6c3ae564e96a007728f4f5e2d631cacf2 Mon Sep 17 00:00:00 2001 From: Jeremy Valentine <38669521+valentine195@users.noreply.github.com> Date: Wed, 16 Aug 2023 09:11:23 -0400 Subject: [PATCH] fix: improves player management in settings --- src/settings/settings.ts | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/settings/settings.ts b/src/settings/settings.ts index b9882f35..b68bc45d 100644 --- a/src/settings/settings.ts +++ b/src/settings/settings.ts @@ -471,8 +471,7 @@ export default class InitiativeTrackerSettings extends PluginSettingTab { .setIcon("trash") .setTooltip("Delete") .onClick(async () => { - this.plugin.data.players = - this.plugin.data.players.filter((p) => p != player); + this.plugin.deletePlayer(player); await this.plugin.saveSettings(); this._displayPlayers(additionalContainer); @@ -541,12 +540,18 @@ export default class InitiativeTrackerSettings extends PluginSettingTab { .setName("XP System") .setDesc("XP system to use for encounters") .addDropdown((d) => { - Object.values(RpgSystemSetting) - .forEach(system => d.addOption(system, getRpgSystem(this.plugin, system).displayName)); - d.setValue(this.plugin.data.rpgSystem ?? RpgSystemSetting.Dnd5e); + Object.values(RpgSystemSetting).forEach((system) => + d.addOption( + system, + getRpgSystem(this.plugin, system).displayName + ) + ); + d.setValue( + this.plugin.data.rpgSystem ?? RpgSystemSetting.Dnd5e + ); d.onChange(async (v) => { - this.plugin.data.rpgSystem = v; - this.plugin.saveSettings(); + this.plugin.data.rpgSystem = v; + this.plugin.saveSettings(); }); }); @@ -1079,11 +1084,11 @@ class NewPlayerModal extends Modal { if (!metaData || !metaData.frontmatter) return; const { ac, hp, modifier, level, name } = metaData.frontmatter; - this.player.name = name ? name : this.player.name; - this.player.ac = ac; - this.player.hp = hp; - this.player.level = level; - this.player.modifier = modifier; + this.player.name = name ?? this.player.name; + this.player.ac = ac ?? this.player.ac; + this.player.hp = hp ?? this.player.hp; + this.player.level = level ?? this.player.level; + this.player.modifier = modifier ?? this.player.modifier; this.player["statblock-link"] = metaData.frontmatter["statblock-link"]; this.display();