From 994e9121bd12dd848feb3d911df0e29458da3e6c Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Fri, 29 Mar 2024 23:04:54 +0100 Subject: [PATCH] Support interpolation in diary page titles --- game/scripts/interface/book.rpy | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/game/scripts/interface/book.rpy b/game/scripts/interface/book.rpy index 7e1fe57e..d016c24a 100644 --- a/game/scripts/interface/book.rpy +++ b/game/scripts/interface/book.rpy @@ -66,7 +66,7 @@ init python: `dictionary` is a dict containing two kinds of entries: - the first kind is to store the possible pages which can be added to the dict. These entries are the form {str page_id : (str|None page_title, str page_text)}. - `page_text` may contain interpolation fields, such as {code}. + `page_title` and `page_text` may contain interpolation fields, such as {code}. - the second kind is to store the for interpolation codes to fill in those blanks. These entries are of the form {str interpo_id : str interpo_text}. `interpo_text` is the text to be used for the interpolation. @@ -78,8 +78,8 @@ init python: """ super().__init__(*args, **kwargs) - self.dictionary_ = dictionary # str id : either (title, text) or text - self.entry_ids = set() # str id + self.dictionary_ = dictionary # type: dict[str, tuple[str|None, str]|str]|str + self.entry_ids = set() # set[str] @property def dictionary(self): @@ -97,7 +97,7 @@ init python: `branches` is a dict of {code : interpo_id} for every happened sub-event specializing the `id` event. The specified interpolation ids will be looked for in the dictionary, and the original entry of id `id` - will be formatted by replacing {code} with the text found in dictionary[interpo_id]. + will be formatted by replacing {code} with the page title and page text found in dictionary[interpo_id]. If `interpo_id` is not a valid entry in the dict, the passed value itself will be interpolated instead, or nothing if it is a false value (like None). @@ -106,8 +106,8 @@ init python: "Today I met Alice and did nothing. I liked it a lot." to the diary, with the title "Tittle". Passing c="" or c=None or c=False will all result in "Today I met Alice and did nothing. I liked it.". - If the page for the key `id` contains interpolation fields, it is a mistake - not to pass all interpolation fields. + If the page and title for the key `id` contain interpolation fields, it is a mistake + not to pass all interpolation fields as kwargs. It is benign to specify keys which are not interpolation fields in the entry : in the previous example, passing d=whatever will not change anything to the result. @@ -124,6 +124,8 @@ init python: if branches: branches = {k : dictionary.get(v, v or "") for k, v in branches.items()} page_text = page_text.format(**branches) + if page_title: + page_title = page_title.format(**branches) if day is None: day = game.day