Commits

Arne Babenhauserheide  committed 592ab7e

Raise Exception in anyrpg, if some HelperFunction gets used which isn't implemented in the specific module.

  • Participants
  • Parent commits c2d0702

Comments (0)

Files changed (2)

 
 This (and other) code can be found at U{http://freehg.org/ArneBab/textrpg}
 
+Doctests: 
+    >>> story_helper = Story()
+    >>> story_helper.story("The flow changes", autoscroll=True)
+    The flow changes
+    >>> story_helper.story("", autoscroll=True)
+    <BLANKLINE>
+
 """
 
 # Structure for the metadata inspired by Fufezan: 
 __version__   = '0.1' 
 
 from textrpg_1d6 import Char as ews_char
+from time import sleep # for autoscrolling
 
 
 ### Classes ###
         if data is not None: 
             data = _(data)
             for i in data.split("\n"): 
-                self.diag(i, localize=False)
+                self.diag(i, localize=False, *args, **kwds)
     
     def diag(self, data, localize=True, autoscroll=False, *args, **kwds):
         if localize: 
             return False
 
 
+class MissingScriptingFunction(Exception): 
+    """A warning to display if any necessary scripting function isn't implemented."""
+    def __init__(self, func, implementation = None): 
+        self.func = func
+        self.implementation = implementation
+        pass
+    def __str__(self): 
+        if self.implementation is None: 
+            return "The function " + str(self.func) + " must be implemented by every rpg scripting module to allow for easy changing of function behaviour."
+        else: 
+            return "The function " + str(self.func) + " must be implemented by every rpg scripting module to allow for easy changing of function behaviour." \
+                    + "\nThe simplest way is to just add the following lines to your script: " \
+                    + "\n\nstory_helper = Story()\n" \
+                    + self.implementation
+        
+    
+
 ### Functions ###
 
 def _(text):
     '''String function to allow localizing later on. '''
     return str(text)
 
+## Functions needed to be implemented in EVERY simple rpg scripting module (changing their effect for all places where they get used can only be done in the Story class) ###
+def ask(question, *args, **kwds): 
+    raise MissingScriptingFunction(ask, implementation = """def ask(question, *args, **kwds): 
+    return story_helper.ask(question, *args, **kwds)""")
+    
+def diag(text, localize=True, autoscroll=False, *args, **kwds): 
+    raise MissingScriptingFunction(ask, implementation = """def diag(text, localize=True, autoscroll=False, *args, **kwds): 
+    return story_helper.diag(text, localize=localize, autoscroll=autoscroll, *args, **kwds)""")
+
+def story(text=None, *args, **kwds): 
+    raise MissingScriptingFunction(ask, implementation = """def story(text=None, *args, **kwds): 
+    return story_helper.story(text, *args, **kwds)""")
+
+def give_exp(char, amount, *args, **kwds): 
+    raise MissingScriptingFunction(ask, implementation = """def give_exp(char, amount, *args, **kwds): 
+    return story_helper.give_exp(char, amount, *args, **kwds)""")
+
+def save(chars=[], *args, **kwds): 
+    raise MissingScriptingFunction(ask, implementation = """def save(chars=[], *args, **kwds): 
+    return story_helper.save(chars=chars, *args, **kwds)""")
+
+def battle(me, other, *args, **kwds): 
+    raise MissingScriptingFunction(ask, implementation = """def battle(me, other, *args, **kwds): 
+    return story_helper.battle(me, other, *args, **kwds)""")
 
 
 
 # AnyRPG classes
 from anyrpg import Char
 from anyrpg import Story as any_story
-# AnyRPG functions
+# AnyRPG function for localizing. 
 from anyrpg import _
 
 # Changing things. I want to display "..." in front of every blank story line.