Skip to content

Commit 172294c

Browse files
committed
Add a way for mods to register as NSFW
1 parent fdb02ce commit 172294c

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

modloader/__init__.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,10 @@ def main():
4343
# function, make a Mod class and apply the loadable_mod decorator
4444
mod_object = importlib.import_module(mod)
4545

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)
53-
5446
# After all mods are loaded, call their respective mod_complete functions
55-
for mod_name, mod_data in modinfo.get_mods().iteritems():
56-
if mod_data[0]:
57-
print "Completing mod {}".format(mod_name)
58-
mod_data[0].mod_complete()
47+
for mod_name, mod in modinfo.get_mods().iteritems():
48+
print "Completing mod {}".format(mod_name)
49+
mod.mod_complete()
5950

6051
# Force renpy to reindex all game files
6152
renpy.loader.old_config_archives = None

modloader/modclass.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def mod_info(self):
1414
"""Get the mod info
1515
1616
Returns:
17-
A tuple with the name, version, and author
17+
A tuple with the name, version, author, and (optionally) if the mod is NSFW
1818
"""
1919
raise NotImplementedError("Mod info isn't overriden")
2020

@@ -49,8 +49,6 @@ def loadable_mod(modclass):
4949
raise Exception("Class must be a subclass of Mod")
5050

5151
mod = modclass()
52-
mod_name, version, author = mod.mod_info()
5352
mod.mod_load()
5453

55-
info = (mod, mod_name, version, author, sys.modules[modclass.__module__])
56-
modinfo.add_mod(modclass.__module__, info)
54+
modinfo.add_mod(mod.mod_info()[0], mod)

mods/core/__init__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,20 @@ def mod_load(self):
5151

5252
modast.get_slscreen('main_menu').children.append(target_display)
5353

54-
# Append the NSFW selection each game
55-
# Credits to yoshisman8 for the code
56-
toggler = modast.find_label("lewdtoggler")
57-
bootup = modast.find_label("nameentry")
58-
modast.call_hook(bootup, toggler)
59-
6054

6155
def mod_complete(self):
56+
# Insert an NSFW warning if any mods register as NSFW
57+
58+
for mod_name, mod in modinfo.get_mods().iteritems():
59+
mod_info = mod.mod_info()
60+
if len(mod_info) == 4 and mod_info[3]:
61+
# Append the NSFW selection each game
62+
# Credits to yoshisman8 for the code
63+
toggler = modast.find_label("lewdtoggler")
64+
bootup = modast.find_label("nameentry")
65+
modast.call_hook(bootup, toggler)
66+
break
67+
6268
# This is called after all mods are loaded, preventing us from getting a partial list of
6369
# mods (say, if core was loaded before myMod1).
6470
modast.set_renpy_global('modsDesc', ', '.join([mod_name for mod_name in modinfo.modlist]))

0 commit comments

Comments
 (0)