Advertisement
Guest User

Untitled

a guest
Aug 11th, 2018
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.05 KB | None | 0 0
  1. init python:
  2.  
  3.     # This is set to the name of the character that is speaking, or
  4.     # None if no character is currently speaking.
  5.     speaking = None
  6.  
  7.     # If True, then all characters will be mute, i. e. their mouths
  8.     # will be closed.
  9.     mute = False
  10.  
  11.     # This is called by Ren'Py with the arguments passed to a say
  12.     # statement.
  13.     #
  14.     # We use this callback to remember the value of the "mute"
  15.     # argument (if any) that was passed to the last say statement.
  16.     def say_arg_cb(who, *args, **kwargs):
  17.         global mute
  18.  
  19.         # NB: Seems like the Ren'Py language uses unicode for keyword
  20.         #     argument names...
  21.         mute = kwargs.get(u"mute")
  22.  
  23.         return args, kwargs
  24.  
  25.     # This makes Ren'Py actually call our callback.
  26.     config.say_arguments_callback = say_arg_cb
  27.  
  28.     # This returns speaking if the character is speaking, and done if the
  29.     # character is not.
  30.     def while_speaking(name, speak_d, done_d, st, at):
  31.         if speaking == name:
  32.             return speak_d, .1
  33.         else:
  34.             return done_d, None
  35.  
  36.     # Curried form of the above.
  37.     curried_while_speaking = renpy.curry(while_speaking)
  38.  
  39.     # Displays speaking when the named character is speaking, and done otherwise.
  40.     def WhileSpeaking(name, speaking_d, done_d=Null()):
  41.         return DynamicDisplayable(curried_while_speaking(name, speaking_d, done_d))
  42.  
  43.     # This callback maintains the speaking variable.
  44.     def speaker_callback(name, event, **kwargs):
  45.         global speaking
  46.  
  47.         if event == "show":
  48.             if mute:
  49.                 # If the say statement has a "truthy" mute attribute (e. g. mute=1),
  50.                 # then we do not make the character's mouth move: We keep it closed.
  51.                 speaking = None
  52.             else:              
  53.                 speaking = name
  54.         elif event == "slow_done":
  55.             speaking = None
  56.         elif event == "end":
  57.             speaking = None
  58.  
  59.     # Curried form of the same.
  60.     speaker = renpy.curry(speaker_callback)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement