Custom defs are easy to add
FirstClass:
def method1(self):
print "Hi!"
def method2(self):
pass
SecondClass(FirstClass):
def method1(self):
print "I override Firstclass method1"
def method3(self):
print "I am a new method"
There are a couple of ways to use your script.
One method is to keep the same script name and store them in different folders:
Levels\Level1\level.py
Levels\Level2\level.py
Another method is some sort of conflig/ini file which is responsible for mapping what levels to load and what order to load them in.
Another method is using a campaign script which connects the levels together (same as above but uses code)
For my irc bot I use the first method described for loading plugins. Here is the code for that if you find it useful. I edited out some extraneous code so forgive me if it breaks. List of plugins to load is stored in a list and is is the folder name of that plugin.
import imp
import glob
def loadAllPlugins(self):
# Unloading anythign we have
self.plugins = {}
self.aliases ={}
for plugin_name in self.config['plugins']:
self.loadPlugin(plugin_name):
def loadPlugin(self, plugin_name):
try:
filepath, pathname, description = imp.find_module(plugin_name, plugins.__path__)
moduleSource = pathname +'/plugin.py'
moduleSource = moduleSource.replace ( '\\', '/' )
handle = open ( moduleSource )
module = imp.load_module ( plugin_name, handle, ( moduleSource ), ( '.py', 'r', imp.PY_SOURCE ) )
# This batch of code will be good for loading plugins in the user directory (which will happen after main ones)
#moduleSource = 'plugins/'+plugin_name+'/plugin.py'
#name = moduleSource.replace ( '.py', '' ).replace ( '\\', '/' ).split ( '/' ) [ 1 ]
# Populate the main database
self.plugins[plugin_name.lower()] = module
log.info("Plugin",plugin_name,"loaded.")
return reboot
except:
log.warning("I couldn't load",plugin_name + '. I placed a report in the errlog.txt file for you.')
To run a plugin I use: self.plugins[plugin_name].run_plugin(), which is a function in plugin.py. You will probably want to change this to match what you are doing like:
self.level = self.level[level_name].LevelClass()
Disclaimer This is probably way too complex and not well explained. It is just one way I used, there may be better