I was thinking about if it would be possible to allow styles to change as the game progresses. After thinking it over a bit, the answer is yes, with the caveat that this only would apply to displayables created after the style change occurs. The screen system makes this caveat acceptable, since the text and windows on the screen are recreated when an interaction is restarted.
Anyway, I'm thinking of an API like this.
Code: Select all
A style preference is a preference that controls one or more style properties. A style preference has a name and one or more alternatives. At any given time, one of the alternatives is the selected for the style preference. The selected alternative is stored in the persistent data, and defaults to the first alternative registered for a style property.
An alternative has one or more associations of style, property, and value associated with it, and represents a promise that when the alternative becomes the selected alternative for the style preference, the property on the style will be assigned the given value. This occurs when Ren'Py first initializes, and then whenever a new alternative is selected.
renpy.register_style_preference(preference, alternative, style, property, value):
Registers information about an alternative for a style preference.
`preference`
A string, the name of the style property.
`alternative`
A string, the name of the alternative.
`style`
The style that will be updated. This may be a style object or a string giving the style name.
`property`
A string giving the name of the style property that will be update.
`value`
The value that will be assigned to the style property.
renpy.set_style_preference(preference, alternative):
Sets the selected alternative for the style preference.
`preference`
A string giving the name of the style preference.
`alternative`
A string giving the name of the alternative.
renpy.get_style_preference(preference):
Returns a string giving the name of the selected alternative for the named style preference.
`preference`
A string giving the name of the style preference.
StylePreference(preference, alternative):
An action that causes `alternative` to become the selected alternative for the given style preference.
`preference`
A string giving the name of the style preference.
`alternative`
A string giving the name of the alternative.
One should ensure that every alternative for a given style preference updates the same set of styles and properties. Otherwise, some styles may not be assigned values, and the result will not be deterministic.
Here's an example of registering a style property that allows the user to choose between large, simple text and smaller outlined text.
::
init python:
renpy.register_style_property("text", "decorated", style.say_dialogue, "outlines", [ (1, "#000", 0, 0) ])
renpy.register_style_property("text", "decorated", style.say_dialogue, "size", 22)
renpy.register_style_property("text", "large", style.say_dialogue, "outlines", [ ])
renpy.register_style_property("text", "large", style.say_dialogue, "size", 24)