Commits

Anonymous committed f7375a1

Fixed and polished text output.

  • Participants
  • Parent commits 60dd717
  • Branches avatarsay

Comments (0)

Files changed (3)

File branching_story.py

 
 So you start your journey
 back through the woods, 
-to the safe mundanity of your car. 
+to the safe mundanity of your car,
+but the way isn't clear anymore. 
 """)
 
 wood = [

File rpg_lib/anyrpg.py

         super(UserInteraction, self).__init__(*args, **kwds)
 	
         
-    def ask(self, question=None, *args, **kwds): 
+    def ask(self, question=None, localize = True, end_with_linebreak = True, *args, **kwds): 
         """Ask a question.
         
         Note: Not console based implementations will want to overwrite this. 
 	"""
         if question is not None: 
 	    sleep(0.01)
-            return raw_input(_(question) + " ")
+	    if localize: 
+		answer = raw_input(_(question) + " ")
+	    else: 
+		answer = raw_input(question + " ")
+	    
+	    if end_with_linebreak: 
+		# Add an empty line with autoscrolling to show that we're now at the next part. the user already provided input, so we don't need to ask for input again. 
+		self.diag("", localize=False, autoscroll=True, *args, **kwds)
+	    
+	    return answer
 
-    def split_diag(self, text, line_length = None, localize=True, autoscroll=False, line_beginning = "", *args, **kwds): 
+    def split_diag(self, text, line_length = None, localize=True, autoscroll=False, wait_for_input = False, line_beginning = "", *args, **kwds): 
 	"""Print a dialog in single lines split at word borders. 
 	
 	@param text: The text to output. 
 	# Print as many words as possible without breaking the max line width. 
 	for j in text.split(): 
 	    if len(line_beginning) + len(text_to_print) + len(j) >= line_length: 
-		self.diag(line_beginning + text_to_print, localize=localize, autoscroll=autoscroll, *args, **kwds)
+		self.diag(line_beginning + text_to_print, localize=localize, autoscroll=autoscroll, wait_for_input = False, *args, **kwds)
 		# If j > self.line_length -> split j and use only the remaining rest as default, printing all else directly. 
 		if len(line_beginning) + len(j) > self.line_length: 
 		    while j[self.line_length - len(line_beginning):]: 
-			self.diag(line_beginning + j[:self.line_length - len(line_beginning)], localize=localize, autoscroll=autoscroll, *args, **kwds)
+			self.diag(line_beginning + j[:self.line_length - len(line_beginning)], localize=localize, autoscroll=autoscroll, wait_for_input = False, *args, **kwds)
 			j = j[self.line_length - len(line_beginning):]
 		text_to_print = j
 	    else: 
 		else: 
 		    text_to_print = j
 	# Print the last line of this dialog. 
-	self.diag(line_beginning + text_to_print, localize=localize, autoscroll=autoscroll, *args, **kwds)
+	if text_to_print: 
+	    self.diag(line_beginning + text_to_print, localize=localize, autoscroll=autoscroll, wait_for_input = wait_for_input, *args, **kwds)
+	else: 
+	    # If the line is empty, print a really empty line. 
+	    self.diag(text_to_print, localize=localize, autoscroll=autoscroll, wait_for_input = wait_for_input, *args, **kwds)
     
-    def diag(self, data, localize=True, autoscroll=False, line_wait = None, char_wait = None, relative_speed = 1, end_with_linebreak = True, position_in_line = 0, *args, **kwds):
+    def diag(self, data, localize=True, autoscroll=False, line_wait = None, char_wait = None, relative_speed = 1, end_with_linebreak = True, wait_for_input = False, position_in_line = 0, *args, **kwds):
 	""" Print a dialog line. 
 	
 	@param line_wait: The time to wait at linebreaks before continuing with the text. 
 	    sys.stdout.write("\n")
             sys.stdout.flush()
 
+	if wait_for_input: 
+	    raw_input("")
+
+
 class Dialogs(object): 
     """Basic dialogs. 
     
         super(Char, self).__init__(template=template, *args, **kwds)
         self.battle_diff_treshold = 4 #: The treshold of the char below which no hit is scored. 
     
-    def say(self, data, autoscroll=True, *args, **kwds): 
+    def say(self, data, autoscroll=True, end_with_linebreak = True, indent = 2, localize = True, *args, **kwds): 
         """Say something -> Show that the char says it."""
-        data = _(data)
-        for i in data.split("\n"): 
-            self.split_diag(i, localize=False, autoscroll=autoscroll, line_beginning = self.name + ': ', *args, **kwds)
+	if localize: 
+	    data = _(data)
+	self.diag(self.name, localize=False, autoscroll=autoscroll, *args, **kwds)
+        for i in data.splitlines()[:-1]: 
+            self.split_diag(i, localize=False, autoscroll=autoscroll, line_beginning = ' ' * indent, *args, **kwds)
+	# Add the last line without autoscrolling to wait for the user to read the next part. 
+	self.split_diag(data.splitlines()[-1], localize=False, autoscroll=autoscroll, end_with_linebreak = False, wait_for_input = True,  line_beginning = ' ' * indent, *args, **kwds)
     
-    def ask(self, data, localize=False, *args, **kwds): 
-        """Say something -> Show that the char says it."""
-        data = _(data)
-        for i in data.split("\n")[:-1]: 
-            self.diag(self.name + ': ' + i, localize=localize, *args, **kwds)
-        return super(Char, self).ask(self.name + ': ' + data.split("\n")[-1], *args, **kwds)
+    def ask(self, data, localize=False, indent = 2, *args, **kwds): 
+        """Ask something -> Show that the char asks it."""
+	if localize: 
+	    data = _(data)
+	if len(data.splitlines()) > 1: 
+	    # First say the first part of the question. 
+	    self.say("\n".join(data.splitlines()[:-1]), localize=False, *args, **kwds)
+	# Then ask the last line
+        return super(Char, self).ask(' ' * indent + data.splitlines()[-1], localize = False, *args, **kwds)
     
     def act(self, data, *args, **kwds): 
         """Do something -> Show that the char does it in the style "<name> walks away.".
         """
         data = _(data)
         for i in data.split("\n"): 
-            self.diag(self.name + ' ' + i, localize=False, *args, **kwds)
+            self.split_diag(self.name + ' ' + i, localize=False, *args, **kwds)
         
     def compete_skill(self, other, skill_name, self_mods=[], other_mods=[]): 
         """Compete with the other char in the specified skill. 
         """Tell a part of the story."""
         if data is not None: 
             data = _(data)
-            for i in data.split("\n"): 
-                self.diag(i, localize=False, *args, **kwds)
+            self.split_diag(i, localize=False, *args, **kwds)
     
     def save(self, chars=[], *args, **kwds):
             """Save the current state."""

File simple_story.py

 avatarsay("size 3, 45")
 story("""Welcome to the world of easy RPG scripting. 
 
-I hope you enjoy your stay!""")
+I hope you enjoy your stay!
+""")
 
 # empty is sometimes needed, when you want to move in later
 avatarsay("empty")
 avatarsay("move in")
 avatarsay("size 6, 65")
 hero.say("""And welcome from me, too!
-
 I hope we'll be able to go adventuring, soon!
-
 besides: I'm Darjad Merejn.""")
 
 hero.name = "Darjad Merejn"
 
-hero.say("""So now you know my name. Would you tell me yours?""")
+name = hero.ask("""So now you know my name. 
+Would you tell me yours?""")
 
-avatarsay("avatarimage none")
-avatarsay("height 1")
-name = ask("Your name:")
+while not name: 
+    name = hero.ask("""Please tell me your name.""")
 
 player = Char(source="tag:1w6.org,2008:" + name)
 
 avatarsay("move in")
 avatarsay("size 3, 60")
 enemy.say("""How nice to see you. I hope you enjoy your glee. 
-
 It won't last too long.""")
 
 avatarsay("avatarimage hero")
 avatarsay("height 3")
 hero.say("""How dare you come here! 
-
 I'll splatter your guts, Granash Barn!""")
 
 enemy.name = "Granash Barn"
    hero.act("won.")
    avatarsay("avatarimage hero-angry")
    hero.say("""That's what they call villain these days. 
-
 So now to you. You look kinda sorry for him. 
-
 Seems I'll have to kill you, too.""")
 
    avatarsay("avatarimage none")
    enemy.act("won.")
    avatarsay("avatarimage bandit")
    enemy.say("""So much for heroes. 
-
 I hope you didn't stand with that bastard. I'm leaving. 
-
 Want to come with me?""")
 
    avatarsay("avatarimage none")
       enemy.say("""A wise decision. Now carry my bag.""")
    else: 
       enemy.say("""That's too bad. Good luck for your future. 
-
 And don't trust the heroes.
-
 Do you want to fight me, then?""")
 
 avatarsay("avatarimage none")