Skip to content

Commit 8ef97ac

Browse files
authored
Add collapsible statblock preview to custom NPCs in Encounter Builder (#338)
2 parents 03e8b76 + 4fb746c commit 8ef97ac

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

src/components/encounters/Entities.vue

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,31 @@
111111
:filter="searchNpc"
112112
wrap-cells
113113
>
114+
<template v-slot:header="props">
115+
<q-tr :props="props">
116+
<q-th auto-width />
117+
<q-th
118+
v-for="col in props.cols"
119+
:key="col.name"
120+
:props="props"
121+
:auto-width="col.name !== 'name'"
122+
>
123+
{{ col.label }}
124+
</q-th>
125+
</q-tr>
126+
</template>
127+
114128
<template v-slot:body="props">
115129
<q-tr :props="props">
130+
<q-td auto-width>
131+
<a @click="toggleCustomNpc(props, props.key)" class="neutral-2">
132+
<i
133+
aria-hidden="true"
134+
class="fas"
135+
:class="props.expand ? 'fa-chevron-up' : 'fa-chevron-down'"
136+
/>
137+
</a>
138+
</q-td>
116139
<q-td
117140
v-for="col in props.cols"
118141
:key="col.name"
@@ -187,6 +210,12 @@
187210
</template>
188211
</q-td>
189212
</q-tr>
213+
<q-tr v-if="props.expand" :props="props">
214+
<q-td colspan="100%" class="p-0" auto-width>
215+
<hk-loader v-if="!npcExpandData[props.key]" name="monster" />
216+
<ViewMonster v-else :data="npcExpandData[props.key]" class="p-0" />
217+
</q-td>
218+
</q-tr>
190219
</template>
191220
<div slot="no-data" />
192221
<hk-loader slot="loading" name="monsters" />
@@ -565,6 +594,7 @@ export default {
565594
maxContent: true,
566595
},
567596
},
597+
npcExpandData: {},
568598
monster_resource_setter: undefined,
569599
loading_monsters: true,
570600
loading_npcs: true,
@@ -992,6 +1022,27 @@ export default {
9921022
? this.$set(this.encounter.entities, uuid(), entity)
9931023
: this.$set(this.encounter, "entities", { [uuid()]: entity });
9941024
},
1025+
async toggleCustomNpc(props, id) {
1026+
props.expand = !props.expand;
1027+
if (props.expand && !this.npcExpandData[id]) {
1028+
try {
1029+
const npc = await this.get_npc({ uid: this.user.uid, id });
1030+
if (!npc) {
1031+
props.expand = false;
1032+
this.$snotify.error("This NPC could not be loaded.", "NPC unavailable", {
1033+
position: "centerTop",
1034+
});
1035+
return;
1036+
}
1037+
this.$set(this.npcExpandData, id, npc);
1038+
} catch (e) {
1039+
props.expand = false;
1040+
this.$snotify.error("Failed to load NPC statblock.", "Load error", {
1041+
position: "centerTop",
1042+
});
1043+
}
1044+
}
1045+
},
9951046
setSize(e) {
9961047
this.width = e.width;
9971048
},

0 commit comments

Comments
 (0)