Cypher actor @Embed #1

Merged
mike merged 3 commits from cypher_embed into main 2026-09-26 04:47:31 +00:00
6 changed files with 169 additions and 0 deletions
Showing only changes of commit d2fa2f3530 - Show all commits
+7
View File
@@ -0,0 +1,7 @@
{
"mb-cypher2": {
"embed": {
"noPermission": "Unauthorized Actor Embed"
}
}
}
+82
View File
@@ -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);
});
+19
View File
@@ -0,0 +1,19 @@
export const MODULE_ID = "mb-cypher2";
export function log(...args) {
console.log(`${MODULE_ID} |`, ...args);
}
export function normalizeTemplatePaths(paths, baseDir = "") {
const templates = {};
log("finding templates", paths, baseDir);
const basePath = `modules/${MODULE_ID}/templates${baseDir ? "/" + baseDir : ""}`;
for (const file of paths) {
templates[file] = `${basePath}/${file}`;
}
return templates;
}
export async function preloadTemplatePaths(normalizedPaths) {
return loadTemplates(Object.values(normalizedPaths));
}
+29
View File
@@ -0,0 +1,29 @@
:root {
--mbcypher2-journal-embed-background: #ccccaa;
--mbcypher2-journal-embed-border-color: #aaaa88;
--mbcypher2-journal-embed-font-color: #000000;
}
body.theme-dark {
--mbcypher2-journal-embed-background: #333300;
--mbcypher2-journal-embed-border-color: #666633;
--mbcypher2-journal-embed-font-color: #eeeecc;
}
.mb-cypher2-embed.content-embed {
background: var(--mbcypher2-journal-embed-background);
border: 1px solid var(--mbcypher2-journal-embed-border-color);
border-radius: 2px;
}
span.mb-cypher2-embed.content-embed {
margin: -1px 0;
padding: 1px 4px 0;
white-space: nowrap;
word-break: break-all;
}
figure.content-embed figcaption cite {
margin-left: 0.5em;
}
}
+32
View File
@@ -0,0 +1,32 @@
<i class="{{icon}}"></i>
<strong>{{actor.name}}</strong>
{{#if (eq actor.type "pc") }}
<em>{{ localize "CYPHERSYSTEM.IsA" }}</em> {{ basic.descriptor }} {{ basic.type }}
<em>{{ localize "CYPHERSYSTEM.Who" }}</em> {{ basic.focus }} {{ basic.additionalSentence }}
{{/if}}
{{#if viewFullDocument}}
{{#if basic.rank}}
<strong>{{ localize "CYPHERSYSTEM.Rank" }}</strong> {{ basic.rank }}
{{/if}}
{{#if basic.level}}
<strong>{{ localize "CYPHERSYSTEM.Level" }}</strong> {{ basic.level }}
{{/if}}
{{#if basic.tier}}
<strong>{{ localize "CYPHERSYSTEM.Tier" }}</strong> {{ basic.tier }}
{{/if}}
{{#if pools.health}}
<strong>{{ localize "CYPHERSYSTEM.Health" }}</strong> {{ pools.health.value }}/{{ pools.health.max}}
{{/if}}
{{#if pools.infrastructure}}
<strong>{{ localize "CYPHERSYSTEM.Infrastructure" }}</strong> {{ pools.infrastructure.value }}/{{ pools.infrastructure.max}}
{{/if}}
{{#if pools.might}}
<strong>{{ localize "CYPHERSYSTEM.Might" }}</strong> {{ pools.might.value }}/{{ pools.might.max}}
{{/if}}
{{#if pools.speed}}
<strong>{{ localize "CYPHERSYSTEM.Speed" }}</strong> {{ pools.speed.value }}/{{ pools.speed.max}}
{{/if}}
{{#if pools.intellect}}
<strong>{{ localize "CYPHERSYSTEM.Intellect" }}</strong> {{ pools.intellect.value }}/{{ pools.intellect.max}}
{{/if}}
{{/if}}
View File