inline styles and actor embeds
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import {
|
||||
preloadTemplatePaths,
|
||||
normalizeTemplatePaths,
|
||||
MODULE_ID,
|
||||
log,
|
||||
} from "./module.js";
|
||||
|
||||
const TEMPLATE_FILES = ["actor.hbs", "actor-inline.hbs"];
|
||||
const TEMPLATE_BASE = "embeds";
|
||||
const TEMPLATES = normalizeTemplatePaths(TEMPLATE_FILES, TEMPLATE_BASE);
|
||||
|
||||
async function buildActorEmbedHTML(doc, content, config, options) {
|
||||
// Types: community, pc, marker, npc, vehicle
|
||||
// LIMITED access can see Name and Description
|
||||
const noPermission = !doc.testUserPermission(
|
||||
game.user,
|
||||
CONST.DOCUMENT_OWNERSHIP_LEVELS.LIMITED,
|
||||
);
|
||||
if (noPermission) {
|
||||
const broken = document.createElement("span");
|
||||
broken.classList.add("broken", "content-embed");
|
||||
const i = document.createElement("i");
|
||||
i.classList.add("fa-solid", "fa-circle-exclamation");
|
||||
i.inert = true;
|
||||
broken.append(
|
||||
i,
|
||||
_loc(`${MODULE_ID}.embed.noPermission`, { uuid: doc.uuid }),
|
||||
);
|
||||
return broken;
|
||||
}
|
||||
let icon = "";
|
||||
switch (doc.type) {
|
||||
case "pc":
|
||||
icon = "fa-solid fa-user";
|
||||
break;
|
||||
case "npc":
|
||||
icon = "fa-solid fa-user-secret";
|
||||
break;
|
||||
case "community":
|
||||
icon = "fa-solid fa-tree-city";
|
||||
break;
|
||||
case "marker":
|
||||
icon = "fa-solid fa-thumbtack";
|
||||
break;
|
||||
case "vehicle":
|
||||
icon = "fa-solid fa-car-side";
|
||||
break;
|
||||
default:
|
||||
icon = "fa-solid fa-person";
|
||||
}
|
||||
const context = {
|
||||
config: { ...config },
|
||||
actor: doc,
|
||||
basic: doc.system.basic,
|
||||
pools: doc.system.pools,
|
||||
options,
|
||||
viewFullDocument: doc.testUserPermission(
|
||||
game.user,
|
||||
CONST.DOCUMENT_OWNERSHIP_LEVELS.OBSERVER,
|
||||
),
|
||||
icon,
|
||||
user: game.user,
|
||||
};
|
||||
const template = config.inline
|
||||
? TEMPLATES["actor-inline.hbs"]
|
||||
: TEMPLATES["actor.hbs"];
|
||||
const el = document.createElement(config.inline ? "span" : "div");
|
||||
el.classList.add(`${MODULE_ID}-embed`, "content-embed");
|
||||
let innerHTML = await renderTemplate(template, context);
|
||||
el.innerHTML = innerHTML;
|
||||
return el;
|
||||
}
|
||||
|
||||
function initializeEmbeds() {
|
||||
CONFIG.Actor.embedHandlers.push(buildActorEmbedHTML);
|
||||
}
|
||||
|
||||
Hooks.once("init", async () => {
|
||||
log(`Initializing ${MODULE_ID}`);
|
||||
initializeEmbeds();
|
||||
preloadTemplatePaths(TEMPLATES);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user