This script requires a little more input, but some people might find it useful nonetheless.
So, what does it do, and why should I bother?
If your game has a lot of characters, or you want to override specific methods for all characters, or the characters you have been defining are complex, you may wind up with lengthy/numerous defining statements and a lot of repeat code.
Let's try to make it a little more manageable.
Code: Select all
init python early:
stw = Character(None, color="#ffffff", font="font/Ubuntu-R.ttf", what_color = "#ffffff", show_two_window=True, what_font="font/Ubuntu-L.ttf")
chars = {
#Chapter 00
"koro": {"color": "#D00a"},
"anon": {"name": "???", "image": None, "color": "#006a"},
"lucas": {"color": "#096a"},
#Chapter 01
"sara": {"color": "#F69a"},
"lucia": {"color": "#C3Ca"},
"cec": {"name": "Cecilia", "image": "cecilia", "color": "#F69a"}
}
for key in chars:
if "name" not in chars[key]:
chars[key]["name"] = key.capitalize()
if "image" not in chars[key]:
chars[key]["image"] = key
character = Character(chars[key]["name"], image=chars[key]["image"], kind=stw, what_outlines=[(1,color(chars[key]["color"]),1,1)])
def f(what, k=character, outfit=None, pose=None, expression=None, **kwargs):
#renpy.transition(dissolve, layer="master") #example transition added to say method
k(what, **kwargs)
setattr(sys.modules[__name__], key, f)
First, we define a template character, stw. We define a bunch of default options for this character that will be inherited by any new characters.
Next, we create a dictionary of characters. Each character includes its own parameters. In the above example, the optional parameters are name and image. The only mandatory parameter I've added above is color.
Then the character dictionary is iterated, checking for optional parameters and overriding the defaults where necessary.
Each iteration defines a new character.
So, this may seem like more work, but with the basic code there, definitions like:
Code: Select all
define sara = Character("Sara", image="sara", color="#ffffff", font="font/Ubuntu-R.ttf", what_color = "#ffffff", show_two_window=True, what_font="font/Ubuntu-L.ttf", what_outlines=[(1,color("#F69a"),1,1)])
Code: Select all
"sara": {"color": "#F69a"}
If you want to go a step further, you can use this method to override character statements, be it selectively or completely.
For example, in the above script I've commented out the line:
Code: Select all
#renpy.transition(dissolve, layer="master") #example transition added to say method
In other words, if I ran:
Code: Select all
sara happy "This is a test."
sara confused "Or is it?"
sara happy "Oh, wait. It is."
Code: Select all
renpy.transition(dissolve, layer="master")
One or two "with dissolve" statements is no big deal, but if you wanted to dissolve between every expression, you'd save yourself a ton of "with dissolve" statements by including the line above just once.