Background Description Function for npckc's Caption Tool
Tags: posts, tutorial, accessibility, renpy,
I really like npckc's caption tool for sound and images. But I got sick of having to copy and paste the background description every time a background showed up, so made a function to do it for me.
This tutorial is pretty sparse, I'm assuming you already understand the original tool and have a moderate grasp of Renpy. I also didn't double check that all the variant code actually runs, so apologies in advance for any bugs.
Dependencies from the Caption Tool
This code is heavily inspired by various techniques in the caption tool, and will be more useful if you use the splash-screen and menu edits. But it only directly relies on two lines:default persistent.image_captions = False
which defines a persistent variable setting whether image descriptions are shown or not, and:
define ic = Character(_(None),condition="persistent.image_captions or _preferences.self_voicing")
which defines a character to say image descriptions if image captions or self-voicing is on.
Simple background description code
init python: # This is the text at the start of each background description. backgroundtext = _("Background: ") #list of background descriptions background_list = { # "room_name": _("Room short description"), "mcroom": _("MC's room."), "kitchen": _("MC's kitchen."), } # Displays image description for the background described by background_name def desc_background(background_name): description = backgroundtext + background_list[background_name] ic(description)
This is used like so within the script:
scene bg mcroom desc_background("mcroom")
which would display the "bg mcroom" background (as defined the usual way elsewhere) and show the text "Background: MC's room."
I didn't include the background itself inside the function since my background image usage has a lot of variety with variants, adding sprites and then using fade etc. But if you do want to show it, use renpy.scene().
Detailed background description code
init python: # This is the text at the start of each background description. backgroundtext = _("Background: ") #list of background descriptions background_list = { # "room_name": _("Room short description"), "mcroom": _("MC's room."), "kitchen": _("MC's kitchen."), } #list of detailed background descriptions for the first time a room is shown detailed_background_list = { # "room_name": _("Room extra details"), "mcroom": _("It is fairly empty with a few gothy decorative choices, as well as a laptop on the desk with some cup noodles."), } # Displays image description for a background described by background_name # If detail = True, add any extra details def desc_background(background_name, detail=False): description = backgroundtext + background_list[background_name] if detail and (bword in detailed_background_list.keys()): #add extra details description+=" "+detailed_background_list[bword] ic(description)
The first time mcroom is called within the script:
scene bg mcroom day desc_background("mcroom",True)
which would would display the "bg mcroom" background and the text "Background: MC's room. It is fairly empty with a few gothy decorative choices, as well as a laptop on the desk with some cup noodles."
Then later you'd just use
scene bg mcroom day desc_background("mcroom")
to get the shorter text "Background: MC's room."
desc_background("kitchen", True) and desc_background("kitchen") would both display the text "Background: MC's kitchen." since no detailed description has been added for the kitchen yet. But one can be added to detailed_background_list later, and then desc_background("kitchen", True) will display it.
Variant Backgrounds
This is kind of specific to how I name and use backgrounds: I have a lot of backgrounds of the form "bg [background name] [time of day]" eg "bg mcroom day". I don't want to write a full separate description for each variant, but do want to be able to quickly note the variant in the description. Everything is the same except the desc_background function.
# Displays image description for a background described by the first word in background_name # If detail = True, add any extra details # Any text after the first word in background_name is added as an extra sentence def desc_background(background_name, detail=False): split_string = background_name.split() #divides string up by whitespace bword = split_string[0] #the first word in background_name description = backgroundtext if len(split_string)>1: #add the rest of background_name as a sentence description += background_name[(len(bword)+1):].capitalize()+". " description += background_list[bword] if detail and (bword in detailed_background_list.keys()): #add extra details description+=" "+detailed_background_list[bword] ic(description)
This is used like so within the script:
scene bg mcroom day desc_background("mcroom day")
which would display the "bg mcroom" background and show the text "Background: Day. MC's room."