Skip to content

Commit 53745b7

Browse files
AWSWCommunityAWSWCommunity
authored andcommitted
Convert core mod to the new format
1 parent a156dfa commit 53745b7

File tree

3 files changed

+48
-45
lines changed

3 files changed

+48
-45
lines changed

modloader/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get_mod_path():
3030
try:
3131
importlib.import_module(mod)
3232
except Exception, e:
33-
print("Oh no in {}".format(mod))
33+
print("Exception while loading: {}".format(mod))
3434
print(e)
3535
raise e # Raise it again even though the stacktrace provides nothing useful
3636

modloader/modclass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def mod_info(self):
1818
def mod_load(self):
1919
"""Executes when a mod is loaded
2020
21-
This is where you put special renpy code
21+
This is where you put patcher code
2222
Other mods may not be fully loaded yet. If you want this functionality, see mod_complete
2323
"""
2424
pass

mods/core/mod.py

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
1-
import modlib
1+
from modloader import modlib
22
import renpy
33
import renpy.parser as parser
44
import renpy.ast as ast
5-
import modinfo
5+
from modloader import modinfo
66
from modlib import sprnt
7-
8-
9-
ml = modlib.base
10-
11-
# This is called due to renpy's screen cache. Any modifications to screens with an enabled cache will fail!
12-
ml.DisableSCache()
13-
14-
# This is called after all mods are loaded, preventing us from getting a partial list of mods (say, if core was loaded before myMod1).
15-
# Rpy python globals are stored in renpy.python.store_dicts["store"], so to access our data from the screen later, we need to put it in this dictionary.
16-
def mod_init():
17-
ml.setRGlobal('modsDesc', ', '.join(modinfo.modlist))
18-
19-
# Hook every point where the chapter is changed and set mod_currentChapter to the integer value of the current chapter. This will allow route mods to make comparisons.
20-
h = ml.getHomeHook()
21-
h.hookChapter1(ml.findlabel("_core_updateChapter"))
22-
23-
24-
stmt = ml.findPyStatement('chapter2unplayed = False')
25-
ml.call_hook(stmt, ml.findlabel("_core_updateChapter"))
26-
stmt = ml.findPyStatement('chapter3unplayed = False')
27-
ml.call_hook(stmt, ml.findlabel("_core_updateChapter"))
28-
stmt = ml.findPyStatement('chapter4unplayed = False')
29-
ml.call_hook(stmt, ml.findlabel("_core_updateChapter"))
30-
31-
32-
# How to abuse the ren'py parser for your own personal gain!
33-
targetDisp = None
34-
35-
tocompile = """
36-
screen dummy:
37-
imagebutton auto "ui/mods_%s.png" action [Show("preferencesbg"), Show('modmenu'), Play("audio", "se/sounds/open.wav")] hovered Play("audio", "se/sounds/select.ogg") xalign 0.03 yalign 0.955
38-
"""
39-
rv = parser.parse("FNDummy", tocompile)
40-
targetDisp = None
41-
for e in rv:
42-
#sprnt(type(e).__name__)
43-
if isinstance(e, ast.Init):
44-
for b in e.block[0].screen.children:
45-
targetDisp = b
46-
47-
ml.getsls('main_menu').children.append(targetDisp)
7+
from modlib import base as ml
8+
from modloader.modclass import Mod, loadable_mod
9+
10+
@loadable_mod
11+
class AWSWMod(Mod):
12+
def mod_info(self):
13+
return ("Core", "v0.1", "")
14+
15+
def mod_load(self):
16+
# This is called due to renpy's screen cache. Any modifications to screens with an enabled cache will fail!
17+
ml.DisableSCache()
18+
19+
# Hook every point where the chapter is changed and set mod_currentChapter to the integer value of the current chapter. This will allow route mods to make comparisons.
20+
h = ml.getHomeHook()
21+
h.hookChapter1(ml.findlabel("_core_updateChapter"))
22+
23+
stmt = ml.findPyStatement('chapter2unplayed = False')
24+
ml.call_hook(stmt, ml.findlabel("_core_updateChapter"))
25+
stmt = ml.findPyStatement('chapter3unplayed = False')
26+
ml.call_hook(stmt, ml.findlabel("_core_updateChapter"))
27+
stmt = ml.findPyStatement('chapter4unplayed = False')
28+
ml.call_hook(stmt, ml.findlabel("_core_updateChapter"))
29+
30+
# How to abuse the ren'py parser for your own personal gain!
31+
targetDisp = None
32+
33+
tocompile = """
34+
screen dummy:
35+
imagebutton auto "ui/mods_%s.png" action [Show("preferencesbg"), Show('modmenu'), Play("audio", "se/sounds/open.wav")] hovered Play("audio", "se/sounds/select.ogg") xalign 0.03 yalign 0.955
36+
"""
37+
rv = parser.parse("FNDummy", tocompile)
38+
targetDisp = None
39+
for e in rv:
40+
#sprnt(type(e).__name__)
41+
if isinstance(e, ast.Init):
42+
for b in e.block[0].screen.children:
43+
targetDisp = b
44+
45+
ml.getsls('main_menu').children.append(targetDisp)
46+
47+
def mod_complete(self):
48+
# This is called after all mods are loaded, preventing us from getting a partial list of mods (say, if core was loaded before myMod1).
49+
# Rpy python globals are stored in renpy.python.store_dicts["store"], so to access our data from the screen later, we need to put it in this dictionary.
50+
ml.setRGlobal('modsDesc', ', '.join(modinfo.modlist))

0 commit comments

Comments
 (0)