mjshi

Autopause At Punctuation

Jan 18th, 2017
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.49 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # Autopause At Punctuation v1.0
  3. #-- Automatically pauses your dialogue, briefly, at punctuation marks.
  4. #-- By mjshi
  5. #-------------------------------------------------------------------------------
  6. # Installation: Plug and play. Put above Main.
  7. #-------------------------------------------------------------------------------
  8. # You know, I bet your eyes paused for a moment at the comma in this sentence.
  9. # And I bet you paused, too (but longer) at that period in the sentence above.
  10. # What this script does is pause dialogue briefly at certain punctuation marks,
  11. # mimicking natural speech.
  12. #-------------------------------------------------------------------------------
  13. # Currently supported punctuation:
  14. # [Pauses for 1/4 second] , - :
  15. # [Pauses for 1/2 second] . ? ! ~ ... ;
  16. #-------------------------------------------------------------------------------
  17. # This script also pauses for 1/2 second whenever there is valid punctuation
  18. # followed by a " or ) or ' character.
  19. # For example: (this would pause.) "this too:" 'and this-' (this would not)
  20. # [Valid punctuation] , - : . ? ! ~ ;
  21. #-------------------------------------------------------------------------------
  22.  
  23. class Window_Base
  24.   alias _autopause_convert_escape_characters convert_escape_characters
  25.   def convert_escape_characters(text)
  26.    
  27.     #handle word chars
  28.     text.gsub!(/\. /, ".\\.\\. ")
  29.     text.gsub!(/\.\.\.\\\.\\\. /, "...\\.\\. ")
  30.    
  31.     text.gsub!(/([.?!~;,-:])" /, "\\1\"\\.\\. ")
  32.     text.gsub!(/([.?!~;,-:])' /, "\\1'\\.\\. ")
  33.    text.gsub!(/([.?!~;,-:])\) /, "\\1)\\.\\. ")
  34.    text.gsub!(/- /, "-\\. ")
  35.    text.gsub!(/, /, ",\\. ")
  36.    text.gsub!(/: /, ":\\. ")
  37.    text.gsub!(/\? /, "?\\.\\. ")
  38.    text.gsub!(/! /, "!\\.\\. ")
  39.    text.gsub!(/; /, ";\\.\\. ")
  40.    text.gsub!(/~ /, "~\\.\\. ")
  41.    
  42.    #handle newlines
  43.    text.gsub!(/\.\n(?!$)/, ".\\.\\.\n")
  44.    text.gsub!(/\.\.\.\\\.\\\.\n(?!$)/, "...\\.\\.\n")
  45.    
  46.    text.gsub!(/([.?!~;,-:])"\n(?!$)/, "\\1\"\\.\\.\n")
  47.     text.gsub!(/([.?!~;,-:])'\n(?!$)/, "\\1'\\.\\.\n")
  48.    text.gsub!(/([.?!~;,-:])\)\n(?!$)/, "\\1)\\.\\.\n")
  49.    text.gsub!(/-\n(?!$)/, "-\\.\n")
  50.    text.gsub!(/,\n(?!$)/, ",\\.\n")
  51.    text.gsub!(/:\n(?!$)/, ":\\.\n")
  52.    text.gsub!(/\?\n(?!$)/, "?\\.\\.\n")
  53.    text.gsub!(/!\n(?!$)/, "!\\.\\.\n")
  54.    text.gsub!(/;\n(?!$)/, ";\\.\\.\n")
  55.    text.gsub!(/~\n(?!$)/, "~\\.\\.\n")
  56.    
  57.    _autopause_convert_escape_characters(text)
  58.  end
  59. end
Add Comment
Please, Sign In to add comment