Module Mod
[hide private]
[frames] | no frames]

Source Code for Module Mod

 1  ##################################################################### 
 2  # -*- coding: iso-8859-1 -*-                                        # 
 3  #                                                                   # 
 4  # Frets on Fire                                                     # 
 5  # Copyright (C) 2006 Sami Kyöstilä                                  # 
 6  #                                                                   # 
 7  # This program is free software; you can redistribute it and/or     # 
 8  # modify it under the terms of the GNU General Public License       # 
 9  # as published by the Free Software Foundation; either version 2    # 
10  # of the License, or (at your option) any later version.            # 
11  #                                                                   # 
12  # This program is distributed in the hope that it will be useful,   # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of    # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     # 
15  # GNU General Public License for more details.                      # 
16  #                                                                   # 
17  # You should have received a copy of the GNU General Public License # 
18  # along with this program; if not, write to the Free Software       # 
19  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,        # 
20  # MA  02110-1301, USA.                                              # 
21  ##################################################################### 
22   
23  import os 
24  import Config 
25  from Language import _ 
26   
27 -def _getModPath(engine):
28 return engine.resource.fileName("mods")
29
30 -def init(engine):
31 # define configuration keys for all available mods 32 for m in getAvailableMods(engine): 33 Config.define("mods", "mod_" + m, bool, False, text = m, options = {False: _("Off"), True: _("On")}) 34 35 # init all active mods 36 for m in getActiveMods(engine): 37 activateMod(engine, m)
38
39 -def getAvailableMods(engine):
40 modPath = _getModPath(engine) 41 return [m for m in os.listdir(modPath) if os.path.isdir(os.path.join(modPath, m)) and not m.startswith(".")]
42
43 -def getActiveMods(engine):
44 mods = [] 45 for mod in getAvailableMods(engine): 46 if engine.config.get("mods", "mod_" + mod): 47 mods.append(mod) 48 mods.sort() 49 return mods
50
51 -def activateMod(engine, modName):
52 modPath = _getModPath(engine) 53 m = os.path.join(modPath, modName) 54 if os.path.isdir(m): 55 engine.resource.addDataPath(m)
56
57 -def deactivateMod(engine, modName):
58 modPath = _getModPath(engine) 59 m = os.path.join(modPath, modName) 60 engine.resource.removeDataPath(m)
61