fungus / random_notes.txt

The default branch has multiple heads

Random notes for later usage
============================

Story
-----

### Intro

"""Wo wir gerade dabei sind: Was glaubst du hat der Infizierte gesagt? 

Ach, halt die Klappe. Ich glaube gar nichts. """


"""That mutant was awful! 

He wasn't a mutant. He was an infested. 

Whatever. I don't know how you can be relaxed, after he almost smashed your arm. 

Just get us back to the bunker before sunset."""


Code
----

### A talk function with scrolling text. 

## TODO: Change to always keep a char name at the top (or "" when telling background information or similar). 

def talk(dt, letters, target=None, talking_speed=6.0): 
  """Return a text incrementally.
  
Example: 
    Ras
  That mutant was awful!

  """
  text = """That mutant was awful! 

He wasn't a mutant. He was an infested. 

Whatever. I don't know how you can be relaxed, after he almost smashed your arm. 

Just get us back to the bunker before sunset."""
  letters["to print"] = letters["printed"]
  # If we didn't stop updating for one step, increase the number of letters to show for one round. 
  if not letters.get("skip update", 0): 
    letters["to print"] += dt*talking_speed
  letters["skip update"] = False
  output = None
  
  # TODO: Check with cocos, if there's a way to have a scrolling
  # textbox, else implement one myself: 
  # Linebreaks have a fixed value of letters, 
  # if the letters before the linebreak are greater than that, 
  # the linebreaks count at least doubled. 
  # The value of a linebreak is exactly one full line. 
  # When 3 lines are full, begin anew (so there's some empty space 
  # for resting the eyes), but don't break off words. 
  
  max_lines = 3
  max_letters_per_line = 42
  
  # Check how many letters we want to get written. 
  
  #: The text we want to show right now. 
  text_to_show = text[letters.get("hidden", 0):int(letters["to print"])] 
  
  #: The lines in the text. 
  text_list = text_to_show.split("\n")
  # Don't show empty first lines. 
  if len(text_list) > 1: 
      while not text_list[0]: 
          text_list = text_list[1:]
          # If the list is empty now, stop here. 
          letters["hidden"] = letters.get("hidden", 0) + 1
          if not text_list: 
              break
  
  # The number of lines is just the length of the list 
  # plus 1 for each line which is bigger than max_letters_per_line
  # More exact: plus 1 for each times the line is bigger than max. 
  # Mind the floor substraction, here. 
  #: The number of lines in the text to show. 
  lines = len(text_list) + sum([len(i) / max_letters_per_line for i in text_list])
  
  # We can only display max_lines, so we need to cut off all lines before max lines. 
  # But we need to make sure, that we display at least one line :) 
  if lines <= max_lines: 
      # The output isn't filled, yet. 
      text = "\n".join(text_list)
  elif lines > max_lines: 
      # If it's too much, we don't show it and will hide it next update. 
      # Reason: This way, the users have one more step to see the text. 
      text = "\n".join(text_list[:-1])
      # increase number of hidden letters by all now hidden letters. Plus 1 linebreak for each hidden item in the list. 
      for i in text_list[:-1]: 
          letters["hidden"] = letters.get("hidden", 0) + len(i) +1 
      
      # Also skip the next text output increasing update, so the next text starts with the same speed as the current. 
      # The effect of this depends on the update speed. 
      # When the system is fast enough, it almost shouldn't show itself. 
      # When the system is too slow, it avoids showing the last letters for only one frame. 
      letters["skip update"] = True
      
      # Plus 1 linebreak for each hidden item in the list. 
      # letters["hidden"] = letters.get("hidden", 0) + len(text_list) -2

  
  # Store how many letters we already printed. 
  letters["printed"] = letters["to print"]
  
  output = text
  
  #text_list = text[:int(letters["printed"])].split("\n")
  #if "\n" in text[:int(letters["printed"])]: 
      #output = text_list[-1][:int(letters["printed"]) - len("\n".join(text_list[:-1]))]
  #else: 
      #output = text[:int(letters["printed"])]
  #if output is None: 
    #output = text_list[-1]
      
  if target is None: 
    return output
  else: 
    target.text = output
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.