summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-11-18 18:21:32 +0100
committermetamuffin <metamuffin@disroot.org>2024-11-18 18:22:17 +0100
commit9d9d4fa85f17c783c7460f61236e3e9e34f6411e (patch)
treef9eb2c15d30495cf4beaf72b105c1c78ce0baece
parentb1abfaff30c50493befc7947980626557c857c8e (diff)
downloadhurrycurry-9d9d4fa85f17c783c7460f61236e3e9e34f6411e.tar
hurrycurry-9d9d4fa85f17c783c7460f61236e3e9e34f6411e.tar.bz2
hurrycurry-9d9d4fa85f17c783c7460f61236e3e9e34f6411e.tar.zst
conditional document elements
-rw-r--r--book/book.js27
-rw-r--r--book/book.typ6
-rw-r--r--book/locale/en.ini2
-rw-r--r--server/protocol/src/lib.rs6
-rw-r--r--test-client/protocol.ts11
5 files changed, 38 insertions, 14 deletions
diff --git a/book/book.js b/book/book.js
index 094068c0..00c83426 100644
--- a/book/book.js
+++ b/book/book.js
@@ -40,17 +40,20 @@ const about = () => ({
t: "page", es: [
{ t: "text", s: tr("b.about"), color: "#000000", size: 30, font: "FreeSans" },
par("b.about.name"),
- { t: "text", s: tr("b.about.image_attrib"), color: "#000000", size: 20, font: "FreeSans" },
+ { t: "conditional", cond: "image_attribution", value: true, e: { t: "text", s: tr("b.about.image_attrib"), color: "#000000", size: 20, font: "FreeSans" } },
{
- t: "table", es: [
- [par("b.about.image_attrib.name", false, true), par("b.about.image_attrib.author", false, true)],
- [par("b.nigiri"), par_raw(plain("Ahtziri Lagarde(unsplash)"))],
- [par("b.icecream"), par_raw(plain("Markus Spiske(unsplash), adapted"))],
- [par("b.curry"), par_raw(plain("Andy Hay(unsplash), adapted"))],
- [par("b.mochi"), par_raw(plain("blackieshoot(unsplash)"))],
- [par("b.burger"), par_raw(plain("Pablo Merchán Montes(unsplash), adapted"))],
- [par("b.tomato_soup"), par_raw(plain("Julia Kicova(unsplash), adapted"))],
- ]
+ t: "conditional", cond: "image_attribution", value: true, e:
+ {
+ t: "table", es: [
+ [par("b.about.image_attrib.name", false, true), par("b.about.image_attrib.author", false, true)],
+ [par("b.nigiri"), par_raw(plain("Ahtziri Lagarde (unsplash)"))],
+ [par("b.icecream"), par_raw(plain("Markus Spiske (unsplash), adapted"))],
+ [par("b.curry"), par_raw(plain("Andy Hay (unsplash), adapted"))],
+ [par("b.mochi"), par_raw(plain("blackieshoot (unsplash)"))],
+ [par("b.burger"), par_raw(plain("Pablo Merchán Montes (unsplash), adapted"))],
+ [par("b.tomato_soup"), par_raw(plain("Julia Kicova (unsplash), adapted"))],
+ ]
+ }
}
]
})
@@ -58,9 +61,7 @@ const recipe = (n, i, th = false, extra = []) => ({
t: "page", background: n, es: [
h2(`b.${n}`, th),
par(`b.${n}.desc`, th),
- {
- t: "list", es: i.map(e => emph(`b.ingred.${e}`, th))
- },
+ { t: "list", es: i.map(e => emph(`b.ingred.${e}`, th)) },
par(`b.${n}.steps`, th),
...extra
]
diff --git a/book/book.typ b/book/book.typ
index 14e617a0..2dc7bdf5 100644
--- a/book/book.typ
+++ b/book/book.typ
@@ -5,6 +5,8 @@
#show list: set text(font: "Gluten", fill: rgb(46, 73, 0), size: 20pt)
#show heading.where(level: 2): set text(font: "Great Vibes", size: 40pt)
+#let document_flags = ("image_attribution",)
+
#let load_locale(name) = {
read("locale/"+name+".ini")
.split("\n")
@@ -51,6 +53,10 @@
#par(..elem.es.map(element))
] else if elem.t == "table" [
#table(columns: elem.es.at(0).len(), ..elem.es.flatten().map(element))
+ ] else if elem.t == "conditional" [
+ #if (elem.cond in document_flags) == elem.value [
+ #element(elem.e)
+ ]
] else [
#elem
]
diff --git a/book/locale/en.ini b/book/locale/en.ini
index 3933dc8a..303c6786 100644
--- a/book/locale/en.ini
+++ b/book/locale/en.ini
@@ -1,5 +1,7 @@
[hurrycurry]
b.about.image_attrib=Background image attribution
+b.about.image_attrib.name=Name
+b.about.image_attrib.author=Author
b.about.name=The Hurry Curry! recipe book.
b.about=About this book
b.bun.desc=The most saturating meal of them all. Best enjoyed with a tomato soup.
diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs
index dd773a3d..ca6e7c8c 100644
--- a/server/protocol/src/lib.rs
+++ b/server/protocol/src/lib.rs
@@ -381,4 +381,10 @@ pub enum DocumentElement {
#[serde(default)]
bold: bool,
},
+ /// Document part that is only shown conditionally. Used for image attribution
+ Conditional {
+ cond: String,
+ value: bool,
+ e: Box<DocumentElement>,
+ },
}
diff --git a/test-client/protocol.ts b/test-client/protocol.ts
index 8fa15c8d..55d2fc15 100644
--- a/test-client/protocol.ts
+++ b/test-client/protocol.ts
@@ -69,7 +69,7 @@ export type PacketC =
| { type: "set_ingame", state: boolean, lobby: boolean } // Set to false when entering the game or switching maps
export type Menu =
- { menu: "book" }
+ { menu: "document", data: DocumentElement }
| { menu: "score", data: Score }
export interface MessageTimeout {
@@ -101,3 +101,12 @@ export type ItemLocation =
| { tile: Vec2 }
export type PlayerClass = "chef" | "bot" | "customer"
+
+export type DocumentElement =
+ { t: "document", es: DocumentElement[] }
+ | { t: "page", background?: string, es: DocumentElement[] }
+ | { t: "list", es: DocumentElement[] }
+ | { t: "table", es: DocumentElement[][] }
+ | { t: "par", es: DocumentElement[] }
+ | { t: "text", s: Message, size: number, color?: string, font?: string, bold: boolean }
+ | { t: "conditional", cond: string, value: boolean, e: DocumentElement }