Cypher actor @Embed #1

Merged
mike merged 3 commits from cypher_embed into main 2026-09-26 04:47:31 +00:00
4 changed files with 141 additions and 47 deletions
Showing only changes of commit dd98aa5e0e - Show all commits
+69 -2
View File
@@ -9,6 +9,17 @@ const TEMPLATE_FILES = ["actor.hbs", "actor-inline.hbs"];
const TEMPLATE_BASE = "embeds"; const TEMPLATE_BASE = "embeds";
const TEMPLATES = normalizeTemplatePaths(TEMPLATE_FILES, TEMPLATE_BASE); const TEMPLATES = normalizeTemplatePaths(TEMPLATE_FILES, TEMPLATE_BASE);
function csLocKey(name) {
return `CYPHERSYSTEM.${name[0].toUpperCase()}${name.slice(1)}`;
}
function enrich(text, options) {
return foundry.applications.ux.TextEditor.implementation.enrichHTML(
text,
options,
);
}
async function buildActorEmbedHTML(doc, content, config, options) { async function buildActorEmbedHTML(doc, content, config, options) {
// Types: community, pc, marker, npc, vehicle // Types: community, pc, marker, npc, vehicle
// LIMITED access can see Name and Description // LIMITED access can see Name and Description
@@ -51,8 +62,11 @@ async function buildActorEmbedHTML(doc, content, config, options) {
const context = { const context = {
config: { ...config }, config: { ...config },
actor: doc, actor: doc,
basic: doc.system.basic, actorName: config?.label ?? doc.name,
pools: doc.system.pools, sentence: doc.system.basic,
stats: [],
pools: [],
enriched: {},
options, options,
viewFullDocument: doc.testUserPermission( viewFullDocument: doc.testUserPermission(
game.user, game.user,
@@ -61,6 +75,59 @@ async function buildActorEmbedHTML(doc, content, config, options) {
icon, icon,
user: game.user, user: game.user,
}; };
for (const basic of ["rank", "level", "tier"]) {
const value = doc.system.basic?.[basic];
if (value !== undefined && value !== null) {
context.stats.push({
name: csLocKey(basic),
value,
});
}
}
if (!config.inline) {
context.enriched.notes = await enrich(doc.system.notes, options);
context.enriched.description = await enrich(
doc.system.description,
options,
);
if (doc.type === "pc") {
context.enriched.gmNotes = await enrich(doc.system.gmNotes, options);
}
}
for (const pool of [
"health",
"infrastructure",
"might",
"speed",
"intellect",
]) {
if (doc.system.pools?.[pool]) {
context.pools.push({
name: csLocKey(pool),
value: doc.system.pools[pool],
});
}
}
let armor = doc.system.combat?.armor;
if (armor !== undefined && armor !== null) {
const ratingTotal = armor?.ratingTotal;
if (ratingTotal !== undefined && ratingTotal != null) {
armor = ratingTotal;
}
context.stats.push({
name: csLocKey("armor"),
value: armor,
noInline: true,
});
}
let damage = doc.system.combat?.damage;
if (damage !== undefined && damage !== null) {
context.stats.push({
name: csLocKey("damage"),
value: damage,
noInline: true,
});
}
const template = config.inline const template = config.inline
? TEMPLATES["actor-inline.hbs"] ? TEMPLATES["actor-inline.hbs"]
: TEMPLATES["actor.hbs"]; : TEMPLATES["actor.hbs"];
+7 -16
View File
@@ -1,19 +1,7 @@
: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 { .mb-cypher2-embed.content-embed {
background: var(--mbcypher2-journal-embed-background); background: var(--table-header-bg-color);
border: 1px solid var(--mbcypher2-journal-embed-border-color); border: 1px solid var(--table-header-border-color);
border-radius: 2px; border-radius: 0.25em;
} }
span.mb-cypher2-embed.content-embed { span.mb-cypher2-embed.content-embed {
@@ -23,7 +11,10 @@ span.mb-cypher2-embed.content-embed {
word-break: break-all; word-break: break-all;
} }
div.mb-cypher2-embed {
padding: 0.25em;
}
figure.content-embed figcaption cite { figure.content-embed figcaption cite {
margin-left: 0.5em; margin-left: 0.5em;
} }
}
+11 -29
View File
@@ -1,32 +1,14 @@
<i class="{{icon}}"></i> <i class="{{icon}}"></i>
<strong>{{actor.name}}</strong> <strong>{{actorName}}</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 viewFullDocument}}
{{#if basic.rank}} {{#each stats}}
<strong>{{ localize "CYPHERSYSTEM.Rank" }}</strong> {{ basic.rank }} {{#unless noInline}}
{{/if}} <span><strong>{{ localize name }}</strong>: {{ value }}</span>
{{#if basic.level}} {{~#unless @last}},{{/unless}}
<strong>{{ localize "CYPHERSYSTEM.Level" }}</strong> {{ basic.level }} {{/unless}}
{{/if}} {{/each}}
{{#if basic.tier}} {{#each pools}}
<strong>{{ localize "CYPHERSYSTEM.Tier" }}</strong> {{ basic.tier }} <span><strong>{{ localize name }}</strong>: {{ value.value }}</span>
{{/if}} {{~#unless @last}},{{/unless}}
{{#if pools.health}} {{/each}}
<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}} {{/if}}
+54
View File
@@ -0,0 +1,54 @@
<section class="mb-cypher2-embed-header">
<h1>{{actorName}}</h1>
{{#if (eq actor.type "pc") }}
<div class="mb-cypher-embed-sentence">
<strong>{{ localize "CYPHERSYSTEM.IsA" }}</strong> {{ sentence.descriptor }} {{ sentence.type }}
<strong>{{ localize "CYPHERSYSTEM.Who" }}</strong> {{ sentence.focus }} {{ sentence.additionalSentence }}
</div>
{{/if}}
{{#if (and viewFullDocument (or stats pools))}}
<h2>Stats</h2>
{{#if stats}}
<div class="mb-cypher-embed-basic-combat">
{{#each stats}}
<span><strong>{{ localize name }}</strong>: {{ value }}</span>
{{~#unless @last}},{{/unless}}
{{/each}}
</div>
{{/if}}
{{#if pools}}
<div class="mb-cypher-embed-pools">
{{#each pools}}
<span class="mb-cypher-embed-pool">
<strong>{{ localize name }}</strong>:
<span>{{value.value}}/{{value.max}}</span>
{{~#if (eq actor.type "pc")}}
<span>({{ localize "CYPHERSYSTEM.Edge" }}: {{value.edge}})</span>
{{~/if~}}
{{~#unless @last}},{{/unless~}}
</span>
{{/each}}
</div>
{{/if}}
{{/if}}
</section>
<section class="mb-cypher2-embed-notes">
{{#if enriched.description}}
<details class="mb-cypher2-embed-detail" open name="mb-cypher2-embed-{{actor.uuid}}">
<summary><strong>Description</strong></summary>
{{{enriched.description}}}
</details>
{{/if}}
{{#if (and enriched.gmNotes user.isGM)}}
<details class="mb-cypher2-embed-detail" name="mb-cypher2-embed-{{actor.uuid}}">
<summary><strong>GM Notes</strong></summary>
{{{enriched.gmNotes}}}
</details>
{{/if}}
{{#if (and enriched.notes viewFullDocument)}}
<details class="mb-cypher2-embed-detail" name="mb-cypher2-embed-{{actor.uuid}}">
<summary><strong>Notes</strong></summary>
{{{enriched.notes}}}
</details>
{{/if}}
</section>