Created
April 6, 2023 16:28
-
-
Save AEnMe/4f636db2bfdb06781a29818313167eb9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const note = dv.current(); | |
function checkEmpty(field) { | |
return field ? field : ""; | |
} | |
let wounds = checkEmpty(note.wounds); | |
let maxWounds = checkEmpty(note.max_wounds); | |
let health = note.health ? `(${note.health})` : "(-)"; | |
let maxHealth = note.max_health ? `(${note.max_health})` : "(-)"; | |
function healthViz() { | |
if (note.wounds == 0 && note.health == 0) return "Dead"; | |
return `${wounds}${health}_/${maxWounds}${maxHealth}_`; | |
} | |
function credits() { | |
let cred = note.credits; | |
if (!cred) return "0 CR"; | |
if (cred >= 1000) return cred / 1000 + " KCR"; | |
return cred + " CR"; | |
} | |
let characData = [ | |
{ label: "Status", value: checkEmpty(note.status) }, | |
{ label: "Pronouns", value: checkEmpty(note.pronouns) }, | |
{ label: "Alignment", value: checkEmpty(note.alignment) }, | |
{ label: "Credit", value: credits() }, | |
]; | |
let statsData = [ | |
{ label: "Health", value: healthViz() }, | |
{ label: "Speed", value: checkEmpty(note.speed) }, | |
{ label: "Instinct", value: checkEmpty(note.instinct) }, | |
{ label: "Combat", value: checkEmpty(note.combat) }, | |
{ label: "Armor Points", value: note.AP ? note.AP : 0 }, | |
{ label: "Loyalty", value: checkEmpty(note.loyalty) }, | |
]; | |
let generateTable = (data) => { | |
let rows = data | |
.map(({ label, value }) => { | |
if (value) { | |
return `| **${label}** | ${value} |\n`; | |
} else { | |
} | |
}) | |
.join(""); // Omit the "," in result | |
return ` | |
| | | | |
|---:|---| | |
${rows} | |
`; | |
}; | |
function title() { | |
let title = ""; | |
if (note.alias) { | |
title += note.alias[0]; | |
} else { | |
title += note.file.name; | |
} | |
let isDead = note.status && note.status.toLowerCase() === "dead" ? " 💀" : ""; | |
if (note.portrait) return `[${title}](${note.portrait})${isDead}`; | |
return title + isDead; | |
} | |
let faction = dv.pages() | |
.where( | |
p => p.file.outlinks.includes(note.file.link) | |
&& p.subject === "faction" | |
).file.link; | |
/* | |
let factionList = ""; | |
for(let i = 0; i < faction.length; i++){ | |
factionList +=`- ${faction[i]}\n`; | |
} | |
*/ | |
let occupation = ""; | |
occupation += note.class; | |
occupation += faction ? `, ${faction[0]}` : "" | |
let traits = note.traits; | |
function listing(input) { | |
let liste = ""; | |
for (let i = 0; i < input.length; i++) { | |
liste += `\n - ${input[i]}`; | |
} | |
return liste; | |
} | |
let gear = note.gear; | |
let gearListe = ""; | |
if (gear) { | |
for (let i = 0; i < gear.length; i++) { | |
gearListe += ">- " + gear[i] + "\n"; | |
} | |
} else { | |
} | |
// CONSTRUCTOR | |
dv.paragraph(` | |
~~~~col | |
~~~col-md | |
# ${title()} | |
${checkEmpty(occupation)} | |
${note.location ? "Currently in " + note.location : ""} | |
${traits ? listing(traits) : ""} | |
~~~ | |
~~~col-md | |
<span style="text-align: right; display: block"> ![|150](${ | |
note.portrait ? note.portrait : "" | |
}) </span> | |
~~~ | |
~~~~ | |
~~~~col | |
~~~col-md | |
> [!tip]+ Stats | |
>${generateTable(statsData)} | |
~~~ | |
~~~col-md | |
> [!quote]+ Characs | |
>${generateTable(characData)} | |
>[!tldr]- ${gear ? "Gear" : "No gear"} | |
${gearListe} | |
~~~ | |
~~~~ | |
`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment