ravenous_typst/setup/macros.typ

149 lines
3.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ----- Project theme -----
#import "variables.typ": theme, theme-var
#import "symbols.typ" as symbols
#import "limits.typ": hunbal
#import "@preview/glossarium:0.5.10": gls
// ----- The ubiquitous ddlvl macro -----
#let ddlvl(n, plus: false, max_number: 5) = {
let plus = if plus {
"+"
} else {
""
}
if n == 0 {
symbols.empty-star-box
} else if n < 0 {
[−#ddlvl(-n)]
} else if n > max_number {
[#plus#n#symbols.star-box]
} else {
plus + symbols.star-box * n
}
}
#let ddsmol(n, plus: false) = {
ddlvl(n, plus: plus, max_number: 4)
}
// ----- Generic repeating macro -----
//
// Examples:
// #repeat(3, [X]) -> XXX
// #repeat(3, [@ar_lvl]) -> @ar_lvl @ar_lvl @ar_lvl
// #repeat(-2, [X]) -> −XX
// #repeat(6, [X], max: 5) -> 6X
// #repeat(3, [X], plus: true) -> +XXX
//
#let repeat(
n,
term,
plus: false,
max-number: 5,
empty: none,
) = {
let prefix = if plus { "+" } else { "" }
if n == 0 {
empty
} else if n < 0 {
[−#repeat(-n, term, max-number: max-number)]
} else if n > max-number {
[#prefix#n#term]
} else {
prefix + term * n
}
}
#let toxlvl(lvl) = { repeat(lvl, symbols.tox-box, max-number: 3) }
#let winelvl(lvl) = { repeat(lvl, symbols.wine-box, max-number: 3) }
#let timelvl(lvl) = { repeat(lvl, symbols.time-box, max-number: 3) }
// ----- Difficulty level macro -----
#let difficulty-stars(difficulty, max: 5) = {
for i in range(max) {
if difficulty >= i + 1 {
text(size: 9pt, fill: theme.dark-gold)[
#theme-var("progress-full")
]
} else if difficulty >= i + 0.5 {
text(size: 9pt, fill: theme.dark-gold)[
#theme-var("progress-half")
]
} else {
text(size: 9pt, fill: theme.border)[
#theme-var("progress-void")
]
}
}
}
// ----- Resistance level -----
#let resist(n) = {
if n == 0 {
"( )"
} else if n < -4 {
"(" + str(-n) + [--] + ")"
} else if n < 0 {
"(" + [--] * -n + ")"
} else if n > 4 {
"(" + str(n) + "+)"
} else {
"(" + "+" * n + ")"
}
}
// ----- Create a styled reminder/information box -----
#let memo_box(title: "À retenir", content) = {
block(
fill: theme.parchment,
stroke: 0.8pt + theme.gold,
inset: 12pt,
radius: 3pt,
)[
#strong[#title]
#content
]
}
// ----- Inline help -----
#let inline_help(content) = {
emph[( #content )]
}
#let noop(..text) = { text }
#let mecaniquejeu(text) = { [ _ #text _ ] }
#let sW = box(
baseline: 12%,
inset: (top: -20%),
image("/images/icons/sword.svg", height: 0.9em),
)
#let sS = box(
baseline: 22%,
inset: (top: -20%),
image("/images/icons/shield.png", height: 1.0em),
)
#let sA = box(
baseline: 21%,
inset: (top: -20%),
image("/images/icons/armor.png", height: 1.1em),
)
#let bigscope = (
box: box,
image: image,
text: text,
sym: sym,
gls: gls,
ddlvl: ddsmol,
resist: resist,
inline_help: inline_help,
hunbal: hunbal,
footnote: footnote,
reference: noop,
mecaniquejeu: mecaniquejeu,
symbols: symbols,
)