Skip to content

Commit 504b4d1

Browse files
AWSWCommunityAWSWCommunity
authored andcommitted
Update devmods to new format
1 parent 5100568 commit 504b4d1

File tree

7 files changed

+124
-112
lines changed

7 files changed

+124
-112
lines changed

devmods/_dev_test/mod.py renamed to devmods/_dev_test/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
# This example allows for rapid development. It will populate the main menu with a button called 'dev test', which will jump directly to to 'jump_mainmenu_test' in Ren'py code.
22
# See the Start(...) block in the string below.
33

4-
5-
import modlib
6-
from modlib import sprnt
7-
import renpy.sl2.slast as slast
8-
import renpy.parser as parser
94
import renpy
105
import renpy.ast as ast
11-
import modinfo
6+
import renpy.sl2.slast as slast
7+
import renpy.parser as parser
128
import sys
9+
from modloader.modlib import base as ml
10+
from modloader.modlib import sprnt
1311

14-
ml = modlib.base
1512

1613
renpy.config.developer = True
1714

devmods/bryce_6thscene/__init__.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import renpy
2+
import renpy.ast as ast
3+
from modloader.modlib import base as ml
4+
from modloader.modlib import sprnt
5+
from modloader.modclass import loadable_mod, Mod
6+
7+
@loadable_mod
8+
class AWSWMod(Mod):
9+
def mod_info(self):
10+
return ("bryce_6thscene", "v0.1", "")
11+
12+
def mod_load(self):
13+
menuNode = ml.findMenu(["Accept.", "Reject.", "Scream."])[0] # Find a menu with the options in this list, grab the first result since we know there's only going to be one.
14+
bryce_menu = ml.getMenuHook(menuNode) #Initialize a menu hook for this menu.
15+
nodes = bryce_menu.getOptionCode("Accept.") # Get the list of nodes that are run when the user presses "Accept."
16+
17+
18+
# This is where modding gets tricky. There are many different ways to accomplish this, but this is the one I chose.
19+
# What we want is the instruction before the "return to apartment menu" if-case so we can hook it and pass execution to our code.
20+
# We accomplish that by searching for a pattern of instructions.
21+
hookNode = ml.searchPostNode(nodes[0], ast.Python) # Find the first python statement in the accept block. This corresponds to "$ mp.bryceromance = True" in the source code.
22+
23+
24+
# Search five statements ahead to get to the last python statement(the statement before the if block)
25+
# This is a 1:1 relation to the source code because each statement here does not consist of multiple nodes. "stop music" is one UserStatement node, so it works.
26+
# If we were dealing with Say instructions, each "say" in the source code corresponds to 3 opcodes in memory, because they are accompanied by StartTranslate and EndTranslate blocks. You would need to compensate for that.
27+
hookNode = ml.stepOp(hookNode, 5)
28+
29+
30+
# For debugging purposes, making sure my math was correct.
31+
# This will print out the class name of the found node for verification.
32+
#sprnt("Found Node" + type(hookNode).__name__)
33+
34+
# The actual hooking is done here once we've found the point in code we want to redirect.
35+
# We redirect hookNode to the bryce_sixthscene label we defined in our additive code.
36+
# A "return" statement in the additive code thereafter will return to hookNode+1 and resume normal execution.
37+
hook = ml.call_hook(hookNode, ml.findlabel("bryce_sixthscene"))

devmods/bryce_6thscene/mod.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

devmods/exampleroute/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from modloader.modlib import base as ml
2+
from modloader.modclass import Mod, loadable_mod
3+
4+
@loadable_mod
5+
class AWSWMod(Mod):
6+
def mod_info(self):
7+
return ("exampleroute", "v0.1", "")
8+
9+
def mod_load(self):
10+
home_hook = ml.getHomeHook()
11+
12+
# Here's how this works:
13+
# Calling addRoute will install a hook into every single instance* where the player can choose who to visit. "Test Route" is the title, and the ml.findlabel... code gets our entry point to the scene logic.
14+
# The third argument ("exampleroutestatus >=...") is evaluated as a python expression every time the menu pops up. If it returns true, the option shows, otherwise the option does not.
15+
# We check for exmapleroute_status >= 1, which will return true as long as we're in good standing for this route, AND exampleroute_lastplayed is less than mod_currentChapter
16+
# First: we can break the logic up into to discrete sections- "exampleroute_status >= 1", "exampleroute_lastplayed < mod_currentChapter". Due to the the AND operator, both must return true for the statement as a whole to return true.
17+
# If either in False, the menu option does not show.
18+
# Second: mod_currentChapter is a variable handled by the modloader. It will always be the integer value of the current chapter (Chapter 1: 1, Chapter 2: 2, etc)
19+
# *There are some unhandled menus at the moment, particularly when there are more than 7 options on the menu, causing the player to get [[Show more options]]. This will be fixed ASAP.
20+
home_hook.addRoute("Test Route", ml.findlabel("exampleroute_entrypoint"), "exampleroute_status >= 1 and exampleroute_lastplayed < mod_currentChapter")
21+
22+
23+
home_hook.hookChapter1(ml.findlabel("exampleroute_init")) # We need to set up our code at the beginning of every game.

devmods/exampleroute/mod.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

devmods/tests/__init__.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import renpy.ast as ast
2+
from modloader.modlib import base as ml
3+
from modloader.modlib import sprnt
4+
from modloader.modclass import Mod, loadable_mod
5+
6+
@loadable_mod
7+
class AWSWMod(Mod):
8+
def mod_info(self):
9+
return ("tests", "v0.1", "")
10+
11+
def mod_load(self):
12+
h = ml.getHomeHook()
13+
e = ml.getEndingHooks()
14+
15+
# These are my bootleg unit tests. They'll let you know whether something's gone wrong due to a code change.
16+
17+
h.addAnswerMachineScene(ml.findlabel("tests_2b"))
18+
19+
h.addAnswerMachineCheckHook(ml.findlabel("tests_1")) # Testing answering machine functionality
20+
h.addAnswerMachineScene(ml.findlabel("tests_2"))
21+
22+
h.addAnswerMachineCheckHook(ml.findlabel("tests_1b")) # Make sure additional hooks work as well
23+
24+
h.addAnswerMachineScene(ml.findlabel("tests_2c"))
25+
26+
hook = e.hookPostTrueEnding(ml.findlabel("tests_3")) # Check for post true ending functionality
27+
28+
h.hookChapterChange(ml.findlabel("tests_4")) # Chapter change testing
29+
30+
def hook_4b(hook, lab):
31+
32+
return False
33+
h.hookChapterChange(hook_4b) # Chapter change testing
34+
35+
test_scr = ml.getscreen("main_menu")
36+
if test_scr is None:
37+
raise AssertionError("Main_menu not found")
38+
39+
test_scr_ast = ml.getsls("main_menu")
40+
if test_scr is None:
41+
raise AssertionError("Main_menu ast not found")
42+
43+
say_test = ml.findSay("Do you have something similar where you come from?")
44+
if not isinstance(say_test, ast.Say):
45+
raise AssertionError("findSay failure.")
46+
47+
test_menu = ml.findMenu(["Scream.", "Accept.", "Reject."])
48+
if len(test_menu) == 0:
49+
raise AssertionError("No menu")
50+
51+
test_menu_hook = ml.getMenuHook(test_menu[0])
52+
test_menu_hook.setConditional("Scream.", "False")
53+
test_menu_hook.deleteItem("Reject.")
54+
55+
test_menu_hook.addItem("Test", test_menu_hook.getOptionCode("Accept.")[0])
56+
57+
ml.call_hook(ml.findlabel("start"), ml.findlabel("tests_6"))
58+
59+
60+
ml.findByLineNumber(1, "AWSWMod")

devmods/tests/mod.py

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)