Skip to content

Commit 701bf22

Browse files
AWSWCommunityAWSWCommunity
authored andcommitted
Update sample code
1 parent 504b4d1 commit 701bf22

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

README.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ MyMod
122122
|-- myBackground.png
123123
```
124124

125-
Any *.rpy file is optional, and will be loaded automatically. The main mod file is mandatory for your mod to be loaded, and **must** be named ```__init__.py```. Every mod should start with ```from modloader.modlib import base as ml```. This will include all the utilities needed to get started. Using ```modlib``` is as simple as calling functions on ```ml```. The ```resource``` folder is optional as well. Files in this folder will be loaded into that game as if they were local to the game/ folder or the root of the archive. Should a file have the same name and location as one in the original game, the mod file will override the original.
125+
Any \*.rpy file is optional, and will be loaded automatically. The main mod file is mandatory for your mod to be loaded, and **must** be named ```__init__.py```. Every mod should start with ```from modloader.modlib import base as ml```. This will include all the utilities needed to get started. Using ```modlib``` is as simple as calling functions on ```ml```. The ```resource``` folder is optional as well. Files in this folder will be loaded into that game as if they were local to the game/ folder or the root of the archive. Should a file have the same name and location as one in the original game, the mod file will override the original.
126126

127127
To get full functionality from the modloader, it is recommended that you inherit from the modclass.Mod class. This will give you access to hooks at various stages during mod loading, and properly inform the user of your mod's status. To do this, include ```from modloader.modclass import Mod, loadable_mod``` at the top of your mod file. Define a class with a decorator as shown below:
128128
```python
@@ -149,18 +149,36 @@ The AWSW mod tools do not modify any of the core game files. They will survive a
149149
This sample code will remove Kevin's encounter and main menu icon. The full mod structure can be found in mods/.
150150

151151
```python
152-
import modlib
153152
import renpy
154153
import renpy.ast as ast
155-
ml = modlib.base
154+
from modloader import modinfo
155+
from modloader.modlib import sprnt
156+
from modloader.modlib import base as ml # ml shortcut
157+
from modloader.modclass import Mod, loadable_mod # Import the base class and the decorator
156158

157-
found = ml.searchPostNode(ml.findlabel("c4hatchery"), ast.Scene, 20) # search max of 20 nodes after c4hatchery label, look for the first scene initialization (which happens to be one opcode away, for now)
158-
hook = ml.hook_opcode(found, None) # insert a hooking node after scene, but before the narrator's say statement
159-
hook.chain(ml.searchPostNode(found, ast.Scene)) # normally the hooking node would point back to the dialogue. Skip all the way to the next scene instead.
159+
@loadable_mod
160+
class AWSWMod(Mod):
161+
def mod_info(self):
162+
return ("byekevin", "v0.1", "")
163+
164+
def mod_load(self):
165+
found = ml.searchPostNode(ml.findlabel("c4hatchery"), ast.Scene, 20) # search max of 20 nodes after c4hatchery label, look for the first scene initialization (which happens to be one opcode away, for now)
166+
hook = ml.hook_opcode(found, None) # insert a hooking node after scene, but before the narrator's say statement
167+
hook.chain(ml.searchPostNode(found, ast.Scene)) # normally the hooking node would point back to the dialogue. Skip all the way to the next scene instead.
160168

161-
mainscr = ml.getsls('main_menu') # get the main screen (cache is disabled)
162-
ml.nullPyexpr(mainscr, 'persistent.playedkevin') # remove the if block
163-
```
169+
mainscr = ml.getsls('main_menu') # get the main screen (cache is disabled)
170+
ml.nullPyexpr(mainscr, 'persistent.playedkevin') # remove the if block
171+
172+
eHooks = ml.getEndingHooks()
173+
true_search = eHooks.getPostTrueEndingIzumiScene()
174+
175+
def kevinCB(node):
176+
if node.next is not None and isinstance(node.next, renpy.ast.Show) and node.next.imspec[0][0] == 'meetingkevin': # imspec is part of the image ID in show opcodes.
177+
return True
178+
179+
kevin_credits = ml.searchPostNodeCB(true_search, kevinCB, 800) # search for a node using the kevinCB callback.
180+
kevin_credits.chain(ml.searchPostNode(kevin_credits, ast.Scene)) # Show and with are separate instructions.
181+
164182

165183
See the mods/ and devmods/ folders for further sample code. devmods/ contains a few different examples with fully annotated code.
166184

0 commit comments

Comments
 (0)