Skip to content

Commit

Permalink
Add a way for mods to register as NSFW
Browse files Browse the repository at this point in the history
  • Loading branch information
scrlys committed May 3, 2017
1 parent fdb02ce commit 172294c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
15 changes: 3 additions & 12 deletions modloader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,10 @@ def main():
# function, make a Mod class and apply the loadable_mod decorator
mod_object = importlib.import_module(mod)

# Put the mod into the registry if it doesn't already exist
# This is for legacy detection of the previous mod importation system
# Avoid using this as it might get removed in later commits
mods = modinfo.get_mods()
if not any(mods[key][4] == mod_object for key in mods):
info = (None, "", "", "", mod_object)
modinfo.add_mod(mod_object.__name__, info)

# After all mods are loaded, call their respective mod_complete functions
for mod_name, mod_data in modinfo.get_mods().iteritems():
if mod_data[0]:
print "Completing mod {}".format(mod_name)
mod_data[0].mod_complete()
for mod_name, mod in modinfo.get_mods().iteritems():
print "Completing mod {}".format(mod_name)
mod.mod_complete()

# Force renpy to reindex all game files
renpy.loader.old_config_archives = None
Expand Down
6 changes: 2 additions & 4 deletions modloader/modclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def mod_info(self):
"""Get the mod info
Returns:
A tuple with the name, version, and author
A tuple with the name, version, author, and (optionally) if the mod is NSFW
"""
raise NotImplementedError("Mod info isn't overriden")

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

mod = modclass()
mod_name, version, author = mod.mod_info()
mod.mod_load()

info = (mod, mod_name, version, author, sys.modules[modclass.__module__])
modinfo.add_mod(modclass.__module__, info)
modinfo.add_mod(mod.mod_info()[0], mod)
18 changes: 12 additions & 6 deletions mods/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,20 @@ def mod_load(self):

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

# Append the NSFW selection each game
# Credits to yoshisman8 for the code
toggler = modast.find_label("lewdtoggler")
bootup = modast.find_label("nameentry")
modast.call_hook(bootup, toggler)


def mod_complete(self):
# Insert an NSFW warning if any mods register as NSFW

for mod_name, mod in modinfo.get_mods().iteritems():
mod_info = mod.mod_info()
if len(mod_info) == 4 and mod_info[3]:
# Append the NSFW selection each game
# Credits to yoshisman8 for the code
toggler = modast.find_label("lewdtoggler")
bootup = modast.find_label("nameentry")
modast.call_hook(bootup, toggler)
break

# This is called after all mods are loaded, preventing us from getting a partial list of
# mods (say, if core was loaded before myMod1).
modast.set_renpy_global('modsDesc', ', '.join([mod_name for mod_name in modinfo.modlist]))

0 comments on commit 172294c

Please sign in to comment.