|
1 | | -import renpy |
| 1 | +"""This file is free software under the GPLv3 license.""" |
| 2 | + |
2 | 3 | import os |
3 | 4 | import sys |
4 | | -import modinfo |
5 | 5 | import importlib |
6 | | -import modinfo |
7 | | -import modclass |
| 6 | +import renpy |
| 7 | +from modloader import modinfo, modclass |
| 8 | + |
| 9 | +print 'AWSW Mod Loader Init' |
8 | 10 |
|
9 | | -print('AWSW Mod Loader Init') |
10 | 11 |
|
11 | 12 | def get_mod_path(): |
12 | 13 | """Get the mod path |
13 | 14 |
|
14 | 15 | Returns: |
15 | 16 | The full path to the mods folder |
16 | 17 | """ |
17 | | - #TODO: Use a path combining function |
18 | | - return renpy.config.gamedir + "/mods/" |
| 18 | + return os.path.join(renpy.config.gamedir, "mods") |
| 19 | + |
19 | 20 |
|
20 | 21 | def main(): |
21 | | - # By setting the import path to the mod folder, we can do something like `import mod` |
22 | | - # NOTE: To import files in the modloader/ folder, do `from modloader import ...` |
23 | | - # If we add the modloader to the path, the modlist would get reloaded again |
| 22 | + """Load the mods""" |
| 23 | + # By appending the mod folder to the import path we can do something like |
| 24 | + # `import test` to import the mod named test in the mod folder. |
24 | 25 | sys.path.append(get_mod_path()) |
| 26 | + # NOTE: To import files in the modloader/ folder, do |
| 27 | + # `from modloader import ...`. If we add the modloader to the path, |
| 28 | + # the modules would be reimported every time they are imported. |
| 29 | + # In most cases, that's fine, but when modinfo is reimported, we lose the |
| 30 | + # current list of mods. |
25 | 31 |
|
26 | 32 | for mod in os.listdir(get_mod_path()): |
27 | | - # Some mods require resources to be recognized by renpy. If a folder exists, force renpy to load it |
28 | | - resource_dir = get_mod_path() + mod + "/resource" |
| 33 | + # Some mods require resources to be recognized by renpy. |
| 34 | + # If a folder exists, force renpy to load it |
| 35 | + resource_dir = os.path.join(get_mod_path(), mod, 'resource') |
29 | 36 | if os.path.isdir(resource_dir): |
30 | 37 | renpy.config.searchpath.append(resource_dir) |
31 | 38 |
|
32 | | - # Try importing the mod. If all goes well, the mod is imported through the Mod class |
33 | | - print("Begin mod load: {}".format(mod)) |
| 39 | + print "Begin mod load: {}".format(mod) |
34 | 40 |
|
| 41 | + # Try importing the mod. |
| 42 | + # Note: This doesn't give my mod functionality. To give the mod |
| 43 | + # function, make a Mod class and apply the loadable_mod decorator |
35 | 44 | mod_object = importlib.import_module(mod) |
36 | 45 |
|
37 | | - # Run through registry to see if the mod implements loadable_mod in some way. |
38 | | - if not any(modinfo.get_mods()[key][4] == mod_object for key in modinfo.get_mods()): |
39 | | - modinfo.add_mod(mod_object.__name__, (None, "", "", "", mod_object)) |
| 46 | + # Put the mod into the registry if it doesn't already exist |
| 47 | + # This is for legacy detection of the previous mod importation system |
| 48 | + # Avoid using this as it might get removed in later commits |
| 49 | + mods = modinfo.get_mods() |
| 50 | + if not any(mods[key][4] == mod_object for key in mods): |
| 51 | + info = (None, "", "", "", mod_object) |
| 52 | + modinfo.add_mod(mod_object.__name__, info) |
40 | 53 |
|
41 | | - # After all ods are loaded, call their respective mod_complete functions |
| 54 | + # After all mods are loaded, call their respective mod_complete functions |
42 | 55 | for mod_name, mod_data in modinfo.get_mods().iteritems(): |
43 | 56 | if mod_data[0]: |
44 | | - print("Completing mod {}".format(mod_name)) |
| 57 | + print "Completing mod {}".format(mod_name) |
45 | 58 | mod_data[0].mod_complete() |
46 | 59 |
|
47 | | - # force renpy to reindex all game files |
| 60 | + # Force renpy to reindex all game files |
48 | 61 | renpy.loader.old_config_archives = None |
49 | 62 |
|
50 | | -# Ensure that we have a stable renpy environment. |
51 | | -# The documentation won't have a stable renpy.config.gamedir, but the game will |
| 63 | +# When we build the documentation, renpy.config.gamedir will not exist |
| 64 | +# However, when the game is ran, it will exist. We take abuse of that |
52 | 65 |
|
53 | 66 | try: |
54 | | - renpy.config.gamedir |
55 | | - building_documentation = False |
| 67 | + _ = renpy.config.gamedir |
| 68 | + BUILDING_DOCUMENTATION = False |
| 69 | +except AttributeError: |
| 70 | + BUILDING_DOCUMENTATION = True |
| 71 | + |
| 72 | +if not BUILDING_DOCUMENTATION: |
56 | 73 | main() |
57 | | -except: |
58 | | - building_documentation = True |
|
0 commit comments