Repository navigation
Portraits
Small round token portraits for chat messages, windows and log lines: one creature's face, or a chain of them for a squad, with the captain marked and the minions drawn smaller. Clicking one pings its token and hovering one highlights it on the canvas, the same way in every module that uses them.
const { faceFromToken, groupFaces, faceChainHTML, activateFaces } = ctlib;
const faces = targets.map((token) => faceFromToken(token));
const html = faceChainHTML(faces);faceFromToken(token, { faded = false, tooltip = null }) takes a Token or a TokenDocument and returns a plain face object, or null when there's no token:
| Field | What it holds |
|---|---|
tokenUuid |
The token's UUID, which is how the face finds its token again. |
src |
The token's image, falling back to the actor's. |
name |
The token's name. |
minion |
Whether the actor is a minion. |
captain |
Whether it's the captain of its squad in the current combat. |
squadId |
The id of its squad's combatant group, or null. |
faded |
Draw it greyed out, for a creature that's only possibly involved. |
tooltip |
A line under the name in the face's rich tooltip, or null for the name alone. |
Faces are plain objects, so you can build one by hand too. Only src is required; a face without a tokenUuid still shows and says it's not on this scene when clicked, using its name.
groupFaces(faces) turns a flat list into groups for display: minions of the same squad that share a name become one group with all their faces, and everyone else stands alone. Each group is { label, faces, faded }, where faded is true only when every face in it is. Within a group, faded faces go last and the captain goes first.
for (const group of groupFaces(faces)) {
row.insertAdjacentHTML('beforeend', `${faceChainHTML(group.faces)} <span>${group.label}</span>`);
}faceChainHTML(faces, { className = '' }) returns the HTML for a chain of portraits that overlap a little and spread apart on hover. Faces without a src are skipped. className goes on the outer element.
| Class | On |
|---|---|
ctlib-faces |
The chain. |
ctlib-face-wrap |
Each portrait's wrapper, which carries the token in data-ctlib-face and the name in data-ctlib-face-name. |
ctlib-face |
The image. |
ctlib-face-minion |
A minion's image, drawn smaller. A captain keeps the full size. |
ctlib-face-captain |
The captain's wrapper, which also holds a small gold helmet, ctlib-face-captain-mark. |
ctlib-face-faded |
A faded face's wrapper. |
Restyle them from your own stylesheet under your own class: Battle Log's turn markers do this to shrink minions a little more and to spread the chain when the whole marker is hovered.
activateFaces(root) makes the portraits inside root work. Call it once per element; calling it again on the same element does nothing, and portraits added to root later work without another call.
| Action | What happens |
|---|---|
| Click | Pings the token. The click stops there, so a portrait inside something clickable doesn't also click its parent. |
| Shift and click | Pings and pulls everyone's view to the token. |
| Hover | Highlights the token, only when the viewer can see it, so a player can't find a hidden creature by hovering its portrait. |
| Token not on this scene | A notice says so, by name. |
It works on any element with a data-ctlib-face attribute holding a token UUID, not only the ones faceChainHTML builds. A module with its own portrait markup can add the attribute (and data-ctlib-face-name, for the notice) and let CTLib handle the rest.
Getting Started
Working With Documents
The Canvas
Interface