Skip to content
dxcufgb edited this page Oct 30, 2026 · 1 revision

API

For macro and module authors.

const ff = game.modules.get("dxcufgbs-familiar-faces").api;
ff.open();                                   // switch to the tab
ff.faces();                                  // [{id, name, img, metAt, info, source, actor, knownBy, ...}]
ff.getFace(id);                              // one NPC, or null (also null when the user doesn't have it)
ff.findByName("Mira Ashgrove");
ff.canSeeEntry(ff.getPlace(id, { any: true }), game.users.getName("Ana")); // has that player got it in their lists?
ff.addFace({ name: "Mira Ashgrove", img: "path/to/mira.webp" });   // opens the Add window
await ff.createFace({ name: "Mira Ashgrove", metAt: "Saltmarsh" }); // no window; returns the id
await ff.updateFace(id, { metAt: "Phandalin", info: "Runs the Stonehill Inn." }); // only the fields given
ff.bindImage("path/to/mira.webp");           // GM: opens the Add image to NPC search
await ff.setImage(id, "path/to/mira.webp");  // set the portrait directly ("" removes it)
ff.addToken(token);                          // GM: for all players; player: to their own Familiar Faces
ff.addActor(actor);                          // GM: add an NPC actor for all players
ff.shareWithParty(id);                       // GM, or a player who has the NPC: put it in everyone's list
ff.forgetFace(id);                           // player: remove an NPC from their own list
await ff.deleteFace(id);                     // remove the NPC and its notes
ff.notes(id);                                // the notes about an NPC the user can see
await ff.addNote(id, { text: "Owes us a favour.", place: "Saltmarsh", visibility: "everyone" }); // returns the note id
await ff.syncNameplates();                   // GM: update the tokens of party-known NPCs now
ff.openFace(id);

// Places
ff.openPlaces();                             // switch to the tab's Places list
ff.places();                                 // [{id, name, img, region, info, source, scene, links, knownBy, ...}]
ff.getPlace(id);
ff.findPlaceByName("Saltmarsh");
ff.addPlace({ name: "Saltmarsh", region: "Sword Coast" });      // opens the Add place window
await ff.createPlace({ name: "Saltmarsh", region: "Sword Coast", scene: scene.uuid }); // no window; returns the id
await ff.updatePlace(id, { region: "The Sword Coast" });
ff.bindPlaceImage("path/to/saltmarsh.webp"); // GM: opens the Add image to place search
await ff.setPlaceImage(id, "path/to/saltmarsh.webp");
ff.addScene(scene);                          // GM: add a scene as a place for all players
await ff.linkFace(placeId, faceId);          // link an NPC to a place
await ff.unlinkFace(placeId, faceId);        // remove that link again
ff.facesOfPlace(placeId);                    // the NPCs met at, noted at or linked to a place
ff.placesOfFace(faceId);                     // the places of an NPC
ff.placeNotes(id); await ff.addPlaceNote(id, { text: "The harbour master is bribable.", visibility: "private" });
ff.sharePlaceWithParty(id); ff.forgetPlace(id); ff.openPlace(id);
await ff.deletePlace(id);

// Factions
ff.openFactions();                           // switch to the tab's Factions list
ff.factions();                               // [{id, name, img, category, info, source, links, placeLinks, knownBy, ...}]
ff.getFaction(id);
ff.findFactionByName("Zhentarim");
ff.addFaction({ name: "Zhentarim", category: "Mercenaries" });  // opens the Add faction window
await ff.createFaction({ name: "Zhentarim", category: "Mercenaries" }); // no window; returns the id
await ff.updateFaction(id, { category: "Thieves' guild" });
ff.bindFactionImage("path/to/zhentarim.webp"); // GM: opens the Add image to faction search
await ff.setFactionImage(id, "path/to/zhentarim.webp");
await ff.linkToFaction(factionId, "faces", faceId, "Leader");    // or "places", placeId, "Headquarters"
await ff.setFactionRole(factionId, "faces", faceId, "Informant");
await ff.unlinkFromFaction(factionId, "faces", faceId);
ff.membersOfFaction(factionId);              // [{face, role}]
ff.placesOfFaction(factionId);               // [{place, role}]
ff.factionsOf("faces", faceId);              // [{faction, role}] (or "places", placeId)
ff.factionNotes(factionId); await ff.addFactionNote(factionId, { text: "They hire in Phandalin.", visibility: "everyone" });
ff.shareFactionWithParty(id); ff.forgetFaction(id); ff.openFaction(id);
await ff.deleteFaction(id);

// Dxcufgb's Quest log
ff.linkQuestLog("We met her on The Silver Thread"); // the text with the quests, rewards and notes it names linked

Dxcufgb's Quest log

ff.linkQuestLog links the quests, rewards and notes a text names; see Works with Quest Log. The Quest log has its own API: see its API page.

What a user gets

Everything only returns and finds what the current user has in their lists: the GM gets everything, a player the party's NPCs, places and factions plus their own. getFace, getPlace, getFaction and the find…ByName calls take { any: true } to also find the ones only other players have. canSeeEntry(entry, user) tells whether a user (default: the current one) has an NPC, place or faction in their lists: a GM always, a player when it is the party's or in their own list. canSeeFace is the older name of canSeeEntry.

Calls in detail

  • Creating: createFace takes name, img, metAt, info, source ({uuid, label}, the link back to a journal), actor (an actor uuid) and knownBy (a list of user ids: only those players get it; leave it out for the whole party). createPlace takes region and scene (a scene uuid) instead of metAt and actor, createFaction takes category. A player can't create or share NPCs while a combat has started; places and factions aren't affected.
  • The add… calls open the Add window with the given values filled in and return a Promise of the new id, or null when it was cancelled or the user may not add.
  • Links: linkFace, unlinkFace, linkToFaction, setFactionRole and unlinkFromFaction return true, or false when nothing changed (already linked, not allowed). Anyone who has both in their lists can link them; the link's maker, the creator of the place or faction and the GM can change or remove it. kind is "faces" or "places".
  • Notes: addNote, addPlaceNote and addFactionNote take {text, visibility, sharedWith}, and NPC notes also place. visibility is "private" (only the author), "everyone" (the party) or "some" with sharedWith a list of user ids (an empty list keeps the note private). They return the note's id, or null for an empty note. With the Quest log active (and Link notes to the Quest log on), the text gets its Quest log links like a note added in the window. A note object has {id, text, place, visibility, sharedWith, createdBy, authorName, createdAt, editedAt}.
  • shareWithParty, forgetFace and the place and faction versions return a Promise of true, or false when the user may not do it.

Permissions

Permissions: the API checks what the module's own windows check, so a player's macro can't do more than the player could in the tab. A call that isn't allowed shows a warning and returns null (create…, add…Note, addActor, addScene, bind…Image) or false (everything else); it doesn't throw. The GM may do everything.

  • Creating (createFace, createPlace, createFaction): a player always may add to their own list (knownBy: [game.user.id]), for the whole party only with Players can add NPCs, places and factions, and never for other players. No NPCs during combat. A player's img can only be a placeholder look, source and actor are the GM's, and scene must be a scene they can view (for a real portrait, a token or an actor, use addToken or the add… windows).
  • Changing and removing (update…, delete…): the GM or whoever added the entry. A player changes only what their edit window has (name, info, metAt / region / category, and a placeholder look as img); source, actor and scene are the GM's. A player removes only an entry the whole party has; one in their own list goes with forget….
  • Pictures (setImage, setPlaceImage, setFactionImage, img in update…): the GM. A player who added the entry may set or clear a placeholder look (assets/placeholders/…) while it has no real picture.
  • Sharing and forgetting: shareWithParty and the others: the GM, or a player who has the entry in their own list (not NPCs during combat). forget…: a player who has it in their own list.
  • Notes (addNote, addPlaceNote, addFactionNote): anyone, about an entry in their lists. Only a note's author changes it in the window.
  • Links (linkFace, linkToFaction): anyone who has both in their lists. unlinkFace, unlinkFromFaction, setFactionRole: the link's maker, whoever added the place or faction, or the GM.
  • GM only: addActor, addScene, bindImage, bindPlaceImage, bindFactionImage; syncNameplates does nothing on other clients.
  • Reading (faces(), getFace, notes…) returns only what the user may see. deleteFace (and the others) also removes the entry from places and factions; run by a GM, it clears everyone's private notes about it too.

From another module

From another module

The API is set in the module's own ready hook, after it has checked its storage (an await), so it isn't there yet while other modules' ready hooks run. Get it when you need it (a button, a later hook) rather than once at ready, and check that it's there:

const familiarFaces = () => game.modules.get("dxcufgbs-familiar-faces")?.active ? game.modules.get("dxcufgbs-familiar-faces").api ?? null : null;

// later, e.g. when the user clicks something:
const ff = familiarFaces();
if (ff) console.log(ff.faces().map(face => face.name));   // null: not installed, not enabled, or not ready yet

Add { "id": "dxcufgbs-familiar-faces", "type": "module" } to relationships.recommends in your module.json. The module calls no hooks of its own, so there is no event that says the API is ready.

Stored data

Its data lives in the flags of journal entries it hides from the Journal directory; that layout is internal and may change, so read and write through the API.

Clone this wiki locally