API
ModGame
The modding library.
This file contains all the functions needed to modify and extend AwSW. Please note that it contains minor spoilers
This file is free software under the MIT license.
-
class
modloader.modgame.
AWSWEndingHooks
(base_)[source] The ending hooks for the game
Get Chapter 5’s menu on who to go to the fireworks.
Get an instance of
AWSWMenuHooks
for use of making new choices on who to go to the festival with.Returns: An instance of AWSWMenuHooks
-
get_post_izumi_node
()[source] Get the post-true Izumi’s tear scene
Returns: A renpy.ast.Say
node object.
-
hook_post_evil_ending
(node)[source] Hook
node
to the post-evil ending nodeTodo
Program this.
-
hook_post_true_ending
(node)[source] Hook
node
to the post-true ending nodeReturns: An ASTHook
instance
-
hook_route_ending
(route)[source] Hook
node
to the end of all routesTodo
Program this.
-
class
modloader.modgame.
AWSWHomeHook
(base_)[source] Hook the menu found in the player’s apartment.
-
base
AWSWModBase – An instance of the mod base
-
addAnswerMachineCheckHook
(dest_node)[source] Check if the answering machine’s output.
Return true if the dialog should pop up and return false if it shouldn’t.
Parameters: dest_node – Can be either a renpy.ast.Node
or a function.TODO: Program this
-
addAnswerMachineScene
(dest_node)[source] Add a hook before the answering machine plays
Parameters: dest_node – Can be either a renpy.ast.Node
or a function. Called after the machine check returns true
-
add_route
(title, route_hook, condition='True')[source] Add a route to the chapter menu
The route will only appear if the condition evaluate to true.
Parameters:
-
hook_chapter_1
(hook)[source] Hook a node to the start of Chapter 1
Parameters: hook (Node) – The node to hook
-
hook_chapter_change
(hook)[source] Hook a change of the chapters
Parameters: hook – A renpy.ast.Node
object or function
-
-
class
modloader.modgame.
AWSWModBase
[source] The modding framework base.
This class contains all the base functions needed to edit the AST, screens, and screen language.
-
ending_hooks
AWSWEndingHooks – An instance of the
AWSWEndingHooks
.
-
home_hook
AWSWHomeHook – An instance of the
AWSWHOmeHook
-
get_ending_hooks
()[source] Get the ending hook class
Returns: An instance of AWSWEndingHooks
-
get_home_hook
()[source] Get the home hook class
Returns: The AWSWHomeHook
object
Get the equivalent
AWSWMenuHook
objectReturns: The equivalent AWSWMenuHook
object
-
search_peak_if
(node, type_, max_depth=200, skip=0)[source] Search recursively for a node type.
This enters if statement blocks in order to find your specified node type
Parameters: - node (Node) – The starting node
- type (Node) – A subclass, not an instance, of a
renpy.ast.Node
object - maxBeforeFailure (int) – How many nodes to iterate through before giving up
Returns: A
renpy.ast.Node
object or None if not found
-
ModAST
Get and modify nodes in the AST tree
This file is free software under the MIT license
-
class
modloader.modast.
ASTHook
(loc, hook_func_=None, from_op_=None)[source] - A custom
renpy.ast.Node
that acts as a hook between - other node objects.
Note
Don’t instantiate this class directly. Ren’Py uses an internal serial for the call stack and other uses. This class emulates that at the base class.
-
hook_func
A function that’s called when the node is executed. If the function returns a non-None value, the next node will be skipped.
-
from_op
The original node before hooking
-
old_next
The original next node before hooking was done
-
exec_continue
()[source] Continue
-
execute
()[source] Execute hook after node is called
-
unhook
()[source] Remove the hook
- A custom
-
class
modloader.modast.
MenuHook
(menu_, base_)[source] A hook class for editing a specific menu
-
add_item
(label, hook, condition='True')[source] Add a new choice to the menu
Parameters: Returns: None if
hook
is arenpy.ast.Node
or aASTHook
ifhook
is a function
-
delete_item
(label)[source] Delete a choice from the menu
Parameters: label (str) – The label to search for
-
get_item
(label)[source] Get a choice from the menu
Parameters: label (str) – The label to search for Returns: A three-element tuple where the format is (label, condition, block). Label is the visible label given to the user, condition is a Python statement that determines whether or not to show the choice, and block is SL code
-
get_items
()[source] Get all the items in the menu
Returns: A list of three-element tuples where the format is (label, condition, block), where label is the visible label given to the user, condition is a Python statement that determines whether or not to show the choice, and block is SL code
-
get_option_code
(label)[source] Get a choice’s SL code from the menu
Parameters: choice (str) – The choice to get
-
set_conditional
(item, new_cond)[source] Change the conditional statement for
item
Returns: True if successful and False if not
-
set_item
(item, new_block)[source] Change the statement for
item
Returns: True if successful and False if not
-
Add a dialog option to a given menu
Parameters: - menu (Menu) – The menu to modify
- option (str) – The option’s text
- node (Node) – The node to execute if the node is selected
-
modloader.modast.
call_hook
(node, dest_node, func=None, return_node=None)[source] - Hook
func
tonode
and once executed, redirect execution to dest_node
Parameters: - node (Node) – The node to hook
- dest_node (Node) – the node to go after
node
is executed - func (function) – The function to call
Returns: An
ASTHook
object- Hook
-
modloader.modast.
disable_bytecode_cache
()[source] Disable bytecode cache
-
modloader.modast.
disable_slast_cache
()[source] Disable SLAst’s load cache
-
modloader.modast.
find_all_hide
(hide_name)[source] Find a list of
renpy.ast.Hide
nodes based on a stringThis searches the entire AST tree for the all the instances of the specified statement.
Parameters: hide_name (str) – The string to search in Hide nodes Returns: A list of renpy.ast.Node
nodes
-
modloader.modast.
find_all_show
(show_name)[source] Find a list of
renpy.ast.Show
nodes based on a stringThis searches the entire AST tree for the all the instances of the specified statement.
Parameters: show_name (str) – The string to search in Show nodes Returns: A list of renpy.ast.Node
nodes
-
modloader.modast.
find_in_source_code
(line_number, file_name)[source] Find a node by line number and file name
Note
Line numbers and file names can change between versions. Use the function as a last resort only.
Parameters: Returns: The node or None if it doesn’t meet the criteria provided
-
modloader.modast.
find_jump_target
(target_label, one=True)[source] Find a jump node (all if one is False) which is bound to the target_label
Parameters: target_label (str) – The target label’s name Returns: Union[Node, List[Node]]
-
modloader.modast.
find_label
(label)[source] Find a label based off of its name
Parameters: label (str) – The label’s name Returns: A renpy.ast.Label
object
Find menus based off a single menu choice
This searches the entire AST tree to find the menu choice.
Parameters: needle – The menu choice to look for. If needle is a string, search for the string. If needle is a list of strings, the program automatically enters multisearch mode Returns: A list of matching menus
-
modloader.modast.
find_python_statement
(statement, all=False)[source] Find a specific Python node in the entire AST
Parameters: Returns: The Python node if found, None if not Or a list of nodes which satisfy the conditions
-
modloader.modast.
find_say
(needle)[source] Find a
renpy.ast.Say
node based on what is saidThis searches the entire AST tree for the specified statement.
Parameters: needle (str) – The statement to search for Returns: A renpy.ast.Node
node
-
modloader.modast.
get_node_after_nodes
(node, location)[source] Get the
location``th node after ``node
Note
This skips
ASTHook
nodesParameters: - node (Node) – The starting search node
- location (int) – The number of nodes to skip
Returns: A
renpy.ast.Node
object
-
modloader.modast.
get_renpy_global
(key)[source] Get a Ren’Py global
Parameters: key (str) – The dictionary key Returns: The value put into the key or None if it doesn’t exist
-
modloader.modast.
get_screen
(scr, nodes=None)[source] Get a screen based off of its name
Parameters: Returns: A
renpy.display.screen.Screen
object
-
modloader.modast.
get_slscreen
(scr, nodes=None)[source] Get a screen’s executable based off of its name
Parameters: Returns: A
renpy.display.screen.Screen
object
-
modloader.modast.
hook_label
(label, func)[source] Hook a function to a label
Parameters: - label (renpy.ast.Label) – The label
- func (function) – The function to be hooked
Returns: An
ASTHook
object
-
modloader.modast.
hook_opcode
(node, func)[source] Hook
func
tonode
Parameters: - node (Node) – The node object for the function to hook
- func (function) – The function to be executed when the node is executed
Todo
Check if a hook already exists and make the code more cohesive
Returns: An ASTHook
object
-
modloader.modast.
jump_ret
(node, dest_node, return_node, func=None)[source] - Hook
func
tonode
and once executed, redirect execution to dest_node
and allowreturn_node
to be executed afterdest_node
returns
Parameters: - node (Node) – The node to hook
- dest_node (Node) – The node to go after
node
is executed - return_node (Node) – The node that is executed after
dest_node
returns - func (function) – The function hook
Returns: An
ASTHook
object- Hook
-
modloader.modast.
remove_slif
(scr, comparison)[source] Remove a block (equivalent to a Node) from a
renpy.sl2.slast.SLIf
objectParameters: - scr (SLScreen) – The SLScreen node to start the search
- comparison (str) – The comparison string for the expression
Returns: True if removed, False if not
-
modloader.modast.
search_for_node_type
(node, type_, max_depth=200)[source] Search for a specific type of node
Parameters: - node (Node) – The node to start the search
- type (class) – The node class, not an instance of the class, to search for
- max_depth (int) – The number of nodes to search before giving up Defaults to 200. The higher the number, the slower the process
Returns: A
renpy.ast.Node
object if a match occurs or None if no match occurs
-
modloader.modast.
search_for_node_with_criteria
(node, func, max_depth=200)[source] Search for a node and check with
func
If
func
returns a truthy value, return the node. Else, skip itParameters: - node (Node) – The node to start the search
- func (function) – Function to check for the given node. Given one argument,
node (of type
renpy.ast.Node
), which is the node that is at the current depth. Do not make the functions complex or it will slow down the game significantly. - max_depth (int) – The number of nodes to search before giving up Defaults to 200. The higher the number, the slower the process
Returns: A
renpy.ast.Node
object if a match occurs or None if no match occurs
-
modloader.modast.
set_renpy_global
(key, val)[source] Set a Ren’Py glboal
Ren’Py globals can be used during execution of rpy.
Parameters:
ModClass
This file is free software under the MIT license
-
class
modloader.modclass.
Mod
[source] The Mod class
This is supposed to act like a superclass for mods. Execution order is as follows:
mod_load()
->mod_complete()
-
mod_complete
()[source] Executes when all mods are loaded
This method is useful for dependency loading but can be left empty otherwise
-
mod_info
()[source] Get the mod info
Returns: A tuple with the name, version, author, and (optionally) if the mod is NSFW
-
mod_load
()[source] Executes when the mod is loaded
This is where you put patcher code.
See also
-