diff --git a/index.ts b/index.ts index f6dcb5f9..b729d5c0 100644 --- a/index.ts +++ b/index.ts @@ -157,6 +157,7 @@ export interface CreatureState extends HomebrewCreature { tempHP: number; currentAC: number | string; initiative: number; + static: boolean; player: boolean; xp: number; active: boolean; @@ -215,6 +216,7 @@ export interface HomebrewCreature { hidden?: boolean; friendly?: boolean; active?: boolean; + static?: boolean; "statblock-link"?: string; } diff --git a/src/encounter/index.ts b/src/encounter/index.ts index 63045066..bedc4a8b 100644 --- a/src/encounter/index.ts +++ b/src/encounter/index.ts @@ -32,6 +32,7 @@ interface CreatureStats { display?: string; hidden: boolean; friendly?: boolean; + static?: boolean; } export const equivalent = ( @@ -45,7 +46,8 @@ export const equivalent = ( equivalentModifiers(creature.modifier, existing.modifier) && creature.xp == existing.xp && creature.hidden == existing.hidden && - creature.friendly == existing.friendly + creature.friendly == existing.friendly && + creature.static == existing.static ); }; diff --git a/src/tracker/stores/tracker.ts b/src/tracker/stores/tracker.ts index 71529d0c..4bb412c8 100644 --- a/src/tracker/stores/tracker.ts +++ b/src/tracker/stores/tracker.ts @@ -87,6 +87,7 @@ function createTracker() { values.forEach((creature, _, arr) => { const equiv = arr.filter((c) => equivalent(c, creature)); equiv.forEach((eq) => { + if (eq.static) return; eq.initiative = Math.max(...equiv.map((i) => i.initiative)); }); }); @@ -572,6 +573,7 @@ function createTracker() { roll: (plugin: InitiativeTracker) => updateAndSave((creatures) => { for (let creature of creatures) { + if (creature.static) continue; creature.initiative = plugin.getInitiativeValue( creature.modifier ); @@ -589,6 +591,7 @@ function createTracker() { : creatures.filter((c) => c.player); if (!state || state?.roll) { for (let creature of creatures) { + if (creature.static && creature.initiative) continue; creature.initiative = plugin.getInitiativeValue( creature.modifier ); diff --git a/src/tracker/ui/create/Create.svelte b/src/tracker/ui/create/Create.svelte index bf3cdc4d..ef398ed0 100644 --- a/src/tracker/ui/create/Create.svelte +++ b/src/tracker/ui/create/Create.svelte @@ -152,6 +152,11 @@ .setValue(creature.hidden) .onChange((v) => (creature.hidden = v)); }; + const staticToggle = (div: HTMLDivElement) => { + new ToggleComponent(div) + .setValue(creature.static) + .onChange((v) => (creature.static = v)); + }; const friendToggle = (div: HTMLDivElement) => { new ToggleComponent(div) .setValue(creature.friendly) @@ -247,6 +252,10 @@ {#key creature} +
+ +
+
diff --git a/src/tracker/ui/create/Creator.svelte b/src/tracker/ui/create/Creator.svelte index d26c6ffb..6cabb184 100644 --- a/src/tracker/ui/create/Creator.svelte +++ b/src/tracker/ui/create/Creator.svelte @@ -52,8 +52,7 @@ tracker.add(plugin, rollHP, ...creatures); } - console.log(creature.player && creature.note); - if (creature.player && creature.path) { + if (creature?.player && creature?.path) { const file = await plugin.app.vault.getAbstractFileByPath( creature.path ); diff --git a/src/utils/creature.ts b/src/utils/creature.ts index 97e22b28..c182f2dc 100644 --- a/src/utils/creature.ts +++ b/src/utils/creature.ts @@ -36,6 +36,7 @@ export class Creature { status: Set = new Set(); marker: string; initiative: number; + static: boolean = false; source: string | string[]; id: string; xp: number; @@ -65,6 +66,7 @@ export class Creature { "initiative" in creature ? (creature as Creature).initiative : Number(initiative ?? 0); + this.static = creature.static ?? false; this.modifier = Number(creature.modifier ?? 0); this.current_ac = this.ac = creature.ac ?? undefined; @@ -142,6 +144,7 @@ export class Creature { *[Symbol.iterator]() { yield this.name; yield this.initiative; + yield this.static; yield this.modifier; yield this.max; yield this.ac; @@ -209,6 +212,7 @@ export class Creature { name: this.name, display: this.display, initiative: this.initiative, + static: this.static, modifier: this.modifier, hp: this.max, currentMaxHP: this.current_max, @@ -240,7 +244,7 @@ export class Creature { creature = plugin.getPlayerByName(state.name) ?? new Creature(state, state.initiative); - creature.initiative = state.initiative; + creature.initiative = state.initiative; } else { creature = new Creature(state, state.initiative); }